2020-01-28 23:16:40 +01:00
|
|
|
const child_process = require("child_process");
|
|
|
|
const path = require("path");
|
|
|
|
const yargs = require("yargs");
|
|
|
|
const args = yargs
|
|
|
|
.options("type", {
|
|
|
|
alias: "t",
|
|
|
|
describe: "Type of the build",
|
|
|
|
choices: ["alpha", "rc", "release"],
|
|
|
|
default: "alpha",
|
|
|
|
})
|
|
|
|
.help()
|
|
|
|
.alias("help", "h")
|
|
|
|
.argv;
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
2024-02-17 00:02:10 +01:00
|
|
|
const versionsPath = path.join(__dirname, "..", "versions");
|
|
|
|
|
|
|
|
function getXPIFileName(id, version){
|
|
|
|
"use strict";
|
|
|
|
return `${id}-${version}.xpi`;
|
|
|
|
}
|
|
|
|
|
2024-02-17 00:07:11 +01:00
|
|
|
async function addAlphaVersionToUpdatesJSON(version){
|
|
|
|
"use strict";
|
|
|
|
const updatesPath = path.join(versionsPath, "updates.json");
|
|
|
|
const data = JSON.parse(await fs.promises.readFile(updatesPath));
|
|
|
|
const versions = data.addons["CanvasBlocker-Beta@kkapsner.de"].updates;
|
|
|
|
if (versions.some(function(entry){
|
|
|
|
return entry.version === version;
|
|
|
|
})){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
versions.push({
|
|
|
|
version,
|
|
|
|
update_link: `https://canvasblocker.kkapsner.de/versions/${getXPIFileName("canvasblocker_beta", version)}`
|
|
|
|
});
|
|
|
|
await fs.promises.writeFile(updatesPath, JSON.stringify(data, undefined, "\t"));
|
|
|
|
}
|
|
|
|
|
2024-02-17 00:02:10 +01:00
|
|
|
async function getAlphaVersion(manifest){
|
2020-01-28 23:16:40 +01:00
|
|
|
"use strict";
|
2023-05-30 13:48:25 +02:00
|
|
|
function f(n){
|
|
|
|
if (n < 10) return "0" + n.toString(10);
|
|
|
|
return n.toString(10);
|
|
|
|
}
|
2020-01-28 23:16:40 +01:00
|
|
|
const now = new Date();
|
2024-02-17 00:02:10 +01:00
|
|
|
const date = `${now.getFullYear()}${f(now.getMonth() + 1)}${f(now.getDate())}`;
|
|
|
|
const baseVersion = `${manifest.version}.${date}`;
|
|
|
|
if (!fs.existsSync(path.join(versionsPath, getXPIFileName("canvasblocker_beta", baseVersion)))){
|
|
|
|
return baseVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
let dayTry = 1;
|
|
|
|
while (fs.existsSync(path.join(versionsPath, getXPIFileName("canvasblocker_beta", `${baseVersion}.${dayTry}`)))){
|
|
|
|
dayTry += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${baseVersion}.${dayTry}`;
|
2020-01-28 23:16:40 +01:00
|
|
|
}
|
|
|
|
function getRCVersion(manifest){
|
|
|
|
"use strict";
|
|
|
|
throw "not implemented";
|
|
|
|
}
|
|
|
|
function getReleaseVersion(manifest){
|
|
|
|
"use strict";
|
|
|
|
return manifest.version.replace(/^([\d.]+).*$/, "$1");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run(){
|
|
|
|
"use strict";
|
|
|
|
const manifestPath = path.join(__dirname, "../manifest.json");
|
|
|
|
|
|
|
|
const oldManifest = await fs.promises.readFile(manifestPath);
|
|
|
|
const manifest = require(manifestPath);
|
|
|
|
if (args.type === "alpha" || args.type === "rc"){
|
|
|
|
manifest.name = "CanvasBlocker-Beta";
|
2024-02-17 00:02:10 +01:00
|
|
|
["gecko", "gecko_android"].forEach(function(browserType){
|
|
|
|
if (!manifest.browser_specific_settings[browserType]) return;
|
|
|
|
manifest.browser_specific_settings[browserType].id = "CanvasBlocker-Beta@kkapsner.de";
|
|
|
|
});
|
2020-01-28 23:16:40 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
manifest.name = "CanvasBlocker";
|
2024-02-17 00:02:10 +01:00
|
|
|
["gecko", "gecko_android"].forEach(function(browserType){
|
|
|
|
if (!manifest.browser_specific_settings[browserType]) return;
|
|
|
|
manifest.browser_specific_settings[browserType].id = "CanvasBlocker@kkapsner.de";
|
|
|
|
delete manifest.browser_specific_settings[browserType].update_url;
|
|
|
|
});
|
2020-01-28 23:16:40 +01:00
|
|
|
}
|
|
|
|
if (args.type === "alpha"){
|
2024-02-17 00:02:10 +01:00
|
|
|
manifest.version = await getAlphaVersion(manifest);
|
2024-02-17 00:07:11 +01:00
|
|
|
addAlphaVersionToUpdatesJSON(manifest.version);
|
2020-01-28 23:16:40 +01:00
|
|
|
}
|
|
|
|
else if (args.type === "rc"){
|
|
|
|
manifest.version = getRCVersion(manifest);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
manifest.version = getReleaseVersion(manifest);
|
|
|
|
}
|
|
|
|
|
|
|
|
await fs.promises.writeFile(manifestPath, JSON.stringify(manifest, null, "\t"));
|
|
|
|
|
|
|
|
const childArgs = [
|
|
|
|
"build",
|
|
|
|
"--overwrite-dest",
|
|
|
|
"--ignore-files",
|
|
|
|
"test",
|
|
|
|
"--ignore-files",
|
|
|
|
"versions",
|
|
|
|
"--ignore-files",
|
2023-05-30 19:04:40 +02:00
|
|
|
"crowdin.yml",
|
|
|
|
"--ignore-files",
|
2020-01-28 23:16:40 +01:00
|
|
|
"package*"
|
|
|
|
];
|
|
|
|
const child = child_process.spawn("web-ext", childArgs, {stdio: "inherit"});
|
|
|
|
child.on("close", function(){
|
|
|
|
fs.promises.writeFile(manifestPath, oldManifest);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
run();
|