Skip to content

Commit b4191e2

Browse files
committed
add workspace build flag to select the images to build
stops the developer needing to mess with the build file
1 parent d72ac50 commit b4191e2

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

workspaces/build.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
import { spawn } from "node:child_process";
22
import { argv } from "node:process";
33

4-
const images = ["chromium", "debian", "zen", "firefox"];
4+
const defaultImages = ["chromium", "debian", "zen", "firefox"];
55
const x64Only = [];
66

7-
const optionalArgs = (a) => (process.argv.includes(a) ? a : "");
7+
const args = argv.slice(2);
8+
9+
const flags = args.filter((value) => value.startsWith("--"));
10+
11+
const optionalFlag = (flag) => (flags.includes(flag) ? flag : "");
12+
13+
function getFlagContents (flag, replacement) {
14+
const indexOf = flags.indexOf(flag)
15+
const nextArg = args[indexOf + 1]
16+
if (indexOf != -1 && nextArg) {
17+
return nextArg
18+
} else {
19+
return replacement
20+
}
21+
}
22+
823
function buildImage(image) {
924
return new Promise((resolve, reject) => {
1025
console.log(`✨ Stardust: Building ${image}...`);
1126
console.log(`Arguments: ${argv}`);
12-
const multiPlatformBuild = argv.includes("--multi-platform");
27+
const multiPlatformBuild = flags.includes("--multi-platform");
1328
const platforms = x64Only.includes(image) ? "linux/amd64" : "linux/amd64,linux/arm64";
1429
const process = spawn(
1530
"docker",
@@ -19,8 +34,8 @@ function buildImage(image) {
1934
".",
2035
"-f",
2136
`${image}/Dockerfile`,
22-
optionalArgs("--quiet"),
23-
optionalArgs("--push"),
37+
optionalFlag("--quiet"),
38+
optionalFlag("--push"),
2439
multiPlatformBuild ? "--platform" : "",
2540
multiPlatformBuild ? platforms : "",
2641
"--tag",
@@ -45,6 +60,14 @@ function buildImage(image) {
4560
}
4661

4762
try {
63+
let images = getFlagContents("--images", undefined)
64+
65+
if (images) {
66+
images = images.split(',')
67+
} else {
68+
images = defaultImages
69+
}
70+
4871
await Promise.all(images.map(buildImage));
4972
console.log("✨ Stardust: All images built successfully!");
5073
} catch (err) {

0 commit comments

Comments
 (0)