Commit 41122a67 by yexing

打包测试

parent 744cab38
......@@ -2,7 +2,7 @@
"type": "module",
"scripts": {
"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"
},
"devDependencies": {
......
......@@ -15,26 +15,14 @@ const changeVersion = () => {
}
const changeManifest = (others = {}) => {
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));
}
const inputs = ["src/main.js", "src/popup.js", "src/background.js"];
const conf = [];
const nodeEnv = process.env.NODE_ENV?.trim() || 'DEV';
console.log(`NODE_ENV: ${nodeEnv}`);
nodeEnv == 'TEST' ? changeManifest({ name: 'Test' }) : changeManifest();
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: [
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,
}),
......@@ -42,26 +30,36 @@ inputs.forEach(input => {
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()
]
});
);
}
conf.push({
return {
input,
output: {
file: `dist/js/${fn}.js`,
format: "iife",
name: "G",
},
plugins: [
nodeResolve({
browser: true,
}),
commonjs(),
]
});
});
output,
plugins
}
}
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" }))
} 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;
import { sleep, xpath, createZip, fmt0 } from "./util.js";
import { sleep, xpath, createZip, fmt0, downloadFile } from "./util.js";
import { addLog } from "./timezone.js";
import { createTasks } from "./base.js";
import { Task } from "./task.js";
......@@ -16,15 +16,13 @@ async function webJump() {
).click();
}
};
async function run(options = {}) {
const { uri, plan, sn } = options;
export async function run(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);
let tasks = await createTasks(uri, fromDate, toDate);
tasks = sn ? [tasks.at(sn)] : tasks;
// 在季度周期过滤掉月度任务
// tasks = tasks.filter((x)=>!x.isMonthly);
let moment = 2000, idx = 0, len = tasks.length;
const allData = [], allFn = [], zipFn = `${Task.partnerId} #${key}# ${fromDate}_${toDate}.zip`;
for (const task of tasks) {
......@@ -48,13 +46,14 @@ async function run(options = {}) {
delete data.__route;
const headers = { 'Content-Type': 'application/json' }
await uploadFile(fn, data, { isJson, headers, route });
// const blob = new Blob([data], { "type": "application/json" });
// downloadFile(fn, blob);
if (isDownload) {
const blob = new Blob([data], { "type": "application/json" });
downloadFile(fn, blob);
}
} else {
fn = fn.replace(/\.\w+$/g, ".zip");
allData.push(data);
allFn.push(fn);
// downloadFile(fn, data);
}
console.log(`${pf} end: ${fn}`);
await sleep(moment);
......@@ -64,6 +63,7 @@ async function run(options = {}) {
const form = new FormData();
form.append("zipfile", zip, zipFn);
await uploadFile(zipFn, form);
isDownload && downloadFile(zipFn, zip);
}
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