feat(tauri.js) add beforeDevCommand and beforeBuildCommand configs (#500)

This commit is contained in:
Lucas Fernandes Nogueira
2020-03-08 23:34:50 -03:00
committed by GitHub
parent a084ccf756
commit 20b70ce38f
4 changed files with 19 additions and 3 deletions

View File

@@ -43,7 +43,7 @@ export const spawnSync = (
cmd: string,
params: string[],
cwd: string,
onFail: () => void
onFail?: () => void
): void => {
log(`[sync] Running "${cmd} ${params.join(' ')}"`)
log()

View File

@@ -9,7 +9,7 @@ import * as entry from './entry'
import { appDir, tauriDir } from './helpers/app-paths'
import logger from './helpers/logger'
import onShutdown from './helpers/on-shutdown'
import { spawn } from './helpers/spawn'
import { spawn, spawnSync } from './helpers/spawn'
const getTauriConfig = require('./helpers/tauri-config')
import { TauriConfig } from './types/config'
@@ -21,6 +21,7 @@ class Runner {
tauriWatcher?: FSWatcher
devPath?: string
killPromise?: Function
ranBeforeDevCommand?: boolean
constructor() {
this.pid = 0
@@ -43,6 +44,12 @@ class Runner {
}
}
if (!this.ranBeforeDevCommand && cfg.build.beforeDevCommand) {
this.ranBeforeDevCommand = true // prevent calling it twice on recursive call on our watcher
const [command, ...args] = cfg.build.beforeDevCommand.split(' ')
spawnSync(command, args, tauriDir)
}
const tomlContents = this.__getManifest()
this.__whitelistApi(cfg, tomlContents)
this.__rewriteManifest(tomlContents)
@@ -127,6 +134,11 @@ class Runner {
}
async build(cfg: TauriConfig): Promise<void> {
if (cfg.build.beforeBuildCommand) {
const [command, ...args] = cfg.build.beforeBuildCommand.split(' ')
spawnSync(command, args, tauriDir)
}
const tomlContents = this.__getManifest()
this.__whitelistApi(cfg, tomlContents)
this.__rewriteManifest(tomlContents)

View File

@@ -1,7 +1,9 @@
export default {
build: {
distDir: '../dist',
devPath: 'http://localhost:4000'
devPath: 'http://localhost:4000',
beforeDevCommand: '',
beforeBuildCommand: ''
},
ctx: {},
tauri: {

View File

@@ -5,6 +5,8 @@ export interface TauriConfig {
build: {
distDir: string
devPath: string
beforeDevCommand?: string
beforeBuildCommand?: string
}
ctx: {
prod?: boolean