ci(editor-core): 添加npm发布流程支持
This commit is contained in:
3
.github/workflows/release.yml
vendored
3
.github/workflows/release.yml
vendored
@@ -10,6 +10,7 @@ on:
|
|||||||
options:
|
options:
|
||||||
- core
|
- core
|
||||||
- behavior-tree
|
- behavior-tree
|
||||||
|
- editor-core
|
||||||
version_type:
|
version_type:
|
||||||
description: '版本更新类型'
|
description: '版本更新类型'
|
||||||
required: true
|
required: true
|
||||||
@@ -51,7 +52,7 @@ jobs:
|
|||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
- name: Build core package (if needed)
|
- name: Build core package (if needed)
|
||||||
if: ${{ github.event.inputs.package == 'behavior-tree' }}
|
if: ${{ github.event.inputs.package == 'behavior-tree' || github.event.inputs.package == 'editor-core' }}
|
||||||
run: |
|
run: |
|
||||||
cd packages/core
|
cd packages/core
|
||||||
npm run build
|
npm run build
|
||||||
|
|||||||
95
packages/editor-core/build-rollup.cjs
Normal file
95
packages/editor-core/build-rollup.cjs
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const { execSync } = require('child_process');
|
||||||
|
|
||||||
|
console.log('🚀 使用 Rollup 构建npm包...');
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
try {
|
||||||
|
// 清理旧的dist目录
|
||||||
|
if (fs.existsSync('./dist')) {
|
||||||
|
console.log('🧹 清理旧的构建文件...');
|
||||||
|
execSync('rimraf ./dist', { stdio: 'inherit' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行Rollup构建
|
||||||
|
console.log('📦 执行 Rollup 构建...');
|
||||||
|
execSync('npx rollup -c rollup.config.cjs', { stdio: 'inherit' });
|
||||||
|
|
||||||
|
// 生成package.json
|
||||||
|
console.log('📋 生成 package.json...');
|
||||||
|
generatePackageJson();
|
||||||
|
|
||||||
|
// 输出构建结果
|
||||||
|
showBuildResults();
|
||||||
|
|
||||||
|
console.log('✅ 构建完成!');
|
||||||
|
console.log('\n🚀 发布命令:');
|
||||||
|
console.log('cd dist && npm publish');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 构建失败:', error.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generatePackageJson() {
|
||||||
|
const sourcePackage = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||||
|
|
||||||
|
const distPackage = {
|
||||||
|
name: sourcePackage.name,
|
||||||
|
version: sourcePackage.version,
|
||||||
|
description: sourcePackage.description,
|
||||||
|
main: 'index.cjs',
|
||||||
|
module: 'index.mjs',
|
||||||
|
unpkg: 'index.umd.js',
|
||||||
|
types: 'index.d.ts',
|
||||||
|
exports: {
|
||||||
|
'.': {
|
||||||
|
import: './index.mjs',
|
||||||
|
require: './index.cjs',
|
||||||
|
types: './index.d.ts'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
files: [
|
||||||
|
'index.mjs',
|
||||||
|
'index.mjs.map',
|
||||||
|
'index.cjs',
|
||||||
|
'index.cjs.map',
|
||||||
|
'index.umd.js',
|
||||||
|
'index.umd.js.map',
|
||||||
|
'index.d.ts'
|
||||||
|
],
|
||||||
|
keywords: sourcePackage.keywords,
|
||||||
|
author: sourcePackage.author,
|
||||||
|
license: sourcePackage.license,
|
||||||
|
repository: sourcePackage.repository,
|
||||||
|
bugs: sourcePackage.bugs,
|
||||||
|
homepage: sourcePackage.homepage,
|
||||||
|
peerDependencies: {
|
||||||
|
'@esengine/ecs-framework': '^2.2.8'
|
||||||
|
},
|
||||||
|
engines: {
|
||||||
|
node: '>=16.0.0'
|
||||||
|
},
|
||||||
|
sideEffects: false
|
||||||
|
};
|
||||||
|
|
||||||
|
fs.writeFileSync('./dist/package.json', JSON.stringify(distPackage, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
function showBuildResults() {
|
||||||
|
const distDir = './dist';
|
||||||
|
const files = ['index.mjs', 'index.cjs', 'index.umd.js', 'index.d.ts'];
|
||||||
|
|
||||||
|
console.log('\n📊 构建结果:');
|
||||||
|
files.forEach(file => {
|
||||||
|
const filePath = path.join(distDir, file);
|
||||||
|
if (fs.existsSync(filePath)) {
|
||||||
|
const size = fs.statSync(filePath).size;
|
||||||
|
console.log(` ${file}: ${(size / 1024).toFixed(1)}KB`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
main().catch(console.error);
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
"build": "npm run build:ts",
|
"build": "npm run build:ts",
|
||||||
"build:watch": "tsc --watch",
|
"build:watch": "tsc --watch",
|
||||||
"rebuild": "npm run clean && npm run build",
|
"rebuild": "npm run clean && npm run build",
|
||||||
|
"build:npm": "npm run build && node build-rollup.cjs",
|
||||||
"test": "jest --config jest.config.cjs",
|
"test": "jest --config jest.config.cjs",
|
||||||
"test:watch": "jest --watch --config jest.config.cjs",
|
"test:watch": "jest --watch --config jest.config.cjs",
|
||||||
"test:coverage": "jest --coverage --config jest.config.cjs"
|
"test:coverage": "jest --coverage --config jest.config.cjs"
|
||||||
@@ -39,15 +40,27 @@
|
|||||||
"author": "yhh",
|
"author": "yhh",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.28.3",
|
||||||
|
"@babel/plugin-transform-nullish-coalescing-operator": "^7.27.1",
|
||||||
|
"@babel/plugin-transform-optional-chaining": "^7.27.1",
|
||||||
|
"@babel/preset-env": "^7.28.3",
|
||||||
|
"@rollup/plugin-babel": "^6.0.4",
|
||||||
|
"@rollup/plugin-commonjs": "^28.0.3",
|
||||||
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||||
|
"@rollup/plugin-terser": "^0.4.4",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
"@types/node": "^20.19.17",
|
"@types/node": "^20.19.17",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"rimraf": "^5.0.0",
|
"rimraf": "^5.0.0",
|
||||||
|
"rollup": "^4.42.0",
|
||||||
|
"rollup-plugin-dts": "^6.2.1",
|
||||||
"ts-jest": "^29.4.0",
|
"ts-jest": "^29.4.0",
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^5.8.3"
|
||||||
},
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@esengine/ecs-framework": "^2.2.8"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@esengine/ecs-framework": "file:../core",
|
|
||||||
"tslib": "^2.8.1"
|
"tslib": "^2.8.1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
132
packages/editor-core/rollup.config.cjs
Normal file
132
packages/editor-core/rollup.config.cjs
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
const resolve = require('@rollup/plugin-node-resolve');
|
||||||
|
const commonjs = require('@rollup/plugin-commonjs');
|
||||||
|
const terser = require('@rollup/plugin-terser');
|
||||||
|
const babel = require('@rollup/plugin-babel');
|
||||||
|
const dts = require('rollup-plugin-dts').default;
|
||||||
|
const { readFileSync } = require('fs');
|
||||||
|
|
||||||
|
const pkg = JSON.parse(readFileSync('./package.json', 'utf8'));
|
||||||
|
|
||||||
|
const banner = `/**
|
||||||
|
* @esengine/editor-core v${pkg.version}
|
||||||
|
* ECS Framework Editor Core - Plugin-based editor framework
|
||||||
|
*
|
||||||
|
* @author ${pkg.author}
|
||||||
|
* @license ${pkg.license}
|
||||||
|
*/`;
|
||||||
|
|
||||||
|
const external = ['@esengine/ecs-framework'];
|
||||||
|
|
||||||
|
const commonPlugins = [
|
||||||
|
resolve({
|
||||||
|
browser: true,
|
||||||
|
preferBuiltins: false
|
||||||
|
}),
|
||||||
|
commonjs({
|
||||||
|
include: /node_modules/
|
||||||
|
}),
|
||||||
|
babel({
|
||||||
|
babelHelpers: 'bundled',
|
||||||
|
exclude: 'node_modules/**',
|
||||||
|
extensions: ['.js', '.ts']
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports = [
|
||||||
|
// ES模块构建
|
||||||
|
{
|
||||||
|
input: 'bin/index.js',
|
||||||
|
output: {
|
||||||
|
file: 'dist/index.mjs',
|
||||||
|
format: 'es',
|
||||||
|
banner,
|
||||||
|
sourcemap: true,
|
||||||
|
exports: 'named'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
...commonPlugins,
|
||||||
|
terser({
|
||||||
|
format: {
|
||||||
|
comments: /^!/
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
external,
|
||||||
|
treeshake: {
|
||||||
|
moduleSideEffects: false,
|
||||||
|
propertyReadSideEffects: false,
|
||||||
|
unknownGlobalSideEffects: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// CommonJS构建
|
||||||
|
{
|
||||||
|
input: 'bin/index.js',
|
||||||
|
output: {
|
||||||
|
file: 'dist/index.cjs',
|
||||||
|
format: 'cjs',
|
||||||
|
banner,
|
||||||
|
sourcemap: true,
|
||||||
|
exports: 'named'
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
...commonPlugins,
|
||||||
|
terser({
|
||||||
|
format: {
|
||||||
|
comments: /^!/
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
external,
|
||||||
|
treeshake: {
|
||||||
|
moduleSideEffects: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// UMD构建
|
||||||
|
{
|
||||||
|
input: 'bin/index.js',
|
||||||
|
output: {
|
||||||
|
file: 'dist/index.umd.js',
|
||||||
|
format: 'umd',
|
||||||
|
name: 'EditorCore',
|
||||||
|
banner,
|
||||||
|
sourcemap: true,
|
||||||
|
exports: 'named',
|
||||||
|
globals: {
|
||||||
|
'@esengine/ecs-framework': 'ECS'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
...commonPlugins,
|
||||||
|
terser({
|
||||||
|
format: {
|
||||||
|
comments: /^!/
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
external,
|
||||||
|
treeshake: {
|
||||||
|
moduleSideEffects: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// 类型定义构建
|
||||||
|
{
|
||||||
|
input: 'bin/index.d.ts',
|
||||||
|
output: {
|
||||||
|
file: 'dist/index.d.ts',
|
||||||
|
format: 'es',
|
||||||
|
banner: `/**
|
||||||
|
* @esengine/editor-core v${pkg.version}
|
||||||
|
* TypeScript definitions
|
||||||
|
*/`
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
dts({
|
||||||
|
respectExternal: true
|
||||||
|
})
|
||||||
|
],
|
||||||
|
external
|
||||||
|
}
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user