Skip to content

Commit

Permalink
Merge pull request #401 from opentable/webpack-verbose
Browse files Browse the repository at this point in the history
Webpack verbose
  • Loading branch information
matteofigus authored Mar 12, 2017
2 parents cef4156 + 25e9e33 commit 0b9ec42
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 23 deletions.
5 changes: 5 additions & 0 deletions src/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ module.exports = {
boolean: true,
description: 'Enables hot reloading. Note: when hot reloading is set to true, each request to the component will make the registry to create a new instance for the javascript closures to be loaded, while when false the instance will be recycled between components executions',
default: true
},
verbose: {
boolean: true,
description: 'Verbosity',
default: false
}
},
usage: 'Usage: $0 dev <dirName> [port] [baseUrl] [options]'
Expand Down
11 changes: 5 additions & 6 deletions src/cli/domain/package-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ var getUnixUtcTimestamp = require('../../utils/get-unix-utc-timestamp');
var validator = require('../../registry/domain/validators');

module.exports = function(){
return function(componentPath, minify, callback){
return function(options, callback){

if(_.isFunction(minify)){
callback = minify;
minify = true;
}
var componentPath = options.componentPath;
var minify = options.minify || true;

var files = fs.readdirSync(componentPath),
publishPath = path.join(componentPath, '_package');
Expand Down Expand Up @@ -72,7 +70,8 @@ module.exports = function(){
componentPath: componentPath,
dependencies: component.dependencies,
ocOptions: component.oc,
publishPath: publishPath
publishPath: publishPath,
verbose: options.verbose
}, function(err, packagedServerScriptInfo){
if(err){ return cb(err); }

Expand Down
7 changes: 5 additions & 2 deletions src/cli/domain/package-server-script/bundle/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*jshint camelcase:false */
'use strict';
var webpackConfig = require('./config');
var console = require('console');
var MemoryFS = require('memory-fs');
var webpack = require('webpack');

Expand Down Expand Up @@ -32,7 +31,11 @@ module.exports = function bundle(params, callBack) {
warning = info.warnings.toString();
}

console.log(stats.toString(params.webpack.stats));
var log = stats.toString(params.webpack.stats);

if(!!log){
console.log(log);
}

var serverContentBundled = memoryFs.readFileSync('/build/server.js', 'UTF8');
callBack(warning, serverContentBundled);
Expand Down
15 changes: 4 additions & 11 deletions src/cli/domain/package-server-script/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@

var fs = require('fs-extra');
var path = require('path');
var hashBuilder = require('../../../utils/hash-builder');
var bundle = require('./bundle');

var webpackDefaults = {
stats: {
chunks: false,
colors: true,
version: false,
hash: false
}
};
var bundle = require('./bundle');
var hashBuilder = require('../../../utils/hash-builder');

module.exports = function packageServerScript(params, callback){
var fileName = 'server.js';
var publishPath = params.publishPath;
var webpackParams = { stats: params.verbose ? 'verbose' : 'errors-only' };

var bundleParams = {
webpack: params.webpack || webpackDefaults,
webpack: params.webpack || webpackParams,
dependencies: params.dependencies || {},
fileName: fileName,
dataPath: path.join(params.componentPath, params.ocOptions.files.data)
Expand Down
9 changes: 8 additions & 1 deletion src/cli/facade/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ module.exports = function(dependencies){
log.warn(strings.messages.cli.PACKAGING_COMPONENTS, true);

async.eachSeries(componentsDirs, function(dir, cb){
local.package(dir, false, function(err){

var packageOptions = {
componentPath: dir,
minify: false,
verbose: opts.verbose
};

local.package(packageOptions, function(err){
if(!err){ i++; }
cb(err);
});
Expand Down
8 changes: 6 additions & 2 deletions tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ module.exports = function(grunt){
fs.writeFileSync(path.join(__dirname, '../client/src/oc-client.min.js'), compressedCode);

var Local = require('../src/cli/domain/local'),
local = new Local({ logger: { log: grunt.log.writeln }});
local = new Local({ logger: { log: grunt.log.writeln }}),
packageOptions = {
componentPath: path.join(__dirname, clientComponentDir),
verbose: false
};

local.package(path.join(__dirname, clientComponentDir), function(err, res){
local.package(packageOptions, function(err, res){
grunt.log[!!err ? 'error' : 'ok'](!!err ? err : 'Client has been built and packaged');
done();
});
Expand Down
6 changes: 5 additions & 1 deletion test/unit/cli-domain-package-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ var initialise = function(){
};

var executePackaging = function(local, callback){
return local('.', false, callback);
return local({
componentPath: '.',
minify: false,
verbose: false
}, callback);
};

describe('cli : domain : local', function(){
Expand Down

0 comments on commit 0b9ec42

Please sign in to comment.