-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateStructure.js
32 lines (26 loc) · 929 Bytes
/
createStructure.js
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
//create Strecture js
const fs = require('fs');
function createStructure(basePath, structure) {
for (const item of structure) {
const itemPath = basePath + '/' + item.name;
if (item.type === 'directory') {
fs.mkdirSync(itemPath, { recursive: true });
if (item.children) {
createStructure(itemPath, item.children);
}
} else if (item.type === 'file') {
if (item.content) {
fs.writeFileSync(itemPath, item.content);
} else {
fs.writeFileSync(itemPath, '');
}
}
}
}
// Load the structure from a JSON file (Structure.js)
const structure = require('./Structure');
// Specify the base directory where the structure will be created
const baseDirectory = '../output';
// Create the file structure using the loaded structure
createStructure(baseDirectory, [structure]);
console.log('File structure created successfully.');