From 39af86e59d656f04dfdf4e4240699b04fd4e9e76 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Wed, 9 Aug 2023 21:30:06 +1000 Subject: [PATCH] Improve project creation. Add `template.json` to templates. Update dependencies. --- v3/examples/binding/go.mod | 6 +- v3/examples/binding/go.sum | 3 + v3/examples/frameless/go.mod | 2 +- v3/examples/frameless/go.sum | 1 + v3/examples/plugins/go.mod | 12 +- v3/examples/plugins/go.sum | 7 + v3/internal/commands/init.go | 4 +- v3/internal/templates/lit-ts/template.json | 8 ++ v3/internal/templates/lit/template.json | 8 ++ v3/internal/templates/preact-ts/template.json | 8 ++ v3/internal/templates/preact/template.json | 8 ++ .../templates/react-swc-ts/template.json | 8 ++ v3/internal/templates/react-swc/template.json | 8 ++ v3/internal/templates/react-ts/template.json | 8 ++ v3/internal/templates/react/template.json | 8 ++ v3/internal/templates/svelte-ts/template.json | 8 ++ v3/internal/templates/svelte/template.json | 8 ++ v3/internal/templates/templates.go | 135 ++++++++++++++++-- .../templates/vanilla-ts/template.json | 7 + v3/internal/templates/vanilla/template.json | 8 ++ v3/internal/templates/vue-ts/template.json | 7 + v3/internal/templates/vue/template.json | 7 + 22 files changed, 259 insertions(+), 20 deletions(-) create mode 100644 v3/internal/templates/lit-ts/template.json create mode 100644 v3/internal/templates/lit/template.json create mode 100644 v3/internal/templates/preact-ts/template.json create mode 100644 v3/internal/templates/preact/template.json create mode 100644 v3/internal/templates/react-swc-ts/template.json create mode 100644 v3/internal/templates/react-swc/template.json create mode 100644 v3/internal/templates/react-ts/template.json create mode 100644 v3/internal/templates/react/template.json create mode 100644 v3/internal/templates/svelte-ts/template.json create mode 100644 v3/internal/templates/svelte/template.json create mode 100644 v3/internal/templates/vanilla-ts/template.json create mode 100644 v3/internal/templates/vanilla/template.json create mode 100644 v3/internal/templates/vue-ts/template.json create mode 100644 v3/internal/templates/vue/template.json diff --git a/v3/examples/binding/go.mod b/v3/examples/binding/go.mod index f46983cc9..7fe99e7db 100644 --- a/v3/examples/binding/go.mod +++ b/v3/examples/binding/go.mod @@ -15,12 +15,12 @@ require ( github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/samber/lo v1.37.0 // indirect - github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b // indirect + github.com/wailsapp/go-webview2 v1.0.2 // indirect github.com/wailsapp/mimetype v1.4.1 // indirect github.com/wailsapp/wails/v2 v2.5.1 // indirect - golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 // indirect + golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.8.0 // indirect + golang.org/x/sys v0.9.0 // indirect ) replace github.com/wailsapp/wails/v3 => ../.. diff --git a/v3/examples/binding/go.sum b/v3/examples/binding/go.sum index b95eaf8ed..e0ecae68e 100644 --- a/v3/examples/binding/go.sum +++ b/v3/examples/binding/go.sum @@ -30,10 +30,12 @@ github.com/tmclane/purego v0.0.0-20230601213035-1f25e70d7b01 h1:oQwu3iNDywGp1Hry github.com/tmclane/purego v0.0.0-20230601213035-1f25e70d7b01/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ= github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b h1:cztK9x+ikg6nFscy5c8NgtfIXv/d0ESdENy9+JkE8i4= github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.2/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 h1:RjggHMcaTVp0LOVZcW0bo8alwHrOaCrGUDgfWUHhnN4= golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= @@ -43,6 +45,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/v3/examples/frameless/go.mod b/v3/examples/frameless/go.mod index c12ee141c..fc7e373b9 100644 --- a/v3/examples/frameless/go.mod +++ b/v3/examples/frameless/go.mod @@ -15,7 +15,7 @@ require ( github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/samber/lo v1.37.0 // indirect - github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b // indirect + github.com/wailsapp/go-webview2 v1.0.2 // indirect github.com/wailsapp/mimetype v1.4.1 // indirect github.com/wailsapp/wails/v2 v2.5.1 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect diff --git a/v3/examples/frameless/go.sum b/v3/examples/frameless/go.sum index 88d82493d..fd1dbcc5d 100644 --- a/v3/examples/frameless/go.sum +++ b/v3/examples/frameless/go.sum @@ -30,6 +30,7 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b h1:cztK9x+ikg6nFscy5c8NgtfIXv/d0ESdENy9+JkE8i4= github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.2/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= diff --git a/v3/examples/plugins/go.mod b/v3/examples/plugins/go.mod index 70cdef8a7..6b15a58cc 100644 --- a/v3/examples/plugins/go.mod +++ b/v3/examples/plugins/go.mod @@ -14,21 +14,21 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/leaanthony/slicer v1.5.0 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pkg/browser v0.0.0-20210706143420-7d21f8c997e2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/samber/lo v1.37.0 // indirect - github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b // indirect + github.com/wailsapp/go-webview2 v1.0.2 // indirect github.com/wailsapp/mimetype v1.4.1 // indirect github.com/wailsapp/wails/v2 v2.5.1 // indirect - golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 // indirect - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect + golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect + golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/tools v0.1.12 // indirect + golang.org/x/sys v0.9.0 // indirect + golang.org/x/tools v0.2.0 // indirect lukechampine.com/uint128 v1.2.0 // indirect modernc.org/cc/v3 v3.40.0 // indirect modernc.org/ccgo/v3 v3.16.13 // indirect diff --git a/v3/examples/plugins/go.sum b/v3/examples/plugins/go.sum index 328514ede..d895b1e97 100644 --- a/v3/examples/plugins/go.sum +++ b/v3/examples/plugins/go.sum @@ -25,6 +25,7 @@ github.com/leaanthony/slicer v1.5.0/go.mod h1:FwrApmf8gOrpzEWM2J/9Lh79tyq8KTX5Az github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -46,12 +47,15 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b h1:cztK9x+ikg6nFscy5c8NgtfIXv/d0ESdENy9+JkE8i4= github.com/wailsapp/go-webview2 v1.0.2-0.20230604075323-d593c659ca7b/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= +github.com/wailsapp/go-webview2 v1.0.2/go.mod h1:Uk2BePfCRzttBBjFrBmqKGJd41P6QIHeV9kTgIeOZNo= github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs= github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o= golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9 h1:RjggHMcaTVp0LOVZcW0bo8alwHrOaCrGUDgfWUHhnN4= golang.org/x/exp v0.0.0-20220930202632-ec3f01382ef9/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= +golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= @@ -61,13 +65,16 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI= lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= diff --git a/v3/internal/commands/init.go b/v3/internal/commands/init.go index 651d4a008..5742caa49 100644 --- a/v3/internal/commands/init.go +++ b/v3/internal/commands/init.go @@ -21,8 +21,8 @@ func Init(options *flags.Init) error { return fmt.Errorf("please use the -n flag to specify a project name") } - if !templates.ValidTemplateName(options.TemplateName) { - return fmt.Errorf("invalid template name: %s. Use -l flag to view available templates", options.TemplateName) + if templates.ValidTemplateName(options.TemplateName) { + return templates.Install(options) } return templates.Install(options) diff --git a/v3/internal/templates/lit-ts/template.json b/v3/internal/templates/lit-ts/template.json new file mode 100644 index 000000000..f6aada621 --- /dev/null +++ b/v3/internal/templates/lit-ts/template.json @@ -0,0 +1,8 @@ +{ + "name": "Lit + Vite (Typescript)", + "shortname": "lit-ts", + "author": "Lea Anthony", + "description": "Lit + TS + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/lit/template.json b/v3/internal/templates/lit/template.json new file mode 100644 index 000000000..76557a94f --- /dev/null +++ b/v3/internal/templates/lit/template.json @@ -0,0 +1,8 @@ +{ + "name": "Lit + Vite", + "shortname": "lit", + "author": "Lea Anthony", + "description": "Lit + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/preact-ts/template.json b/v3/internal/templates/preact-ts/template.json new file mode 100644 index 000000000..bd4ccc20b --- /dev/null +++ b/v3/internal/templates/preact-ts/template.json @@ -0,0 +1,8 @@ +{ + "name": "Preact + Vite (Typescript)", + "shortname": "preact-ts", + "author": "Lea Anthony", + "description": "Preact + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/preact/template.json b/v3/internal/templates/preact/template.json new file mode 100644 index 000000000..bf14fc655 --- /dev/null +++ b/v3/internal/templates/preact/template.json @@ -0,0 +1,8 @@ +{ + "name": "Preact + Vite", + "shortname": "preact", + "author": "Lea Anthony", + "description": "Preact + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/react-swc-ts/template.json b/v3/internal/templates/react-swc-ts/template.json new file mode 100644 index 000000000..f708a5b5d --- /dev/null +++ b/v3/internal/templates/react-swc-ts/template.json @@ -0,0 +1,8 @@ +{ + "name": "React + SWC + Vite (Typescript)", + "shortname": "react-swc-ts", + "author": "Lea Anthony", + "description": "React + SWC + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/react-swc/template.json b/v3/internal/templates/react-swc/template.json new file mode 100644 index 000000000..0cf5958e3 --- /dev/null +++ b/v3/internal/templates/react-swc/template.json @@ -0,0 +1,8 @@ +{ + "name": "React + SWC + Vite", + "shortname": "react-swc", + "author": "Lea Anthony", + "description": "React + SWC + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/react-ts/template.json b/v3/internal/templates/react-ts/template.json new file mode 100644 index 000000000..4208f72be --- /dev/null +++ b/v3/internal/templates/react-ts/template.json @@ -0,0 +1,8 @@ +{ + "name": "React + Vite (Typescript)", + "shortname": "react-ts", + "author": "Lea Anthony", + "description": "React + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/react/template.json b/v3/internal/templates/react/template.json new file mode 100644 index 000000000..c84df2629 --- /dev/null +++ b/v3/internal/templates/react/template.json @@ -0,0 +1,8 @@ +{ + "name": "React + Vite", + "shortname": "react", + "author": "Lea Anthony", + "description": "React + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/svelte-ts/template.json b/v3/internal/templates/svelte-ts/template.json new file mode 100644 index 000000000..82fbc8cd9 --- /dev/null +++ b/v3/internal/templates/svelte-ts/template.json @@ -0,0 +1,8 @@ +{ + "name": "Svelte + Vite (Typescript)", + "shortname": "svelte-ts", + "author": "Lea Anthony", + "description": "Svelte + TS + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/svelte/template.json b/v3/internal/templates/svelte/template.json new file mode 100644 index 000000000..b4d6a7e69 --- /dev/null +++ b/v3/internal/templates/svelte/template.json @@ -0,0 +1,8 @@ +{ + "name": "Svelte + Vite", + "shortname": "svelte", + "author": "Lea Anthony", + "description": "Svelte + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/templates.go b/v3/internal/templates/templates.go index c3fae1bb6..d3880ce27 100644 --- a/v3/internal/templates/templates.go +++ b/v3/internal/templates/templates.go @@ -2,7 +2,9 @@ package templates import ( "embed" + "encoding/json" "fmt" + "github.com/pkg/errors" "github.com/pterm/pterm" "github.com/wailsapp/wails/v3/internal/debug" "io/fs" @@ -152,28 +154,145 @@ type TemplateOptions struct { LocalModulePath string } +func getInternalTemplate(templateName string) (*Template, error) { + templateData, found := lo.Find(defaultTemplates, func(template TemplateData) bool { + return template.Name == templateName + }) + + if !found { + return nil, nil + } + + template, err := parseTemplate(templateData.FS, templateData.Name) + if err != nil { + return nil, err + } + + return &template, nil +} + +func getLocalTemplate(templateName string) (*Template, error) { + var template Template + var err error + _, err = os.Stat(templateName) + if err != nil { + return nil, err + } + + template, err = parseTemplate(os.DirFS(templateName), templateName) + if err != nil { + return nil, err + } + + return &template, nil +} + +// Template holds data relating to a template including the metadata stored in template.yaml +type Template struct { + + // Template details + Name string `json:"name"` + ShortName string `json:"shortname"` + Author string `json:"author"` + Description string `json:"description"` + HelpURL string `json:"helpurl"` + Version int8 `json:"version"` + + // Other data + FS fs.FS `json:"-"` +} + +func parseTemplate(template fs.FS, templateName string) (Template, error) { + var result Template + data, err := fs.ReadFile(template, templateName+"/template.json") + if err != nil { + return result, errors.Wrap(err, "Error parsing template") + } + err = json.Unmarshal(data, &result) + if err != nil { + return result, err + } + result.FS = template + + // We need to do a version check here + if result.Version == 0 { + return result, fmt.Errorf("template not supported by wails 3. This template is probably for wails 2") + } + if result.Version != 3 { + return result, fmt.Errorf("template version %d is not supported by wails 3. Ensure 'version' is set to 3 in the `template.json` file", result.Version) + } + + return result, nil +} + func Install(options *flags.Init) error { templateData := TemplateOptions{ options, filepath.FromSlash(debug.LocalModulePath + "/"), } - template, found := lo.Find(defaultTemplates, func(template TemplateData) bool { - return template.Name == options.TemplateName - }) - if !found { - return fmt.Errorf("template '%s' not found", options.TemplateName) + + defer func() { + // if `template.json` exists, remove it + _ = os.Remove(filepath.Join(templateData.ProjectDir, "template.json")) + }() + + template, err := getInternalTemplate(options.TemplateName) + if err != nil { + return err + } + if template == nil { + template, err = getLocalTemplate(options.TemplateName) + } + if err != nil { + return err + } + //if templateFS == nil { + // templateFS = getRemoteTemplate(options.TemplateName) + //} + + if template == nil { + return fmt.Errorf("invalid template name: %s. Use -l flag to view available templates or use a valid filepath / url to a template", options.TemplateName) } if options.ProjectDir == "." || options.ProjectDir == "" { templateData.ProjectDir = lo.Must(os.Getwd()) } - templateData.ProjectDir = fmt.Sprintf("%s/%s", options.ProjectDir, options.ProjectName) - pterm.Printf("Installing template '%s' into '%s'\n", options.TemplateName, filepath.FromSlash(options.ProjectDir)) + templateData.ProjectDir = filepath.Join(options.ProjectDir, options.ProjectName) + + // If project directory already exists and is not empty, error + if _, err := os.Stat(templateData.ProjectDir); !os.IsNotExist(err) { + // Check if the directory is empty + files := lo.Must(os.ReadDir(templateData.ProjectDir)) + if len(files) > 0 { + return fmt.Errorf("project directory '%s' already exists and is not empty", templateData.ProjectDir) + } + } + + pterm.Printf("Creating project\n") + pterm.Printf("----------------\n\n") + table := pterm.TableData{ + {"Project Name", options.ProjectName}, + {"Project Directory", filepath.FromSlash(options.ProjectDir)}, + {"Template", template.Name}, + {"Template Source", template.HelpURL}, + } + err = pterm.DefaultTable.WithData(table).Render() + if err != nil { + return err + } tfs, err := fs.Sub(template.FS, options.TemplateName) if err != nil { return err } - return gosod.New(tfs).Extract(options.ProjectDir, templateData) + err = gosod.New(tfs).Extract(options.ProjectDir, templateData) + if err != nil { + return err + } + + pterm.Printf("\nProject '%s' created successfully.\n", options.ProjectName) + + return nil + } diff --git a/v3/internal/templates/vanilla-ts/template.json b/v3/internal/templates/vanilla-ts/template.json new file mode 100644 index 000000000..5aed52c89 --- /dev/null +++ b/v3/internal/templates/vanilla-ts/template.json @@ -0,0 +1,7 @@ +{ + "name": "Vanilla + Vite (Typescript)", + "shortname": "vanilla-ts", + "author": "Lea Anthony", + "description": "Vanilla + Vite development server", + "helpurl": "https://wails.io" +} \ No newline at end of file diff --git a/v3/internal/templates/vanilla/template.json b/v3/internal/templates/vanilla/template.json new file mode 100644 index 000000000..0c7f8ba82 --- /dev/null +++ b/v3/internal/templates/vanilla/template.json @@ -0,0 +1,8 @@ +{ + "name": "Vanilla + Vite", + "shortname": "vanilla", + "author": "Lea Anthony", + "description": "Vanilla + Vite development server", + "helpurl": "https://wails.io", + "version": 3 +} \ No newline at end of file diff --git a/v3/internal/templates/vue-ts/template.json b/v3/internal/templates/vue-ts/template.json new file mode 100644 index 000000000..6efc20293 --- /dev/null +++ b/v3/internal/templates/vue-ts/template.json @@ -0,0 +1,7 @@ +{ + "name": "Vue + Vite (Typescript)", + "shortname": "vue-ts", + "author": "Lea Anthony", + "description": "Vue + Vite development server", + "helpurl": "https://wails.io" +} \ No newline at end of file diff --git a/v3/internal/templates/vue/template.json b/v3/internal/templates/vue/template.json new file mode 100644 index 000000000..c2529e353 --- /dev/null +++ b/v3/internal/templates/vue/template.json @@ -0,0 +1,7 @@ +{ + "name": "Vue + Vite", + "shortname": "vue", + "author": "Lea Anthony", + "description": "Vue + Vite development server", + "helpurl": "https://wails.io" +} \ No newline at end of file