Selaa lähdekoodia

feat: add command update and hooks

zhangyuhan 3 vuotta sitten
vanhempi
commit
c66559948b
4 muutettua tiedostoa jossa 31 lisäystä ja 13 poistoa
  1. 5 13
      package.json
  2. 15 0
      src/commands/update/index.ts
  3. 10 0
      src/hooks/postrun/index.ts
  4. 1 0
      tsconfig.json

+ 5 - 13
package.json

@@ -51,20 +51,12 @@
     "commands": "./dist/commands",
     "commands": "./dist/commands",
     "plugins": [
     "plugins": [
       "@oclif/plugin-help",
       "@oclif/plugin-help",
-      "@oclif/plugin-plugins",
-      "@oclif/plugin-update"
+      "@oclif/plugin-plugins"
     ],
     ],
-    "topicSeparator": " ",
-    "topics": {
-      "create": {
-        "description": "创建项目-命令行交互式"
-      },
-      "init": {
-        "description": "使用指定的模版创建初始化项目"
-      },
-      "sync": {
-        "description": "同步到物料平台(内网注册表)"
-      }
+    "hooks": {
+      "postrun": [
+        "./dist/hooks/postrun/index"
+      ]
     }
     }
   },
   },
   "scripts": {
   "scripts": {

+ 15 - 0
src/commands/update/index.ts

@@ -0,0 +1,15 @@
+import { Command } from '@oclif/core'
+import checkUpdate from '../../utils/update'
+
+export default class Update extends Command {
+  static description = '检测 CLI 版本更新'
+
+  static examples = [
+    '$ jianyu update',
+  ]
+
+  async run(): Promise<void> {
+    await this.parse(Update)
+    checkUpdate()
+  }
+}

+ 10 - 0
src/hooks/postrun/index.ts

@@ -0,0 +1,10 @@
+import { Hook } from '@oclif/core'
+import checkUpdate from '../../utils/update'
+
+const hook: Hook<'postrun'> = async function (opts) {
+  if (opts.Command.id !== 'update') {
+    checkUpdate()
+  }
+}
+
+export default hook

+ 1 - 0
tsconfig.json

@@ -3,6 +3,7 @@
     "declaration": true,
     "declaration": true,
     "importHelpers": true,
     "importHelpers": true,
     "module": "commonjs",
     "module": "commonjs",
+    "resolveJsonModule": true,
     "outDir": "dist",
     "outDir": "dist",
     "rootDir": "src",
     "rootDir": "src",
     "strict": true,
     "strict": true,