Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directly build to core-js without grunt-cli #106

Merged
merged 1 commit into from
Oct 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions core-js-custom-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@ 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 targetFile = 'core-js-no-number-' + coreJsVersion + '.js';
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 (!fs.existsSync(path.join(dirs.lib, targetFile))) {
if (coreJsVersion !== currentFileVersion) {
echo('Building core-js@' + coreJsVersion + ' without ES6 number constructor...');
cd('node_modules/core-js');
exec('npm install');
cd(__dirname);
exec('npm run build-core-js');
cd('node_modules/core-js');
mv('core-js-no-number.js', path.join(dirs.lib, targetFile));
rm('-rf', 'node_modules');
cd(dirs.lib);
ln('-sf', targetFile, 'core-js-no-number.js');
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');
Expand Down
6 changes: 3 additions & 3 deletions dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var loadClientBundleLink = path.join(dirs.meteor, 'client/loadClientBundle.html'

var requireServerBundleJs = path.join(dirs.meteor, 'server/require.server.bundle.js');

require('./core-js-custom-build');
exec('node core-js-custom-build.js');

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does require not work here for some reason? I'd rather use require if possible because shelljs claims that synchronous exec can have performance problems for long-running processes. Probably not a big deal here but just makes me want to avoid synchronous exec if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because before the code has inside exec ( L16 and L18 ) in core-js-custom-build.js file.
but, now core-js-custom-build.js doesn't have a exec then it does changed non-blocking code.
so, I replaced exec instead of require.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, makes sense. Yeah I think exec is better than going to the trouble of passing a callback from the main scripts

if (fs.existsSync(clientBundleLink)) rm(clientBundleLink);
if (fs.existsSync(serverBundleLink)) rm(serverBundleLink);
Expand All @@ -52,7 +52,7 @@ serverCompiler.watch({
serverBundleReady = true;
compileClient();
runMeteor();
}
}
});

function compileClient() {
Expand All @@ -74,4 +74,4 @@ function updateRequireServerBundleJs(stats) {
('//' + jsonStats.hash + '\n' +
'Meteor.__mwrContext__ = {Npm: Npm, Assets: Assets};\n' +
'Npm.require("' + serverBundleRequirePath + '");').to(requireServerBundleJs);
}
}
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
"babel-eslint": "^4.0.5",
"babel-loader": "^5.1.2",
"babel-plugin-react-transform": "^1.1.0",
"core-js": "^1.0.0",
"core-js": "^1.2.2",
"css-loader": "^0.15.3",
"eslint-config-airbnb": "0.0.7",
"eslint-plugin-react": "^3.2.2",
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"karma": "^0.13.9",
"karma-chrome-launcher": "^0.2.0",
"karma-jasmine": "^0.2.2",
Expand All @@ -40,8 +38,7 @@
"react-mixin": "^2.0.1"
},
"scripts": {
"lint": "eslint app",
"build-core-js": "grunt --gruntfile node_modules/core-js/Gruntfile.js build:es5,es6,es7,js,web --blacklist=es6.number.constructor --path=core-js-no-number"
"lint": "eslint app"
},
"author": "",
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion predeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var loadClientBundleLink = path.join(dirs.meteor, 'client/loadClientBundle.html'
var requireServerBundleJs = path.join(dirs.meteor, 'server/require.server.bundle.js');

module.exports = function(callback) {
require('./core-js-custom-build');
exec('node core-js-custom-build.js');

if (!process.env.NODE_ENV) {
process.env.NODE_ENV = env.NODE_ENV = 'production';
Expand Down
6 changes: 3 additions & 3 deletions prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var loadClientBundleHtml = path.join(dirs.webpack, 'loadClientBundle.html');
var loadClientBundleLink = path.join(dirs.meteor, 'client/loadClientBundle.html');
var requireServerBundleJs = path.join(dirs.meteor, 'server/require.server.bundle.js');

require('./core-js-custom-build');
exec('node core-js-custom-build.js');

if (fs.existsSync(loadClientBundleLink)) rm(loadClientBundleLink);
if (fs.existsSync(requireServerBundleJs)) rm(requireServerBundleJs);
Expand All @@ -41,7 +41,7 @@ serverCompiler.watch(serverConfig.watchOptions || {}, function(err, stats) {
serverBundleReady = true;
ln('-sf', serverBundlePath, serverBundleLink);
compileClient();
}
}
});

function compileClient() {
Expand All @@ -52,7 +52,7 @@ function compileClient() {
clientBundleReady = true;
ln('-sf', clientBundlePath, clientBundleLink);
runMeteor();
}
}
});
}

Expand Down