Files
playlet-piped/scripts/update-manifest-symbols.js
T
Brahim Hadriche 7a155c689e Sign app for publishing (#38)
* Sign app for publishing

* update gitignore

* refactor input args

* Change instance api sorting

* Better instance sorting

* Instance filter

* remove hardcoded instance

* script cleanups

* Unused function
2023-01-11 11:52:43 -05:00

33 lines
1.1 KiB
JavaScript

const fs = require('fs');
if (process.argv.length < 3) {
console.error("Invalid usage! usage: npm run manifest-symbols -- SYMBOL1=true [SYMBOL2=false]");
exit(-1);
}
function argsToSymbolsObject(arr) {
return arr.reduce(function (acc, value) {
keyValue = value.split("=");
acc[keyValue[0]] = keyValue[1];
return acc;
}, {});
}
const newSymbols = argsToSymbolsObject(process.argv.slice(2));
let currentSymbols = {}
const appManifestLines = fs.readFileSync("./src/manifest", { encoding: 'utf8', flag: 'r' }).split('\n');
const bsConstIndex = appManifestLines.findIndex(line => line.startsWith("bs_const="));
if (bsConstIndex !== -1) {
let bsConst = appManifestLines[bsConstIndex];
bsConst = bsConst.substring("bs_const=".length);
currentSymbols = argsToSymbolsObject(bsConst.split(";"))
}
mergedSymbols = { ...currentSymbols, ...newSymbols };
bsConst = "bs_const=" + Object.keys(mergedSymbols).map(key => `${key}=${mergedSymbols[key]}`).join(";");
appManifestLines[bsConstIndex] = bsConst;
fs.writeFileSync("./src/manifest", appManifestLines.join("\n"));