Fix: build async bug
This commit is contained in:
parent
fdbf369454
commit
8bad0cffff
154
build.js
154
build.js
@ -83,89 +83,93 @@ function dateFormat(fmt, date) {
|
|||||||
return fmt;
|
return fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
const t = new Date();
|
async function main() {
|
||||||
const buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
|
const t = new Date();
|
||||||
const buildDir = "builds";
|
const buildTime = dateFormat("YYYY-mm-dd HH:MM:SS", t);
|
||||||
|
const buildDir = "builds";
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`[Build] BUILD_DIR=${buildDir}, VERSION=${version}, BUILD_TIME=${buildTime}`
|
`[Build] BUILD_DIR=${buildDir}, VERSION=${version}, BUILD_TIME=${buildTime}`
|
||||||
);
|
);
|
||||||
|
|
||||||
clearFolder(buildDir);
|
clearFolder(buildDir);
|
||||||
|
|
||||||
copyFolderRecursiveSync("addon", buildDir);
|
copyFolderRecursiveSync("addon", buildDir);
|
||||||
|
|
||||||
esbuild
|
await esbuild
|
||||||
.build({
|
.build({
|
||||||
entryPoints: ["src/index.ts"],
|
entryPoints: ["src/index.ts"],
|
||||||
bundle: true,
|
bundle: true,
|
||||||
// Entry should be the same as addon/chrome/content/overlay.xul
|
// Entry should be the same as addon/chrome/content/overlay.xul
|
||||||
outfile: path.join(buildDir, "addon/chrome/content/scripts/index.js"),
|
outfile: path.join(buildDir, "addon/chrome/content/scripts/index.js"),
|
||||||
// minify: true,
|
// minify: true,
|
||||||
})
|
})
|
||||||
.catch(() => process.exit(1));
|
.catch(() => process.exit(1));
|
||||||
|
|
||||||
console.log("[Build] Run esbuild OK");
|
console.log("[Build] Run esbuild OK");
|
||||||
|
|
||||||
const optionsAddon = {
|
const optionsAddon = {
|
||||||
files: [
|
files: [
|
||||||
path.join(buildDir, "**/*.rdf"),
|
path.join(buildDir, "**/*.rdf"),
|
||||||
path.join(buildDir, "**/*.dtd"),
|
path.join(buildDir, "**/*.dtd"),
|
||||||
path.join(buildDir, "**/*.xul"),
|
path.join(buildDir, "**/*.xul"),
|
||||||
path.join(buildDir, "**/*.manifest"),
|
path.join(buildDir, "**/*.manifest"),
|
||||||
path.join(buildDir, "addon/defaults", "**/*.js"),
|
path.join(buildDir, "addon/defaults", "**/*.js"),
|
||||||
"update.rdf",
|
"update.rdf",
|
||||||
],
|
],
|
||||||
from: [
|
from: [
|
||||||
/__author__/g,
|
/__author__/g,
|
||||||
/__description__/g,
|
/__description__/g,
|
||||||
/__homepage__/g,
|
/__homepage__/g,
|
||||||
/__releasepage__/g,
|
/__releasepage__/g,
|
||||||
/__updaterdf__/g,
|
/__updaterdf__/g,
|
||||||
/__addonName__/g,
|
/__addonName__/g,
|
||||||
/__addonID__/g,
|
/__addonID__/g,
|
||||||
/__addonRef__/g,
|
/__addonRef__/g,
|
||||||
/__buildVersion__/g,
|
/__buildVersion__/g,
|
||||||
/__buildTime__/g,
|
/__buildTime__/g,
|
||||||
/<em:version>\S*<\/em:version>/g,
|
/<em:version>\S*<\/em:version>/g,
|
||||||
],
|
],
|
||||||
to: [
|
to: [
|
||||||
author,
|
author,
|
||||||
description,
|
description,
|
||||||
homepage,
|
homepage,
|
||||||
releasepage,
|
releasepage,
|
||||||
updaterdf,
|
updaterdf,
|
||||||
addonName,
|
addonName,
|
||||||
addonID,
|
addonID,
|
||||||
addonRef,
|
addonRef,
|
||||||
version,
|
version,
|
||||||
buildTime,
|
buildTime,
|
||||||
`<em:version>${version}</em:version>`,
|
`<em:version>${version}</em:version>`,
|
||||||
],
|
],
|
||||||
countMatches: true,
|
countMatches: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
_ = replace.sync(optionsAddon);
|
_ = replace.sync(optionsAddon);
|
||||||
console.log(
|
console.log(
|
||||||
"[Build] Run replace in ",
|
"[Build] Run replace in ",
|
||||||
_.filter((f) => f.hasChanged).map(
|
_.filter((f) => f.hasChanged).map(
|
||||||
(f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`
|
(f) => `${f.file} : ${f.numReplacements} / ${f.numMatches}`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log("[Build] Replace OK");
|
console.log("[Build] Replace OK");
|
||||||
|
|
||||||
console.log("[Build] Addon prepare OK");
|
console.log("[Build] Addon prepare OK");
|
||||||
|
|
||||||
compressing.zip.compressDir(
|
compressing.zip.compressDir(
|
||||||
path.join(buildDir, "addon"),
|
path.join(buildDir, "addon"),
|
||||||
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.`
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
main();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user