Commit 41122a67 by yexing

打包测试

parent 744cab38
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"type": "module", "type": "module",
"scripts": { "scripts": {
"build": "rollup -c && chrome.exe --pack-extension=%cd%/dist --pack-extension-key=%cd%/dist.pem", "build": "rollup -c && chrome.exe --pack-extension=%cd%/dist --pack-extension-key=%cd%/dist.pem",
"build:test": "set NODE_ENV=TEST && rollup -c && chrome.exe --pack-extension=%cd%/dist --pack-extension-key=%cd%/dist.test.pem", "build:test": "set NODE_ENV=TEST && rollup -c",
"lint": "eslint src/**/*.js" "lint": "eslint src/**/*.js"
}, },
"devDependencies": { "devDependencies": {
......
...@@ -15,53 +15,51 @@ const changeVersion = () => { ...@@ -15,53 +15,51 @@ const changeVersion = () => {
} }
const changeManifest = (others = {}) => { const changeManifest = (others = {}) => {
let manifest = JSON.parse(fs.readFileSync("manifest.json", { encoding: "utf8" })); let manifest = JSON.parse(fs.readFileSync("manifest.json", { encoding: "utf8" }));
manifest = {...manifest, version: changeVersion(), ...others} manifest = { ...manifest, version: changeVersion(), ...others }
fs.writeFileSync("dist/manifest.json", JSON.stringify(manifest)); fs.writeFileSync("dist/manifest.json", JSON.stringify(manifest));
} }
const inputs = ["src/main.js", "src/popup.js", "src/background.js"]; const pack = (input, options = {}) => {
const fn = Path.parse(input);
const { isProd = false, outDir = "dist/js/" } = options;
fs.mkdirSync(outDir, { recursive: true });
const plugins = [
nodeResolve({
browser: true,
}),
commonjs({
include: /node_modules/,
requireReturnsDefault: "auto",
}),
]
const output = {
file: Path.join(outDir, fn.base),
format: "iife",
name: "G",
}
if (isProd) {
output.file = Path.join(outDir, `${fn.name}.min.js`);
output.sourcemap = true;
plugins.push(
babel({
babelHelpers: "bundled",
}),
terser()
);
}
return {
input,
output,
plugins
}
}
const conf = []; const conf = [];
const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV'; const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV';
console.log(`NODE_ENV: ${nodeEnv}`); console.log(`NODE_ENV: ${nodeEnv}`);
nodeEnv == 'TEST' ? changeManifest({ name: 'Test' }) : changeManifest(); if (nodeEnv == 'TEST') {
inputs.forEach(input => { conf.push(pack("test/main.js", { outDir: "test/js" }))
const fn = Path.parse(input).name; } else {
if (process.env.NODE_ENV == 'PROD') { changeManifest();
conf.push({ const inputs = ["src/main.js", "src/popup.js", "src/background.js"];
input, inputs.forEach(input => conf.push(pack(input, { isProd: nodeEnv == 'PROD' })));
output: { }
file: `dist/js/${fn}.min.js`, export default conf;
format: "umd",
name: "G",
sourcemap: true
},
plugins: [
nodeResolve({
browser: true,
}),
commonjs({
include: /node_modules/,
requireReturnsDefault: "auto",
}),
babel({
babelHelpers: "bundled",
}),
terser()
]
});
}
conf.push({
input,
output: {
file: `dist/js/${fn}.js`,
format: "iife",
name: "G",
},
plugins: [
nodeResolve({
browser: true,
}),
commonjs(),
]
});
});
export default conf;
\ No newline at end of file
import { sleep, xpath, createZip, fmt0 } from "./util.js"; import { sleep, xpath, createZip, fmt0, downloadFile } from "./util.js";
import { addLog } from "./timezone.js"; import { addLog } from "./timezone.js";
import { createTasks } from "./base.js"; import { createTasks } from "./base.js";
import { Task } from "./task.js"; import { Task } from "./task.js";
...@@ -16,15 +16,13 @@ async function webJump() { ...@@ -16,15 +16,13 @@ async function webJump() {
).click(); ).click();
} }
}; };
async function run(options = {}) { export async function run(options = {}) {
const { uri, plan, sn } = options; const { uri, plan, sn, isDownload=false } = options;
plan.period ||= [fmt0(new Date(), -10), fmt0(new Date(), -1)]; plan.period ||= [fmt0(new Date(), -10), fmt0(new Date(), -1)];
const [fromDate, toDate] = plan.period; const [fromDate, toDate] = plan.period;
const [key, { name }] = Object.entries(TABLE).find((item) => item[1].uri === uri); const [key, { name }] = Object.entries(TABLE).find((item) => item[1].uri === uri);
let tasks = await createTasks(uri, fromDate, toDate); let tasks = await createTasks(uri, fromDate, toDate);
tasks = sn ? [tasks.at(sn)] : tasks; tasks = sn ? [tasks.at(sn)] : tasks;
// 在季度周期过滤掉月度任务
// tasks = tasks.filter((x)=>!x.isMonthly);
let moment = 2000, idx = 0, len = tasks.length; let moment = 2000, idx = 0, len = tasks.length;
const allData = [], allFn = [], zipFn = `${Task.partnerId} #${key}# ${fromDate}_${toDate}.zip`; const allData = [], allFn = [], zipFn = `${Task.partnerId} #${key}# ${fromDate}_${toDate}.zip`;
for (const task of tasks) { for (const task of tasks) {
...@@ -48,13 +46,14 @@ async function run(options = {}) { ...@@ -48,13 +46,14 @@ async function run(options = {}) {
delete data.__route; delete data.__route;
const headers = { 'Content-Type': 'application/json' } const headers = { 'Content-Type': 'application/json' }
await uploadFile(fn, data, { isJson, headers, route }); await uploadFile(fn, data, { isJson, headers, route });
// const blob = new Blob([data], { "type": "application/json" }); if (isDownload) {
// downloadFile(fn, blob); const blob = new Blob([data], { "type": "application/json" });
downloadFile(fn, blob);
}
} else { } else {
fn = fn.replace(/\.\w+$/g, ".zip"); fn = fn.replace(/\.\w+$/g, ".zip");
allData.push(data); allData.push(data);
allFn.push(fn); allFn.push(fn);
// downloadFile(fn, data);
} }
console.log(`${pf} end: ${fn}`); console.log(`${pf} end: ${fn}`);
await sleep(moment); await sleep(moment);
...@@ -64,6 +63,7 @@ async function run(options = {}) { ...@@ -64,6 +63,7 @@ async function run(options = {}) {
const form = new FormData(); const form = new FormData();
form.append("zipfile", zip, zipFn); form.append("zipfile", zip, zipFn);
await uploadFile(zipFn, form); await uploadFile(zipFn, form);
isDownload && downloadFile(zipFn, zip);
} }
addLog(`${name} 运行完成`); addLog(`${name} 运行完成`);
} }
......
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