feat: refine BoosAPI console and user workspace
This commit is contained in:
@@ -35,9 +35,18 @@ const variants = {
|
||||
|
||||
function run(command, args, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const env = { ...process.env, ...(options.env || {}) };
|
||||
if (options.cleanPackageEnv) {
|
||||
Object.keys(env)
|
||||
.filter((key) => key.startsWith('npm_package_'))
|
||||
.forEach((key) => {
|
||||
delete env[key];
|
||||
});
|
||||
Object.assign(env, options.env || {});
|
||||
}
|
||||
const child = spawn(command, args, {
|
||||
cwd: options.cwd || ROOT,
|
||||
env: { ...process.env, ...(options.env || {}) },
|
||||
env,
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32',
|
||||
});
|
||||
@@ -55,6 +64,11 @@ function selectedVariants() {
|
||||
throw new Error(`Unknown workflow-ui variant: ${VARIANT}. Use external, cloud, or all.`);
|
||||
}
|
||||
|
||||
async function readPackageInfo(dir) {
|
||||
const raw = await fs.readFile(path.join(dir, 'package.json'), 'utf8');
|
||||
return JSON.parse(raw);
|
||||
}
|
||||
|
||||
async function buildVariant(name, config) {
|
||||
const ref = config.ref;
|
||||
const dist = config.dist;
|
||||
@@ -77,17 +91,39 @@ async function buildVariant(name, config) {
|
||||
await run('git', ['submodule', 'update', '--init', '--recursive'], { cwd: dir });
|
||||
}
|
||||
|
||||
const packageInfo = await readPackageInfo(dir);
|
||||
const packageEnv = {
|
||||
npm_package_name: packageInfo.name || '',
|
||||
npm_package_version: packageInfo.version || ref.replace(/^v/, ''),
|
||||
};
|
||||
const hasPnpmLock = await fs.access(path.join(dir, 'pnpm-lock.yaml')).then(() => true, () => false);
|
||||
if (hasPnpmLock) {
|
||||
await run('pnpm', ['install', '--frozen-lockfile'], { cwd: dir });
|
||||
await run('pnpm', ['exec', 'vite', 'build', '--config', 'vite.config.mts'], { cwd: dir });
|
||||
await run('pnpm', ['exec', 'vite', 'build', '--config', 'vite.config.mts'], {
|
||||
cwd: dir,
|
||||
cleanPackageEnv: true,
|
||||
env: packageEnv,
|
||||
});
|
||||
} else {
|
||||
await run('npm', ['ci'], { cwd: dir });
|
||||
await run('npm', ['run', 'build'], { cwd: dir });
|
||||
await run('npm', ['run', 'build'], {
|
||||
cwd: dir,
|
||||
cleanPackageEnv: true,
|
||||
env: packageEnv,
|
||||
});
|
||||
}
|
||||
|
||||
await fs.rm(dist, { recursive: true, force: true });
|
||||
await fs.cp(path.join(dir, 'dist'), dist, { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(dist, 'boosapi-workflow-ui.json'),
|
||||
`${JSON.stringify({
|
||||
variant: name,
|
||||
ref,
|
||||
packageName: packageInfo.name || null,
|
||||
packageVersion: packageInfo.version || null,
|
||||
}, null, 2)}\n`,
|
||||
);
|
||||
console.log(`workflow-ui:${name} installed to ${dist}`);
|
||||
|
||||
if (name === 'cloud') {
|
||||
|
||||
Reference in New Issue
Block a user