Skip to content

Commit

Permalink
added config module
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Balestra committed Jan 11, 2017
1 parent b7461f3 commit 14acc12
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 67 deletions.
56 changes: 13 additions & 43 deletions src/cli/domain/package-server-script/bundle/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*jshint camelcase:false */
'use strict';

var _ = require('underscore');
var config = require('./webpack.server.config');
var console = require('console');
var webpack = require('webpack');
var path = require('path');
var MemoryFS = require('memory-fs');
var path = require('path');
var webpack = require('webpack');

var memoryFs = new MemoryFS();

function bundle(dataPath, fileName, options, callBack) {

if (typeof options === 'function') {
callBack = options;
options = {
Expand All @@ -22,58 +22,28 @@ function bundle(dataPath, fileName, options, callBack) {
};
}


var webpackConfig = {
entry: dataPath,
output: {
path: '/build',
filename: fileName
var webpackConfig = _.extend(
{
entry: dataPath,
output: {
path: '/build',
filename: fileName
}
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false,
screw_ie8: true
}
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
],
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
'presets': [
['env', {
'targets': {
'node': 'current'
}
}]
]
}
}
]
}
};
config
);

var compiler = webpack(webpackConfig);
compiler.outputFileSystem = memoryFs;

compiler.run(function(err, stats){

// handleFatalError
var error = err;
if (error) {
return callBack(error);
}

var info = stats.toJson();

// handleSoftErrors
if (stats.hasErrors()) {
error = info.errors;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*jshint camelcase:false */
'use strict';
var webpack = require('webpack');

var config = {
module: {
loaders: [
{
test: /\.json$/,
loader: 'json-loader',
exclude: /node_modules/
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
'presets': [
['env', {
'targets': {
'node': 0.10
}
}]
]
}
}
]
},
plugins: [
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false,
screw_ie8: true
},
sourceMap: false
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
})
]
};

module.exports = config;
22 changes: 22 additions & 0 deletions src/cli/domain/package-server-script/bundle/wrapLoops.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
var CONST_MAX_ITERATIONS = 10000;

var wrapLoops = function(node){
var loopKeywords = ['WhileStatement', 'ForStatement', 'DoWhileStatement'];

if(loopKeywords.indexOf(node.type) > -1){
node.update('{ var __ITER = ' + CONST_MAX_ITERATIONS + ';'
+ node.source() + '}');
}

if(!node.parent){
return;
}

if(loopKeywords.indexOf(node.parent.type) > -1 && node.type === 'BlockStatement') {
node.update('{ if(__ITER <=0){ throw new Error("loop exceeded maximum allowed iterations"); } '
+ node.source() + ' __ITER--; }');
}
};

module.exports = wrapLoops;
24 changes: 0 additions & 24 deletions src/cli/domain/package-server-script/getSandBoxedJs/wrapLoops.js

This file was deleted.

0 comments on commit 14acc12

Please sign in to comment.