diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index cc62051..8e06804 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -28,7 +28,7 @@ jobs: - uses: actions/checkout@v4 if: ${{ steps.release.outputs.release_created }} # 设置 Node.js 环境 - - uses: actions/setup-node@v3 + - uses: actions/setup-node@v4 with: # 设置 Node.js 版本 node-version: 20 @@ -42,12 +42,12 @@ jobs: - run: npm install -g pnpm if: ${{ steps.release.outputs.release_created }} # 安装依赖 不安装对等依赖 - - run: pnpm install --ignore-scripts --config.auto-install-peers=false + - run: pnpm install --config.auto-install-peers=false env: NODE_AUTH_TOKEN: ${{ secrets.RELEASE }} if: ${{ steps.release.outputs.release_created }} # 构建输出 - - run: pnpm run build + - run: pnpm run build:npm if: ${{ steps.release.outputs.release_created }} # 删除开发依赖 使用jq工具删除 - run: jq 'del(.devDependencies)' package.json > package.json.tmp && mv package.json.tmp package.json diff --git a/package.json b/package.json index 80218cd..b2a7d28 100644 --- a/package.json +++ b/package.json @@ -132,15 +132,15 @@ "plugins/**" ], "scripts": { - "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && npm run fix", + ".": "node lib/cli/start.js .", + "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json", + "build:npm": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json", + "dev": "node lib/cli/start.js dev", "fix": "eslint lib/**/*.js --fix", "fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.d.ts --fix", "pub": "npm publish --access public", "sort": "npx sort-package-json && sort-json tsconfig.json", - "dev": "node lib/cli/dev.js" - }, - "peerDependencies": { - "node-karin": "link:./lib" + "start": "node lib/cli/start.js start" }, "dependencies": { "art-template": "4.13.2", @@ -172,6 +172,9 @@ "tsx": "^4.16.2", "typescript": "^5.5.3" }, + "peerDependencies": { + "node-karin": "link:./lib" + }, "engines": { "node": ">=18" }, diff --git a/src/cli/dev.ts b/src/cli/dev.ts deleted file mode 100644 index 451834a..0000000 --- a/src/cli/dev.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { KarinCli, Mode, Runner, Lang } from './index' - -const karin = new KarinCli() -karin.start(Mode.Dev, Lang.Js, Runner.Node) diff --git a/src/cli/index.ts b/src/cli/index.ts index a25d0b2..ef6bd00 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -38,6 +38,7 @@ export class KarinCli { /** 入口文件(注意后缀) */ this.file = path.join(path.dirname(this.filename), '../index.js') this.child = null as unknown as ChildProcess + process.env.karin_app_version = this.pkg(true).version } /** diff --git a/src/cli/start.ts b/src/cli/start.ts new file mode 100644 index 0000000..30c3751 --- /dev/null +++ b/src/cli/start.ts @@ -0,0 +1,9 @@ +import { program } from 'commander' +import { KarinCli, Mode, Runner, Lang } from './index' + +const karin = new KarinCli() +program.version(karin.pkg(true).version, '-v, --version', '显示版本号') +program.command('.').description('启动karin').action(() => karin.start(Mode.Prod, Lang.Js, Runner.Node)) +program.command('start').description('启动karin').action(() => karin.start(Mode.Prod, Lang.Js, Runner.Node)) +program.command('dev').description('dev开发模式').action(() => karin.start(Mode.Dev, Lang.Js, Runner.Node)) +program.parse(process.argv) diff --git a/src/core/init/init.ts b/src/core/init/init.ts index b66d78b..676f7ec 100644 --- a/src/core/init/init.ts +++ b/src/core/init/init.ts @@ -4,6 +4,7 @@ import { logger } from 'karin/utils' * 启动日志 */ logger.mark('Karin 启动中...') +logger.mark(`当前版本: ${process.env.karin_app_version}`) logger.mark('https://github.com/KarinJS/Karin') /** * 设置标题 diff --git a/src/types/type/global.ts b/src/types/type/global.ts index dc9699d..15033c1 100644 --- a/src/types/type/global.ts +++ b/src/types/type/global.ts @@ -15,6 +15,8 @@ declare global { karin_app_lang: `${Lang}` /** 运行器 "node" | "tsx" | "pm2" */ karin_app_runner: `${Runner}` + /** 版本 */ + karin_app_version: string } } } diff --git a/tsconfig.json b/tsconfig.json index dd4b7fa..5aceefc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -32,4 +32,4 @@ "resolveFullExtension": ".js", "resolveFullPaths": true } -} \ No newline at end of file +}