forked from padloc/padloc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-config-xml.js
34 lines (25 loc) · 1.2 KB
/
update-config-xml.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { resolve, join } = require("path");
const fs = require("fs");
const { xml2js, js2xml } = require("xml-js");
require("dotenv").config();
const rootDir = resolve(__dirname, "../..");
const assetsDir = resolve(rootDir, process.env.PL_ASSETS_DIR || "assets");
const configPath = resolve(__dirname, "config.xml");
const { version } = require("./package.json");
const { name, appId } = require(join(assetsDir, "manifest.json"));
const vendorVersion = process.env.PL_VENDOR_VERSION || version;
const vendorBuild = `${vendorVersion}.${process.env.PL_BUILD_ENV === "Production" ? process.env.RELEASE_BUILD : "0"}`;
async function main() {
const configXML = fs.readFileSync(configPath, "utf-8");
const configObj = xml2js(configXML, { compact: true });
configObj.widget._attributes.id = appId;
configObj.widget._attributes.version = vendorVersion;
configObj.widget._attributes["ios-CFBundleVersion"] = vendorBuild;
configObj.widget._attributes["android-versionCode"] = vendorBuild
.split(".")
.map((part) => part.padStart(2, "0"))
.join("");
configObj.widget.name._text = name;
fs.writeFileSync(configPath, js2xml(configObj, { compact: true, spaces: 4 }));
}
main();