mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
feat(tauri.js) add beforeDevCommand and beforeBuildCommand configs (#500)
This commit is contained in:
committed by
GitHub
parent
a084ccf756
commit
20b70ce38f
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
export default {
|
||||
build: {
|
||||
distDir: '../dist',
|
||||
devPath: 'http://localhost:4000'
|
||||
devPath: 'http://localhost:4000',
|
||||
beforeDevCommand: '',
|
||||
beforeBuildCommand: ''
|
||||
},
|
||||
ctx: {},
|
||||
tauri: {
|
||||
|
||||
@@ -5,6 +5,8 @@ export interface TauriConfig {
|
||||
build: {
|
||||
distDir: string
|
||||
devPath: string
|
||||
beforeDevCommand?: string
|
||||
beforeBuildCommand?: string
|
||||
}
|
||||
ctx: {
|
||||
prod?: boolean
|
||||
|
||||
Reference in New Issue
Block a user