Commit 748ce478 by yexing

替换测试

parent 41122a67
......@@ -10,6 +10,7 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.2",
"@rollup/plugin-node-resolve": "^16.0.0",
"@rollup/plugin-replace": "^6.0.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/chrome": "^0.0.306",
"@types/node": "^22.13.10",
......
import babel from "@rollup/plugin-babel";
import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import replace from '@rollup/plugin-replace';
import babel from "@rollup/plugin-babel";
import terser from "@rollup/plugin-terser";
import Path from "path";
import fs from "fs";
......@@ -20,7 +21,7 @@ const changeManifest = (others = {}) => {
}
const pack = (input, options = {}) => {
const fn = Path.parse(input);
const { isProd = false, outDir = "dist/js/" } = options;
const { isProd = false, isReplace = false, outDir = "dist/js/" } = options;
fs.mkdirSync(outDir, { recursive: true });
const plugins = [
nodeResolve({
......@@ -36,6 +37,14 @@ const pack = (input, options = {}) => {
format: "iife",
name: "G",
}
if (isReplace) {
plugins.push(
replace({
'chrome': 'undefined',
preventAssignment: true
}),
);
}
if (isProd) {
output.file = Path.join(outDir, `${fn.name}.min.js`);
output.sourcemap = true;
......@@ -56,7 +65,7 @@ const conf = [];
const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV';
console.log(`NODE_ENV: ${nodeEnv}`);
if (nodeEnv == 'TEST') {
conf.push(pack("test/main.js", { outDir: "test/js" }))
conf.push(pack("test/main.js", { outDir: "test/js", isReplace: true }));
} else {
changeManifest();
const inputs = ["src/main.js", "src/popup.js", "src/background.js"];
......
......@@ -17,7 +17,7 @@ async function webJump() {
}
};
export async function run(options = {}) {
const { uri, plan, sn, isDownload=false } = options;
const { uri, plan, sn, isDownload = false } = options;
plan.period ||= [fmt0(new Date(), -10), fmt0(new Date(), -1)];
const [fromDate, toDate] = plan.period;
const [key, { name }] = Object.entries(TABLE).find((item) => item[1].uri === uri);
......@@ -67,18 +67,20 @@ export async function run(options = {}) {
}
addLog(`${name} 运行完成`);
}
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
(async () => {
try {
if (msg.type === "jump") {
await webJump();
} else if (msg.type === "run") {
await run(msg.data); // 默认
if (typeof chrome !== 'undefined' && chrome.runtime) {
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
(async () => {
try {
if (msg.type === "jump") {
await webJump();
} else if (msg.type === "run") {
await run(msg.data); // 默认
}
sendResponse({ status: "ok" });
} catch (err) {
sendResponse({ status: "error", error: err.message });
}
sendResponse({ status: "ok" });
} catch (err) {
sendResponse({ status: "error", error: err.message });
}
})();
return true;
});
})();
return true;
});
}
......@@ -81,7 +81,11 @@ export const makeLogEntry = (message) => {
message
}
};
export const addLog = (message, push) => chrome.runtime.sendMessage({ type: "addLog", data: makeLogEntry(message), push });
export const addLog = (message, push) => {
if (typeof chrome !== 'undefined' && chrome.runtime) {
chrome.runtime.sendMessage({ type: "addLog", data: makeLogEntry(message), push });
}
};
const checkTime = (time) => {
if (!time.isValid()) throw new Error("无效时间");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment