2024-07-29 11:33:23 +02:00
|
|
|
import { Argument, Option, program } from "commander"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { runDevBuild } from "./buildSrc/DevBuild.js"
|
2023-04-20 17:14:30 +02:00
|
|
|
import { spawn } from "node:child_process"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { chalk } from "zx"
|
2017-08-15 13:54:22 +02:00
|
|
|
|
2022-04-28 14:36:24 +02:00
|
|
|
await program
|
2022-12-27 15:37:40 +01:00
|
|
|
.usage("[options] [test|prod|local|host <url>]")
|
2025-08-11 11:15:05 +02:00
|
|
|
.addArgument(new Argument("stage").choices(["test", "prod", "local", "localSecure", "host"]).default("local").argOptional())
|
2022-04-28 14:36:24 +02:00
|
|
|
.addArgument(new Argument("host").argOptional())
|
2024-07-29 11:33:23 +02:00
|
|
|
.addOption(new Option("-a, --app <type>", "app to build").choices(["mail", "calendar"]).default("mail"))
|
2022-12-27 15:37:40 +01:00
|
|
|
.option("-c, --clean", "Clean build directory")
|
2025-02-18 16:06:30 +01:00
|
|
|
.option("-d, --start-desktop", "Assemble & start desktop client")
|
|
|
|
.option("--desktop-build-only", "Assemble desktop client without starting")
|
2025-03-10 16:19:11 +01:00
|
|
|
.option("-v, --verbose", "activate verbose logging in desktop client")
|
2022-12-27 15:37:40 +01:00
|
|
|
.option("-s, --serve", "Start a local server to serve the website")
|
2025-03-10 16:19:11 +01:00
|
|
|
.option("--network-debugging", "activate network debugging, sending attributeNames and attributeIds in the json request/response payloads", false)
|
2025-06-06 10:55:27 +02:00
|
|
|
.option("-D, --dev-tools", "Start the desktop client with DevTools open")
|
2021-11-05 17:11:35 +01:00
|
|
|
.action(async (stage, host, options) => {
|
2022-12-27 15:37:40 +01:00
|
|
|
if ((stage === "host" && host == null) || (stage !== "host" && host != null)) {
|
2022-04-28 14:36:24 +02:00
|
|
|
program.outputHelp()
|
2018-12-21 13:29:35 +01:00
|
|
|
process.exit(1)
|
|
|
|
}
|
2021-07-28 12:20:36 +02:00
|
|
|
|
2025-07-15 12:52:22 +02:00
|
|
|
if (stage === "localSecure") {
|
|
|
|
stage = "host"
|
|
|
|
host = "https://app.local.tuta.com:9000"
|
|
|
|
}
|
|
|
|
|
2025-08-15 10:55:58 +02:00
|
|
|
const { clean, watch, serve, startDesktop, desktopBuildOnly, app, networkDebugging, devTools } = options
|
2021-11-05 17:11:35 +01:00
|
|
|
|
2022-05-02 17:17:33 +02:00
|
|
|
if (serve) {
|
|
|
|
console.error("--serve is currently disabled, point any server to ./build directory instead or build desktop")
|
|
|
|
}
|
|
|
|
|
2021-11-05 17:11:35 +01:00
|
|
|
try {
|
|
|
|
await runDevBuild({
|
|
|
|
stage: stage ?? "local",
|
|
|
|
host,
|
|
|
|
clean,
|
|
|
|
watch,
|
|
|
|
serve,
|
2025-02-18 16:06:30 +01:00
|
|
|
desktop: startDesktop || desktopBuildOnly,
|
2025-03-10 16:19:11 +01:00
|
|
|
networkDebugging,
|
2024-07-29 11:33:23 +02:00
|
|
|
app,
|
2021-11-05 17:11:35 +01:00
|
|
|
})
|
|
|
|
|
2025-02-18 16:06:30 +01:00
|
|
|
if (startDesktop) {
|
2024-07-29 11:33:23 +02:00
|
|
|
const buildDir = app === "calendar" ? "build-calendar-app" : "build"
|
2025-06-06 10:55:27 +02:00
|
|
|
const env = Object.assign({}, process.env, { ELECTRON_ENABLE_SECURITY_WARNINGS: "TRUE", ELECTRON_START_WITH_DEV_TOOLS: devTools })
|
2021-11-05 17:11:35 +01:00
|
|
|
// we don't want to quit here because we want to keep piping output to our stdout.
|
2025-09-25 18:05:10 +02:00
|
|
|
spawn("node_modules/.bin/electron", ["--inspect=5858", `./${buildDir}/`], {
|
2022-07-11 17:40:08 +02:00
|
|
|
stdio: "inherit",
|
2023-02-08 13:58:13 +01:00
|
|
|
env: options.verbose ? Object.assign({}, env, { ELECTRON_ENABLE_LOGGING: 1 }) : env,
|
2022-07-11 17:40:08 +02:00
|
|
|
})
|
2021-11-05 17:11:35 +01:00
|
|
|
} else if (!watch) {
|
|
|
|
// Don't wait for spawned child processes to exit (because they never will)
|
|
|
|
process.exit(0)
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2022-05-17 17:40:44 +02:00
|
|
|
console.error(chalk.red.underline("Build failed:"), e)
|
2021-11-05 17:11:35 +01:00
|
|
|
process.exit(1)
|
2021-07-28 12:20:36 +02:00
|
|
|
}
|
2021-11-05 17:11:35 +01:00
|
|
|
})
|
2022-12-27 15:37:40 +01:00
|
|
|
.parseAsync(process.argv)
|