-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistFiles.js
More file actions
101 lines (84 loc) · 2.48 KB
/
Copy pathlistFiles.js
File metadata and controls
101 lines (84 loc) · 2.48 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// listFiles.js
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const exclude = [
'node_modules',
'.git',
'.vite',
'generated',
'immutable',
'chunks',
'entries',
'nodes',
'.svelte-kit',
'_app',
'ambient.d.ts',
'non-ambient.d.ts',
'route_meta_data.json',
'$types.d.ts',
'manifest.json',
'version.json',
'root.js',
'root.svelte',
'internal.js',
'remote-entry.js',
'.npmrc',
'package-lock.json',
'pnpm-lock.yaml',
'yarn.lock',
'docs',
'staging'
];
function listFiles(dir, indent = '') {
try {
const items = fs.readdirSync(dir);
items.sort((a, b) => {
const pathA = path.join(dir, a);
const pathB = path.join(dir, b);
const statA = fs.statSync(pathA);
const statB = fs.statSync(pathB);
if (statA.isDirectory() && !statB.isDirectory()) return -1;
if (!statA.isDirectory() && statB.isDirectory()) return 1;
return a.localeCompare(b);
});
for (const item of items) {
if (exclude.some(pattern => {
if (pattern.includes('*')) {
const regex = new RegExp(pattern.replace('*', '.*'));
return regex.test(item);
}
return item === pattern;
})) continue;
const fullPath = path.join(dir, item);
try {
const stats = fs.statSync(fullPath);
// Detect country folder
const isCountryDataFolder =
stats.isDirectory() &&
fullPath.includes(path.join('data', 'countries')) &&
fs.readdirSync(fullPath).includes('index.ts');
if (isCountryDataFolder) {
console.log(indent + `🌍 ${item}/ (index.ts, contains city data)`);
// Virtual cities folder
console.log(indent + ' 📁 cities/ (defined inside index.ts)');
// Do not recurse into country folder
continue;
}
// Normal printing
console.log(indent + (stats.isDirectory() ? '📁 ' : '📄 ') + item);
if (stats.isDirectory()) {
listFiles(fullPath, indent + ' ');
}
} catch (err) {
console.log(indent + '❌ ' + item + ' (error reading)');
}
}
} catch (err) {
console.log('Error reading directory:', dir, err.message);
}
}
console.log('🚀 Travel Planner Project Structure:\n');
listFiles('.');