File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,12 @@ import type { CAC } from "cac";
3
3
import fs from "fs-extra" ;
4
4
5
5
import path from "node:path" ;
6
- import { randomUUID } from "node:crypto" ;
7
6
8
7
import enquirer from "enquirer" ;
9
8
10
9
import {
11
10
emptyDir ,
11
+ generateRandom ,
12
12
getVariantByFramework ,
13
13
isEmptyDir ,
14
14
isValidFramework ,
@@ -154,7 +154,7 @@ export default function templateInstaller(cli: CAC) {
154
154
cli
155
155
. command ( "template" , "快速创建CodeGenius基础项目" )
156
156
. option ( "-n, --project-name <project-name>" , "项目名称" , {
157
- default : `project-${ randomUUID ( ) . slice ( 0 , 8 ) } ` ,
157
+ default : `project-${ generateRandom ( 8 ) } ` ,
158
158
} )
159
159
. option ( "-f, --framework <framework>" , "项目框架" )
160
160
. action ( async ( options ) => {
Original file line number Diff line number Diff line change @@ -223,3 +223,14 @@ export function isValidVariant(framework: string) {
223
223
const variants = getVariantByFramework ( framework ) ;
224
224
return variants . length > 0 ;
225
225
}
226
+
227
+ export function generateRandom ( length : number ) {
228
+ let result = "" ;
229
+ const characters =
230
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
231
+ const charactersLength = characters . length ;
232
+ for ( let i = 0 ; i < length ; i ++ ) {
233
+ result += characters . charAt ( Math . floor ( Math . random ( ) * charactersLength ) ) ;
234
+ }
235
+ return result ;
236
+ }
You can’t perform that action at this time.
0 commit comments