-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconcat.js
More file actions
26 lines (20 loc) · 779 Bytes
/
Copy pathconcat.js
File metadata and controls
26 lines (20 loc) · 779 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
// concat.js
const fs = require('fs');
const path = require('path');
const [, , targetDir, outputFile] = process.argv;
if (!targetDir || !outputFile) {
console.error('Usage: node concat.js <directory> <outputFile>');
process.exit(1);
}
const outputPath = path.join(targetDir, outputFile);
const ext = path.extname(outputFile);
const files = fs.readdirSync(targetDir)
.filter(file => file.endsWith(ext) && file !== outputFile && !file.includes('.min.'));
const content = files
.map(file => {
const fileContent = fs.readFileSync(path.join(targetDir, file), 'utf8');
// Wrap JS files in IIFEs to create private block scopes
return ext === '.js' ? `(() => {\n${fileContent}\n})();` : fileContent;
})
.join('\n\n');
fs.writeFileSync(outputPath, content);