-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextract_sources.js
More file actions
29 lines (22 loc) · 792 Bytes
/
Copy pathextract_sources.js
File metadata and controls
29 lines (22 loc) · 792 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
const fs = require('fs');
const path = require('path');
const outputDir = 'extracted_sources';
const data = JSON.parse(fs.readFileSync('cli.js.map', 'utf8'));
let extracted = 0;
let skipped = 0;
for (let i = 0; i < data.sources.length; i++) {
const sourcePath = data.sources[i];
const content = data.sourcesContent[i];
if (!content) {
skipped++;
continue;
}
// Normalize path: remove leading ../ and resolve
const normalized = sourcePath.replace(/^(\.\.\/)+/, '');
const outPath = path.join(outputDir, normalized);
fs.mkdirSync(path.dirname(outPath), { recursive: true });
fs.writeFileSync(outPath, content);
extracted++;
}
console.log(`Done! Extracted ${extracted} files, skipped ${skipped} (no content).`);
console.log(`Output directory: ${outputDir}/`);