-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
57 lines (49 loc) · 1.59 KB
/
build.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const fs = require('fs');
const path = require('path');
function scanDirectory(dir, basePath = '') {
try {
const items = fs.readdirSync(dir);
const structure = [];
for (const item of items) {
const fullPath = path.join(dir, item);
const relativePath = path.join(basePath, item);
if (fs.statSync(fullPath).isDirectory() &&
!item.startsWith('.') &&
!['node_modules', 'dist'].includes(item)) {
structure.push({
path: '/' + relativePath.replace(/\\/g, '/') + '/',
type: 'directory',
name: item,
children: scanDirectory(fullPath, relativePath)
});
}
}
return structure;
} catch (error) {
console.error(`Error scanning ${dir}:`, error);
return [];
}
}
function writeOutput(structure) {
try {
fs.writeFileSync('directory-list.json', JSON.stringify(structure, null, 2));
fs.writeFileSync('directory-flat.json',
JSON.stringify(structure.map(item => item.path), null, 2));
return true;
} catch (error) {
console.error('Error writing output:', error);
return false;
}
}
function build() {
console.log('Starting build...');
const structure = scanDirectory('.');
if (writeOutput(structure)) {
console.log('Build successful');
process.exit(0);
} else {
console.log('Build failed');
process.exit(1);
}
}
build();