File tree Expand file tree Collapse file tree 4 files changed +72
-1
lines changed Expand file tree Collapse file tree 4 files changed +72
-1
lines changed Original file line number Diff line number Diff line change
1
+ import enquirer from "enquirer" ;
2
+
3
+ import { execCommand , loggerInfo } from "@/shared/index" ;
4
+ import { ACTIVATION } from "@/shared/config" ;
5
+ import { ProjectSource } from "@/shared/types" ;
6
+
7
+ interface PromptResult {
8
+ command : string ;
9
+ }
10
+
11
+ export const createProject = async ( sources : ProjectSource [ ] ) => {
12
+ if ( ACTIVATION ) {
13
+ loggerInfo ( "createProject 参数信息: \n" ) ;
14
+ console . table ( sources ) ;
15
+ }
16
+
17
+ const sourceChoices = sources . map ( ( { name, description } ) => {
18
+ const formatName = `${ name } :` . padEnd ( 15 ) ;
19
+ return {
20
+ name : name ,
21
+ message : `${ formatName } ${ description } ` ,
22
+ } ;
23
+ } ) ;
24
+
25
+ const result = await enquirer . prompt < PromptResult > ( [
26
+ {
27
+ name : "command" ,
28
+ type : "select" ,
29
+ message : "请选择提交类型" ,
30
+ choices : sourceChoices ,
31
+ } ,
32
+ ] ) ;
33
+
34
+ await execCommand ( "npm" , [ "create" , result . command ] , {
35
+ stdio : "inherit" ,
36
+ } ) ;
37
+ } ;
Original file line number Diff line number Diff line change 9
9
formatGlob ,
10
10
gitCommitScopes ,
11
11
gitCommitTypes ,
12
+ projectSources ,
12
13
} from "./shared/config" ;
13
14
14
15
import { CommandSet } from "./shared/types" ;
@@ -20,6 +21,7 @@ import { clear } from "./command/clear";
20
21
import { npmRun } from "./command/npm-run" ;
21
22
import { npmDepCheck } from "./command/npm-dep-check" ;
22
23
import { npmRegistry } from "./command/npm-registry" ;
24
+ import { createProject } from "./command/create-project" ;
23
25
24
26
export const commandSet : CommandSet = {
25
27
gitCommitCmd : ( cli : CAC ) => {
@@ -109,4 +111,11 @@ export const commandSet: CommandSet = {
109
111
await prettierFormat ( patterns ) ;
110
112
} ) ;
111
113
} ,
114
+ createProjectCmd : ( cli : CAC ) => {
115
+ cli
116
+ . command ( "create" , "运行 npm create 快速创建基础项目" )
117
+ . action ( async ( ) => {
118
+ await createProject ( projectSources ) ;
119
+ } ) ;
120
+ } ,
112
121
} ;
Original file line number Diff line number Diff line change 1
- import { CommitScope , CommitType , KeyValue } from "@/shared/types" ;
1
+ import {
2
+ CommitScope ,
3
+ CommitType ,
4
+ KeyValue ,
5
+ ProjectSource ,
6
+ } from "@/shared/types" ;
2
7
3
8
export const clearGlob = [ "./dist/" ] ;
4
9
@@ -122,3 +127,18 @@ export const npmRegisters: Array<KeyValue> = [
122
127
value : "https://skimdb.npmjs.com/registry/" ,
123
128
} ,
124
129
] ;
130
+
131
+ export const projectSources : Array < ProjectSource > = [
132
+ {
133
+ name : "vite@latest" ,
134
+ description : "创建由 Vite 驱动的新的项目" ,
135
+ } ,
136
+ {
137
+ name : "vue@latest" ,
138
+ description : "创建由 Vite 驱动的 Vue3 项目" ,
139
+ } ,
140
+ {
141
+ name : "vue@legacy" ,
142
+ description : "创建由 Vite 驱动的 Vue2 项目(支持 IE11)" ,
143
+ } ,
144
+ ] ;
Original file line number Diff line number Diff line change @@ -19,3 +19,8 @@ export interface KeyValue {
19
19
key : string ;
20
20
value : string ;
21
21
}
22
+
23
+ export interface ProjectSource {
24
+ name : string ;
25
+ description : string ;
26
+ }
You can’t perform that action at this time.
0 commit comments