Skip to content

Commit

Permalink
fix: 更新npx脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
CakmLexi committed Jul 8, 2024
1 parent afe270b commit b78219e
Show file tree
Hide file tree
Showing 9 changed files with 387 additions and 87 deletions.
42 changes: 42 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: 提交Bug / Submit Bug
about: 向我们报告一个Bug以帮助我们改进
title: 'Bug: '
labels: bug
---

警告: 在进一步操作之前,请检查下列选项。如果您忽视此模板或者没有提供关键信息,您的 Issue 将直接被关闭

- 确保您使用的是最新版本的`Karin`
- 确保您的问题尚未在 Issues 列表中提出.
- 确保您的问题不是由于您的代码错误导致的.

## 描述问题

简要描述遇到的问题。

## 复现步骤

详细描述如何复现该问题:

1. 第一步
2. 第二步
3. ...

## 预期行为

预期应该发生什么?

## 实际行为

实际发生了什么?

## 环境信息

- 操作系统:
- Node.js 版本:
- 项目版本:

## 附加信息

任何额外的上下文或截图。
37 changes: 37 additions & 0 deletions .github/ISSUE_TEMPLATE/feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: 功能请求 / Feature Request
about: 向我们提交一个新功能的请求
title: 'Feat: '
labels: enhancement
---

警告: 在进一步操作之前,请检查下列选项。如果您忽视此模板或者没有提供关键信息,您的 Issue 将直接被关闭

- 确保您使用的是 最新版本的`Karin`
- 确保您的功能请求尚未在 Issues 列表中提出.
- 确保您的功能请求是与 `Karin` 相关的,且可以实现.

## 描述功能

请清晰地描述您想要的功能,并提供相关的信息。

## 动机

为什么需要这个功能?它将如何改进项目?

## 实现方法

请提供您认为可以实现此功能的方法,如果您不知道如何实现,可以留空。
当然,如果您有兴趣,也可以自己实现并向我们提交 Pull Request。

## 功能描述

简要描述你希望增加的功能。

## 替代方案

是否有其他可行的替代方案?

## 附加信息

任何额外的上下文或截图。
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"bin": {
"init": "./lib/tools/init.js"
"init": "./lib/cli/init.js",
"log": "./lib/cli/log.js"
},
"files": [
"/lib/**/*.js",
Expand All @@ -38,32 +39,32 @@
"app": "node .",
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json && npm run cp && npm run fix",
"cp": "cp ./lib/modules.d.ts ./modules.d.ts && cp ./lib/modules.js ./modules.js",
"debug": "node . --dev",
"delete": "pm2 delete ./config/config/pm2.yaml",
"dev": "tsx ./lib/index.js --dev",
"debug": "tsx watch ./lib/index.js --dev",
"fix": "eslint lib/**/*.js --fix",
"fix:all": "eslint lib/**/*.js --fix && eslint lib/**/*.ts --fix",
"init": "node lib/tools/install.js",
"init:dev": "node lib/tools/install.js",
"init:pack": "node lib/tools/install.js",
"log": "node lib/tools/pm2Log.js",
"hook": "node lib/cli/hook.js",
"init": "node lib/cli/install.js",
"postinstall": "node lib/cli/postinstall.js",
"log": "node lib/cli/log.js",
"monit": "pm2 monit",
"pub": "npm publish --access public",
"restart": "pm2 restart ./config/config/pm2.yaml",
"sort:pack": "npx sort-package-json",
"start": "pm2 start ./config/config/pm2.yaml && pm2 monit",
"stop": "pm2 delete ./config/config/pm2.yaml",
"uninstall": "node lib/tools/uninstall.js"
"stop": "pm2 delete ./config/config/pm2.yaml"
},
"dependencies": {
"@grpc/grpc-js": "1.10.10",
"@grpc/proto-loader": "0.7.13",
"@inquirer/prompts": "5.1.2",
"art-template": "4.13.2",
"axios": "1.7.2",
"chalk": "5.3.0",
"chokidar": "3.6.0",
"express": "4.19.2",
"kritor-proto": "^1.0.2",
"kritor-proto": "latest",
"level": "8.0.1",
"lodash": "4.17.21",
"log4js": "6.9.1",
Expand Down
36 changes: 36 additions & 0 deletions src/cli/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env node

import { select } from '@inquirer/prompts'
import { KarinInit } from 'karin/utils/init'

async function main () {
/** 捕获错误 打印日志 */
process.on('uncaughtException', err => console.error(err))
process.on('unhandledRejection', err => console.error(err))

const init = new KarinInit()
init.init()

const prompt = await select({
message: '请选择npm源 中国大陆服务器一定要更换!!!',
choices: [
{ name: '淘宝源(推荐)', value: 'https://registry.npmmirror.com' },
{ name: '官方源', value: 'https://registry.npmjs.org' },
],
})

/** 结果 */
await init.changeRegistry(prompt)

const pkg = await select({
message: '请选择包管理器 如果不知道怎么选 请选pnpm',
choices: [
{ name: 'pnpm', value: 'pnpm' },
{ name: 'yarn', value: 'yarn' },
],
}) as 'pnpm' | 'yarn'

/** 结果 */
await init.install(pkg)
}
main().then(() => process.exit(0)).catch(() => process.exit(0))
15 changes: 15 additions & 0 deletions src/cli/log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

import fs from 'fs'
import yaml from 'yaml'
import path from 'path'
import { spawn } from 'child_process'

const cwd = process.cwd()
const _path = path.resolve(cwd + '/config/config/pm2.yaml')
const data = yaml.parse(fs.readFileSync(_path, 'utf8'))

const name = data.apps[0].name
const lines = data.lines || 1000
const cmd = process.platform === 'win32' ? 'pm2.cmd' : 'pm2'
spawn(cmd, ['logs', '--lines', lines, name], { stdio: 'inherit', shell: true, cwd })
31 changes: 31 additions & 0 deletions src/cli/postinstall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node

import fs from 'fs'
import { KarinInit } from 'karin/utils/init'

async function main () {
/** 捕获错误 打印日志 */
process.on('uncaughtException', err => console.error(err))
process.on('unhandledRejection', err => console.error(err))

/** 在src目录说明为开发环境 不执行任何初始化操作 */
if (fs.existsSync('./src')) return

const init = new KarinInit()
init.init()

/** 判断锁文件 优先度: pnpm > yarn > cnpm > npm */
let pkg: 'pnpm' | 'yarn' | 'cnpm' | 'npm'
if (fs.existsSync('pnpm-lock.yaml')) {
pkg = 'pnpm'
} else if (fs.existsSync('yarn.lock')) {
pkg = 'yarn'
} else if (fs.existsSync('cnpm-lock.yaml')) {
pkg = 'cnpm'
} else {
pkg = 'npm'
}

await init.install(pkg)
}
main().then(() => process.exit(0)).catch(() => process.exit(0))
77 changes: 0 additions & 77 deletions src/tools/init.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export const config = new (class Cfg {
this.projPath + '/plugins/karin-plugin-example',
this.projConfigPath + '/config',
this.projConfigPath + '/plugin',

]

list.forEach(path => this.mkdir(path))
Expand Down
Loading

0 comments on commit b78219e

Please sign in to comment.