5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-05 17:31:37 +08:00
wails/v3/internal/commands/init.go
Travis McLane b8d780ba4a
Feature/template consolidation (#3046)
* remove 'test' project

* dynamic template list generation

- uses a single fs.Embed to contain all templates
- walks and rebuilds the list of TemplateData using the cached data
- pulls the `description` out of the required `template.json` file in
  the template directory

* [v3] template handling update

- move "common" template files to a _common directory
- update generator to render from _common/* first
- render selected template last to overwrite anything provided by
  _common if needed
- remove duplicate files from all templates that do not change

* cleanup template project directory after test

* add linux to _common/Taskfile.yaml

* noop: whitespace cleanup _common/Taskfile.yaml
2023-11-11 12:26:28 +11:00

57 lines
1.3 KiB
Go

package commands
import (
"fmt"
"path/filepath"
"github.com/wailsapp/wails/v3/internal/flags"
"github.com/wailsapp/wails/v3/internal/templates"
"github.com/pterm/pterm"
)
func Init(options *flags.Init) error {
if options.List {
return printTemplates()
}
if options.Quiet {
pterm.DisableOutput()
}
if options.ProjectName == "" {
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 list valid templates", options.TemplateName)
}
err := templates.Install(options)
if err != nil {
return err
}
// Generate build assets
buildAssetsOptions := &BuildAssetsOptions{
Name: options.ProjectName,
Dir: filepath.Join(options.ProjectDir, "build"),
Silent: true,
}
return GenerateBuildAssets(buildAssetsOptions)
}
func printTemplates() error {
defaultTemplates := templates.GetDefaultTemplates()
pterm.DefaultSection.Println("Available templates")
table := pterm.TableData{{"Name", "Description"}}
for _, template := range defaultTemplates {
table = append(table, []string{template.Name, template.Description})
}
err := pterm.DefaultTable.WithHasHeader(true).WithBoxed(true).WithData(table).Render()
pterm.Println()
return err
}