Skip to content

Instantly share code, notes, and snippets.

@sudhin
Created February 28, 2016 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudhin/fdbf0bdcaaaaf7d26e64 to your computer and use it in GitHub Desktop.
Save sudhin/fdbf0bdcaaaaf7d26e64 to your computer and use it in GitHub Desktop.
mup update build.js for fixing React build error
var spawn = require('child_process').spawn;
var archiver = require('archiver');
var fs = require('fs');
var pathResolve = require('path').resolve;
var _ = require('underscore');
function buildApp(appPath, meteorBinary, buildLocaltion, callback) {
buildMeteorApp(appPath, meteorBinary, buildLocaltion, function(code) {
if(code == 0) {
archiveIt(buildLocaltion, callback);
} else {
console.log("\n=> Build Error. Check the logs printed above.");
callback(new Error("build-error"));
}
});
}
function buildMeteorApp(appPath, meteorBinary, buildLocaltion, callback) {
var executable = meteorBinary;
var args = [
"build", "--directory", buildLocaltion,
"--server", "http://localhost:3000"
];
var isWin = /^win/.test(process.platform);
if(isWin) {
// Sometimes cmd.exe not available in the path
// See: http://goo.gl/ADmzoD
executable = process.env.comspec || "cmd.exe";
args = ["/c", "meteor"].concat(args);
}
var options = {cwd: appPath};
var meteor = spawn(executable, args, options);
var stdout = "";
var stderr = "";
meteor.stdout.pipe(process.stdout, {end: false});
meteor.stderr.pipe(process.stderr, {end: false});
meteor.on('close', callback);
}
function archiveIt(buildLocaltion, callback) {
callback = _.once(callback);
var bundlePath = pathResolve(buildLocaltion, 'bundle.tar.gz');
var sourceDir = pathResolve(buildLocaltion, 'bundle');
+ var esprimaFolder = sourceDir+'/programs/server/npm/react-runtime-prod/node_modules/react/node_modules/envify/node_modules/jstransform/node_modules/esprima-fb/';
+ if(fs.existsSync(esprimaFolder+'#README.md#')){
+ fs.renameSync(esprimaFolder+'#README.md#',esprimaFolder+'.#README.md');
+ }
var output = fs.createWriteStream(bundlePath);
var archive = archiver('tar', {
gzip: true,
gzipOptions: {
level: 6
}
});
archive.pipe(output);
output.once('close', callback);
archive.once('error', function(err) {
console.log("=> Archiving failed:", err.message);
callback(err);
});
archive.directory(sourceDir, 'bundle').finalize();
}
module.exports = buildApp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment