mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 18:19:36 +08:00
Fix taskfile in templates. Sanitize the project name
This commit is contained in:
parent
eefeadc018
commit
ae38d1e020
@ -3,6 +3,7 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v3/internal/flags"
|
"github.com/wailsapp/wails/v3/internal/flags"
|
||||||
"github.com/wailsapp/wails/v3/internal/templates"
|
"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")
|
return fmt.Errorf("please use the -n flag to specify a project name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.ProjectName = sanitizeFileName(options.ProjectName)
|
||||||
|
|
||||||
if !templates.ValidTemplateName(options.TemplateName) {
|
if !templates.ValidTemplateName(options.TemplateName) {
|
||||||
return fmt.Errorf("invalid template name: %s. Use -l flag to list valid templates", 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()
|
pterm.Println()
|
||||||
return err
|
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, "_")
|
||||||
|
}
|
||||||
|
@ -6,131 +6,131 @@ vars:
|
|||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
pre-build:
|
pre-build:
|
||||||
summary: Pre-build hooks
|
summary: Pre-build hooks
|
||||||
|
|
||||||
post-build:
|
post-build:
|
||||||
summary: Post-build hooks
|
summary: Post-build hooks
|
||||||
|
|
||||||
install-frontend-deps:
|
install-frontend-deps:
|
||||||
summary: Install frontend dependencies
|
summary: Install frontend dependencies
|
||||||
dir: frontend
|
dir: frontend
|
||||||
sources:
|
sources:
|
||||||
- package.json
|
- package.json
|
||||||
- package-lock.json
|
- package-lock.json
|
||||||
generates:
|
generates:
|
||||||
- node_modules/*
|
- node_modules/*
|
||||||
preconditions:
|
preconditions:
|
||||||
- sh: npm version
|
- sh: npm version
|
||||||
msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/"
|
msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/"
|
||||||
cmds:
|
cmds:
|
||||||
- npm install
|
- npm install
|
||||||
|
|
||||||
build-frontend:
|
build-frontend:
|
||||||
summary: Build the frontend project
|
summary: Build the frontend project
|
||||||
dir: frontend
|
dir: frontend
|
||||||
deps:
|
deps:
|
||||||
- install-frontend-deps
|
- install-frontend-deps
|
||||||
cmds:
|
cmds:
|
||||||
- npm run build
|
- npm run build
|
||||||
|
|
||||||
build:darwin:
|
build:darwin:
|
||||||
summary: Builds the application
|
summary: Builds the application
|
||||||
platforms:
|
platforms:
|
||||||
- darwin
|
- darwin
|
||||||
cmds:
|
cmds:
|
||||||
- task: pre-build
|
- task: pre-build
|
||||||
- task: build-frontend
|
- task: build-frontend
|
||||||
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}
|
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}
|
||||||
- task: post-build
|
- task: post-build
|
||||||
env:
|
env:
|
||||||
CGO_CFLAGS: "-mmacosx-version-min=10.13"
|
CGO_CFLAGS: "-mmacosx-version-min=10.13"
|
||||||
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
|
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
|
||||||
MACOSX_DEPLOYMENT_TARGET: "10.13"
|
MACOSX_DEPLOYMENT_TARGET: "10.13"
|
||||||
|
|
||||||
build:linux:
|
build:linux:
|
||||||
summary: Builds the application for Linux
|
summary: Builds the application for Linux
|
||||||
platforms:
|
platforms:
|
||||||
- linux
|
- linux
|
||||||
cmds:
|
cmds:
|
||||||
- task: pre-build
|
- task: pre-build
|
||||||
- task: build-frontend
|
- task: build-frontend
|
||||||
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}
|
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}
|
||||||
- task: post-build
|
- task: post-build
|
||||||
|
|
||||||
build:windows:
|
build:windows:
|
||||||
summary: Builds the application for Windows
|
summary: Builds the application for Windows
|
||||||
platforms:
|
platforms:
|
||||||
- windows
|
- windows
|
||||||
cmds:
|
cmds:
|
||||||
- task: pre-build
|
- task: pre-build
|
||||||
- task: build-frontend
|
- task: build-frontend
|
||||||
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}.exe
|
- go build -gcflags=all="-N -l" -o bin/{{.ProjectName}}.exe
|
||||||
- task: post-build
|
- task: post-build
|
||||||
|
|
||||||
build:
|
build:
|
||||||
summary: Builds the application
|
summary: Builds the application
|
||||||
cmds:
|
cmds:
|
||||||
- task: build:darwin
|
- task: build:darwin
|
||||||
- task: build:linux
|
- task: build:linux
|
||||||
- task: build:windows
|
- task: build:windows
|
||||||
|
|
||||||
generate-icons:
|
generate-icons:
|
||||||
summary: Generates Windows `.ico` and Mac `.icns` files from an image
|
summary: Generates Windows `.ico` and Mac `.icns` files from an image
|
||||||
dir: build
|
dir: build
|
||||||
cmds:
|
cmds:
|
||||||
# Generates both .ico and .icns files
|
# Generates both .ico and .icns files
|
||||||
- wails generate icons -input appicon.png
|
- wails generate icons -input appicon.png
|
||||||
|
|
||||||
build-app-prod-darwin:
|
build-app-prod-darwin:
|
||||||
summary: Creates a production build of the application
|
summary: Creates a production build of the application
|
||||||
cmds:
|
cmds:
|
||||||
- task: pre-build
|
- task: pre-build
|
||||||
- task: build-frontend
|
- 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 build/bin/{{ "{{.APP_NAME}}" }}
|
||||||
- task: post-build
|
- task: post-build
|
||||||
env:
|
env:
|
||||||
CGO_CFLAGS: "-mmacosx-version-min=10.13"
|
CGO_CFLAGS: "-mmacosx-version-min=10.13"
|
||||||
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
|
CGO_LDFLAGS: "-mmacosx-version-min=10.13"
|
||||||
MACOSX_DEPLOYMENT_TARGET: "10.13"
|
MACOSX_DEPLOYMENT_TARGET: "10.13"
|
||||||
vars:
|
vars:
|
||||||
ARCH: $GOARCH
|
ARCH: $GOARCH
|
||||||
|
|
||||||
|
|
||||||
create-app-bundle:
|
create-app-bundle:
|
||||||
summary: Builds a `.app` bundle
|
summary: Builds a `.app` bundle
|
||||||
cmds:
|
cmds:
|
||||||
- mkdir -p {{ "{{.APP_NAME}}" }}.app/Contents/{MacOS,Resources}
|
- mkdir -p {{ "{{.APP_NAME}}" }}.app/Contents/{MacOS,Resources}
|
||||||
- cp build/icons.icns {{ "{{.APP_NAME}}" }}.app/Contents/Resources
|
- cp build/icons.icns {{ "{{.APP_NAME}}" }}.app/Contents/Resources
|
||||||
- cp build/bin/{{ "{{.APP_NAME}}" }} {{ "{{.APP_NAME}}" }}.app/Contents/MacOS
|
- cp build/bin/{{ "{{.APP_NAME}}" }} {{ "{{.APP_NAME}}" }}.app/Contents/MacOS
|
||||||
- cp build/Info.plist {{ "{{.APP_NAME}}" }}.app/Contents
|
- cp build/Info.plist {{ "{{.APP_NAME}}" }}.app/Contents
|
||||||
|
|
||||||
package-darwin-arm64:
|
package-darwin-arm64:
|
||||||
summary: Packages a production build of the application into a `.app` bundle
|
summary: Packages a production build of the application into a `.app` bundle
|
||||||
platform: darwin
|
platform: darwin
|
||||||
deps:
|
deps:
|
||||||
- task: build-app-prod-darwin
|
- task: build-app-prod-darwin
|
||||||
vars:
|
vars:
|
||||||
ARCH: arm64
|
ARCH: arm64
|
||||||
- generate-icons
|
- generate-icons
|
||||||
cmds:
|
cmds:
|
||||||
- task: create-app-bundle
|
- task: create-app-bundle
|
||||||
|
|
||||||
generate:syso:
|
generate:syso:
|
||||||
dir: build
|
dir: build
|
||||||
platform: windows
|
platform: windows
|
||||||
cmds:
|
cmds:
|
||||||
- wails generate syso -arch {{ "{{.ARCH}}" }} -icon icon.ico -manifest wails.exe.manifest -info info.json -out ../wails.syso
|
- wails generate syso -arch {{ "{{.ARCH}}" }} -icon icon.ico -manifest wails.exe.manifest -info info.json -out ../wails.syso
|
||||||
vars:
|
vars:
|
||||||
ARCH: $GOARCH
|
ARCH: $GOARCH
|
||||||
|
|
||||||
package:windows:
|
package:windows:
|
||||||
summary: Packages a production build of the application into a `.exe` bundle
|
summary: Packages a production build of the application into a `.exe` bundle
|
||||||
platform: windows
|
platform: windows
|
||||||
deps:
|
deps:
|
||||||
- generate-icons
|
- generate-icons
|
||||||
cmds:
|
cmds:
|
||||||
- task: generate:syso
|
- task: generate:syso
|
||||||
vars:
|
vars:
|
||||||
ARCH: amd64
|
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 bin/{{ "{{.APP_NAME}}" }}.exe
|
||||||
- powershell Remove-item wails.syso
|
- powershell Remove-item wails.syso
|
||||||
|
Loading…
Reference in New Issue
Block a user