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,26 +15,14 @@ const changeVersion = () => { ...@@ -15,26 +15,14 @@ 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 conf = []; const fn = Path.parse(input);
const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV'; const { isProd = false, outDir = "dist/js/" } = options;
console.log(`NODE_ENV: ${nodeEnv}`); fs.mkdirSync(outDir, { recursive: true });
nodeEnv == 'TEST' ? changeManifest({ name: 'Test' }) : changeManifest(); const plugins = [
inputs.forEach(input => {
const fn = Path.parse(input).name;
if (process.env.NODE_ENV == 'PROD') {
conf.push({
input,
output: {
file: `dist/js/${fn}.min.js`,
format: "umd",
name: "G",
sourcemap: true
},
plugins: [
nodeResolve({ nodeResolve({
browser: true, browser: true,
}), }),
...@@ -42,26 +30,36 @@ inputs.forEach(input => { ...@@ -42,26 +30,36 @@ inputs.forEach(input => {
include: /node_modules/, include: /node_modules/,
requireReturnsDefault: "auto", 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({ babel({
babelHelpers: "bundled", babelHelpers: "bundled",
}), }),
terser() terser()
] );
});
} }
conf.push({ return {
input, input,
output: { output,
file: `dist/js/${fn}.js`, plugins
format: "iife", }
name: "G", }
}, const conf = [];
plugins: [ const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV';
nodeResolve({ console.log(`NODE_ENV: ${nodeEnv}`);
browser: true, if (nodeEnv == 'TEST') {
}), conf.push(pack("test/main.js", { outDir: "test/js" }))
commonjs(), } else {
] changeManifest();
}); const inputs = ["src/main.js", "src/popup.js", "src/background.js"];
}); inputs.forEach(input => conf.push(pack(input, { isProd: nodeEnv == 'PROD' })));
}
export default conf; export default conf;
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