forked from jedwards1211/meteor-webpack-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore-js-custom-build.js
34 lines (31 loc) · 1.27 KB
/
core-js-custom-build.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
29
30
31
32
33
34
require('shelljs/global');
var dirs = require('./dirs');
var fs = require('fs');
var path = require('path');
var coreJsBuild = require('core-js/build');
dirs.lib = path.join(dirs.webpack, 'lib');
if (!fs.existsSync(dirs.lib)) mkdir(dirs.lib);
var coreJsVersion = JSON.parse(fs.readFileSync('node_modules/core-js/package.json')).version;
var targetFileName = 'core-js-no-number.js';
var currentFileExist = fs.existsSync(path.join(dirs.lib, targetFileName));
var currentFileFewLines = currentFileExist ?
fs.readFileSync(path.join(dirs.lib, targetFileName)).toString().substr(0, 130) : '';
var currentFileVersionRegex = /core-js (\d.\d.\d+)/m;
var currentFileVersion = currentFileVersionRegex.test(currentFileFewLines) ?
currentFileVersionRegex.exec(currentFileFewLines)[1] : false;
if (coreJsVersion !== currentFileVersion) {
echo('Building core-js@' + coreJsVersion + ' without ES6 number constructor...');
coreJsBuild({
modules: ['es5', 'es6', 'es7', 'js', 'web'],
blacklist: ['es6.number.constructor'],
}, function(error, code) {
if (error) {
console.error('core-js build error');
return;
}
fs.writeFileSync(path.join(dirs.lib, targetFileName), code);
});
}
else {
echo('core-js@' + coreJsVersion + ' without ES6 number constructor is up to date');
}