feat: 更新构建配置,添加清理输出目录功能并修改版本号
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { buildWithBun } from './src/index.ts'
|
||||
|
||||
await buildWithBun({ dts: true })
|
||||
// await buildWithBun({ dts: true })
|
||||
|
||||
await buildWithBun({ naming: 'app', entry: 'src/index.ts', dts: true });
|
||||
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/code-builder",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"description": "",
|
||||
"main": "src/index.ts",
|
||||
"bin": {
|
||||
@@ -25,9 +25,9 @@
|
||||
"type": "module",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@kevisual/types": "^0.0.10",
|
||||
"commander": "^14.0.2",
|
||||
"@types/bun": "^1.3.5",
|
||||
"@types/node": "^25.0.3"
|
||||
"@kevisual/types": "^0.0.12",
|
||||
"commander": "^14.0.3",
|
||||
"@types/bun": "^1.3.8",
|
||||
"@types/node": "^25.2.0"
|
||||
}
|
||||
}
|
||||
50
pnpm-lock.yaml
generated
50
pnpm-lock.yaml
generated
@@ -9,34 +9,34 @@ importers:
|
||||
.:
|
||||
devDependencies:
|
||||
'@kevisual/types':
|
||||
specifier: ^0.0.10
|
||||
version: 0.0.10
|
||||
specifier: ^0.0.12
|
||||
version: 0.0.12
|
||||
'@types/bun':
|
||||
specifier: ^1.3.5
|
||||
version: 1.3.5
|
||||
specifier: ^1.3.8
|
||||
version: 1.3.8
|
||||
'@types/node':
|
||||
specifier: ^25.0.3
|
||||
version: 25.0.3
|
||||
specifier: ^25.2.0
|
||||
version: 25.2.0
|
||||
commander:
|
||||
specifier: ^14.0.2
|
||||
version: 14.0.2
|
||||
specifier: ^14.0.3
|
||||
version: 14.0.3
|
||||
|
||||
packages:
|
||||
|
||||
'@kevisual/types@0.0.10':
|
||||
resolution: {integrity: sha512-Q73uzzjk9UidumnmCvOpgzqDDvQxsblz22bIFuoiioUFJWwaparx8bpd8ArRyFojicYL1YJoFDzDZ9j9NN8grA==}
|
||||
'@kevisual/types@0.0.12':
|
||||
resolution: {integrity: sha512-zJXH2dosir3jVrQ6QG4i0+iLQeT9gJ3H+cKXs8ReWboxBSYzUZO78XssVeVrFPsJ33iaAqo4q3DWbSS1dWGn7Q==}
|
||||
|
||||
'@types/bun@1.3.5':
|
||||
resolution: {integrity: sha512-RnygCqNrd3srIPEWBd5LFeUYG7plCoH2Yw9WaZGyNmdTEei+gWaHqydbaIRkIkcbXwhBT94q78QljxN0Sk838w==}
|
||||
'@types/bun@1.3.8':
|
||||
resolution: {integrity: sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA==}
|
||||
|
||||
'@types/node@25.0.3':
|
||||
resolution: {integrity: sha512-W609buLVRVmeW693xKfzHeIV6nJGGz98uCPfeXI1ELMLXVeKYZ9m15fAMSaUPBHYLGFsVRcMmSCksQOrZV9BYA==}
|
||||
'@types/node@25.2.0':
|
||||
resolution: {integrity: sha512-DZ8VwRFUNzuqJ5khrvwMXHmvPe+zGayJhr2CDNiKB1WBE1ST8Djl00D0IC4vvNmHMdj6DlbYRIaFE7WHjlDl5w==}
|
||||
|
||||
bun-types@1.3.5:
|
||||
resolution: {integrity: sha512-inmAYe2PFLs0SUbFOWSVD24sg1jFlMPxOjOSSCYqUgn4Hsc3rDc7dFvfVYjFPNHtov6kgUeulV4SxbuIV/stPw==}
|
||||
bun-types@1.3.8:
|
||||
resolution: {integrity: sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q==}
|
||||
|
||||
commander@14.0.2:
|
||||
resolution: {integrity: sha512-TywoWNNRbhoD0BXs1P3ZEScW8W5iKrnbithIl0YH+uCmBd0QpPOA8yc82DS3BIE5Ma6FnBVUsJ7wVUDz4dvOWQ==}
|
||||
commander@14.0.3:
|
||||
resolution: {integrity: sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==}
|
||||
engines: {node: '>=20'}
|
||||
|
||||
undici-types@7.16.0:
|
||||
@@ -44,20 +44,20 @@ packages:
|
||||
|
||||
snapshots:
|
||||
|
||||
'@kevisual/types@0.0.10': {}
|
||||
'@kevisual/types@0.0.12': {}
|
||||
|
||||
'@types/bun@1.3.5':
|
||||
'@types/bun@1.3.8':
|
||||
dependencies:
|
||||
bun-types: 1.3.5
|
||||
bun-types: 1.3.8
|
||||
|
||||
'@types/node@25.0.3':
|
||||
'@types/node@25.2.0':
|
||||
dependencies:
|
||||
undici-types: 7.16.0
|
||||
|
||||
bun-types@1.3.5:
|
||||
bun-types@1.3.8:
|
||||
dependencies:
|
||||
'@types/node': 25.0.3
|
||||
'@types/node': 25.2.0
|
||||
|
||||
commander@14.0.2: {}
|
||||
commander@14.0.3: {}
|
||||
|
||||
undici-types@7.16.0: {}
|
||||
|
||||
@@ -19,4 +19,6 @@ code-builder build
|
||||
import { buildWithBun } from '@kevisual/code-builder'
|
||||
|
||||
await buildWithBun({ meta: import.meta, dts: true })
|
||||
|
||||
await buildWithBun({ naming: 'app', entry: 'src/index.ts' });
|
||||
```
|
||||
45
src/index.ts
45
src/index.ts
@@ -1,6 +1,7 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
import { BuildConfig } from 'bun';
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
type EntryOptions = {
|
||||
/** 入口文件路径 */
|
||||
entry?: string;
|
||||
@@ -20,6 +21,7 @@ type EntryOptions = {
|
||||
* 相对路径基准,比如bun.config.ts所在路径
|
||||
*/
|
||||
meta?: ImportMeta;
|
||||
clean?: boolean;
|
||||
};
|
||||
|
||||
const resolvePath = (cwd: string, relativePath: string) => {
|
||||
@@ -63,6 +65,12 @@ export const gererateBunConfig = (options: EntryOptions = {}): { config: BuildCo
|
||||
|
||||
export const buildWithBun = async (options: EntryOptions = {}) => {
|
||||
const { config, dtsCommand } = gererateBunConfig(options);
|
||||
if (options.clean) {
|
||||
execSync(`rm -rf ${config.outdir}`, {
|
||||
stdio: 'inherit',
|
||||
cwd: options.cwd || process.cwd(),
|
||||
});
|
||||
}
|
||||
await Bun.build(config);
|
||||
if (dtsCommand) {
|
||||
execSync(dtsCommand, {
|
||||
@@ -80,14 +88,16 @@ export const parse = async () => {
|
||||
program
|
||||
.name('code-builder')
|
||||
.description('使用 Bun 的代码构建工具')
|
||||
.version('0.0.2');
|
||||
.version('0.0.3');
|
||||
const build = new Command('build').description('使用 Bun 构建项目');
|
||||
build
|
||||
.option('-e, --entry <path>', '入口文件', 'src/index.ts')
|
||||
.option('-o, --outDir <path>', '输出目录', './dist')
|
||||
.option('-n, --naming <name>', '输出文件命名', 'app')
|
||||
.option('-t, --target <target>', '构建目标 (node 或 browser)', 'node')
|
||||
.option('--dts', '生成 TypeScript 声明文件', false).action(async (options) => {
|
||||
.option('--dts', '生成 TypeScript 声明文件', false)
|
||||
.option('--clean', '清理输出目录', false)
|
||||
.action(async (options) => {
|
||||
const cwd = process.cwd();
|
||||
|
||||
await buildWithBun({
|
||||
@@ -97,8 +107,33 @@ export const parse = async () => {
|
||||
naming: options.naming,
|
||||
target: options.target,
|
||||
dts: options.dts,
|
||||
clean: options.clean,
|
||||
});
|
||||
program.addCommand(build);
|
||||
|
||||
const init = new Command('init').option('-f, --force', 'force').description('初始化build配置文件');
|
||||
init
|
||||
.action((opts) => {
|
||||
const cwd = process.cwd();
|
||||
const configPath = path.join(cwd, 'bun.config.ts');
|
||||
const template = `import { buildWithBun } from '@kevisual/code-builder';
|
||||
|
||||
await buildWithBun({ naming: 'app', entry: 'src/index.ts', dts: true, clean: true });
|
||||
`;
|
||||
const exists = fs.existsSync(configPath);
|
||||
if (exists && !opts?.force) {
|
||||
console.error('bun.config.ts 已存在,使用 --force 强制覆盖');
|
||||
process.exit(1);
|
||||
}
|
||||
execSync(`echo "${template}" > ${configPath}`, {
|
||||
stdio: 'inherit',
|
||||
cwd,
|
||||
});
|
||||
console.log('已生成 bun.config.ts 配置文件');
|
||||
});
|
||||
|
||||
program.addCommand(init);
|
||||
|
||||
program.parse(process.argv);
|
||||
});
|
||||
program.addCommand(build);
|
||||
program.parse(process.argv);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user