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 99 formatGlob ,
1010 gitCommitScopes ,
1111 gitCommitTypes ,
12+ projectSources ,
1213} from "./shared/config" ;
1314
1415import { CommandSet } from "./shared/types" ;
@@ -20,6 +21,7 @@ import { clear } from "./command/clear";
2021import { npmRun } from "./command/npm-run" ;
2122import { npmDepCheck } from "./command/npm-dep-check" ;
2223import { npmRegistry } from "./command/npm-registry" ;
24+ import { createProject } from "./command/create-project" ;
2325
2426export const commandSet : CommandSet = {
2527 gitCommitCmd : ( cli : CAC ) => {
@@ -109,4 +111,11 @@ export const commandSet: CommandSet = {
109111 await prettierFormat ( patterns ) ;
110112 } ) ;
111113 } ,
114+ createProjectCmd : ( cli : CAC ) => {
115+ cli
116+ . command ( "create" , "运行 npm create 快速创建基础项目" )
117+ . action ( async ( ) => {
118+ await createProject ( projectSources ) ;
119+ } ) ;
120+ } ,
112121} ;
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" ;
27
38export const clearGlob = [ "./dist/" ] ;
49
@@ -122,3 +127,18 @@ export const npmRegisters: Array<KeyValue> = [
122127 value : "https://skimdb.npmjs.com/registry/" ,
123128 } ,
124129] ;
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 {
1919 key : string ;
2020 value : string ;
2121}
22+
23+ export interface ProjectSource {
24+ name : string ;
25+ description : string ;
26+ }
You can’t perform that action at this time.
0 commit comments