File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,12 +3,12 @@ import type { CAC } from "cac";
33import fs from "fs-extra" ;
44
55import path from "node:path" ;
6- import { randomUUID } from "node:crypto" ;
76
87import enquirer from "enquirer" ;
98
109import {
1110 emptyDir ,
11+ generateRandom ,
1212 getVariantByFramework ,
1313 isEmptyDir ,
1414 isValidFramework ,
@@ -154,7 +154,7 @@ export default function templateInstaller(cli: CAC) {
154154 cli
155155 . command ( "template" , "快速创建CodeGenius基础项目" )
156156 . option ( "-n, --project-name <project-name>" , "项目名称" , {
157- default : `project-${ randomUUID ( ) . slice ( 0 , 8 ) } ` ,
157+ default : `project-${ generateRandom ( 8 ) } ` ,
158158 } )
159159 . option ( "-f, --framework <framework>" , "项目框架" )
160160 . action ( async ( options ) => {
Original file line number Diff line number Diff line change @@ -223,3 +223,14 @@ export function isValidVariant(framework: string) {
223223 const variants = getVariantByFramework ( framework ) ;
224224 return variants . length > 0 ;
225225}
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