add mkdir

This commit is contained in:
Star 2024-12-13 19:29:31 +08:00
parent 2f705435c1
commit c6bf664b50
3 changed files with 15 additions and 6 deletions

View File

@ -21,6 +21,13 @@ func init() {
args := gojs.MakeArgs(&argsIn, vm).Check(1)
return vm.ToValue(u.FileExists(args.Path(0)))
},
"mkdir": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args := gojs.MakeArgs(&argsIn, vm).Check(1)
if err := os.MkdirAll(args.Path(0), 0755); err != nil {
panic(vm.NewGoError(err))
}
return nil
},
"read": func(argsIn goja.FunctionCall, vm *goja.Runtime) goja.Value {
args := gojs.MakeArgs(&argsIn, vm).Check(1)
if r, err := u.ReadFile(args.Path(0)); err == nil {

View File

@ -2,6 +2,7 @@
export default {
exists,
mkdir,
read,
readBytes,
write,
@ -15,6 +16,7 @@ export default {
}
function exists(filename: string): boolean { return false }
function mkdir(filename: string): void { }
function read(filename: string): string { return '' }
function readBytes(filename: string): any { return null }
function write(filename: string, data: any): void { }

12
go.mod
View File

@ -3,20 +3,20 @@ module apigo.cc/gojs/file
go 1.18
require (
apigo.cc/gojs v0.0.4
github.com/ssgo/u v1.7.9
apigo.cc/gojs v0.0.8
github.com/ssgo/u v1.7.13
)
require (
github.com/dlclark/regexp2 v1.11.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/ssgo/config v1.7.7 // indirect
github.com/ssgo/config v1.7.9 // indirect
github.com/ssgo/log v1.7.7 // indirect
github.com/ssgo/standard v1.7.7 // indirect
github.com/ssgo/tool v0.4.27 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)