|
@@ -1,18 +1,21 @@
|
|
|
const
|
|
|
- chokidar = require('chokidar'),
|
|
|
- debounce = require('lodash.debounce'),
|
|
|
- path = require('path'),
|
|
|
- { readFileSync, writeFileSync } = require('fs-extra')
|
|
|
+ chokidar = require('chokidar')
|
|
|
+const debounce = require('lodash.debounce')
|
|
|
+const path = require('path')
|
|
|
+const { readFileSync, writeFileSync } = require('fs-extra')
|
|
|
|
|
|
const
|
|
|
- { spawn } = require('./helpers/spawn'),
|
|
|
- log = require('./helpers/logger')('app:tauri'),
|
|
|
- onShutdown = require('./helpers/on-shutdown'),
|
|
|
- generator = require('./generator'),
|
|
|
- { appDir, tauriDir } = require('./helpers/app-paths')
|
|
|
+ { spawn } = require('./helpers/spawn')
|
|
|
+const onShutdown = require('./helpers/on-shutdown')
|
|
|
+const generator = require('./generator')
|
|
|
+const { appDir, tauriDir } = require('./helpers/app-paths')
|
|
|
+
|
|
|
+const logger = require('./helpers/logger')
|
|
|
+const log = logger('app:tauri', 'green')
|
|
|
+const warn = log('app:tauri (template)', 'red')
|
|
|
|
|
|
class Runner {
|
|
|
- constructor() {
|
|
|
+ constructor () {
|
|
|
this.pid = 0
|
|
|
this.tauriWatcher = null
|
|
|
onShutdown(() => {
|
|
@@ -20,7 +23,7 @@ class Runner {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- async run(cfg) {
|
|
|
+ async run (cfg) {
|
|
|
process.env.TAURI_DIST_DIR = cfg.build.distDir
|
|
|
process.env.TAURI_CONFIG_DIR = tauriDir
|
|
|
const url = cfg.build.APP_URL
|
|
@@ -72,7 +75,7 @@ class Runner {
|
|
|
return startDevTauri()
|
|
|
}
|
|
|
|
|
|
- async build(cfg) {
|
|
|
+ async build (cfg) {
|
|
|
process.env.TAURI_DIST_DIR = cfg.build.distDir
|
|
|
process.env.TAURI_CONFIG_DIR = tauriDir
|
|
|
|
|
@@ -107,14 +110,14 @@ class Runner {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- stop() {
|
|
|
+ stop () {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
this.tauriWatcher && this.tauriWatcher.close()
|
|
|
this.__stopCargo().then(resolve)
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- __runCargoCommand({
|
|
|
+ __runCargoCommand ({
|
|
|
cargoArgs,
|
|
|
extraArgs
|
|
|
}) {
|
|
@@ -122,16 +125,16 @@ class Runner {
|
|
|
this.pid = spawn(
|
|
|
'cargo',
|
|
|
|
|
|
- extraArgs ?
|
|
|
- cargoArgs.concat(['--']).concat(extraArgs) :
|
|
|
- cargoArgs,
|
|
|
+ extraArgs
|
|
|
+ ? cargoArgs.concat(['--']).concat(extraArgs)
|
|
|
+ : cargoArgs,
|
|
|
|
|
|
tauriDir,
|
|
|
|
|
|
code => {
|
|
|
if (code) {
|
|
|
warn()
|
|
|
- warn(`⚠️ [FAIL] Cargo CLI has failed`)
|
|
|
+ warn('⚠️ [FAIL] Cargo CLI has failed')
|
|
|
warn()
|
|
|
process.exit(1)
|
|
|
}
|
|
@@ -152,7 +155,7 @@ class Runner {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- __stopCargo() {
|
|
|
+ __stopCargo () {
|
|
|
const pid = this.pid
|
|
|
|
|
|
if (!pid) {
|
|
@@ -168,11 +171,11 @@ class Runner {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- __manipulateToml(callback) {
|
|
|
- const toml = require('@iarna/toml'),
|
|
|
- tomlPath = path.join(tauriDir, 'Cargo.toml'),
|
|
|
- tomlFile = readFileSync(tomlPath),
|
|
|
- tomlContents = toml.parse(tomlFile)
|
|
|
+ __manipulateToml (callback) {
|
|
|
+ const toml = require('@iarna/toml')
|
|
|
+ const tomlPath = path.join(tauriDir, 'Cargo.toml')
|
|
|
+ const tomlFile = readFileSync(tomlPath)
|
|
|
+ const tomlContents = toml.parse(tomlFile)
|
|
|
|
|
|
callback(tomlContents)
|
|
|
|
|
@@ -180,7 +183,7 @@ class Runner {
|
|
|
writeFileSync(tomlPath, output)
|
|
|
}
|
|
|
|
|
|
- __whitelistApi(cfg, tomlContents) {
|
|
|
+ __whitelistApi (cfg, tomlContents) {
|
|
|
if (!tomlContents.dependencies.tauri.features) {
|
|
|
tomlContents.dependencies.tauri.features = []
|
|
|
}
|