|
@@ -1,5 +1,5 @@
|
|
|
import Inliner from '@tauri-apps/tauri-inliner'
|
|
|
-import toml from '@tauri-apps/toml'
|
|
|
+import toml, { JsonMap } from '@tauri-apps/toml'
|
|
|
import chokidar, { FSWatcher } from 'chokidar'
|
|
|
import { existsSync, readFileSync, writeFileSync } from 'fs-extra'
|
|
|
import { JSDOM } from 'jsdom'
|
|
@@ -14,7 +14,7 @@ const getTauriConfig = require('./helpers/tauri-config')
|
|
|
import { TauriConfig } from './types/config'
|
|
|
|
|
|
const log = logger('app:tauri', 'green')
|
|
|
-const warn = logger('app:tauri (template)', 'red')
|
|
|
+const warn = logger('app:tauri (runner)', 'red')
|
|
|
|
|
|
class Runner {
|
|
|
pid: number
|
|
@@ -43,9 +43,9 @@ class Runner {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- this.__manipulateToml(toml => {
|
|
|
- this.__whitelistApi(cfg, toml)
|
|
|
- })
|
|
|
+ const tomlContents = this.__getManifest()
|
|
|
+ this.__whitelistApi(cfg, tomlContents)
|
|
|
+ this.__rewriteManifest(tomlContents)
|
|
|
|
|
|
entry.generate(tauriDir, cfg)
|
|
|
|
|
@@ -67,19 +67,35 @@ class Runner {
|
|
|
cargoArgs: ['run'].concat(
|
|
|
features.length ? ['--features', ...features] : []
|
|
|
),
|
|
|
- dev: true
|
|
|
+ dev: true,
|
|
|
+ exitOnPanic: cfg.ctx.exitOnPanic
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// Start watching for tauri app changes
|
|
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
|
+
|
|
|
+ let tauriPaths: string[] = []
|
|
|
+ // @ts-ignore
|
|
|
+ if (tomlContents.dependencies.tauri.path) {
|
|
|
+ // @ts-ignore
|
|
|
+ const tauriPath = path.resolve(tauriDir, tomlContents.dependencies.tauri.path)
|
|
|
+ tauriPaths = [
|
|
|
+ tauriPath,
|
|
|
+ `${tauriPath}-api`,
|
|
|
+ `${tauriPath}-updater`,
|
|
|
+ `${tauriPath}-utils`
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
this.tauriWatcher = chokidar
|
|
|
.watch(
|
|
|
[
|
|
|
path.join(tauriDir, 'src'),
|
|
|
path.join(tauriDir, 'Cargo.toml'),
|
|
|
path.join(tauriDir, 'build.rs'),
|
|
|
- path.join(appDir, 'tauri.conf.json')
|
|
|
+ path.join(tauriDir, 'tauri.conf.json'),
|
|
|
+ ...tauriPaths
|
|
|
],
|
|
|
{
|
|
|
ignoreInitial: true
|
|
@@ -88,7 +104,7 @@ class Runner {
|
|
|
.on(
|
|
|
'change',
|
|
|
debounce((path: string) => {
|
|
|
- this.__stopCargo()
|
|
|
+ (this.pid ? this.__stopCargo() : Promise.resolve())
|
|
|
.then(() => {
|
|
|
if (path.includes('tauri.conf.json')) {
|
|
|
this.run(getTauriConfig({ ctx: cfg.ctx })).catch(e => {
|
|
@@ -111,9 +127,9 @@ class Runner {
|
|
|
}
|
|
|
|
|
|
async build(cfg: TauriConfig): Promise<void> {
|
|
|
- this.__manipulateToml(toml => {
|
|
|
- this.__whitelistApi(cfg, toml)
|
|
|
- })
|
|
|
+ const tomlContents = this.__getManifest()
|
|
|
+ this.__whitelistApi(cfg, tomlContents)
|
|
|
+ this.__rewriteManifest(tomlContents)
|
|
|
|
|
|
entry.generate(tauriDir, cfg)
|
|
|
|
|
@@ -243,11 +259,13 @@ class Runner {
|
|
|
async __runCargoCommand({
|
|
|
cargoArgs,
|
|
|
extraArgs,
|
|
|
- dev = false
|
|
|
+ dev = false,
|
|
|
+ exitOnPanic = true
|
|
|
}: {
|
|
|
cargoArgs: string[]
|
|
|
extraArgs?: string[]
|
|
|
- dev?: boolean
|
|
|
+ dev?: boolean,
|
|
|
+ exitOnPanic?: boolean
|
|
|
}): Promise<void> {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
this.pid = spawn(
|
|
@@ -258,6 +276,12 @@ class Runner {
|
|
|
tauriDir,
|
|
|
|
|
|
code => {
|
|
|
+ if (dev && !exitOnPanic && code === 101) {
|
|
|
+ this.pid = 0
|
|
|
+ resolve()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if (code) {
|
|
|
warn()
|
|
|
warn('⚠️ [FAIL] Cargo CLI has failed')
|
|
@@ -308,14 +332,19 @@ class Runner {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- __manipulateToml(callback: (tomlContents: object) => void): void {
|
|
|
- const tomlPath = path.join(tauriDir, 'Cargo.toml')
|
|
|
- const tomlFile = readFileSync(tomlPath)
|
|
|
- // @ts-ignore
|
|
|
- const tomlContents = toml.parse(tomlFile)
|
|
|
+ __getManifestPath(): string {
|
|
|
+ return path.join(tauriDir, 'Cargo.toml')
|
|
|
+ }
|
|
|
|
|
|
- callback(tomlContents)
|
|
|
+ __getManifest(): JsonMap {
|
|
|
+ const tomlPath = this.__getManifestPath()
|
|
|
+ const tomlFile = readFileSync(tomlPath).toString()
|
|
|
+ const tomlContents = toml.parse(tomlFile)
|
|
|
+ return tomlContents
|
|
|
+ }
|
|
|
|
|
|
+ __rewriteManifest(tomlContents: JsonMap) {
|
|
|
+ const tomlPath = this.__getManifestPath()
|
|
|
const output = toml.stringify(tomlContents)
|
|
|
writeFileSync(tomlPath, output)
|
|
|
}
|