feat: refactor build process to use Bun, removing Rollup configuration
- Implemented `gererateBunConfig` and `buildWithBun` functions for building projects with Bun. - Added command-line interface using Commander for building projects. - Removed Rollup-related code and configuration. - Deleted unused config module. - Updated TypeScript configuration to extend from a shared config. - Added .npmrc for authentication tokens. - Created bun.config.ts for Bun build configuration. - Added README documentation for usage instructions.
This commit is contained in:
2
.npmrc
Normal file
2
.npmrc
Normal file
@@ -0,0 +1,2 @@
|
||||
//npm.xiongxiao.me/:_authToken=${ME_NPM_TOKEN}
|
||||
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
|
||||
6
bin/code.js
Normal file → Executable file
6
bin/code.js
Normal file → Executable file
@@ -1,3 +1,5 @@
|
||||
#!/usr/bin/env node
|
||||
#!/usr/bin/env bun
|
||||
import { parse } from '../dist/app.js';
|
||||
|
||||
console.log('Hello World');
|
||||
const args = process.argv.slice(2);
|
||||
const result = parse(args);
|
||||
|
||||
3
bun.config.ts
Normal file
3
bun.config.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { buildWithBun } from './src/index.ts'
|
||||
|
||||
await buildWithBun({ meta: import.meta, dts: true })
|
||||
33
package.json
33
package.json
@@ -1,33 +1,36 @@
|
||||
{
|
||||
"name": "@kevisual/code-builder",
|
||||
"version": "0.0.1",
|
||||
"version": "0.0.2",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"main": "src/index.ts",
|
||||
"bin": {
|
||||
"code-builder": "./bin/code.js"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "rollup -c"
|
||||
"start": "bun run dev",
|
||||
"build": "bun ./bun.config.ts",
|
||||
"dev": " bun run build --watch"
|
||||
},
|
||||
"keywords": [],
|
||||
"files": [
|
||||
"dist",
|
||||
"bin",
|
||||
"tsconfig.json"
|
||||
"src"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@kevisual/router": "0.0.7",
|
||||
"@kevisual/use-config": "^1.0.8",
|
||||
"nanoid": "^5.1.2"
|
||||
"@kevisual/use-config": "^1.0.21",
|
||||
"nanoid": "^5.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-commonjs": "^28.0.2",
|
||||
"@rollup/plugin-json": "^6.1.0",
|
||||
"@rollup/plugin-node-resolve": "^16.0.0",
|
||||
"@rollup/plugin-typescript": "^12.1.2",
|
||||
"@types/node": "^22.13.5",
|
||||
"rollup": "^4.34.8",
|
||||
"typescript": "^5.7.3"
|
||||
"@kevisual/types": "^0.0.10",
|
||||
"commander": "^14.0.2",
|
||||
"@types/bun": "^1.3.5",
|
||||
"@types/node": "^25.0.3"
|
||||
}
|
||||
}
|
||||
1629
pnpm-lock.yaml
generated
1629
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
22
readme.md
Normal file
22
readme.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# 对bun的build命令进行封装
|
||||
|
||||
|
||||
## npx
|
||||
使用方式
|
||||
```bash
|
||||
npx @kevisual/code-builder build
|
||||
```
|
||||
|
||||
## global安装
|
||||
```bash
|
||||
npm install -g @kevisual/code-builder
|
||||
code-builder build
|
||||
```
|
||||
|
||||
## 作为库使用
|
||||
|
||||
```ts
|
||||
import { buildWithBun } from '@kevisual/code-builder'
|
||||
|
||||
await buildWithBun({ meta: import.meta, dts: true })
|
||||
```
|
||||
99
src/index.ts
99
src/index.ts
@@ -1,23 +1,78 @@
|
||||
// rollup.config.js
|
||||
|
||||
import typescript from '@rollup/plugin-typescript';
|
||||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import commonjs from '@rollup/plugin-commonjs';
|
||||
import json from '@rollup/plugin-json';
|
||||
|
||||
import { rollup } from 'rollup';
|
||||
|
||||
export const build = async () => {
|
||||
const bundle = await rollup({
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
file: 'dist/app.mjs',
|
||||
format: 'es',
|
||||
},
|
||||
watch: {
|
||||
include: 'src/**',
|
||||
},
|
||||
// @ts-ignore
|
||||
plugins: [typescript(), resolve(), commonjs(), json()],
|
||||
});
|
||||
import { resolvePath } from '@kevisual/use-config';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { BuildConfig } from 'bun';
|
||||
type EntryOptions = {
|
||||
entry?: string;
|
||||
outDir?: string;
|
||||
naming?: string;
|
||||
external?: string[];
|
||||
target?: 'node' | 'browser';
|
||||
dts?: boolean,
|
||||
meta?: { url: string };
|
||||
};
|
||||
export const gererateBunConfig = (options: EntryOptions = {}): { config: BuildConfig, dtsCommand?: string } => {
|
||||
const {
|
||||
entry = 'src/index.ts',
|
||||
outDir = './dist',
|
||||
naming = 'app',
|
||||
external = [],
|
||||
target = 'node',
|
||||
dts = false,
|
||||
meta
|
||||
} = options;
|
||||
const entrypoint = resolvePath(entry, { meta });
|
||||
const outputDir = resolvePath(outDir, { meta });
|
||||
return {
|
||||
config: {
|
||||
target: target,
|
||||
format: 'esm',
|
||||
entrypoints: [entrypoint],
|
||||
outdir: outputDir,
|
||||
naming: {
|
||||
entry: `${naming}.js`,
|
||||
},
|
||||
external,
|
||||
},
|
||||
dtsCommand: dts ? `dts -i ${entry} -o ${naming}.d.ts` : undefined
|
||||
}
|
||||
}
|
||||
|
||||
export const buildWithBun = async (options: EntryOptions = {}) => {
|
||||
const { config, dtsCommand } = gererateBunConfig(options);
|
||||
const meta = options.meta;
|
||||
await Bun.build(config);
|
||||
if (dtsCommand) {
|
||||
execSync(dtsCommand, {
|
||||
stdio: 'inherit',
|
||||
cwd: resolvePath('./', { meta })
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const parse = async () => {
|
||||
const { Command } = await import('commander');
|
||||
const program = new Command();
|
||||
program
|
||||
.name('code-builder')
|
||||
.description('使用 Bun 的代码构建工具')
|
||||
.version('0.0.2');
|
||||
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) => {
|
||||
await buildWithBun({
|
||||
entry: options.entry,
|
||||
outDir: options.outDir,
|
||||
naming: options.naming,
|
||||
target: options.target,
|
||||
dts: options.dts,
|
||||
});
|
||||
});
|
||||
program.addCommand(build);
|
||||
program.parse(process.argv);
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { resolve } from 'path';
|
||||
|
||||
export const runPath = () => {
|
||||
return resolve(process.cwd());
|
||||
};
|
||||
@@ -1,33 +1,24 @@
|
||||
{
|
||||
"extends": "@kevisual/types/json/backend.json",
|
||||
"compilerOptions": {
|
||||
"module": "nodenext",
|
||||
"module": "NodeNext",
|
||||
"target": "esnext",
|
||||
"noImplicitAny": false,
|
||||
"outDir": "./dist",
|
||||
"sourceMap": false,
|
||||
"allowJs": true,
|
||||
"newLine": "LF",
|
||||
"baseUrl": "./",
|
||||
"baseUrl": ".",
|
||||
"typeRoots": [
|
||||
"node_modules/@types",
|
||||
// "node_modules/@kevisual/types"
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@kevisual/types/index.d.ts"
|
||||
],
|
||||
"declaration": true,
|
||||
"noEmit": false,
|
||||
"allowImportingTsExtensions": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"moduleResolution": "NodeNext",
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"esModuleInterop": true,
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
],
|
||||
"@agent/*": [
|
||||
"agent/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"src/**/*",
|
||||
"agent/**/*",
|
||||
],
|
||||
"exclude": [],
|
||||
}
|
||||
Reference in New Issue
Block a user