Skip to content

Commit 6d6094e

Browse files
committed
fix: provide the way to override url protocol for the upstream build
While there is the way to provide different name for protocol handler installation and protocol, so it is not hardcoded anymore, it is useless for downstream until new API is published. This fix provides workaround to configure new url protocol for specific downstream build. Signed-off-by: Denis Golovin <dgolovin@redhat.com>
1 parent 806a35e commit 6d6094e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scripts/build.cjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,36 @@ const zipDirectory = path.resolve(builtinDirectory, `${package.name}.cdix`);
3232
const extFiles = path.resolve(__dirname, '../.extfiles');
3333
const fileStream = fs.createReadStream(extFiles, { encoding: 'utf8' });
3434

35+
/** @type {string | undefined} */
36+
let urlProtocol;
37+
const argv = process.argv.slice(2);
38+
for (let i = 0; i < argv.length; i++) {
39+
if (argv[i] === '--url-protocol') {
40+
const next = argv[i + 1];
41+
if (next !== undefined && !next.startsWith('--')) {
42+
urlProtocol = next;
43+
i++;
44+
}
45+
}
46+
}
47+
3548
const includedFiles = [];
3649
const excludedFiles = [];
3750

51+
function applyUrlProtocolToSuccessHtml() {
52+
if (urlProtocol === undefined || urlProtocol === '') {
53+
return;
54+
}
55+
const successHtmlPath = path.join(zipDirectory, 'www/success.html');
56+
if (!fs.existsSync(successHtmlPath)) {
57+
console.error(`Error: file not found: ${successHtmlPath}`);
58+
process.exit(1);
59+
}
60+
const content = fs.readFileSync(successHtmlPath, 'utf8');
61+
const updated = content.replaceAll('podman-desktop', urlProtocol);
62+
fs.writeFileSync(successHtmlPath, updated, 'utf8');
63+
}
64+
3865
// remove the .cdix file before zipping
3966
if (fs.existsSync(destFile)) {
4067
fs.rmSync(destFile);
@@ -74,6 +101,7 @@ cproc.exec('pnpm init', { cwd: './dist' }, (error, stdout, stderr) => {
74101
if (error) {
75102
throw new Error('Error copying files', error);
76103
}
104+
applyUrlProtocolToSuccessHtml();
77105
console.log(`Zipping files to ${destFile}`);
78106
const zip = new AdmZip();
79107
zip.addLocalFolder(zipDirectory);

0 commit comments

Comments
 (0)