-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathcore-js-custom-build.js
31 lines (28 loc) · 1.24 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
require('shelljs/global');
var dirs = require('./dirs');
var fs = require('fs');
var path = require('path');
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...');
require('core-js-builder')({
modules: ['es5', 'es6', 'es7', 'core.dict', 'web'],
blacklist: ['es6.number.constructor'],
}).then(function(code) {
fs.writeFileSync(path.join(dirs.lib, targetFileName), code);
}).catch(function(error) {
console.error('core-js build error');
});
}
else {
echo('core-js@' + coreJsVersion + ' without ES6 number constructor is up to date');
}