Skip to content

Commit 929981c

Browse files
committed
🐛fix(core): 兼容14.17版本
1 parent 34fecec commit 929981c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/command/template.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import type { CAC } from "cac";
33
import fs from "fs-extra";
44

55
import path from "node:path";
6-
import { randomUUID } from "node:crypto";
76

87
import enquirer from "enquirer";
98

109
import {
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) => {

src/shared/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

0 commit comments

Comments
 (0)