5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 14:13:00 +08:00

Fix taskfile in templates. Sanitize the project name

This commit is contained in:
Lea Anthony 2023-11-12 16:35:44 +11:00
parent eefeadc018
commit ae38d1e020
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
2 changed files with 113 additions and 101 deletions

View File

@ -3,6 +3,7 @@ package commands
import (
"fmt"
"path/filepath"
"regexp"
"github.com/wailsapp/wails/v3/internal/flags"
"github.com/wailsapp/wails/v3/internal/templates"
@ -23,6 +24,8 @@ func Init(options *flags.Init) error {
return fmt.Errorf("please use the -n flag to specify a project name")
}
options.ProjectName = sanitizeFileName(options.ProjectName)
if !templates.ValidTemplateName(options.TemplateName) {
return fmt.Errorf("invalid template name: %s. Use -l flag to list valid templates", options.TemplateName)
}
@ -54,3 +57,12 @@ func printTemplates() error {
pterm.Println()
return err
}
func sanitizeFileName(fileName string) string {
// Regular expression to match non-allowed characters in file names
// You can adjust this based on the specific requirements of your file system
reg := regexp.MustCompile(`[^a-zA-Z0-9_.-]`)
// Replace matched characters with an underscore or any other safe character
return reg.ReplaceAllString(fileName, "_")
}

View File

@ -6,131 +6,131 @@ vars:
tasks:
pre-build:
summary: Pre-build hooks
summary: Pre-build hooks
post-build:
summary: Post-build hooks
summary: Post-build hooks
install-frontend-deps:
summary: Install frontend dependencies
dir: frontend
sources:
- package.json
- package-lock.json
generates:
- node_modules/*
preconditions:
- sh: npm version
msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/"
cmds:
- npm install
summary: Install frontend dependencies
dir: frontend
sources:
- package.json
- package-lock.json
generates:
- node_modules/*
preconditions:
- sh: npm version
msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/"
cmds:
- npm install
build-frontend:
summary: Build the frontend project
dir: frontend
deps:
- install-frontend-deps
cmds:
- npm run build
summary: Build the frontend project
dir: frontend
deps:
- install-frontend-deps
cmds:
- npm run build
build:darwin:
summary: Builds the application
platforms:
- darwin
cmds:
- task: pre-build
- task: build-frontend
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}
- task: post-build
env:
CGO_CFLAGS: "-mmacosx-version-min=10.13"
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
MACOSX_DEPLOYMENT_TARGET: "10.13"
summary: Builds the application
platforms:
- darwin
cmds:
- task: pre-build
- task: build-frontend
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}
- task: post-build
env:
CGO_CFLAGS: "-mmacosx-version-min=10.13"
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
MACOSX_DEPLOYMENT_TARGET: "10.13"
build:linux:
summary: Builds the application for Linux
platforms:
- linux
cmds:
- task: pre-build
- task: build-frontend
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}
- task: post-build
summary: Builds the application for Linux
platforms:
- linux
cmds:
- task: pre-build
- task: build-frontend
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}
- task: post-build
build:windows:
summary: Builds the application for Windows
platforms:
- windows
cmds:
- task: pre-build
- task: build-frontend
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}.exe
- task: post-build
summary: Builds the application for Windows
platforms:
- windows
cmds:
- task: pre-build
- task: build-frontend
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}.exe
- task: post-build
build:
summary: Builds the application
cmds:
- task: build:darwin
- task: build:linux
- task: build:windows
summary: Builds the application
cmds:
- task: build:darwin
- task: build:linux
- task: build:windows
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
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
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}}" }}
- task: post-build
env:
CGO_CFLAGS: "-mmacosx-version-min=10.13"
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
MACOSX_DEPLOYMENT_TARGET: "10.13"
vars:
ARCH: $GOARCH
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}}" }}
- task: post-build
env:
CGO_CFLAGS: "-mmacosx-version-min=10.13"
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
MACOSX_DEPLOYMENT_TARGET: "10.13"
vars:
ARCH: $GOARCH
create-app-bundle:
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
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
package-darwin-arm64:
summary: Packages a production build of the application into a `.app` bundle
platform: darwin
deps:
- task: build-app-prod-darwin
vars:
ARCH: arm64
- generate-icons
cmds:
- task: create-app-bundle
summary: Packages a production build of the application into a `.app` bundle
platform: darwin
deps:
- task: build-app-prod-darwin
vars:
ARCH: arm64
- generate-icons
cmds:
- task: create-app-bundle
generate:syso:
dir: build
platform: windows
cmds:
- wails generate syso -arch {{ "{{.ARCH}}" }} -icon icon.ico -manifest wails.exe.manifest -info info.json -out ../wails.syso
vars:
ARCH: $GOARCH
dir: build
platform: windows
cmds:
- wails generate syso -arch {{ "{{.ARCH}}" }} -icon icon.ico -manifest wails.exe.manifest -info info.json -out ../wails.syso
vars:
ARCH: $GOARCH
package:windows:
summary: Packages a production build of the application into a `.exe` bundle
platform: windows
deps:
- generate-icons
cmds:
- task: generate:syso
vars:
ARCH: amd64
- go build -tags production -ldflags="-w -s -H windowsgui" -o bin/{{ "{{.APP_NAME}}" }}.exe
- powershell Remove-item wails.syso
summary: Packages a production build of the application into a `.exe` bundle
platform: windows
deps:
- generate-icons
cmds:
- task: generate:syso
vars:
ARCH: amd64
- go build -tags production -ldflags="-w -s -H windowsgui" -o bin/{{ "{{.APP_NAME}}" }}.exe
- powershell Remove-item wails.syso