2021-11-05 17:11:35 +01:00
|
|
|
import path from "path"
|
|
|
|
|
import {BuildServerClient} from "@tutao/tutanota-build-server"
|
|
|
|
|
import {fetchDictionaries} from "./DictionaryFetcher.js"
|
|
|
|
|
import fs from "fs-extra"
|
|
|
|
|
|
|
|
|
|
export async function runDevBuild({stage, host, desktop, clean, watch, serve}) {
|
|
|
|
|
|
|
|
|
|
if (clean) {
|
|
|
|
|
console.log("cleaning build dir")
|
|
|
|
|
fs.emptyDir("build")
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 13:35:54 +01:00
|
|
|
const doClean = clean ?? false
|
|
|
|
|
|
2021-11-05 17:11:35 +01:00
|
|
|
let buildServerOptions = {
|
2021-11-10 13:35:54 +01:00
|
|
|
forceRestart: doClean,
|
2021-11-05 17:11:35 +01:00
|
|
|
builderPath: path.resolve("./buildSrc/Builder.js"),
|
|
|
|
|
preserveLogs: true,
|
2021-11-10 13:35:54 +01:00
|
|
|
autoRebuild: watch ?? false,
|
2021-11-05 17:11:35 +01:00
|
|
|
buildOpts: {
|
2021-11-10 13:35:54 +01:00
|
|
|
desktop: desktop ?? false,
|
|
|
|
|
stage: stage ?? "local",
|
|
|
|
|
host,
|
|
|
|
|
clean: doClean
|
2021-11-05 17:11:35 +01:00
|
|
|
},
|
|
|
|
|
watchFolders: [path.resolve("src")]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (serve) {
|
|
|
|
|
buildServerOptions.devServerPort = 9001
|
|
|
|
|
buildServerOptions.webRoot = path.resolve('build')
|
|
|
|
|
buildServerOptions.spaRedirect = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const buildServerClient = new BuildServerClient("make")
|
|
|
|
|
await buildServerClient.buildWithServer(buildServerOptions)
|
|
|
|
|
|
|
|
|
|
const dictPath = "build/dictionaries"
|
|
|
|
|
if (!fs.existsSync(dictPath)) {
|
|
|
|
|
const {devDependencies} = JSON.parse(await fs.readFile("package.json", "utf8"))
|
|
|
|
|
await fetchDictionaries(devDependencies.electron, [dictPath])
|
|
|
|
|
}
|
|
|
|
|
}
|