forked from LHNCBC/lforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concatenate.js
28 lines (23 loc) · 1.16 KB
/
concatenate.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
// Concatenates several source files to produce lhc-forms.js and its source map.
const ConcatWithSourceMaps = require('concat-with-sourcemaps');
const concat = new ConcatWithSourceMaps(true, 'all.js', '\n');
const fs = require('fs');
const path = require('path');
(async function build() {
// es2017 files from angular 14 build
const jsFileDir = './dist/@elimuinformatics/lforms/webcomponent';
const jsFiles = ['scripts.js', 'runtime.js', 'polyfills.js', 'main.js'
].map(f=>path.join(jsFileDir, f));
jsFiles.forEach(f=>{
let content = fs.readFileSync(f, {encoding: 'utf8'});
// Remove the sourcemapping statement from the file
content = content.replace(/\/\/# sourceMappingURL=\S+\.js\.map/, '');
const fileName = path.basename(f);
const sourceMapContent = fs.readFileSync(f+'.map', {encoding: 'utf8'});
concat.add(f, content, sourceMapContent);
});
// Add sourcemapping statement to the combined content
let outputContent = concat.content + "\n//# sourceMappingURL=lhc-forms.js.map\n";
fs.writeFileSync(path.join(jsFileDir, 'lhc-forms.js'), outputContent);
fs.writeFileSync(path.join(jsFileDir, 'lhc-forms.js.map'), concat.sourceMap);
})()