5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-03 06:01:52 +08:00

[windows-x] Add wailsjs directory flag

This commit is contained in:
Lea Anthony 2021-08-26 23:25:29 +10:00
parent a7c04ac891
commit f20ce7411d
3 changed files with 34 additions and 7 deletions

View File

@ -83,6 +83,9 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
noreload := false noreload := false
command.BoolFlag("noreload", "Disable reload on asset change", &noreload) command.BoolFlag("noreload", "Disable reload on asset change", &noreload)
wailsjsdir := ""
command.StringFlag("wailsjsdir", "Directory to generate api module", &wailsjsdir)
// Verbosity // Verbosity
verbosity := 1 verbosity := 1
command.IntFlag("v", "Verbosity level (0 - silent, 1 - default, 2 - verbose)", &verbosity) command.IntFlag("v", "Verbosity level (0 - silent, 1 - default, 2 - verbose)", &verbosity)
@ -126,6 +129,27 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
assetDir = projectConfig.AssetDirectory assetDir = projectConfig.AssetDirectory
} }
wailsjsdir, err = filepath.Abs(wailsjsdir)
if err != nil {
return err
}
if wailsjsdir == "" && projectConfig.WailsJSDir != "" {
wailsjsdir = projectConfig.WailsJSDir
}
if wailsjsdir == "" {
wailsjsdir = filepath.Join(cwd, "frontend")
}
if wailsjsdir != projectConfig.WailsJSDir {
projectConfig.WailsJSDir = wailsjsdir
err := projectConfig.Save()
if err != nil {
return err
}
}
watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
return err return err
@ -152,7 +176,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
// Do initial build // Do initial build
logger.Println("Building application for development...") logger.Println("Building application for development...")
newProcess, appBinary, err := restartApp(logger, ldflags, compilerCommand, debugBinaryProcess, loglevel, passthruArgs, verbosity, assetDir, true, exitCodeChannel) newProcess, appBinary, err := restartApp(logger, ldflags, compilerCommand, debugBinaryProcess, loglevel, passthruArgs, verbosity, assetDir, true, exitCodeChannel, wailsjsdir)
if err != nil { if err != nil {
return err return err
} }
@ -259,7 +283,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
rebuild = false rebuild = false
LogGreen("[Rebuild triggered] files updated") LogGreen("[Rebuild triggered] files updated")
// Try and build the app // Try and build the app
newBinaryProcess, _, err = restartApp(logger, ldflags, compilerCommand, debugBinaryProcess, loglevel, passthruArgs, verbosity, assetDir, false, exitCodeChannel) newBinaryProcess, _, err = restartApp(logger, ldflags, compilerCommand, debugBinaryProcess, loglevel, passthruArgs, verbosity, assetDir, false, exitCodeChannel, wailsjsdir)
if err != nil { if err != nil {
LogRed("Error during build: %s", err.Error()) LogRed("Error during build: %s", err.Error())
continue continue
@ -304,9 +328,9 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error {
return nil return nil
} }
func restartApp(logger *clilogger.CLILogger, ldflags string, compilerCommand string, debugBinaryProcess *process.Process, loglevel string, passthruArgs []string, verbosity int, assetDir string, firstRun bool, exitCodeChannel chan int) (*process.Process, string, error) { func restartApp(logger *clilogger.CLILogger, ldflags string, compilerCommand string, debugBinaryProcess *process.Process, loglevel string, passthruArgs []string, verbosity int, assetDir string, firstRun bool, exitCodeChannel chan int, wailsjsdir string) (*process.Process, string, error) {
appBinary, err := buildApp(logger, ldflags, compilerCommand, verbosity) appBinary, err := buildApp(logger, ldflags, compilerCommand, verbosity, wailsjsdir)
println() println()
if err != nil { if err != nil {
if firstRun { if firstRun {
@ -328,8 +352,6 @@ func restartApp(logger *clilogger.CLILogger, ldflags string, compilerCommand str
debugBinaryProcess = nil debugBinaryProcess = nil
} }
// TODO: Generate `backend.js`
// Start up new binary with correct args // Start up new binary with correct args
args := slicer.StringSlicer{} args := slicer.StringSlicer{}
args.Add("-loglevel", loglevel) args.Add("-loglevel", loglevel)
@ -354,7 +376,7 @@ func restartApp(logger *clilogger.CLILogger, ldflags string, compilerCommand str
return newProcess, appBinary, nil return newProcess, appBinary, nil
} }
func buildApp(logger *clilogger.CLILogger, ldflags string, compilerCommand string, verbosity int) (string, error) { func buildApp(logger *clilogger.CLILogger, ldflags string, compilerCommand string, verbosity int, wailsjsdir string) (string, error) {
// Create random output file // Create random output file
outputFile := "wailsdev" outputFile := "wailsdev"
@ -374,6 +396,7 @@ func buildApp(logger *clilogger.CLILogger, ldflags string, compilerCommand strin
//OutputFile: outputFile, //OutputFile: outputFile,
IgnoreFrontend: false, IgnoreFrontend: false,
Verbosity: verbosity, Verbosity: verbosity,
WailsJSDir: wailsjsdir,
} }
return build.Build(buildOptions) return build.Build(buildOptions)

View File

@ -19,6 +19,9 @@ type Project struct {
BuildCommand string `json:"frontend:build"` BuildCommand string `json:"frontend:build"`
InstallCommand string `json:"frontend:install"` InstallCommand string `json:"frontend:install"`
// Directory to generate the API Module
WailsJSDir string `json:"wailsjsdir"`
/*** Internal Data ***/ /*** Internal Data ***/
// The path to the project directory // The path to the project directory

View File

@ -49,6 +49,7 @@ type Options struct {
AppleIdentity string AppleIdentity string
WebView2Strategy string // WebView2 installer strategy WebView2Strategy string // WebView2 installer strategy
RunDelve bool // Indicates if we should run delve after the build RunDelve bool // Indicates if we should run delve after the build
WailsJSDir string // Directory to generate the wailsjs module
} }
// Build the project! // Build the project!