tutanota/make.js

68 lines
2.6 KiB
JavaScript
Raw Normal View History

import { Argument, Option, program } from "commander"
2022-12-27 15:37:40 +01:00
import { runDevBuild } from "./buildSrc/DevBuild.js"
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>]")
.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())
.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")
.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")
.option("--ignore-migrations", "Dont check offline database migrations.")
.option("--network-debugging", "activate network debugging, sending attributeNames and attributeIds in the json request/response payloads", false)
.option("-D, --dev-tools", "Start the desktop client with DevTools open")
.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
if (stage === "localSecure") {
stage = "host"
host = "https://app.local.tuta.com:9000"
}
const { clean, watch, serve, startDesktop, desktopBuildOnly, ignoreMigrations, app, networkDebugging, devTools } = options
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")
}
try {
await runDevBuild({
stage: stage ?? "local",
host,
clean,
watch,
serve,
2025-02-18 16:06:30 +01:00
desktop: startDesktop || desktopBuildOnly,
2022-12-27 15:37:40 +01:00
ignoreMigrations,
networkDebugging,
app,
})
2025-02-18 16:06:30 +01:00
if (startDesktop) {
const buildDir = app === "calendar" ? "build-calendar-app" : "build"
const env = Object.assign({}, process.env, { ELECTRON_ENABLE_SECURITY_WARNINGS: "TRUE", ELECTRON_START_WITH_DEV_TOOLS: devTools })
// we don't want to quit here because we want to keep piping output to our stdout.
spawn("npx", [`electron --inspect=5858 ./${buildDir}/`], {
shell: true,
stdio: "inherit",
env: options.verbose ? Object.assign({}, env, { ELECTRON_ENABLE_LOGGING: 1 }) : env,
})
} else if (!watch) {
// Don't wait for spawned child processes to exit (because they never will)
process.exit(0)
}
} catch (e) {
console.error(chalk.red.underline("Build failed:"), e)
process.exit(1)
2021-07-28 12:20:36 +02:00
}
})
2022-12-27 15:37:40 +01:00
.parseAsync(process.argv)