add: prerelease do not change update.json
This commit is contained in:
parent
3c780febc9
commit
a5517736fa
@ -22,6 +22,8 @@ const t = new Date();
|
|||||||
const buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", new Date());
|
const buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", new Date());
|
||||||
const buildDir = "build";
|
const buildDir = "build";
|
||||||
|
|
||||||
|
const isPreRelease = version.includes("-");
|
||||||
|
|
||||||
function copyFileSync(source, target) {
|
function copyFileSync(source, target) {
|
||||||
var targetFile = target;
|
var targetFile = target;
|
||||||
|
|
||||||
@ -81,7 +83,7 @@ function dateFormat(fmt, date) {
|
|||||||
if (ret) {
|
if (ret) {
|
||||||
fmt = fmt.replace(
|
fmt = fmt.replace(
|
||||||
ret[1],
|
ret[1],
|
||||||
ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0"),
|
ret[1].length == 1 ? opt[k] : opt[k].padStart(ret[1].length, "0")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +108,7 @@ function renameLocaleFiles() {
|
|||||||
if (localeSubFile.endsWith(".ftl")) {
|
if (localeSubFile.endsWith(".ftl")) {
|
||||||
renameSync(
|
renameSync(
|
||||||
path.join(localeSubDir, localeSubFile),
|
path.join(localeSubDir, localeSubFile),
|
||||||
path.join(localeSubDir, `${config.addonRef}-${localeSubFile}`),
|
path.join(localeSubDir, `${config.addonRef}-${localeSubFile}`)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,7 +126,7 @@ function replaceString() {
|
|||||||
const replaceTo = [author, description, homepage, version, buildTime];
|
const replaceTo = [author, description, homepage, version, buildTime];
|
||||||
|
|
||||||
replaceFrom.push(
|
replaceFrom.push(
|
||||||
...Object.keys(config).map((k) => new RegExp(`__${k}__`, "g")),
|
...Object.keys(config).map((k) => new RegExp(`__${k}__`, "g"))
|
||||||
);
|
);
|
||||||
replaceTo.push(...Object.values(config));
|
replaceTo.push(...Object.values(config));
|
||||||
|
|
||||||
@ -135,13 +137,16 @@ function replaceString() {
|
|||||||
`${buildDir}/addon/prefs.js`,
|
`${buildDir}/addon/prefs.js`,
|
||||||
`${buildDir}/addon/manifest.json`,
|
`${buildDir}/addon/manifest.json`,
|
||||||
`${buildDir}/addon/bootstrap.js`,
|
`${buildDir}/addon/bootstrap.js`,
|
||||||
"update.json",
|
|
||||||
],
|
],
|
||||||
from: replaceFrom,
|
from: replaceFrom,
|
||||||
to: replaceTo,
|
to: replaceTo,
|
||||||
countMatches: true,
|
countMatches: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!isPreRelease) {
|
||||||
|
optionsAddon.files.push("update.json");
|
||||||
|
}
|
||||||
|
|
||||||
const replaceResult = replaceInFileSync(optionsAddon);
|
const replaceResult = replaceInFileSync(optionsAddon);
|
||||||
|
|
||||||
const localeMessage = new Set();
|
const localeMessage = new Set();
|
||||||
@ -154,7 +159,7 @@ function replaceString() {
|
|||||||
const prefixedLines = lines.map((line) => {
|
const prefixedLines = lines.map((line) => {
|
||||||
// https://regex101.com/r/lQ9x5p/1
|
// https://regex101.com/r/lQ9x5p/1
|
||||||
const match = line.match(
|
const match = line.match(
|
||||||
/^(?<message>[a-zA-Z]\S*)([ ]*=[ ]*)(?<pattern>.*)$/m,
|
/^(?<message>[a-zA-Z]\S*)([ ]*=[ ]*)(?<pattern>.*)$/m
|
||||||
);
|
);
|
||||||
if (match) {
|
if (match) {
|
||||||
localeMessage.add(match.groups.message);
|
localeMessage.add(match.groups.message);
|
||||||
@ -175,7 +180,7 @@ function replaceString() {
|
|||||||
if (localeMessage.has(match[2])) {
|
if (localeMessage.has(match[2])) {
|
||||||
input = input.replace(
|
input = input.replace(
|
||||||
match[0],
|
match[0],
|
||||||
`${match[1]}="${config.addonRef}-${match[2]}"`,
|
`${match[1]}="${config.addonRef}-${match[2]}"`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
localeMessageMiss.add(match[2]);
|
localeMessageMiss.add(match[2]);
|
||||||
@ -191,14 +196,14 @@ function replaceString() {
|
|||||||
.filter((f) => f.hasChanged)
|
.filter((f) => f.hasChanged)
|
||||||
.map((f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`),
|
.map((f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`),
|
||||||
replaceResultFlt.filter((f) => f.hasChanged).map((f) => `${f.file} : OK`),
|
replaceResultFlt.filter((f) => f.hasChanged).map((f) => `${f.file} : OK`),
|
||||||
replaceResultXhtml.filter((f) => f.hasChanged).map((f) => `${f.file} : OK`),
|
replaceResultXhtml.filter((f) => f.hasChanged).map((f) => `${f.file} : OK`)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (localeMessageMiss.size !== 0) {
|
if (localeMessageMiss.size !== 0) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`[Build] [Warn] Fluent message [${new Array(
|
`[Build] [Warn] Fluent message [${new Array(
|
||||||
...localeMessageMiss,
|
...localeMessageMiss
|
||||||
)}] do not exsit in addon's locale files.`,
|
)}] do not exsit in addon's locale files.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,7 +218,7 @@ async function esbuild() {
|
|||||||
target: "firefox102",
|
target: "firefox102",
|
||||||
outfile: path.join(
|
outfile: path.join(
|
||||||
buildDir,
|
buildDir,
|
||||||
`addon/chrome/content/scripts/${config.addonRef}.js`,
|
`addon/chrome/content/scripts/${config.addonRef}.js`
|
||||||
),
|
),
|
||||||
// Don't turn minify on
|
// Don't turn minify on
|
||||||
// minify: true,
|
// minify: true,
|
||||||
@ -224,14 +229,20 @@ async function main() {
|
|||||||
console.log(
|
console.log(
|
||||||
`[Build] BUILD_DIR=${buildDir}, VERSION=${version}, BUILD_TIME=${buildTime}, ENV=${[
|
`[Build] BUILD_DIR=${buildDir}, VERSION=${version}, BUILD_TIME=${buildTime}, ENV=${[
|
||||||
env.NODE_ENV,
|
env.NODE_ENV,
|
||||||
]}`,
|
]}`
|
||||||
);
|
);
|
||||||
|
|
||||||
clearFolder(buildDir);
|
clearFolder(buildDir);
|
||||||
|
|
||||||
copyFolderRecursiveSync("addon", buildDir);
|
copyFolderRecursiveSync("addon", buildDir);
|
||||||
|
|
||||||
|
if (isPreRelease) {
|
||||||
|
console.log(
|
||||||
|
"[Build] [Warn] Running in pre-release mode. update.json will not be replaced."
|
||||||
|
);
|
||||||
|
} else {
|
||||||
copyFileSync("update-template.json", "update.json");
|
copyFileSync("update-template.json", "update.json");
|
||||||
|
}
|
||||||
|
|
||||||
await esbuild();
|
await esbuild();
|
||||||
|
|
||||||
@ -251,12 +262,12 @@ async function main() {
|
|||||||
path.join(buildDir, `${name}.xpi`),
|
path.join(buildDir, `${name}.xpi`),
|
||||||
{
|
{
|
||||||
ignoreBase: true,
|
ignoreBase: true,
|
||||||
},
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("[Build] Addon pack OK");
|
console.log("[Build] Addon pack OK");
|
||||||
console.log(
|
console.log(
|
||||||
`[Build] Finished in ${(new Date().getTime() - t.getTime()) / 1000} s.`,
|
`[Build] Finished in ${(new Date().getTime() - t.getTime()) / 1000} s.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user