Better vanilla taskfile. Better asset generation at init.

This commit is contained in:
Lea Anthony 2023-09-09 17:31:48 +10:00
commit 0d8b4aafd5
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
7 changed files with 27 additions and 72 deletions

View file

@ -25,6 +25,7 @@ type BuildAssetsOptions struct {
ProductCopyright string `description:"The copyright notice"`
ProductComments string `description:"Comments to add to the generated files" default:"This is a comment"`
ProductIdentifier string `description:"The product identifier, e.g com.mycompany.myproduct"`
Silent bool `description:"Suppress output to console"`
}
func GenerateBuildAssets(options *BuildAssetsOptions) error {
@ -56,7 +57,9 @@ func GenerateBuildAssets(options *BuildAssetsOptions) error {
return err
}
println("Generating build assets in " + options.Dir)
if !options.Silent {
println("Generating build assets in " + options.Dir)
}
return gosod.New(tfs).Extract(options.Dir, options)
}

View file

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/wailsapp/wails/v3/internal/flags"
"github.com/wailsapp/wails/v3/internal/templates"
"path/filepath"
"github.com/pterm/pterm"
)
@ -21,11 +22,22 @@ 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 templates.Install(options)
if !templates.ValidTemplateName(options.TemplateName) {
return fmt.Errorf("invalid template name: %s. Use -l flag to list valid templates", options.TemplateName)
}
return templates.Install(options)
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 {

View file

@ -17,7 +17,7 @@ tasks:
generate:build-assets:
summary: Generates the build assets
cmds:
- wails3 generate build-assets -dir {{.BUILD_DIR}} -name "{{.APP_NAME}}" -productname "{{.PRODUCT_NAME}}" -productdescription "{{.PRODUCT_DESCRIPTION}}" -productversion "{{.PRODUCT_VERSION}}" -productcompany "{{.PRODUCT_COMPANY}}" -productcopyright "{{.PRODUCT_COPYRIGHT}}" -productcomments "{{.PRODUCT_COMMENTS}}" -productidentifier "{{.PRODUCT_IDENTIFIER}}"
- wails3 generate build-assets -dir "{{ "{{.BUILD_DIR}}" }}" -name "{{ "{{.APP_NAME}}" }}" -productname "{{ "{{.PRODUCT_NAME}}" }}" -productdescription "{{ "{{.PRODUCT_DESCRIPTION}}" }}" -productversion "{{ "{{.PRODUCT_VERSION}}" }}" -productcompany "{{ "{{.PRODUCT_COMPANY}}" }}" -productcopyright "{{ "{{.PRODUCT_COPYRIGHT}}" }}" -productcomments "{{ "{{.PRODUCT_COMMENTS}}" }}" -productidentifier "{{ "{{.PRODUCT_IDENTIFIER}}" }}"
pre-build:
summary: Pre-build hooks
@ -79,17 +79,16 @@ tasks:
generate-icons:
summary: Generates Windows `.ico` and Mac `.icns` files from an image
dir: build
cmds:
# Generates both .ico and .icns files
- wails generate icons -input appicon.png
- wails3 generate icons -input {{ "{{.BUILD_DIR}}" }}/appicon.png
build-app-prod-darwin:
summary: Creates a production build of the application
cmds:
- task: pre-build
- task: build-frontend
- GOOS=darwin GOARCH={{ "{{.ARCH}}" }} go build -tags production -ldflags="-w -s" -o build/bin/{{ "{{.APP_NAME}}" }}
- GOOS=darwin GOARCH={{ "{{.ARCH}}" }} go build -tags production -ldflags="-w -s" -o bin/{{ "{{.APP_NAME}}" }}
- task: post-build
env:
CGO_CFLAGS: "-mmacosx-version-min=10.13"
@ -103,9 +102,9 @@ tasks:
summary: Builds a `.app` bundle
cmds:
- mkdir -p {{ "{{.APP_NAME}}" }}.app/Contents/{MacOS,Resources}
- cp build/icons.icns {{ "{{.APP_NAME}}" }}.app/Contents/Resources
- cp build/bin/{{ "{{.APP_NAME}}" }} {{ "{{.APP_NAME}}" }}.app/Contents/MacOS
- cp build/Info.plist {{ "{{.APP_NAME}}" }}.app/Contents
- cp {{ "{{.BUILD_DIR}}" }}/icons.icns {{ "{{.APP_NAME}}" }}.app/Contents/Resources
- cp bin/{{ "{{.APP_NAME}}" }} {{ "{{.APP_NAME}}" }}.app/Contents/MacOS
- cp {{ "{{.BUILD_DIR}}" }}/Info.plist {{ "{{.APP_NAME}}" }}.app/Contents
package-darwin-arm64:
summary: Packages a production build of the application into a `.app` bundle
@ -122,7 +121,7 @@ tasks:
dir: build
platform: windows
cmds:
- wails generate syso -arch {{ "{{.ARCH}}" }} -icon icon.ico -manifest wails.exe.manifest -info info.json -out ../wails.syso
- wails3 generate syso -arch {{ "{{.ARCH}}" }} -icon {{ "{{.BUILD_DIR}}" }}/icon.ico -manifest {{ "{{.BUILD_DIR}}" }}/wails.exe.manifest -info {{ "{{.BUILD_DIR}}" }}/info.json -out ../wails.syso
vars:
ARCH: $GOARCH
@ -135,5 +134,5 @@ tasks:
- task: generate:syso
vars:
ARCH: amd64
- go build -tags production -ldflags="-w -s -H windowsgui" -o bin/{{ "{{.APP_NAME}}" }}.exe
- go build -tags production -ldflags="-w -s -H windowsgui" -o "{{ "{{.BUILD_DIR}}" }}"/bin/{{ "{{.APP_NAME}}" }}.exe
- powershell Remove-item wails.syso

View file

@ -1,32 +0,0 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>My Product Name</string>
<key>CFBundleExecutable</key>
<string>{{.ProjectName}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.ProjectName}}</string>
<key>CFBundleVersion</key>
<string>v1.0.0</string>
<key>CFBundleGetInfoString</key>
<string>This is a comment</string>
<key>CFBundleShortVersionString</key>
<string>v1.0.0</string>
<key>CFBundleIconFile</key>
<string>icons</string>
<key>LSMinimumSystemVersion</key>
<string>10.13.0</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>(c) 2023 My Company Name</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
</dict>
</plist>

View file

@ -1,27 +0,0 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>My Product Name</string>
<key>CFBundleExecutable</key>
<string>{{.ProjectName}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.ProjectName}}</string>
<key>CFBundleVersion</key>
<string>v1.0.0</string>
<key>CFBundleGetInfoString</key>
<string>This is a comment</string>
<key>CFBundleShortVersionString</key>
<string>v1.0.0</string>
<key>CFBundleIconFile</key>
<string>icons</string>
<key>LSMinimumSystemVersion</key>
<string>10.13.0</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>(c) 2023 My Company Name</string>
</dict>
</plist>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 130 KiB