2022-02-14 10:19:20 +01:00
|
|
|
/**
|
|
|
|
* Script to build and publish release versions of the app.
|
|
|
|
*
|
|
|
|
* <h2>Bundling</h2>
|
|
|
|
*
|
|
|
|
* Bundling is manual. Rollup makes no attempt to optimize chunk sizes anymore and we can do it much better manually anyway because we
|
|
|
|
* know what is needed together.
|
|
|
|
*
|
|
|
|
* Unfortunately manual bundling is "infectious" in a sense that if you manually put module in a chunk all its dependencies will also be
|
|
|
|
* put in that chunk unless they are sorted into another manual chunk. Ideally this would be semi-automatic with directory-based chunks.
|
|
|
|
*/
|
2022-12-27 15:37:40 +01:00
|
|
|
import { program, Argument } from "commander"
|
2022-02-14 10:19:20 +01:00
|
|
|
import fs from "fs-extra"
|
2023-04-20 17:14:30 +02:00
|
|
|
import path, { dirname } from "node:path"
|
2022-12-27 15:37:40 +01:00
|
|
|
import { buildWebapp } from "./buildSrc/buildWebapp.js"
|
|
|
|
import { getTutanotaAppVersion, measure } from "./buildSrc/buildUtils.js"
|
2023-04-20 17:14:30 +02:00
|
|
|
import { fileURLToPath } from "node:url"
|
2022-02-14 10:19:20 +01:00
|
|
|
|
2022-12-27 15:37:40 +01:00
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
2022-02-14 10:19:20 +01:00
|
|
|
|
|
|
|
// We use terser for minimifaction but we don't use nameCache because it does not work.
|
|
|
|
// It does not work because there's no top-level code besides invocations of System.register and non-top-level code is not put into cache
|
|
|
|
// which looks like a problem e.g. for accessing fields.
|
|
|
|
|
2022-04-28 14:36:24 +02:00
|
|
|
await program
|
2022-02-14 10:19:20 +01:00
|
|
|
.usage('[options] [test|prod|local|release|host <url>], "release" is default')
|
2023-11-03 17:01:47 +01:00
|
|
|
.description("Utility to build the web part of tuta")
|
2022-12-27 15:37:40 +01:00
|
|
|
.addArgument(new Argument("stage").choices(["test", "prod", "local", "host", "release"]).default("prod").argOptional())
|
2022-04-28 14:36:24 +02:00
|
|
|
.addArgument(new Argument("host").argOptional())
|
2022-12-27 15:37:40 +01:00
|
|
|
.option("--disable-minify", "disable minification")
|
|
|
|
.option("--out-dir <outDir>", "where to copy the client")
|
2022-04-28 14:36:24 +02:00
|
|
|
.action(async (stage, host, options) => {
|
|
|
|
if (process.env.DEBUG_SIGN && !fs.existsSync(path.join(process.env.DEBUG_SIGN, "test.p12"))) {
|
|
|
|
console.error("ERROR:\nPlease make sure your DEBUG_SIGN test certificate authority is set up properly!\n\n")
|
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2022-12-27 15:37:40 +01:00
|
|
|
if ((stage === "host" && host == null) || (stage !== "host" && host != null) || (stage !== "release" && options.publish)) {
|
2022-04-28 14:36:24 +02:00
|
|
|
program.outputHelp()
|
2022-02-14 10:19:20 +01:00
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
|
2022-04-28 14:36:24 +02:00
|
|
|
options.stage = stage ?? "release"
|
|
|
|
options.host = host
|
|
|
|
|
|
|
|
await doBuild(options)
|
|
|
|
})
|
|
|
|
.parseAsync(process.argv)
|
2022-02-14 10:19:20 +01:00
|
|
|
|
2022-04-28 14:36:24 +02:00
|
|
|
async function doBuild(options) {
|
2022-02-14 10:19:20 +01:00
|
|
|
try {
|
|
|
|
measure()
|
2022-03-02 18:21:01 +01:00
|
|
|
const version = getTutanotaAppVersion()
|
2022-02-14 10:19:20 +01:00
|
|
|
const minify = options.disableMinify !== true
|
|
|
|
|
|
|
|
if (!minify) {
|
|
|
|
console.warn("Minification is disabled")
|
|
|
|
}
|
|
|
|
|
2022-12-27 15:37:40 +01:00
|
|
|
await buildWebapp({
|
|
|
|
version,
|
|
|
|
stage: options.stage,
|
|
|
|
host: options.host,
|
|
|
|
measure,
|
|
|
|
minify,
|
|
|
|
projectDir: __dirname,
|
|
|
|
})
|
2022-02-14 10:19:20 +01:00
|
|
|
|
|
|
|
const now = new Date(Date.now()).toTimeString().substr(0, 5)
|
|
|
|
console.log(`\nBuild time: ${measure()}s (${now})`)
|
2023-01-20 16:08:09 +01:00
|
|
|
process.exit(0)
|
2022-02-14 10:19:20 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.error("\nBuild error:", e)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2022-12-27 15:37:40 +01:00
|
|
|
}
|