|
4 | 4 | // It requires a version argument, e.g. "v1.0.0-beta".
|
5 | 5 | // This allow us to host multiple versions of the showcase in the same domain.
|
6 | 6 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 7 | +import packageJson from "@genexus/mercury/package.json" with { type: "json" }; |
7 | 8 | import { spawn } from "child_process";
|
| 9 | +import { rename } from "fs/promises"; |
8 | 10 | import { styleText } from "util";
|
9 | 11 |
|
10 | 12 | const start = Date.now();
|
11 | 13 |
|
12 |
| -const VERSION = process.argv[2]; |
| 14 | +const VERSION = process.argv[2] || `v${packageJson.version}`; |
13 | 15 |
|
14 |
| -if (VERSION === undefined) { |
15 |
| - console.error( |
16 |
| - styleText("red", "error: version argument is required."), |
17 |
| - "Example:", |
| 16 | +if (process.argv[2] === undefined) { |
| 17 | + console.warn( |
| 18 | + styleText( |
| 19 | + "yellow", |
| 20 | + "warn: version argument was not provided. Using the current version from @genexus/mercury package." |
| 21 | + ), |
| 22 | + "Example to customize the version:", |
18 | 23 | styleText(["bold", "cyanBright"], "bun build.version v1.0.0-beta")
|
19 | 24 | );
|
20 |
| - process.exit(1); |
21 | 25 | }
|
22 | 26 |
|
23 | 27 | const child = spawn(
|
24 | 28 | `bun compute-version && bun mercury -i=/${VERSION}/assets/icons/ -f=/${VERSION}/assets/fonts/ --outDir=.mercury/ && ng build --base-href /${VERSION}/`,
|
25 | 29 | { stdio: "inherit", shell: true }
|
26 | 30 | );
|
27 | 31 |
|
28 |
| -child.on("close", code => { |
| 32 | +child.on("close", async code => { |
29 | 33 | const duration = Date.now() - start;
|
30 | 34 |
|
31 | 35 | if (code === 0) {
|
| 36 | + // Rename the output folder to include the version |
| 37 | + try { |
| 38 | + await rename("dist/browser", `dist/browser-${VERSION}`); |
| 39 | + } catch (err) { |
| 40 | + console.error("Error renaming dist/browser folder:", err); |
| 41 | + } |
| 42 | + |
32 | 43 | console.log(styleText("green", `✓ version ${VERSION} built in ${duration}ms`));
|
33 | 44 | } else {
|
34 | 45 | console.log(
|
|
0 commit comments