Skip to content

Commit

Permalink
Merge pull request #145 from lemieux/f/reactify
Browse files Browse the repository at this point in the history
React / Redux + better test coverage
  • Loading branch information
lemieux committed Jan 8, 2016
2 parents 1081734 + bfbfb3f commit bf31e24
Show file tree
Hide file tree
Showing 123 changed files with 4,700 additions and 3,369 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"presets": [
"stage-2",
"es2015",
"react"
],
"plugins": [
"transform-runtime"
]
}
36 changes: 29 additions & 7 deletions .esformatter
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"AssignmentExpression": 1,
"BinaryExpression": 1,
"ConditionalExpression": 1,
"CallExpression": 0,
"CallExpression": 1,
"CatchClause": 1,
"ConditionalExpression": 1,
"DoWhileStatement": 1,
Expand All @@ -17,15 +17,14 @@
"MemberExpression": 1,
"MultipleVariableDeclaration": 1,
"ObjectExpression": 1,
"ReturnStatement": 0,
"ReturnStatement": 1,
"SwitchCase": 1,
"SwitchStatement": 1,
"TopLevelFunctionBlock": 1,
"TryStatement": 1,
"WhileStatement": 1
},


"lineBreak": {
"value": "\n",

Expand Down Expand Up @@ -303,11 +302,34 @@
"plugins": [
"esformatter-quotes",
"esformatter-braces",
"esformatter-var-each",
"esformatter-dot-notation"
"esformatter-dot-notation",
"esformatter-jsx"
],
"quotes": {
"type": "single",
"avoidEscape": false
}
}
},
"jsx": {
// keep the node attributes on the same line as the open tag. Default is true.
// Setting this to false will put each one of the attributes on a single line
"attrsOnSameLineAsTag": false,
// how many attributes should the node have before having to put each
// attribute in a new line. Default 1
"maxAttrsOnTag": 3,
// if the attributes are going to be put each one on its own line, then keep the first
// on the same line as the open tag
"firstAttributeOnSameLine": true,
// default to one space. Make it empty if you don't like spaces between JSXExpressionContainers
"spaceInJSXExpressionContainers": " ",
// align the attributes with the first attribute (if the first attribute was kept on the same line as on the open tag)
"alignWithFirstAttribute": true,
"htmlOptions": { // same as the ones passed to js-beautifier.html
"brace_style": "collapse",
"indent_char": " ",
"indent_size": 4,
"max_preserve_newlines": 2,
"preserve_newlines": true
//wrap_line_length: 250
}
}
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
38 changes: 38 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"parser": "babel-eslint",
"rules": {
"indent": [
2,
4,
{"SwitchCase": 1}
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
],
"no-unused-vars": 0
},
"env": {
"es6": true,
"node": true,
"commonjs": true,
"browser": true,
"mocha": true
},
"globals": {
"expect": true,
"VERSION": true
},
"ecmaFeatures": {
"jsx": true
},
"extends": "eslint:recommended"
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
node_modules
bower_components
*.log
build
tmp
dist/
grunt-aws.json
grunt-maxcdn.json
*.sublime-workspace
junit
config/*
!config/build
!config/default
!config/default/*.json
example/*
!example/template
!example/template/*.html
npm-debug*
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@
"alert",
"module",
"Promise",
"global"
"global",
"VERSION"
],
"maxparams" : 30,
"maxdepth" : 5,
Expand Down
76 changes: 16 additions & 60 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

/* global process:false */

var _ = require('underscore');

module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.registerTask('awsconfig', function() {
Expand Down Expand Up @@ -46,19 +44,6 @@ module.exports = function(grunt) {
license: grunt.file.read('LICENSE'),
globalVersion: '<%= pkg.version %>',
clean: ['dist/*'],
karma: {
unit: {
configFile: 'karma.conf.js',
singleRun: false,
browsers: ['PhantomJS', 'Chrome'],
reporters: ['progress']
},
ci: {
configFile: 'karma.conf.js',
singleRun: true,
browsers: ['PhantomJS']
}
},

s3: {
options: {
Expand All @@ -76,14 +61,6 @@ module.exports = function(grunt) {
src: 'dist/smooch.js.map',
dest: 'smooch.js.map'
}]
},
images: {
upload: [
{
src: 'src/images/**',
dest: 'images/'
}
]
}
},

Expand All @@ -95,21 +72,20 @@ module.exports = function(grunt) {
},

maxcdn: {
purgeCache: {
options: {
companyAlias: '<%= maxcdn.options.companyAlias %>',
consumerKey: '<%= maxcdn.options.consumerKey %>',
consumerSecret: '<%= maxcdn.options.consumerSecret %>',
zone_id: '<%= maxcdn.options.zoneId %>',
method: 'delete'
},
files: [
{ dest: '/smooch.min.js' },
{ dest: '/smooch.js.map' },
{ dest: '/images/logo_webwidget.png' },
{ dest: '/images/logo_webwidget_2x.png' }
],
},
purgeCache: {
options: {
companyAlias: '<%= maxcdn.options.companyAlias %>',
consumerKey: '<%= maxcdn.options.consumerKey %>',
consumerSecret: '<%= maxcdn.options.consumerSecret %>',
zone_id: '<%= maxcdn.options.zoneId %>',
method: 'delete'
},
files: [
{
dest: '/smooch.min.js'
}
]
}
},

release: {
Expand Down Expand Up @@ -254,39 +230,19 @@ module.exports = function(grunt) {
grunt.task.run('branchCheck', 'publish:prepare', 'publish:release', 'publish:cleanup');
});

grunt.registerTask('loadConfig', 'Loads config from config folder (uses default if none present', function() {
var defaultConfig = grunt.file.readJSON('config/default/config.json');
var config = {};

try {
config = grunt.file.readJSON('config/config.json');
}
catch (err) {
grunt.log.warn('You might want to create a config with your app token at config/config.json');
}

var merged = _.extend(defaultConfig, config);
grunt.config.set('config', merged);
});

grunt.registerTask('setMinMode', function() {
grunt.config.set('config.WIDGET_CODE', 'smooch.min.js');
});
grunt.registerTask('build', ['clean', 'exec:build']);
grunt.registerTask('dev', ['concurrent:dev']);


grunt.registerTask('build', ['clean', 'exec:build']);
grunt.registerTask('dev', ['concurrent:dev']);

grunt.registerTask('deploy', ['build', 'awsconfig', 'maxcdnconfig', 's3:js', 'maxcdn']);
grunt.registerTask('test', ['karma:unit']);
grunt.registerTask('test:ci', ['karma:ci']);
grunt.registerTask('default', ['dev']);

grunt.registerTask('publish:prepare', ['versionBump', 'exec:commitFiles', 'exec:createRelease', 'build', 'exec:addDist']);
grunt.registerTask('publish:release', ['release']);
grunt.registerTask('publish:cleanup', ['exec:cleanRelease', 'exec:push']);

grunt.registerTask('branchCheck', 'Checks that you are publishing from Master branch with no working changes', ['gitinfo', 'checkBranchStatus']);

grunt.registerTask('cdnify', ['awsconfig', 's3:images']);
};
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dependencies:
- npm install -g npm@3
test:
override:
- grunt test:ci
- npm run test:ci
post:
- grunt build

Expand Down
3 changes: 1 addition & 2 deletions config/default/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"USER_ID": "",
"GIVEN_NAME": "DEFAULT_NAME",
"SURNAME": "DEFAULT_SURNAME",
"EMAIL": "[email protected]",
"WIDGET_CODE": "smooch.js"
"EMAIL": "[email protected]"
}
12 changes: 7 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Karma configuration
// Generated on Fri Nov 07 2014 08:13:06 GMT-0500 (EST)

module.exports = function(config) {
var testReportsPath = process.env.CIRCLE_TEST_REPORTS || '.';
var _ = require('underscore');
Expand All @@ -22,7 +19,10 @@ module.exports = function(config) {
frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'],

// list of files / patterns to load in the browser
files: ['test/specs/**/*.spec.js'],
files: [
'test/specs/**/*.spec.js',
'test/specs/**/*.spec.jsx'
],


// list of files to exclude
Expand All @@ -32,7 +32,8 @@ module.exports = function(config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/specs/**/*.spec.js': ['webpack', 'sourcemap']
'test/specs/**/*.spec.js': ['webpack', 'sourcemap'],
'test/specs/**/*.spec.jsx': ['webpack', 'sourcemap']
},


Expand Down Expand Up @@ -81,5 +82,6 @@ module.exports = function(config) {
// i. e.
noInfo: true
},
specReporter: {}
});
};
29 changes: 18 additions & 11 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ module.exports = function(options) {
'http://localhost:2992/_assets/' :
'/_assets/';

var config = require('../config/default/config.json');

try {
Object.assign(config, require('../config/config.json'));
}
catch (e) {}

var renderer = new Renderer({
scriptUrl: publicPath + 'smooch.js',
data: require('../config/config.json')
data: config
});

var app = express();
Expand All @@ -30,22 +37,22 @@ module.exports = function(options) {
// application
app.get('/*', function(req, res) {
renderer.render(
req.path, {}, function(err, html) {
if (err) {
res.statusCode = 500;
res.contentType = 'text; charset=utf8';
res.end(err.message);
return;
req.path, {}, function(err, html) {
if (err) {
res.statusCode = 500;
res.contentType = 'text; charset=utf8';
res.end(err.message);
return;
}
res.contentType = 'text/html; charset=utf8';
res.end(html);
}
res.contentType = 'text/html; charset=utf8';
res.end(html);
}
);
});


var port = process.env.PORT || options.defaultPort || 8080;
app.listen(port, function() {
console.log('Server listening on port ' + port);
console.log('Server listening on port ' + port); //eslint-disable-line no-console
});
};
Loading

0 comments on commit bf31e24

Please sign in to comment.