Skip to content

Commit

Permalink
fix: start显示版本
Browse files Browse the repository at this point in the history
  • Loading branch information
sj817 committed Aug 18, 2024
1 parent 00c5fa7 commit c823f59
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -172,6 +172,9 @@
"tsx": "^4.16.2",
"typescript": "^5.5.3"
},
"peerDependencies": {
"node-karin": "link:./lib"
},
"engines": {
"node": ">=18"
},
Expand Down
4 changes: 0 additions & 4 deletions src/cli/dev.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/cli/start.ts
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions src/core/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
/**
* 设置标题
Expand Down
2 changes: 2 additions & 0 deletions src/types/type/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ declare global {
karin_app_lang: `${Lang}`
/** 运行器 "node" | "tsx" | "pm2" */
karin_app_runner: `${Runner}`
/** 版本 */
karin_app_version: string
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
"resolveFullExtension": ".js",
"resolveFullPaths": true
}
}
}

0 comments on commit c823f59

Please sign in to comment.