forked from kizu/bemto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concat.js
28 lines (25 loc) · 867 Bytes
/
concat.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
const concat = require('concat-files'),
{ readdirSync, readFileSync, writeFileSync } = require('fs');
const files = readdirSync(`./lib/`).map((fileName) => `./lib/${fileName}`),
targetName = 'bemto_webpack.pug',
targetPath = `./${targetName}`;
concat(files,
targetPath,
(error) => {
if (error) {
console.error('\x1b[31m', error, '\x1b[0m')
process.exit(1)
}
console.log('\x1b[32m', 'Concat done (1/2)', '\x1b[0m');
removeImports()
}
);
function removeImports() {
const file = readFileSync(targetPath).toString(),
lines = file.split('\n'),
filteredLines = lines.filter((line) =>
!line.includes('include')
);
writeFileSync(targetPath, filteredLines.join('\n'));
console.log('\x1b[32m', 'Remove imports done (2/2)', '\x1b[0m');
}