Skip to content

Commit d613d03

Browse files
committed
fix:修复随意删除的问题
1 parent a0a5002 commit d613d03

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

common/utils/createQuestion.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ const path = require("path");
33

44
function createQuestion(newPath){
55
return new Promise((resolve, reject) => {
6+
const newDir = path.normalize( `./src/${newPath}`);
7+
const sourceFilePath = path.normalize("./common/template/template.js")
8+
const newFilePath = path.join(newDir,"index.js")
69
// 判断是否存在
7-
fs.exists(newPath, (exists) => {
10+
fs.exists(newFilePath, (exists) => {
811
if (exists) {
912
reject(`./src/${newPath} 已存在,请检查目录!`);
10-
return;
11-
}
12-
try {
13-
const newDir = path.normalize( `./src/${newPath}`);
14-
const sourceFilePath = path.normalize("./common/template/template.js")
15-
const newFilePath = path.join(newDir,"index.js")
16-
// 创建目录
17-
fs.mkdir(newDir, { recursive: true },()=>{
18-
// 复制文件
19-
fs.copyFile(sourceFilePath, newFilePath,0,()=>{
20-
resolve(newFilePath);
21-
console.log(`File '${sourceFilePath}' copied to '${newFilePath}'`);
13+
}else{
14+
try {
15+
16+
// 创建目录
17+
fs.mkdir(newDir, { recursive: true },()=>{
18+
// 复制文件
19+
fs.copyFile(sourceFilePath, newFilePath,0,()=>{
20+
resolve(newFilePath);
21+
console.log(`File '${sourceFilePath}' copied to '${newFilePath}'`);
22+
});
2223
});
23-
});
24-
} catch (error) {
25-
reject('Error:', error.message);
24+
} catch (error) {
25+
reject('Error:', error.message);
26+
}
2627
}
27-
2828
})
2929
})
3030
}

0 commit comments

Comments
 (0)