Permalink
Browse files

Run babel-boilerplate

Handling removing Grunt will be done on a separate PR
- Keep both old and new configurations for ff:
  .editorconfig
  .jscrc
  .jshintrc
  .travis.yml (commented code-climate scripts for now
  for future plans to use it)
- Added non-default modules to package.json
  gulp-lintspaces
  gulp-yaml-validate
- test/setup/** is currently unused except for browserify
  Keep using test/unit/setup/** the same as Grunt
- Modify style changes suggested by eslint
- Model 'test' task similar to current grunt task
  • Loading branch information...
1 parent 7a0dcab commit aea39e2e084c76e170dc725c0786cebc2e8809c2 @cmisenas cmisenas committed with jasonLaster Aug 22, 2015
View
@@ -0,0 +1,6 @@
+{
+ "whitelist": [
+ "es6.modules",
+ "es6.templateLiterals"
+ ]
+}
View
@@ -1,11 +1,16 @@
-; EditorConfig is awesome: http://EditorConfig.org
+# EditorConfig is awesome: http://EditorConfig.org
root = true;
[*]
+# Ensure there's no lingering whitespace
trim_trailing_whitespace = true
+# Ensure a newline at the end of each file
insert_final_newline = true
[*.js]
+# Unix-style newlines
+end_of_line = lf
+charset = utf-8
indent_style = space
-indent_size = 2
+indent_size = 2
View
@@ -0,0 +1,11 @@
+{
+ "parser": "babel-eslint",
+ "rules": {
+ "strict": 0,
+ "quotes": [2, "single"]
+ },
+ "env": {
+ "browser": true,
+ "node": true
+ }
+}
View
@@ -3,14 +3,40 @@
*.swo
*.orig
.idea
-tmp/
ext/
-node_modules/
-coverage/
-.grunt/
-npm-debug.log
-bower_components/
-.grunt
+
reports
jsdoc
test/src/
+
+# Logs
+logs
+*.log
+
+# Runtime data
+pids
+*.pid
+*.seed
+
+# Directory for instrumented libs generated by jscoverage/JSCover
+lib-cov
+
+# Coverage directory used by tools like istanbul
+coverage
+
+# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Compiled binary addons (http://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directory
+# Commenting this out is preferred by some people, see
+# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
+node_modules
+bower_components
+coverage
+tmp
+
+# Users Environment Variables
+.lock-wscript
View
@@ -1,4 +1,5 @@
{
"preset": "google",
- "maximumLineLength": 120
-}
+ "maximumLineLength": 120,
+ "esnext": true
+}
View
@@ -42,7 +42,7 @@
"boss" : false,
"debug" : false,
"eqnull" : false,
- "esnext" : false,
+ "esnext" : true,
"evil" : false,
"expr" : false,
"funcscope" : false,
View
@@ -0,0 +1,200 @@
+// Load Gulp and all of our Gulp plugins
+import gulp from 'gulp';
+import loadPlugins from 'gulp-load-plugins'
+const $ = loadPlugins({rename: {'gulp-yaml-validate': 'yaml'}});
+
+// Load other npm modules
+import del from 'del';
+import glob from 'glob';
+import path from 'path';
+import isparta from 'isparta';
+import babelify from 'babelify';
+import watchify from 'watchify';
+import buffer from 'vinyl-buffer';
+import esperanto from 'esperanto';
+import browserify from 'browserify';
+import runSequence from 'run-sequence';
+import source from 'vinyl-source-stream';
+
+// Gather the library data from `package.json`
+import manifest from './package.json';
+const config = manifest.babelBoilerplateOptions;
+const mainFile = manifest.main;
+const destinationFolder = path.dirname(mainFile);
+const exportFileName = path.basename(mainFile, path.extname(mainFile));
+
+// Remove the built files
+gulp.task('clean', function(cb) {
+ del([destinationFolder], cb);
+});
+
+// Remove our temporary files
+gulp.task('clean-tmp', function(cb) {
+ del(['tmp'], cb);
+});
+
+// Send a notification when JSCS fails,
+// so that you know your changes didn't build
+function jscsNotify(file) {
+ if (!file.jscs) { return; }
+ return file.jscs.success ? false : 'JSCS failed';
+}
+
+function createLintTask(taskName, files, options) {
+ gulp.task(taskName, function() {
+ return gulp.src(files)
+ .pipe($.plumber())
+ .pipe($.lintspaces({editorconfig: '.editorconfig'}))
+ .pipe($.lintspaces.reporter())
+ .pipe($.eslint())
+ .pipe($.eslint.format())
+ .pipe($.eslint.failOnError())
+ .pipe($.jscs(options))
+ .pipe($.notify(jscsNotify));
+ });
+}
+
+// Lint our source code
+createLintTask('lint-src', ['src/**/*.js']);
+
+// Lint our test code
+createLintTask('lint-test', ['test/**/*.js'], { maximumLineLength: 200 });
+
+// Lint docs
+gulp.task('lint-docs', function() {
+ return gulp.src('docs/*.md')
+ .pipe($.lintspaces({editorconfig: '.editorconfig'}))
+ .pipe($.lintspaces.reporter());
+});
+
+// Build two versions of the library
+gulp.task('build', ['lint-src', 'clean'], function(done) {
+ esperanto.bundle({
+ base: 'src',
+ entry: config.entryFileName,
+ }).then(function(bundle) {
+ var res = bundle.toUmd({
+ // Don't worry about the fact that the source map is inlined at this step.
+ // `gulp-sourcemaps`, which comes next, will externalize them.
+ sourceMap: 'inline',
+ name: config.mainVarName
+ });
+
+ $.file(exportFileName + '.js', res.code, { src: true })
+ .pipe($.plumber())
+ .pipe($.sourcemaps.init({ loadMaps: true }))
+ .pipe($.babel())
+ .pipe($.sourcemaps.write('./'))
+ .pipe(gulp.dest(destinationFolder))
+ .pipe($.filter(['*', '!**/*.js.map']))
+ .pipe($.rename(exportFileName + '.min.js'))
+ .pipe($.sourcemaps.init({ loadMaps: true }))
+ .pipe($.uglify())
+ .pipe($.sourcemaps.write('./'))
+ .pipe(gulp.dest(destinationFolder))
+ .on('end', done);
+ })
+ .catch(done);
+});
+
+function bundle(bundler) {
+ return bundler.bundle()
+ .on('error', function(err) {
+ console.log(err.message);
+ this.emit('end');
+ })
+ .pipe($.plumber())
+ .pipe(source('./tmp/__spec-build.js'))
+ .pipe(buffer())
+ .pipe(gulp.dest(''))
+ .pipe($.livereload());
+}
+
+function getBundler() {
+ // Our browserify bundle is made up of our unit tests, which
+ // should individually load up pieces of our application.
+ // We also include the browserify setup file.
+ var testFiles = glob.sync('./test/unit/**/*.js');
+ var allFiles = ['./test/setup/browserify.js'].concat(testFiles);
+
+ // Create our bundler, passing in the arguments required for watchify
+ var bundler = browserify(allFiles, watchify.args);
+
+ // Watch the bundler, and re-bundle it whenever files change
+ bundler = watchify(bundler);
+ bundler.on('update', function() {
+ bundle(bundler);
+ });
+
+ // Set up Babelify so that ES6 works in the tests
+ bundler.transform(babelify.configure({
+ sourceMapRelative: __dirname + '/src'
+ }));
+
+ return bundler;
+};
+
+// Build the unit test suite for running tests
+// in the browser
+gulp.task('browserify', function() {
+ return bundle(getBundler());
+});
+
+function test() {
+ return gulp.src(['test/unit/setup/helpers.js', 'test/unit/**/*.spec.js'], {read: false})
+ .pipe($.mocha({
+ require: ['./test/unit/setup/node.js'],
+ reporter: 'dot',
+ globals: config.mochaGlobals
+ }));
+}
+
+gulp.task('coverage', ['lint-src', 'lint-test'], function(done) {
+ require('babel-core/register');
+ gulp.src(['src/**/*.js'])
+ .pipe($.istanbul({ instrumenter: isparta.Instrumenter }))
+ .pipe($.istanbul.hookRequire())
+ .on('finish', function() {
+ return test()
+ .pipe($.istanbul.writeReports())
+ .on('end', done);
+ });
+});
+
+// Lint and run our tests
+gulp.task('test', ['lint-src', 'lint-test', 'api'], function() {
+ require('babel-core/register');
+ test();
+});
+
+gulp.task('api', function() {
+ gulp.src(['api/*.yaml'])
+ .pipe($.yaml());
+});
+
+// Ensure that linting occurs before browserify runs. This prevents
+// the build from breaking due to poorly formatted code.
+gulp.task('build-in-sequence', function(callback) {
+ runSequence(['lint-src', 'lint-test'], 'browserify', callback);
+});
+
+// These are JS files that should be watched by Gulp. When running tests in the browser,
+// watchify is used instead, so these aren't included.
+const jsWatchFiles = ['src/**/*', 'test/**/*'];
+// These are files other than JS files which are to be watched. They are always watched.
+const otherWatchFiles = ['package.json', '**/.eslintrc', '.jscsrc'];
+
+// Run the headless unit tests as you make changes.
+gulp.task('watch', function() {
+ const watchFiles = jsWatchFiles.concat(otherWatchFiles);
+ gulp.watch(watchFiles, ['test']);
+});
+
+// Set up a livereload environment for our spec runner
+gulp.task('test-browser', ['build-in-sequence'], function() {
+ $.livereload.listen({port: 35729, host: 'localhost', start: true});
+ return gulp.watch(otherWatchFiles, ['build-in-sequence']);
+});
+
+// An alias of test
+gulp.task('default', ['test']);
View
@@ -23,8 +23,10 @@
}
],
"scripts": {
- "test": "grunt test --mocha-reporter=dot",
- "coverage": "grunt coverage --mocha-reporter=dot"
+ "test": "gulp",
+ "test-browser": "gulp test-browser",
+ "build": "gulp build",
+ "coverage": "gulp coverage"
},
"author": {
"name": "Derick Bailey",
@@ -47,10 +49,35 @@
"underscore": "1.4.4 - 1.8.3"
},
"devDependencies": {
- "chai": "1.9.1",
- "chai-jq": "0.0.7",
- "chai-jquery": "1.2.1",
+ "babel-core": "^5.2.17",
+ "babel-eslint": "^4.0.5",
+ "babelify": "^6.0.0",
+ "browserify": "^11.0.1",
+ "chai": "^3.2.0",
+ "chai-jq": "^0.0.7",
+ "chai-jquery": "^2.0.0",
+ "del": "^1.1.1",
"dox": "git://github.com/jasonLaster/dox.git#marked",
+ "esperanto": "^0.7.4",
+ "glob": "^5.0.14",
+ "gulp": "^3.8.10",
+ "gulp-babel": "^5.0.0",
+ "gulp-eslint": "^1.0.0",
+ "gulp-file": "^0.2.0",
+ "gulp-filter": "^3.0.0",
+ "gulp-istanbul": "^0.10.0",
+ "gulp-jscs": "^2.0.0",
+ "gulp-lintspaces": "^0.3.0",
+ "gulp-livereload": "^3.4.0",
+ "gulp-load-plugins": "^0.10.0",
+ "gulp-mocha": "^2.0.0",
+ "gulp-notify": "^2.1.0",
+ "gulp-plumber": "^1.0.1",
+ "gulp-rename": "^1.2.0",
+ "gulp-sourcemaps": "^1.3.0",
+ "gulp-uglify": "^1.2.0",
+ "gulp-yaml-validate": "^1.0.2",
+
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-clean": "0.5.0",
@@ -68,16 +95,31 @@
"grunt-plato": "0.1.4",
"grunt-preprocess": "4.0.0",
"grunt-template": "0.2.3",
- "highlight.js": "8.2.0",
+ "load-grunt-tasks": "0.3.0",
+ "grunt-yaml-validate": "~0.1.1",
+
+ "highlight.js": "^8.7.0",
+ "isparta": "^3.0.3",
"jquery": "2.1.1",
"js-yaml": "3.1.0",
"jsdom": "2.0.0",
- "load-grunt-tasks": "0.3.0",
"marked": "0.3",
- "mocha": "1.19.0",
+ "mocha": "^2.1.0",
+ "run-sequence": "^1.0.2",
"sinon": "1.10.3",
- "sinon-chai": "2.5.0",
+ "sinon-chai": "^2.7.0",
"unwrap": "0.1.0",
- "grunt-yaml-validate": "~0.1.1"
+ "vinyl-buffer": "^1.0.0",
+ "vinyl-source-stream": "^1.0.0",
+ "watchify": "^3.3.1"
+ },
+ "babelBoilerplateOptions": {
+ "entryFileName": "backbone.marionette",
+ "mainVarName": "Marionette",
+ "mochaGlobals": [
+ "stub",
+ "spy",
+ "expect"
+ ]
}
}
Oops, something went wrong.

0 comments on commit aea39e2

Please sign in to comment.