diff --git a/packages/ensure-binaries/src/index.ts b/packages/ensure-binaries/src/index.ts index 3e885457d7..06f0a9cfa0 100644 --- a/packages/ensure-binaries/src/index.ts +++ b/packages/ensure-binaries/src/index.ts @@ -23,16 +23,31 @@ const options = arg({ "--base-dir": String, }); -const pathToPackage = options["--package"]; -const pathToBaseDir = options["--base-dir"]; +type Options = typeof options; -if (typeof pathToPackage !== "string") { - throw new Error("--package is required"); -} +const assertOption = (key: Key): NonNullable => { + const raw = options[key]; -if (typeof pathToBaseDir !== "string") { - throw new Error("--base-dir is required"); -} + if (raw === undefined) { + console.error(`missing ${key} option`); + process.exit(1); + } + + return raw; +}; + +const joinWithInitCwd = (relativePath: string): string => { + const { INIT_CWD } = process.env; + + if (!INIT_CWD) { + return relativePath; + } + + return path.join(INIT_CWD, relativePath); +}; + +const pathToPackage = joinWithInitCwd(assertOption("--package")); +const pathToBaseDir = joinWithInitCwd(assertOption("--base-dir")); function setTimeoutFor(controller: AbortController, timeout: number): void { const handle = setTimeout(() => controller.abort(), timeout); diff --git a/packages/generate-tray-icons/src/index.ts b/packages/generate-tray-icons/src/index.ts index 6b84a8f078..5372d98722 100644 --- a/packages/generate-tray-icons/src/index.ts +++ b/packages/generate-tray-icons/src/index.ts @@ -23,7 +23,7 @@ type Options = typeof options; const assertOption = (key: Key): NonNullable => { const raw = options[key]; - if (!raw) { + if (raw === undefined) { console.error(`missing ${key} option`); process.exit(1); } @@ -31,11 +31,21 @@ const assertOption = (key: Key): NonNullable { + const { INIT_CWD } = process.env; + + if (!INIT_CWD) { + return relativePath; + } + + return path.join(INIT_CWD, relativePath); +}; + const size = options["--output-size"] ?? 16; -const inputFile = assertOption("--input"); -const outputFolder = assertOption("--output"); -const noticeFile = assertOption("--notice-icon"); -const spinnerFile = assertOption("--spinner-icon"); +const inputFile = joinWithInitCwd(assertOption("--input")); +const outputFolder = joinWithInitCwd(assertOption("--output")); +const noticeFile = joinWithInitCwd(assertOption("--notice-icon")); +const spinnerFile = joinWithInitCwd(assertOption("--spinner-icon")); const getSvgStyling = (colouring: "dark" | "light") => ( ` diff --git a/packages/open-lens/package.json b/packages/open-lens/package.json index 2475cb120b..6412cb29c6 100644 --- a/packages/open-lens/package.json +++ b/packages/open-lens/package.json @@ -33,8 +33,8 @@ "dev:main": "cross-env NODE_ENV=development webpack --config webpack/main.ts --progress --watch", "dev:renderer": "cross-env NODE_ENV=development ts-node ./webpack/dev-server.ts", "test:integration": "jest -xyz --runInBand --modulePaths=[\"/integration/\"];", - "build:tray-icons": "npm run --workspace @k8slens/generate-tray-icons generate -- --output $INIT_CWD/static/build/tray --input $INIT_CWD/../core/src/renderer/components/icon/logo-lens.svg --notice-icon $INIT_CWD/../core/src/renderer/components/icon/notice.svg --spinner-icon $INIT_CWD/../core/src/renderer/components/icon/arrow-spinner.svg", - "download:binaries": "npm run --workspace @k8slens/ensure-binaries ensure -- --package $INIT_CWD/package.json --base-dir $INIT_CWD/binaries/client", + "build:tray-icons": "npm run --workspace @k8slens/generate-tray-icons generate -- --output static/build/tray --input ../core/src/renderer/components/icon/logo-lens.svg --notice-icon ../core/src/renderer/components/icon/notice.svg --spinner-icon ../core/src/renderer/components/icon/arrow-spinner.svg", + "download:binaries": "npm run --workspace @k8slens/ensure-binaries ensure -- --package package.json --base-dir binaries/client", "postinstall": "electron-rebuild" }, "config": {