Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

Commit 7f0e660

Browse files
committed
1.1.3 文件夹名称不允许包含某些特殊字符
1 parent 745cacd commit 7f0e660

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

create.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ function checkInputID(id: string): true | string {
7474
return true
7575
}
7676

77+
const filenameAntiChar = '\\/:*?"<>|'
78+
79+
function checkDirectoryName(name: string): true | string {
80+
for (const i of name) {
81+
if (filenameAntiChar.includes(i))
82+
return 'Cannot contain characters: ' + filenameAntiChar
83+
}
84+
if (fs.existsSync(name))
85+
return 'Directory exists!'
86+
return true
87+
}
88+
7789
try {
7890
{
7991
const answerLang = await inquirer.prompt([{
@@ -89,7 +101,7 @@ try {
89101
type: 'input',
90102
name: 'id',
91103
message: 'Extension ID:',
92-
validate: (id) => checkInputID(id)
104+
validate: checkInputID,
93105
}])
94106
id = answerID.id;
95107
[author, extensionName] = id.split('.', 2)
@@ -100,7 +112,7 @@ try {
100112
name: 'dir',
101113
message: 'Directory Name:',
102114
default: extensionDir,
103-
validate: (v) => (!fs.existsSync(v) || 'Directory exists!')
115+
validate: checkDirectoryName,
104116
}])
105117
if (answerDir.dir) {
106118
extensionDir = answerDir.dir

0 commit comments

Comments
 (0)