From cac15cf95c1d6520acb67d89a399242af580266d Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Mon, 20 Sep 2021 06:05:39 +1000 Subject: [PATCH] [v2] Print template support link. Update base templates --- .../commands/initialise/initialise.go | 4 ++- .../initialise/templates/templates.go | 29 +++++++++---------- .../templates/templates/vanilla/template.json | 2 +- .../initialise/templates/templates_test.go | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/v2/cmd/wails/internal/commands/initialise/initialise.go b/v2/cmd/wails/internal/commands/initialise/initialise.go index e0a86ceb..abb42eda 100644 --- a/v2/cmd/wails/internal/commands/initialise/initialise.go +++ b/v2/cmd/wails/internal/commands/initialise/initialise.go @@ -109,7 +109,7 @@ func initProject(options *templates.Options) error { start := time.Now() // Install the template - remote, err := templates.Install(options) + remote, template, err := templates.Install(options) if err != nil { return err } @@ -133,6 +133,8 @@ func initProject(options *templates.Options) error { options.Logger.Println("Project Name: " + options.ProjectName) options.Logger.Println("Project Directory: " + options.TargetDir) options.Logger.Println("Project Template: " + options.TemplateName) + options.Logger.Println("Template Support: " + template.HelpURL) + if options.GenerateVSCode { options.Logger.Println("VSCode config files generated.") } diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates.go b/v2/cmd/wails/internal/commands/initialise/templates/templates.go index 02beedab..59174268 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates.go @@ -4,6 +4,7 @@ import ( "embed" "encoding/json" "fmt" + "github.com/go-git/go-git/v5" gofs "io/fs" "io/ioutil" "log" @@ -12,8 +13,6 @@ import ( "runtime" "strings" - "github.com/go-git/go-git/v5" - "github.com/pkg/errors" "github.com/leaanthony/debme" @@ -161,11 +160,11 @@ func loadTemplateCache() error { } // Install the given template. Returns true if the template is remote. -func Install(options *Options) (bool, error) { +func Install(options *Options) (bool, *Template, error) { // Get cwd cwd, err := os.Getwd() if err != nil { - return false, err + return false, nil, err } // Did the user want to install in current directory? @@ -174,7 +173,7 @@ func Install(options *Options) (bool, error) { // If the current directory is empty, use it isEmpty, err := fs.DirIsEmpty(cwd) if err != nil { - return false, err + return false, nil, err } if isEmpty { @@ -183,7 +182,7 @@ func Install(options *Options) (bool, error) { } else { options.TargetDir = filepath.Join(cwd, options.ProjectName) if fs.DirExists(options.TargetDir) { - return false, fmt.Errorf("cannot create project directory. Dir exists: %s", options.TargetDir) + return false, nil, fmt.Errorf("cannot create project directory. Dir exists: %s", options.TargetDir) } } @@ -191,13 +190,13 @@ func Install(options *Options) (bool, error) { // Get the absolute path of the given directory targetDir, err := filepath.Abs(filepath.Join(cwd, options.TargetDir)) if err != nil { - return false, err + return false, nil, err } options.TargetDir = targetDir if !fs.DirExists(options.TargetDir) { err := fs.Mkdir(options.TargetDir) if err != nil { - return false, err + return false, nil, err } } } @@ -214,7 +213,7 @@ func Install(options *Options) (bool, error) { templateFS := os.DirFS(templatePath) template, err = parseTemplate(templateFS) if err != nil { - return false, errors.Wrap(err, "Error installing template") + return false, nil, errors.Wrap(err, "Error installing template") } } else { // git clone to temporary dir @@ -226,18 +225,18 @@ func Install(options *Options) (bool, error) { } }(tempdir) if err != nil { - return false, err + return false, nil, err } // Remove the .git directory err = os.RemoveAll(filepath.Join(tempdir, ".git")) if err != nil { - return false, err + return false, nil, err } templateFS := os.DirFS(tempdir) template, err = parseTemplate(templateFS) if err != nil { - return false, err + return false, nil, err } remoteTemplate = true } @@ -275,15 +274,15 @@ func Install(options *Options) (bool, error) { // Extract the template err = installer.Extract(options.TargetDir, templateData) if err != nil { - return false, err + return false, nil, err } err = generateIDEFiles(options) if err != nil { - return false, err + return false, nil, err } - return remoteTemplate, nil + return remoteTemplate, &template, nil } // Clones the given uri and returns the temporary cloned directory diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/template.json b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/template.json index 734c87a6..66a1d3ed 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/template.json +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates/vanilla/template.json @@ -3,5 +3,5 @@ "shortname": "vanilla", "author": "Lea Anthony", "description": "A simple template using only HTML/CSS/JS", - "helpurl": "https://wails.app/help/templates/vanilla" + "helpurl": "https://github.com/wailsapp/wails" } \ No newline at end of file diff --git a/v2/cmd/wails/internal/commands/initialise/templates/templates_test.go b/v2/cmd/wails/internal/commands/initialise/templates/templates_test.go index 02a191f3..dcff8d6e 100644 --- a/v2/cmd/wails/internal/commands/initialise/templates/templates_test.go +++ b/v2/cmd/wails/internal/commands/initialise/templates/templates_test.go @@ -41,6 +41,6 @@ func TestInstall(t *testing.T) { AuthorEmail: "lea.anthony@gmail.com", } - err := Install(options) + _, _, err := Install(options) is2.NoErr(err) }