File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ npm i -g code-genius
24
24
| cmv | -- | 帮助验证 git commit 的内容是否符合规范 |
25
25
| cup | --ignore <path > | 清理运行时生成的文件 |
26
26
| ihooks | -- | 使用且有修改 simple-git-hooks 后需要重新初始化 |
27
+ | run | -- | 运行列出的脚本 |
27
28
28
29
## API
29
30
@@ -33,6 +34,7 @@ npm i -g code-genius
33
34
| 2 | ` gitCommitVerify() ` | ` -- ` | ` Promise<void> ` |
34
35
| 3 | ` cleanUp(paths) ` | ` paths: string[] ` | ` Promise<void> ` |
35
36
| 4 | ` gitInitSimpleHooks(cwd) ` | ` cwd?: string ` | ` Promise<void> ` |
37
+ | 5 | ` npmRun(cwd) ` | ` cwd?: string ` | ` Promise<void> ` |
36
38
37
39
## API 示例
38
40
@@ -84,6 +86,18 @@ gitInitSimpleHooks(cwd);
84
86
npx esno index .ts
85
87
```
86
88
89
+ npmRun()
90
+
91
+ ``` typescript
92
+ // ./index.ts
93
+ import { gitInnpmRunitSimpleHooks , cwd } from " code-genius" ;
94
+
95
+ npmRun (cwd );
96
+
97
+ // 运行
98
+ npx esno index .ts
99
+ ```
100
+
87
101
## 执照
88
102
89
103
MIT License
Original file line number Diff line number Diff line change
1
+ import enquirer from "enquirer" ;
2
+ import path from "node:path" ;
3
+ import fs from "fs/promises" ;
4
+ import { execCommand } from "../shared/index" ;
5
+
6
+ export const npmRun = async ( cwd = process . cwd ( ) ) => {
7
+ const root = path . join ( cwd , "package.json" ) ;
8
+ const pkgContent = await fs . readFile ( root , { encoding : "utf-8" } ) ;
9
+ const scripts = JSON . parse ( pkgContent ) ?. scripts ;
10
+ const scriptChoices = Object . keys ( scripts ) . map ( ( key ) => {
11
+ console . log ( key , scripts [ key ] ) ;
12
+ return {
13
+ name : scripts [ key ] ,
14
+ message : key ,
15
+ } ;
16
+ } ) ;
17
+
18
+ const result = await enquirer . prompt < { script : string } > ( [
19
+ {
20
+ name : "script" ,
21
+ type : "select" ,
22
+ message : "请选择运行脚本" ,
23
+ choices : scriptChoices ,
24
+ } ,
25
+ ] ) ;
26
+
27
+ if ( result . script ) {
28
+ const script = result . script ;
29
+ const cmd = script . split ( " " ) [ 0 ] ;
30
+ const args = script . split ( " " ) . slice ( 1 ) ;
31
+ execCommand ( cmd , args , { stdio : "inherit" } ) ;
32
+ }
33
+ } ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { gitCommitVerify } from "./command/git-commit-verify";
7
7
import { gitCommit } from "./command/git-commit" ;
8
8
import { gitInitSimpleHooks } from "./command/git-init-hooks" ;
9
9
import { cleanUp } from "./command/cheanup" ;
10
+ import { npmRun } from "./command/npm-run" ;
10
11
11
12
export const setupSet : SetupSet = {
12
13
cmSetup : ( cli : CAC ) => {
@@ -53,4 +54,9 @@ export const setupSet: SetupSet = {
53
54
await gitInitSimpleHooks ( ) ;
54
55
} ) ;
55
56
} ,
57
+ npmRunSetup : ( cli : CAC ) => {
58
+ cli . command ( "run" , "Run the script listed" ) . action ( async ( ) => {
59
+ await npmRun ( ) ;
60
+ } ) ;
61
+ } ,
56
62
} ;
You can’t perform that action at this time.
0 commit comments