2021-11-05 17:11:35 +01:00
|
|
|
import path from "path"
|
|
|
|
|
import fs from "fs-extra"
|
2022-02-18 09:12:05 +01:00
|
|
|
import {spawnSync} from "child_process"
|
2022-01-12 14:43:01 +01:00
|
|
|
import {build} from "./Builder.js"
|
|
|
|
|
import {BuildServerClient} from "@tutao/tutanota-build-server"
|
2022-02-14 10:19:20 +01:00
|
|
|
import {fetchDictionaries} from "./fetchDictionaries.js"
|
2021-11-05 17:11:35 +01:00
|
|
|
|
|
|
|
|
export async function runDevBuild({stage, host, desktop, clean, watch, serve}) {
|
|
|
|
|
|
|
|
|
|
if (clean) {
|
|
|
|
|
console.log("cleaning build dir")
|
2022-01-12 14:43:01 +01:00
|
|
|
await fs.emptyDir("build")
|
2021-11-05 17:11:35 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-14 10:19:20 +01:00
|
|
|
console.log("building packages")
|
|
|
|
|
spawnSync("npm", ["run", "build-packages"], {stdio: "inherit"})
|
|
|
|
|
|
2022-02-18 09:12:05 +01:00
|
|
|
|
2021-11-10 13:35:54 +01:00
|
|
|
const doClean = clean ?? false
|
|
|
|
|
|
2022-01-07 15:58:30 +01:00
|
|
|
const 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
|
|
|
watchFolders: [path.resolve("src")]
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-07 15:58:30 +01:00
|
|
|
const buildOpts = {
|
|
|
|
|
desktop: desktop ?? false,
|
|
|
|
|
stage: stage ?? "local",
|
|
|
|
|
host,
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-05 17:11:35 +01:00
|
|
|
if (serve) {
|
|
|
|
|
buildServerOptions.devServerPort = 9001
|
|
|
|
|
buildServerOptions.webRoot = path.resolve('build')
|
|
|
|
|
buildServerOptions.spaRedirect = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const buildServerClient = new BuildServerClient("make")
|
2022-01-07 15:58:30 +01:00
|
|
|
await buildServerClient.buildWithServer(buildServerOptions, buildOpts)
|
2022-01-12 14:43:01 +01:00
|
|
|
// await buildWithoutServer(buildOpts, buildServerOptions)
|
2021-11-05 17:11:35 +01:00
|
|
|
|
|
|
|
|
const dictPath = "build/dictionaries"
|
|
|
|
|
if (!fs.existsSync(dictPath)) {
|
2022-01-12 14:43:01 +01:00
|
|
|
const {dependencies} = JSON.parse(await fs.readFile("package.json", "utf8"))
|
|
|
|
|
await fetchDictionaries(dependencies.electron, [dictPath])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function buildWithoutServer(buildOptions, serverOptions) {
|
|
|
|
|
const bundleWrappers = await build(buildOptions, serverOptions, console.log.bind(console))
|
|
|
|
|
for (const wrapper of bundleWrappers) {
|
|
|
|
|
await wrapper.generate()
|
2021-11-05 17:11:35 +01:00
|
|
|
}
|
|
|
|
|
}
|