niucloud/admin/scripts/build-addon.cjs
wangchen14709853322 3e71008192 v2.0-beta-20260626
v2框架公测版测试流程请看v2.0-beta.md
2026-06-26 17:56:38 +08:00

57 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 编译单个 addon
*
* 流程generate-addon-entry → vite lib build → sync-addon
* 输出 stagingdist/.addons/{key}/
* 同步部署目录dist/assets/addons/{key}/
*
* 用法:
* node scripts/build-addon.cjs shop
* ADDON_KEY=shop node scripts/build-addon.cjs
*/
const { spawnSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const { ROOT } = require('./addon-utils.cjs')
const key = process.argv[2] || process.env.ADDON_KEY
if (!key) {
console.error('Usage: node build-addon.cjs <addon-key>')
process.exit(1)
}
// 生成 .build/addons/{key}/entry.ts
require('./generate-addon-entry.cjs')
const env = {
...process.env,
ADDON_KEY: key,
NODE_OPTIONS: process.env.NODE_OPTIONS || '--max-old-space-size=4096'
}
console.log(`[build-addon] building "${key}"...`)
const r = spawnSync('npx', ['vite', 'build', '--config', 'vite.config.addon.ts'], {
cwd: ROOT,
env,
stdio: 'inherit',
shell: process.platform === 'win32'
})
if (r.status !== 0) {
console.error(`[build-addon] FAILED: ${key}`)
process.exit(r.status ?? 1)
}
// 复制到 dist/assets/addons 并更新 build-report.json
const sync = spawnSync('node', ['scripts/sync-addon.cjs', key], {
cwd: ROOT,
stdio: 'inherit',
shell: process.platform === 'win32'
})
if (sync.status !== 0) {
process.exit(sync.status ?? 1)
}
console.log(`[build-addon] OK: ${key}`)
process.exit(0)