Skip to content

Commit

Permalink
more gulping
Browse files Browse the repository at this point in the history
  • Loading branch information
beneidel committed Feb 15, 2014
1 parent 7e74280 commit 05ea12c
Show file tree
Hide file tree
Showing 24 changed files with 844 additions and 804 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Expand Up @@ -15,6 +15,4 @@ results

npm-debug.log

build
bundle.js
test-bundle.js
build
86 changes: 86 additions & 0 deletions .jshintrc
@@ -0,0 +1,86 @@
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details

"maxerr" : 10, // {int} Maximum error before stopping

// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : true, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : false, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"indent" : 4, // {int} Number of spaces to use for indentation
"latedef" : true, // true: Require variables/functions to be defined before being used
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : false, // true: Prohibit use of empty blocks
"nonew" : true, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : false, // true: Prohibit use of `++` & `--`
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : true, // true: Require all defined variables be used
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
"trailing" : true, // true: Prohibit trailing whitespaces
"maxparams" : 6, // {int} Max number of formal params allowed per function
"maxdepth" : 6, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
"maxlen" : 120, // {int} Max number of characters per line

// Relaxing
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // true: Tolerate use of `== null`
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// (ex: `for each`, multiple try/catch, function expression…)
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements"
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : false, // true: Tolerate functions being defined in loops
"multistr" : false, // true: Tolerate multi-line strings
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function

// Environments
"browser" : true, // Web Browser (window, document, etc)
"couch" : false, // CouchDB
"devel" : false, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jquery" : false, // jQuery
"mootools" : false, // MooTools
"node" : true, // Node.js
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
"prototypejs" : false, // Prototype and Scriptaculous
"rhino" : false, // Rhino
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface

// Legacy
"nomen" : false, // true: Prohibit dangling `_` in variables
"onevar" : false, // true: Allow only one `var` statement per function
"passfail" : false, // true: Stop on first error
"white" : false, // true: Check against strict whitespace and indentation rules

// Custom Globals
"predef" : [ ] // additional predefined global variables
}
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -2,5 +2,6 @@ language: node_js
node_js:
- 0.10
before_install:
- "export BROWSERS=Firefox"
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
6 changes: 2 additions & 4 deletions bower.json
@@ -1,6 +1,5 @@
{
"name": "jsondiffpatch",
"version": "0.0.11",
"homepage": "https://github.com/benjamine/JsonDiffPatch",
"main": "src/main.js",
"authors": [
Expand All @@ -15,10 +14,9 @@
"license": "MIT",
"ignore": [
"**/.*",
"lib",
"src",
"test",
"bin",
"demo",
"tools"
"demo"
]
}
File renamed without changes.
137 changes: 86 additions & 51 deletions gulpfile.js
@@ -1,75 +1,110 @@
var fs = require('fs');
var gulp = require('gulp');
var gutil = require('gulp-util');
var plugins = require("gulp-load-plugins")();
var plugins = require('gulp-load-plugins')();

var packageInfo = JSON.parse(fs.readFileSync('./package.json'));
var browsers = process.env.BROWSERS || process.env.BROWSER || 'PhantomJS';
browsers = browsers ? browsers.split(' ') : undefined;

gulp.task('build', function() {
gulp.src('./src/main.js')
.pipe(plugins.browserify({
standalone: packageInfo.name,
exclude: "../../lib/diff_match_patch_uncompressed"
}))
.pipe(plugins.rename('bundle.js'))
.pipe(gulp.dest('./build'))
.pipe(plugins.uglify())
.pipe(plugins.rename('bundle.min.js'))
.pipe(gulp.dest('./build'))
gulp.task('default', ['test']);

gulp.task('clean', function() {
return gulp.src('./build', {read: false})
.pipe(plugins.clean());
});

gulp.task('build-full', function() {
gulp.src('./src/main.js')
.pipe(plugins.browserify({
standalone: "jsondiffpatch"
}))
.pipe(plugins.rename('bundle-full.js'))
.pipe(gulp.dest('./build'))
.pipe(plugins.uglify())
.pipe(plugins.rename('bundle-full.min.js'))
.pipe(gulp.dest('./build'))
var watching = false;
var plumber = function() {
return watching ? plugins.plumber() : gutil.noop();
};

gulp.task('lint', function() {
var jshintOptions = fs.readFileSync('./.jshintrc').toString().replace(/\/\/.*/g, '');
jshintOptions = JSON.parse(jshintOptions);
return gulp.src([
'gulpfile.js',
'./src/**/*.js',
'./test/**/*.js',
'!./src/jsondiffpatch*.js',
'!**/*_old.js'
])
.pipe(plumber())
.pipe(plugins.jshint(jshintOptions))
.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.jshint.reporter('fail'))
.pipe(plumber());
});

gulp.task('build-test', ['build'], function() {
gulp.src('./test/test.js')
.pipe(plugins.browserify({
}))
.pipe(plugins.rename('test-bundle.js'))
.pipe(gulp.dest('./build'))
var buildDependencies = ['lint'];
var bundle = function(options) {
var name = options.name || 'bundle';
var src = options.src || './src/main.js';
var minify = options.minify !== false;
gulp.task(name, ['clean'], function() {
if (fs.existsSync('./build/'+name+'.js') && (!minify || fs.existsSync('./build/'+name+'.min.js'))) {
console.log(name + ' already exists');
return;
}

var stream = gulp.src(src)
.pipe(plugins.replace('{{package-version}}', packageInfo.version))
.pipe(plugins.replace('{{package-homepage}}', packageInfo.homepage))
.pipe(plugins.browserify(options.browserifyOptions || {}))
.pipe(plugins.rename(name+'.js'))
.pipe(gulp.dest('./build'));
if (!minify) { return stream; }
return stream.pipe(plugins.uglify())
.pipe(plugins.rename(name+'.min.js'))
.pipe(gulp.dest('./build'));
});
buildDependencies.push(name);
};

bundle({
browserifyOptions: {
standalone: packageInfo.name,
exclude: '../../external/diff_match_patch_uncompressed'
}
});
bundle({
name: 'bundle-full',
browserifyOptions: {
standalone: packageInfo.name
}
});

bundle({
name: 'test-bundle',
src: './test/test.js',
minify: false
});

gulp.task('test', ['build-test'], function () {
gulp.src('./test/**.js')
gulp.task('build', buildDependencies, function() {
});

gulp.task('test', ['lint'], function () {
return gulp.src('./test/**.js')
.pipe(plumber())
.pipe(plugins.mocha({
grep: process.env.FILTER || undefined,
reporter: 'spec',
growl: true
}));
});

var browsers = process.env.BROWSERS || process.env.BROWSER || 'Firefox';

gulp.task('test-browser', ['build-test'], function() {
return gulp.src('./file-list-at-karma-conf-file')
.pipe(plugins.karma({
configFile: 'karma.conf.js',
browsers: browsers.split(' '),
action: 'run'
}))
.pipe(plumber());
});

gulp.task('watch-browser', ['build-test'], function() {
gulp.task('test-browser', ['build'], function() {
return gulp.src('./file-list-at-karma-conf-file')
.pipe(plugins.karma({
configFile: 'karma.conf.js',
browsers: browsers.split(' '),
action: 'watch'
}))
});

gulp.task('watch', function() {

gulp.watch(['./lib/**', './src/**', './test/**'], ['test']);
browsers: browsers,
action: 'run'
}));
});

gulp.task('default', ['test']);
gulp.task('watch', ['test'], function() {
watching = true;
return gulp.watch(['external/**', 'src/**', 'test/**'], ['test'])
.on('error', gutil.log);
});
4 changes: 2 additions & 2 deletions karma.conf.js
Expand Up @@ -3,8 +3,8 @@ module.exports = function(config) {
basePath: '.',
frameworks: ['mocha'],
files: [
'build/bundle.js',
'lib/diff_match_patch_uncompressed.js',
'build/bundle.js',
'external/diff_match_patch_uncompressed.js',
'node_modules/expect.js/expect.js',
'build/test-bundle.js'
],
Expand Down
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -39,8 +39,12 @@
"gulp-load-plugins": "~0.3.0",
"gulp-karma": "0.0.2",
"mocha": "~1.17.1",
"gulp-filter": "~0.2.1",
"karma-growler-reporter": "0.0.1"
"karma-growler-reporter": "0.0.1",
"gulp-clean": "~0.2.4",
"gulp-jshint": "~1.4.2",
"jshint-stylish": "~0.1.5",
"gulp-replace": "~0.2.0",
"gulp-plumber": "~0.5.6"
},
"bundleDependencies": [],
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/context.js
Expand Up @@ -16,7 +16,7 @@ Context.prototype.exit = function() {
};

Context.prototype.switchTo = function(next, pipe) {
if (typeof next == 'string' || next instanceof Pipe) {
if (typeof next === 'string' || next instanceof Pipe) {
this.nextPipe = next;
} else {
this.next = next;
Expand Down

0 comments on commit 05ea12c

Please sign in to comment.