11import { spawn } from "node:child_process" ;
22import { argv } from "node:process" ;
33
4- const images = [ "chromium" , "debian" , "zen" , "firefox" ] ;
4+ const defaultImages = [ "chromium" , "debian" , "zen" , "firefox" ] ;
55const 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+
823function 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
4762try {
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