mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
69 lines
2.2 KiB
JavaScript
69 lines
2.2 KiB
JavaScript
import { createHash } from 'node:crypto';
|
|
import { copyFileSync, mkdirSync, readFileSync, writeFileSync, existsSync, rmSync } from 'node:fs';
|
|
import { dirname, resolve } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { build } from 'vite';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const root = resolve(__dirname, '..');
|
|
const outDir = resolve(root, 'dist-features');
|
|
const backendStatic = resolve(
|
|
root,
|
|
'../ecom-dmb-backend/src/main/resources/static/extension-features',
|
|
);
|
|
|
|
async function main() {
|
|
await build({
|
|
configFile: resolve(root, 'vite.features.config.ts'),
|
|
});
|
|
|
|
const entryFile = 'pdd-ad-fee.js';
|
|
const jsPath = resolve(outDir, entryFile);
|
|
const code = readFileSync(jsPath, 'utf8');
|
|
const sha256 = createHash('sha256').update(code).digest('hex');
|
|
|
|
const manifest = {
|
|
schemaVersion: 1,
|
|
updatedAt: new Date().toISOString(),
|
|
features: [
|
|
{
|
|
id: 'pdd-ad-fee',
|
|
name: '拼多多商品推广费同步',
|
|
version: '0.1.0',
|
|
description: '从推广总览读取单日总花费并同步到 BI(壳内嵌入执行;远程包用于版本校验)',
|
|
matchUrlPatterns: [
|
|
'*://yingxiao.pinduoduo.com/*',
|
|
'https://yingxiao.pinduoduo.com/',
|
|
],
|
|
entry: entryFile,
|
|
sha256,
|
|
executionWorld: 'extension',
|
|
},
|
|
],
|
|
};
|
|
|
|
writeFileSync(resolve(outDir, 'manifest.json'), `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
|
|
|
|
// 同步到后端 classpath 静态目录,便于本地联调;部署时也可只拷 dist-features
|
|
if (existsSync(backendStatic)) {
|
|
rmSync(backendStatic, { recursive: true, force: true });
|
|
}
|
|
mkdirSync(backendStatic, { recursive: true });
|
|
copyFileSync(jsPath, resolve(backendStatic, entryFile));
|
|
copyFileSync(resolve(outDir, 'manifest.json'), resolve(backendStatic, 'manifest.json'));
|
|
// sourcemap 可选
|
|
const mapPath = `${jsPath}.map`;
|
|
if (existsSync(mapPath)) {
|
|
copyFileSync(mapPath, resolve(backendStatic, `${entryFile}.map`));
|
|
}
|
|
|
|
console.log(`[build-features] wrote ${outDir}`);
|
|
console.log(`[build-features] synced → ${backendStatic}`);
|
|
console.log(`[build-features] pdd-ad-fee sha256=${sha256}`);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|