envision-cli/assistant/bun.config.mjs
2025-05-17 03:32:38 +08:00

67 lines
1.6 KiB
JavaScript

// @ts-check
// https://bun.sh/docs/bundler
import path from 'node:path';
import pkg from './package.json';
import fs from 'node:fs';
// bun run src/index.ts --
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
/**
*
* @param {string} p
* @returns
*/
export const w = (p) => path.join(__dirname, p);
await Bun.build({
target: 'node',
format: 'esm',
entrypoints: [w('./src/index.ts')],
outdir: w('./dist'),
naming: {
entry: 'assistant.js',
},
external: ['pm2'],
define: {
ENVISION_VERSION: JSON.stringify(pkg.version),
},
env: 'ENVISION_*',
});
await Bun.build({
target: 'node',
format: 'esm',
entrypoints: [w('./src/server.ts')],
outdir: w('./dist'),
naming: {
entry: 'assistant-server.js',
},
define: {
ENVISION_VERSION: JSON.stringify(pkg.version),
},
external: ['pm2'],
env: 'ENVISION_*',
});
// const copyDist = ['dist', 'bin'];
const copyDist = ['dist'];
export const copyFileToEnvision = async () => {
const src = copyDist.map((dir) => {
return { absolute: path.join(__dirname, dir), name: dir };
});
const dest = path.join(__dirname, '..');
for (const dir of src) {
const files = fs.readdirSync(dir.absolute);
for (const file of files) {
const srcFile = path.join(dir.absolute, file);
const destFile = path.join(dest, dir.name, file);
try {
fs.copyFileSync(srcFile, destFile);
} catch (err) {
console.error('Error copying files: origin: ', srcFile, 'dest: ', destFile);
console.error('Error copying files:', err);
continue;
}
}
}
};
await copyFileToEnvision();