update: ztoolkit init
This commit is contained in:
parent
a5517736fa
commit
b48953f405
@ -83,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"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,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}`),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,13 +126,14 @@ 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));
|
||||||
|
|
||||||
const optionsAddon = {
|
const optionsAddon = {
|
||||||
files: [
|
files: [
|
||||||
`${buildDir}/addon/**/*.xhtml`,
|
`${buildDir}/addon/**/*.xhtml`,
|
||||||
|
`${buildDir}/addon/**/*.html`,
|
||||||
`${buildDir}/addon/**/*.json`,
|
`${buildDir}/addon/**/*.json`,
|
||||||
`${buildDir}/addon/prefs.js`,
|
`${buildDir}/addon/prefs.js`,
|
||||||
`${buildDir}/addon/manifest.json`,
|
`${buildDir}/addon/manifest.json`,
|
||||||
@ -159,7 +160,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);
|
||||||
@ -180,7 +181,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]);
|
||||||
@ -196,14 +197,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.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,7 +219,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,
|
||||||
@ -229,7 +230,7 @@ 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);
|
||||||
@ -238,7 +239,7 @@ async function main() {
|
|||||||
|
|
||||||
if (isPreRelease) {
|
if (isPreRelease) {
|
||||||
console.log(
|
console.log(
|
||||||
"[Build] [Warn] Running in pre-release mode. update.json will not be replaced."
|
"[Build] [Warn] Running in pre-release mode. update.json will not be replaced.",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
copyFileSync("update-template.json", "update.json");
|
copyFileSync("update-template.json", "update.json");
|
||||||
@ -262,12 +263,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.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ async function onMainWindowLoad(win: Window): Promise<void> {
|
|||||||
// Create ztoolkit for every window
|
// Create ztoolkit for every window
|
||||||
const _ztoolkit = createZToolkit();
|
const _ztoolkit = createZToolkit();
|
||||||
addon.data.ztoolkit = _ztoolkit;
|
addon.data.ztoolkit = _ztoolkit;
|
||||||
_globalThis.ztoolkit = _ztoolkit;
|
|
||||||
|
|
||||||
const popupWin = new ztoolkit.ProgressWindow(config.addonName, {
|
const popupWin = new ztoolkit.ProgressWindow(config.addonName, {
|
||||||
closeOnClick: true,
|
closeOnClick: true,
|
||||||
|
10
src/index.ts
10
src/index.ts
@ -12,16 +12,20 @@ if (!basicTool.getGlobal("Zotero")[config.addonInstance]) {
|
|||||||
defineGlobal("ZoteroPane");
|
defineGlobal("ZoteroPane");
|
||||||
defineGlobal("Zotero_Tabs");
|
defineGlobal("Zotero_Tabs");
|
||||||
_globalThis.addon = new Addon();
|
_globalThis.addon = new Addon();
|
||||||
_globalThis.ztoolkit = addon.data.ztoolkit;
|
defineGlobal("ztoolkit", () => {
|
||||||
|
return _globalThis.addon.data.ztoolkit;
|
||||||
|
});
|
||||||
Zotero[config.addonInstance] = addon;
|
Zotero[config.addonInstance] = addon;
|
||||||
// Trigger addon hook for initialization
|
// Trigger addon hook for initialization
|
||||||
addon.hooks.onStartup();
|
addon.hooks.onStartup();
|
||||||
}
|
}
|
||||||
|
|
||||||
function defineGlobal(name: Parameters<BasicTool["getGlobal"]>[0]) {
|
function defineGlobal(name: Parameters<BasicTool["getGlobal"]>[0]): void;
|
||||||
|
function defineGlobal(name: string, getter: () => any): void;
|
||||||
|
function defineGlobal(name: string, getter?: () => any) {
|
||||||
Object.defineProperty(_globalThis, name, {
|
Object.defineProperty(_globalThis, name, {
|
||||||
get() {
|
get() {
|
||||||
return basicTool.getGlobal(name);
|
return getter ? getter() : basicTool.getGlobal(name);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user