-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinit
More file actions
32 lines (24 loc) · 938 Bytes
/
init
File metadata and controls
32 lines (24 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
const path = require('path');
function generateFiles(answers) {
const projectPath = path.dirname(path.dirname(__dirname)); // 输出:/Users/username/project
const files = fs.readdirSync(projectPath);
if (files.includes('init.lock')) {
return ;
}
const entries = fs.readdirSync(__dirname, { withFileTypes: true });
const excludeFiles = ['node_modules']; // 需排除的文件名列表
const filteredEntries = entries.filter(entry =>
!excludeFiles.includes(entry.name)
);
filteredEntries.forEach(entry => {
const srcPath = path.join(__dirname, entry.name);
const destPath = path.join(projectPath, entry.name);
if (entry.isFile()) {
fs.copyFileSync(srcPath, destPath);
} else if (entry.isDirectory()) {
fs.cpSync(srcPath, destPath, { recursive: true });
}
});
}
generateFiles({});