update: scripts import
This commit is contained in:
parent
c2808745c8
commit
d45b72111d
@ -1,6 +1,6 @@
|
|||||||
import { build } from "esbuild";
|
import { build } from "esbuild";
|
||||||
import { zip } from "compressing";
|
import { zip } from "compressing";
|
||||||
import { join, basename } from "path";
|
import path from "path";
|
||||||
import {
|
import {
|
||||||
existsSync,
|
existsSync,
|
||||||
lstatSync,
|
lstatSync,
|
||||||
@ -13,7 +13,7 @@ import {
|
|||||||
} from "fs";
|
} from "fs";
|
||||||
import { env, exit } from "process";
|
import { env, exit } from "process";
|
||||||
import replaceInFile from "replace-in-file";
|
import replaceInFile from "replace-in-file";
|
||||||
const { sync } = replaceInFile;
|
const { replaceInFileSync } = replaceInFile;
|
||||||
import details from "../package.json" assert { type: "json" };
|
import details from "../package.json" assert { type: "json" };
|
||||||
|
|
||||||
const { name, author, description, homepage, version, config } = details;
|
const { name, author, description, homepage, version, config } = details;
|
||||||
@ -28,7 +28,7 @@ function copyFileSync(source, target) {
|
|||||||
// If target is a directory, a new file with the same name will be created
|
// If target is a directory, a new file with the same name will be created
|
||||||
if (existsSync(target)) {
|
if (existsSync(target)) {
|
||||||
if (lstatSync(target).isDirectory()) {
|
if (lstatSync(target).isDirectory()) {
|
||||||
targetFile = join(target, basename(source));
|
targetFile = path.join(target, path.basename(source));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ function copyFolderRecursiveSync(source, target) {
|
|||||||
var files = [];
|
var files = [];
|
||||||
|
|
||||||
// Check if folder needs to be created or integrated
|
// Check if folder needs to be created or integrated
|
||||||
var targetFolder = join(target, basename(source));
|
var targetFolder = path.join(target, path.basename(source));
|
||||||
if (!existsSync(targetFolder)) {
|
if (!existsSync(targetFolder)) {
|
||||||
mkdirSync(targetFolder);
|
mkdirSync(targetFolder);
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ function copyFolderRecursiveSync(source, target) {
|
|||||||
if (lstatSync(source).isDirectory()) {
|
if (lstatSync(source).isDirectory()) {
|
||||||
files = readdirSync(source);
|
files = readdirSync(source);
|
||||||
files.forEach(function (file) {
|
files.forEach(function (file) {
|
||||||
var curSource = join(source, file);
|
var curSource = path.join(source, file);
|
||||||
if (lstatSync(curSource).isDirectory()) {
|
if (lstatSync(curSource).isDirectory()) {
|
||||||
copyFolderRecursiveSync(curSource, targetFolder);
|
copyFolderRecursiveSync(curSource, targetFolder);
|
||||||
} else {
|
} else {
|
||||||
@ -89,13 +89,13 @@ function dateFormat(fmt, date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renameLocaleFiles() {
|
function renameLocaleFiles() {
|
||||||
const localeDir = join(buildDir, "addon/locale");
|
const localeDir = path.join(buildDir, "addon/locale");
|
||||||
const localeFolders = readdirSync(localeDir, { withFileTypes: true })
|
const localeFolders = readdirSync(localeDir, { withFileTypes: true })
|
||||||
.filter((dirent) => dirent.isDirectory())
|
.filter((dirent) => dirent.isDirectory())
|
||||||
.map((dirent) => dirent.name);
|
.map((dirent) => dirent.name);
|
||||||
|
|
||||||
for (const localeSubFolder of localeFolders) {
|
for (const localeSubFolder of localeFolders) {
|
||||||
const localeSubDir = join(localeDir, localeSubFolder);
|
const localeSubDir = path.join(localeDir, localeSubFolder);
|
||||||
const localeSubFiles = readdirSync(localeSubDir, {
|
const localeSubFiles = readdirSync(localeSubDir, {
|
||||||
withFileTypes: true,
|
withFileTypes: true,
|
||||||
})
|
})
|
||||||
@ -105,8 +105,8 @@ function renameLocaleFiles() {
|
|||||||
for (const localeSubFile of localeSubFiles) {
|
for (const localeSubFile of localeSubFiles) {
|
||||||
if (localeSubFile.endsWith(".ftl")) {
|
if (localeSubFile.endsWith(".ftl")) {
|
||||||
renameSync(
|
renameSync(
|
||||||
join(localeSubDir, localeSubFile),
|
path.join(localeSubDir, localeSubFile),
|
||||||
join(localeSubDir, `${config.addonRef}-${localeSubFile}`)
|
path.join(localeSubDir, `${config.addonRef}-${localeSubFile}`)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,11 +130,11 @@ function replaceString() {
|
|||||||
|
|
||||||
const optionsAddon = {
|
const optionsAddon = {
|
||||||
files: [
|
files: [
|
||||||
join(buildDir, "**/*.xhtml"),
|
path.join(buildDir, "**/*.xhtml"),
|
||||||
join(buildDir, "**/*.json"),
|
path.join(buildDir, "**/*.json"),
|
||||||
join(buildDir, "addon/prefs.js"),
|
path.join(buildDir, "addon/prefs.js"),
|
||||||
join(buildDir, "addon/manifest.json"),
|
path.join(buildDir, "addon/manifest.json"),
|
||||||
join(buildDir, "addon/bootstrap.js"),
|
path.join(buildDir, "addon/bootstrap.js"),
|
||||||
"update.json",
|
"update.json",
|
||||||
],
|
],
|
||||||
from: replaceFrom,
|
from: replaceFrom,
|
||||||
@ -142,13 +142,13 @@ function replaceString() {
|
|||||||
countMatches: true,
|
countMatches: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const replaceResult = sync(optionsAddon);
|
const replaceResult = replaceInFileSync(optionsAddon);
|
||||||
|
|
||||||
const localeMessage = new Set();
|
const localeMessage = new Set();
|
||||||
const localeMessageMiss = new Set();
|
const localeMessageMiss = new Set();
|
||||||
|
|
||||||
const replaceResultFlt = sync({
|
const replaceResultFlt = replaceInFileSync({
|
||||||
files: [join(buildDir, "addon/**/*.ftl")],
|
files: [path.join(buildDir, "addon/**/*.ftl")],
|
||||||
processor: (fltContent) => {
|
processor: (fltContent) => {
|
||||||
const lines = fltContent.split("\n");
|
const lines = fltContent.split("\n");
|
||||||
const prefixedLines = lines.map((line) => {
|
const prefixedLines = lines.map((line) => {
|
||||||
@ -167,8 +167,8 @@ function replaceString() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const replaceResultXhtml = sync({
|
const replaceResultXhtml = replaceInFileSync({
|
||||||
files: [join(buildDir, "addon/**/*.xhtml")],
|
files: [path.join(buildDir, "addon/**/*.xhtml")],
|
||||||
processor: (input) => {
|
processor: (input) => {
|
||||||
const matchs = [...input.matchAll(/(data-l10n-id)="(\S*)"/g)];
|
const matchs = [...input.matchAll(/(data-l10n-id)="(\S*)"/g)];
|
||||||
matchs.map((match) => {
|
matchs.map((match) => {
|
||||||
@ -211,7 +211,7 @@ async function esbuild() {
|
|||||||
},
|
},
|
||||||
bundle: true,
|
bundle: true,
|
||||||
target: "firefox102",
|
target: "firefox102",
|
||||||
outfile: join(buildDir, "addon/chrome/content/scripts/index.js"),
|
outfile: path.join(buildDir, "addon/chrome/content/scripts/index.js"),
|
||||||
// Don't turn minify on
|
// Don't turn minify on
|
||||||
// minify: true,
|
// minify: true,
|
||||||
}).catch(() => exit(1));
|
}).catch(() => exit(1));
|
||||||
@ -244,8 +244,8 @@ async function main() {
|
|||||||
console.log("[Build] Addon prepare OK");
|
console.log("[Build] Addon prepare OK");
|
||||||
|
|
||||||
await zip.compressDir(
|
await zip.compressDir(
|
||||||
join(buildDir, "addon"),
|
path.join(buildDir, "addon"),
|
||||||
join(buildDir, `${name}.xpi`),
|
path.join(buildDir, `${name}.xpi`),
|
||||||
{
|
{
|
||||||
ignoreBase: true,
|
ignoreBase: true,
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { execSync } from "child_process";
|
import { execSync } from "child_process";
|
||||||
import { exit } from "process";
|
import { exit } from "process";
|
||||||
import { existsSync, writeFileSync, readFileSync } from "fs";
|
import { existsSync, writeFileSync, readFileSync } from "fs";
|
||||||
import { join, resolve } from "path";
|
import path from "path"
|
||||||
import details from "../package.json" assert { type: "json" };
|
import details from "../package.json" assert { type: "json" };
|
||||||
import cmd from "./zotero-cmd.json" assert { type: "json" };
|
import cmd from "./zotero-cmd.json" assert { type: "json" };
|
||||||
|
|
||||||
@ -13,8 +13,8 @@ if (!existsSync(zoteroBinPath)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (existsSync(profilePath)) {
|
if (existsSync(profilePath)) {
|
||||||
const addonProxyFilePath = join(profilePath, `extensions/${addonID}`);
|
const addonProxyFilePath = path.join(profilePath, `extensions/${addonID}`);
|
||||||
const buildPath = resolve("build/addon");
|
const buildPath = path.resolve("build/addon");
|
||||||
|
|
||||||
function writeAddonProxyFile() {
|
function writeAddonProxyFile() {
|
||||||
writeFileSync(addonProxyFilePath, buildPath);
|
writeFileSync(addonProxyFilePath, buildPath);
|
||||||
@ -33,7 +33,7 @@ if (existsSync(profilePath)) {
|
|||||||
writeAddonProxyFile();
|
writeAddonProxyFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
const prefsPath = join(profilePath, "prefs.js");
|
const prefsPath = path.join(profilePath, "prefs.js");
|
||||||
if (existsSync(prefsPath)) {
|
if (existsSync(prefsPath)) {
|
||||||
const PrefsLines = readFileSync(prefsPath, "utf-8").split("\n");
|
const PrefsLines = readFileSync(prefsPath, "utf-8").split("\n");
|
||||||
const filteredLines = PrefsLines.map((line) => {
|
const filteredLines = PrefsLines.map((line) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user