From a3098819344314453f72dcd6611ca8270a3de970 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Wed, 1 Apr 2015 14:29:46 +0100 Subject: [PATCH 01/29] Configures webpack, not working nicely with bower --- lib/tasks/build.js | 105 ++++++++++++++++++++++++--------------------- package.json | 10 ++--- 2 files changed, 62 insertions(+), 53 deletions(-) diff --git a/lib/tasks/build.js b/lib/tasks/build.js index facea9a5..9d05addb 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -1,24 +1,19 @@ "use strict"; -var browserify = require('browserify'); -var source = require('vinyl-source-stream'); +var path = require('path'); +var fs = require('fs'); +var merge = require('merge-stream'); +var BowerPlugin = require('bower-webpack-plugin'); +var webpack = require('gulp-webpack'); var streamify = require('gulp-streamify'); var sass = require('gulp-ruby-sass'); var cleanCss = require('gulp-minify-css'); var uglify = require('gulp-uglify'); var rename = require('gulp-rename'); var gulpif = require('gulp-if'); -var merge = require('merge-stream'); var autoprefixer = require('gulp-autoprefixer'); var files = require('../helpers/files'); var log = require('../helpers/log'); -var hash = require('gulp-hash'); - -var hashOptions = { - algorithm: 'sha1', - hashLength: 10, - template: '<%= name %>-<%= hash %><%= ext %>' -}; module.exports = function(gulp, config) { var jsStream = module.exports.js(gulp, config); @@ -29,52 +24,69 @@ module.exports = function(gulp, config) { return jsStream || sassStream; }; +function BowerPlugin() { + var validPositions[]; + // Hacky way to get main file when bowerConfig.main is an array + function getMainFilePositions(modulePath) { + var bowerMain = JSON.parse(fs.readFileSync(path.join(modulePath, 'bower.json'))).main; + var validFilePositions = []; + if (Array.isArray(bowerMain)) { + for (var i = 0; i < bowerMain.length; i++) { + // Checks if file name ends in '.js' + if (bowerMain[i].indexOf('.js', bowerMain[i].length - 3) !== -1) { + validFilePositions.push(['main', i]); + } + } + } else { + validFilePositions.push(['main', 0]); + } + + return validFilePositions; + } + + var validFiles = ['main'].concat(getMainFilePositions()); + return new ResolverPlugin(new ResolverPlugin.DirectoryDescriptionFilePlugin('bower.json', validFiles)); +} + module.exports.js = function(gulp, config) { config = config || {}; var src = config.js || files.getMainJsPath() || null; if (src) { - var transforms = ['babelify', 'debowerify', 'textrequireify'].concat(config.transforms || []); - delete config.transforms; - - // Hackily shallow clone the config object - config = Object.keys(config).reduce(function(newConfig, current) { - newConfig[current] = config[current]; - return newConfig; - }, {}); - - var useSourceMaps = config.sourcemaps === true; + var loaders = ['babel-loader'].concat(config.loaders || []); config.env = config.env || 'development'; - config.debug = useSourceMaps || config.env === 'development'; + var useSourceMaps = config.sourcemaps === true || config.env === 'development'; var destFolder = config.buildFolder || files.getBuildFolderPath(); var dest = config.buildJs || 'main.js'; - log.secondary("Browserifying " + src); - - var bundle = browserify(src) - .require(src, {}); - - transforms.forEach(function(transform) { - // the usual use case - most of the time transforms work without needing any custom config - if (typeof transform === 'string') { - bundle.transform({}, transform); - // sometimes a config option is needed too, in which case the user will pass in an array [config, 'transform-name'] - } else if (transform.length === 2) { - bundle.transform.apply(bundle, transform); - // some transforms use a seemingly undocumented (deprecated?) API where they pass in an object generated using the transform's own js API - } else { - bundle.transform(transform); - } - }); - - return bundle.bundle(config) - .pipe(source(dest)) - .pipe(gulpif(config.env === 'production', streamify(uglify()))) - .pipe(gulpif(config.hash === true, streamify(hash(hashOptions)))) - .pipe(gulpif(config.hash === true, gulp.dest(destFolder))) - .pipe(gulpif(config.hash === true, hash.manifest(dest + '-asset-hash.json'))) + var webpackConfig = { + resolve: { + root: [path.join(process.cwd(), 'bower_components')] + }, + resolveLoader: { + root: path.join(__dirname, '../../node_modules') + }, + plugins: [ + BowerPlugin() + ], + module: { + loaders: [ + { test: /\.js$/, exclude: /node_modules/, loaders: loaders} + ] + }, + output: { + filename: dest + }, + devtool: useSourceMaps ? '#source-map' : '' + }; + + log.secondary("Webpacking " + src); + + return gulp.src(src) + .pipe(webpack(webpackConfig)) + // .pipe(gulpif(config.env === 'production', streamify(uglify()))) .pipe(gulp.dest(destFolder)); } }; @@ -113,9 +125,6 @@ module.exports.sass = function(gulp, config) { advanced: false }))) .pipe(rename(dest)) - .pipe(gulpif(config.hash === true, hash(hashOptions))) - .pipe(gulpif(config.hash === true, gulp.dest(destFolder))) - .pipe(gulpif(config.hash === true, hash.manifest(dest + '-asset-hash.json'))) .pipe(gulp.dest(destFolder)); } }; diff --git a/package.json b/package.json index d6798ca4..ecfc00b6 100644 --- a/package.json +++ b/package.json @@ -14,17 +14,16 @@ "test": "mocha -t 50000 `find . -name '*.test.js' -path './test/*'`" }, "dependencies": { - "babelify": "^5.0.3", + "babel-core": "^4.7.16", + "babel-loader": "^4.2.0", "bower-config": "^0.5.2", - "browserify": "~3.44.2", + "bower-webpack-plugin": "^0.1.6", "colors": "^0.6.2", "configstore": "^0.3.1", - "debowerify": "Financial-Times/debowerify", "es6-promise": "^1.0.0", "findit": "^1.1.1", "gulp": "^3.8.7", "gulp-autoprefixer": "^2.1.0", - "gulp-hash": "^2.0.3", "gulp-if": "^1.2.5", "gulp-jshint": "^1.8.4", "gulp-lintspaces": "^0.2.3", @@ -36,6 +35,7 @@ "gulp-streamify": "0.0.5", "gulp-uglify": "^1.0.1", "gulp-util": "^3.0.1", + "gulp-webpack": "^1.3.1", "gulp-webserver": "^0.9.0", "merge-stream": "^0.1.6", "minimist": "0.0.8", @@ -44,9 +44,9 @@ "portfinder": "0.2.x", "sassdoc": "^2.1.2", "semver": "^2.2.1", - "textrequireify": "^1.0.0", "through2": "^0.6.2", "vinyl-source-stream": "^1.0.0", + "webpack": "^1.7.3", "which": "^1.0.5" }, "devDependencies": { From 8653af14ba54707dbcf17432a4993bbc31065d5f Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Wed, 15 Jul 2015 18:59:19 +0100 Subject: [PATCH 02/29] Removes jsHint in favour of ESLint. Adds Babel-Runtime polyfill and transformer to fix paths --- .eslintrc | 25 +++++++++++++ .jshintrc | 17 --------- .npmignore | 2 +- README.md | 6 +-- config/.eslintrc | 38 +++++++++++++++++++ config/jshint.json | 26 ------------- gulpfile.js | 2 +- lib/origami-build-tools-cli.js | 2 +- lib/plugins/babelRuntimePathResolver.js | 50 +++++++++++++++++++++++++ lib/tasks/build.js | 20 ++++++++-- lib/tasks/demo.js | 7 +++- lib/tasks/test.js | 7 +++- lib/tasks/verify.js | 18 +++++---- lib/tasks/version.js | 2 +- package.json | 4 +- test/fixtures/o-test/.eslintrc | 38 +++++++++++++++++++ test/fixtures/o-test/demos/src/demo.js | 2 +- test/fixtures/o-test/jshint.json | 25 ------------- test/fixtures/o-test/main.js | 2 +- test/fixtures/o-test/src/js/test.js | 3 +- test/tasks/verify.test.js | 14 +++---- 21 files changed, 209 insertions(+), 101 deletions(-) create mode 100644 .eslintrc delete mode 100644 .jshintrc create mode 100644 config/.eslintrc delete mode 100644 config/jshint.json create mode 100644 lib/plugins/babelRuntimePathResolver.js create mode 100644 test/fixtures/o-test/.eslintrc delete mode 100644 test/fixtures/o-test/jshint.json diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000..222b59b7 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,25 @@ +{ + "env": { + "node": true, + "es6": true + }, + "ecmaFeatures": { + "modules": false + }, + "rules": { + "eqeqeq": 2, + "guard-for-in": 2, + "no-extend-native": 2, + "wrap-iife": 2, + "new-cap": 2, + "no-caller": 2, + "no-irregular-whitespace": 1, + "no-trailing-spaces": 2, + "strict": [2, "global"], + "quotes": [1, "single"], + "no-loop-func": 2, + "no-multi-spaces": 2, + "no-multiple-empty-lines": 2, + "one-var": [2, "never"] + } +} diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 5f356a47..00000000 --- a/.jshintrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "forin": true, - "noarg": true, - "noempty": true, - "eqeqeq": true, - "bitwise": true, - "strict": true, - "undef": true, - "unused": true, - "curly": true, - "newcap": true, - "immed": true, - "trailing": true, - "smarttabs": true, - "node": true, - "predef": ["Promise", "fetch"] -} diff --git a/.npmignore b/.npmignore index 5f2a6d72..9b1e1180 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,6 @@ .idea/ test/ *.md -.jshintrc +.eslintrc gulpfile.js .travis.yml diff --git a/README.md b/README.md index 4bcc0d21..225e37e9 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ All the tasks are built using [gulp](http://gulpjs.com/), and almost all of them [--buildCss=] Compiled CSS file (default: main.css) [--buildFolder=] Compiled assets directory (default: ./build/) [--scssLintPath=] Custom scss-lint configuration - [--jsHintPath=] Custom JSHint configuration + [--esLintPath=] Custom esLint configuration [--editorconfigPath=] Custom .editorconfig ### `install` @@ -145,8 +145,8 @@ Runs: * __scssLint(gulp, config)__ Config accepts: - scssLintPath: `String` Path to your custom 'scss-lint.yml' config file. (Default: 'origami-build-tools/config/scss-lint.yml') _This may be set for product development, but developers of Origami-compliant components are required to accept the default_ - excludeFiles `Array` e.g. `['!**/demo.scss']` -* __jsHint(gulp, config)__ Config accepts: - - jsHintPath: `String` Path to your custom jsHint config file. (Default: 'origami-build-tools/config/jshint.json' _This may be set for product development, but developers of Origami-compliant components are required to accept the default_ +* __esLint(gulp, config)__ Config accepts: + - esLintPath: `String` Path to your custom esLint config file. (Default: 'origami-build-tools/config/.eslintrc' _This may be set for product development, but developers of Origami-compliant components are required to accept the default_ - excludeFiles `Array` e.g. `['!**/demo.js']` * __lintspaces(gulp, config)__ Config accepts: - editorconfigPath: `String` Path to your '.editorconfig' that lintspaces uses for linting. (Default: 'origami-build-tools/config/.editorconfig') _This may be set for product development, but developers of Origami-compliant components are required to accept the default_ diff --git a/config/.eslintrc b/config/.eslintrc new file mode 100644 index 00000000..e8049373 --- /dev/null +++ b/config/.eslintrc @@ -0,0 +1,38 @@ +{ + "ecmaFeatures": { + "modules": true + }, + "env": { + "es6": true, + "browser": true + }, + "rules": { + "eqeqeq": 2, + "guard-for-in": 2, + "no-extend-native": 2, + "wrap-iife": 2, + "new-cap": 2, + "no-caller": 2, + "no-irregular-whitespace": 1, + "no-trailing-spaces": 2, + "no-multi-str": 0, + "dot-notation": 0, + "strict": [2, "global"], + "quotes": [1, "single"], + "valid-jsdoc": 1, + "no-multi-spaces": 2, + "no-multiple-empty-lines": 2, + "one-var": [2, "never"], + "constructor-super": 2, + "no-this-before-super": 2, + "no-var": 2, + "no-unused-vars": 2, + "prefer-const": 1 + }, + "globals": { + "require": true, + "module": true, + "exports": true, + "requireText": true + } +} diff --git a/config/jshint.json b/config/jshint.json deleted file mode 100644 index a6d52d43..00000000 --- a/config/jshint.json +++ /dev/null @@ -1,26 +0,0 @@ - { - "eqeqeq": true, - "forin": true, - "freeze": true, - "immed": true, - "newcap": true, - "noarg": true, - "nonbsp": true, - "undef": true, - "unused": "vars", - "strict": true, - "trailing": true, - - "esnext": true, - "expr": true, - "gcl": true, - "globalstrict": true, - "lastsemic": true, - "multistr": true, - "smarttabs": true, - "sub": true, - - "browser": true, - "nonstandard": true, - "predef": ["require", "module", "exports", "requireText"] -} diff --git a/gulpfile.js b/gulpfile.js index 4b2cd457..73a31d7c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -5,7 +5,7 @@ var obt = require('./lib/origami-build-tools'); gulp.task('verify', function() { return obt.verify(gulp, { - jsHintPath: '.jshintrc', + esLintPath: '.eslintrc', editorconfigPath: '.editorconfig' }); }); diff --git a/lib/origami-build-tools-cli.js b/lib/origami-build-tools-cli.js index 2b046a6f..a112feb2 100755 --- a/lib/origami-build-tools-cli.js +++ b/lib/origami-build-tools-cli.js @@ -47,7 +47,7 @@ function printUsage(commands) { console.log(' [--buildCss=] Compiled CSS file (default: main.css)'); console.log(' [--buildFolder=] Compiled assets directory (default: ./build/)'); console.log(' [--scssLintPath=] Custom scss-lint configuration'); - console.log(' [--jsHintPath=] Custom JSHint configuration'); + console.log(' [--esLintPath=] Custom esLint configuration'); console.log(' [--editorconfigPath=] Custom .editorconfig'); console.log(' [--npmRegistry=] Custom npm registry'); console.log(''); diff --git a/lib/plugins/babelRuntimePathResolver.js b/lib/plugins/babelRuntimePathResolver.js new file mode 100644 index 00000000..851364d8 --- /dev/null +++ b/lib/plugins/babelRuntimePathResolver.js @@ -0,0 +1,50 @@ +'use strict'; + +var path = require('path'); +var through = require('through2'); +var falafel = require('falafel'); +var fs = require('fs'); + +var prefix = /babel-runtime/; + +function create(config) { + return function(file) { + if (!(/\.js$/).test(file)) return through(); + + var rootDirectory = path.resolve(path.normalize(config.rootDirectory || './node_modules')); + + var tr = through(function(chunk, enc, callback) { + try { + this.push(parse(chunk)); + } catch(err) { + err.debowerifyFile = file; + err.sourcecode = chunk; + this.emit('error', err); + } + + return callback(); + }); + + return tr; + + function parse(source) { + return String(falafel(source, { locations: true, ecmaVersion: 6 }, function(node) { + // Find require() calls + if (node.type === 'CallExpression' && node.callee.type === 'Identifier') { + var requirePath; + + if (node.callee.name === 'require' && prefix.test(node.arguments[0].value)) { // require("babel-runtime/*") + requirePath = rootDirectory + '/' + node.arguments[0].value; + } else {// none of the above, skip + return; + } + + node.update('require('+JSON.stringify(requirePath)+');'); + } + })); + } + }; +} + +module.exports = create({}); +module.exports.create = create; diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 3da63ad9..529edc49 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -21,6 +21,7 @@ var log = require('../helpers/log'); var textrequireify = require('textrequireify'); var debowerify = require('debowerify'); var babelify = require('babelify'); +var babelRuntimePathResolver = require('../plugins/babelRuntimePathResolver'); module.exports = function(gulp, config) { var jsStream; @@ -43,9 +44,21 @@ module.exports.js = function(gulp, config) { var cwd = config.cwd || process.cwd(); if (src) { // See; https://github.com/substack/node-browserify#btransformtr-opts - var transforms = [babelify, { transform: debowerify, options: { bowerOptions: { cwd: cwd, relative: true }}}, textrequireify.create({ - rootDirectory: cwd - })].concat(config.transforms || []); + var transforms = [ + babelify.configure({ + optional: ['runtime'] + }), + babelRuntimePathResolver.create({ + rootDirectory: path.resolve(__dirname, '../../node_modules') + }), + { + transform: debowerify, + options: { bowerOptions: { cwd: cwd, relative: true }} + }, + textrequireify.create({ + rootDirectory: cwd + }) + ].concat(config.transforms || []); config.env = config.env || 'development'; var useSourceMaps = config.sourcemaps === true || config.env === 'development'; @@ -107,7 +120,6 @@ module.exports.sass = function(gulp, config) { config.env = config.env || 'development'; var useSourceMaps = config.sourcemaps === true || config.env === 'development'; - console.log("Current working directory: ", cwd); var sassConfig = { includePaths: [path.join(cwd, 'bower_components')].concat(config.sassIncludePaths || []), outputStyle: config.env === 'production' ? 'compressed' : 'nested' diff --git a/lib/tasks/demo.js b/lib/tasks/demo.js index 4d9de6ec..b2795d59 100644 --- a/lib/tasks/demo.js +++ b/lib/tasks/demo.js @@ -119,7 +119,12 @@ function buildHtml(gulp, demoConfig, staticSource) { var origamiJsonPath = path.join(process.cwd(), 'origami.json'); var origamiJsonFile = fs.readFileSync(origamiJsonPath, { encoding: 'utf8' }); - var origamiJson = JSON.parse(origamiJsonFile); + var origamiJson; + try { + origamiJson = JSON.parse(origamiJsonFile); + } catch(e) { + throw e + ' in ' + origamiJsonPath; + } var browserFeatures = []; if (origamiJson.browserFeatures) { browserFeatures = browserFeatures diff --git a/lib/tasks/test.js b/lib/tasks/test.js index f5dddf95..905e2dfc 100644 --- a/lib/tasks/test.js +++ b/lib/tasks/test.js @@ -177,10 +177,15 @@ module.exports.browserTest = function(gulp, config) { var commit; var packageJsonContent = fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf8'); - function cleanupTest() { + function cleanupTest(output) { fs.unlink('Procfile'); fs.unlink(config.nightwatchConfig.replace('json', 'tmp.json')); fs.writeFileSync(path.join(process.cwd(), 'package.json'), packageJsonContent, 'utf8'); + + if (output && output.stdout) { + log.secondary(output.stdout); + } + return haikro.destroy({ token: token, app: appName diff --git a/lib/tasks/verify.js b/lib/tasks/verify.js index e8b41278..9227b9f3 100644 --- a/lib/tasks/verify.js +++ b/lib/tasks/verify.js @@ -3,7 +3,7 @@ var log = require('../helpers/log'); var path = require('path'); var fs = require('fs'); -var jshint = require('gulp-jshint'); +var eslint = require('gulp-eslint'); var scsslint = require('gulp-scss-lint'); var lintspaces = require('gulp-lintspaces'); var through = require('through2'); @@ -24,7 +24,7 @@ if (fs.existsSync(excludePath)) { module.exports = function(gulp, config) { module.exports.origamiJson(); return merge( - module.exports.jsHint(gulp, config), + module.exports.esLint(gulp, config), module.exports.scssLint(gulp, config), module.exports.lintspaces(gulp, config) ); @@ -149,20 +149,22 @@ module.exports.scssLint = function(gulp, config) { }; /** - * Run the JSHint gulp plugin. + * Run the ESLint gulp plugin. */ -module.exports.jsHint = function(gulp, config) { +module.exports.esLint = function(gulp, config) { config = config || {}; - var configPath = config.jsHintPath || path.join(__dirname, '/../../config/jshint.json'); + var configPath = config.esLintPath || path.join(__dirname, '/../../config/.eslintrc'); // Exclude files specified in config.excludeFiles excludeFiles = excludeFiles.concat(config.excludeFiles || []); var combinedStream = combine( gulp.src(['**/*.js'].concat(excludeFiles)), - jshint(configPath), - jshint.reporter('default'), - jshint.reporter('fail') + eslint({ + configFile: configPath + }), + eslint.format('compact', process.stdout), + eslint.failAfterError() ); // Returns a combined stream so an error handler can be attached to the end of the pipeline, diff --git a/lib/tasks/version.js b/lib/tasks/version.js index 58e22bab..66720b16 100644 --- a/lib/tasks/version.js +++ b/lib/tasks/version.js @@ -1,6 +1,6 @@ 'use strict'; module.exports = function() { - console.log("v"+require(__dirname + '/../../package.json').version); + console.log("v"+require(path.join(__dirname, '/../../package.json')).version); }; module.exports.description = 'Print the installed version of Origami Build Tools'; diff --git a/package.json b/package.json index 5e1176f9..70e9a08d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test": "mocha -t 50000 `find . -name '*.test.js' -path './test/*'`" }, "dependencies": { + "babel-runtime": "^5.6.15", "babelify": "^6.1.2", "bower-config": "^0.6.1", "browserify": "^10.2.4", @@ -23,11 +24,12 @@ "debowerify": "^1.3.1", "denodeify": "^1.2.1", "es6-promise": "^2.3.0", + "falafel": "^1.2.0", "findit": "^2.0.0", "gulp": "^3.9.0", "gulp-autoprefixer": "^2.3.1", + "gulp-eslint": "^0.15.0", "gulp-if-else": "^1.0.3", - "gulp-jshint": "^1.11.0", "gulp-lintspaces": "^0.3.0", "gulp-minify-css": "^1.1.6", "gulp-mustache": "^1.0.2", diff --git a/test/fixtures/o-test/.eslintrc b/test/fixtures/o-test/.eslintrc new file mode 100644 index 00000000..0440d65d --- /dev/null +++ b/test/fixtures/o-test/.eslintrc @@ -0,0 +1,38 @@ +{ + "ecmaFeatures": { + "modules": true + }, + "env": { + "es6": true, + "browser": true + }, + "rules": { + "eqeqeq": 2, + "guard-for-in": 2, + "no-extend-native": 2, + "wrap-iife": 2, + "new-cap": 2, + "no-caller": 2, + "no-irregular-whitespace": 1, + "no-trailing-spaces": 2, + "no-multi-str": 0, + "dot-notation": 0, + "strict": [2, "global"], + "quotes": [1, "single"], + "valid-jsdoc": 1, + "no-multi-spaces": 2, + "no-multiple-empty-lines": 2, + "one-var": [2, "never"], + "constructor-super": 2, + "no-this-before-super": 2, + "no-var": 2, + "no-unused-vars": 0, + "prefer-const": 1 + }, + "globals": { + "require": true, + "module": true, + "exports": true, + "requireText": true + } +} diff --git a/test/fixtures/o-test/demos/src/demo.js b/test/fixtures/o-test/demos/src/demo.js index 4a5096e2..5f762797 100644 --- a/test/fixtures/o-test/demos/src/demo.js +++ b/test/fixtures/o-test/demos/src/demo.js @@ -1 +1 @@ -var demo = require('../../main'); // jshint ignore:line +var demo = require('../../main'); // eslint-disable-line diff --git a/test/fixtures/o-test/jshint.json b/test/fixtures/o-test/jshint.json deleted file mode 100644 index ee2b7ad5..00000000 --- a/test/fixtures/o-test/jshint.json +++ /dev/null @@ -1,25 +0,0 @@ - { - "eqeqeq": true, - "forin": true, - "freeze": true, - "immed": true, - "newcap": true, - "noarg": true, - "nonbsp": true, - "undef": true, - "strict": false, - "trailing": true, - - "esnext": true, - "expr": true, - "gcl": true, - "globalstrict": true, - "lastsemic": true, - "multistr": true, - "smarttabs": true, - "sub": true, - - "browser": true, - "nonstandard": true, - "predef": ["require", "module", "exports", "requireText"] -} diff --git a/test/fixtures/o-test/main.js b/test/fixtures/o-test/main.js index e8f98fc5..f35e0b62 100644 --- a/test/fixtures/o-test/main.js +++ b/test/fixtures/o-test/main.js @@ -1 +1 @@ -var Test = require('./src/js/test'); // jshint ignore:line +var Test = require('./src/js/test'); // eslint-disable-line diff --git a/test/fixtures/o-test/src/js/test.js b/test/fixtures/o-test/src/js/test.js index 85f246c3..94ee0942 100644 --- a/test/fixtures/o-test/src/js/test.js +++ b/test/fixtures/o-test/src/js/test.js @@ -1,6 +1,5 @@ -'use strict'; function Test() { - let name = 'test'; // jshint ignore:line + let name = 'test'; // eslint-disable-line } module.exports = Test; diff --git a/test/tasks/verify.test.js b/test/tasks/verify.test.js index ef86d69b..1418cf2c 100644 --- a/test/tasks/verify.test.js +++ b/test/tasks/verify.test.js @@ -19,7 +19,7 @@ describe('Verify task', function() { fs.copySync(path.resolve(obtPath, oTestPath), verifyTestPath); process.chdir(verifyTestPath); fs.writeFileSync('src/scss/verify.scss', '$color: #ccc;\n\np {\n color: $color!important ;\n}\n', 'utf8'); - fs.writeFileSync('src/js/verify.js', 'var test = "We live in financial times";'); + fs.writeFileSync('src/js/verify.js', 'const test = \'We live in financial times\';\n'); }); after(function() { @@ -45,17 +45,17 @@ describe('Verify task', function() { }); }); - it('should run jsHint with default config', function(done) { - verify.jsHint(gulp) + it('should run esLint with default config', function(done) { + verify.esLint(gulp) .on('error', function(error) { - expect(error.message).to.be('JSHint failed for: ' + path.resolve(verifyTestPath, 'src/js/verify.js')); + expect(error.message).to.be('Failed with 1 error'); done(); }); }); - it('should run jsHint with custom config', function(done) { - var stream = verify.jsHint(gulp, { - jsHintPath: 'jshint.json' + it('should run esLint with custom config', function(done) { + var stream = verify.esLint(gulp, { + esLintPath: '.eslintrc' }) .on('error', function(error) { expect(error.message).to.be(undefined); From 447eb8bf9b48dc847486e97d8c4824c92d76908b Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Thu, 6 Aug 2015 13:33:19 +0100 Subject: [PATCH 03/29] Passes new eslint rules and removed default rootDirectory path in babelRuntimeResolver --- .eslintrc | 4 ++ lib/helpers/command-line.js | 10 +-- lib/helpers/files.js | 90 ++++++++++++------------- lib/helpers/log.js | 2 +- lib/helpers/update-notifier.js | 3 +- lib/origami-build-tools-cli.js | 10 +-- lib/origami-build-tools.js | 2 +- lib/plugins/babelRuntimePathResolver.js | 13 ++-- lib/tasks/build.js | 10 +-- lib/tasks/demo.js | 30 ++++----- lib/tasks/install.js | 64 +++++++++--------- lib/tasks/test.js | 24 +++---- lib/tasks/verify.js | 4 +- lib/tasks/version.js | 4 +- test/fixtures/o-test/.eslintrc | 2 +- test/fixtures/o-test/src/js/test.js | 2 + test/helpers/files.test.js | 16 ++--- test/tasks/build.test.js | 8 +-- test/tasks/demo.test.js | 8 +-- 19 files changed, 160 insertions(+), 146 deletions(-) diff --git a/.eslintrc b/.eslintrc index 222b59b7..e8b48093 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,6 +8,7 @@ }, "rules": { "eqeqeq": 2, + "no-underscore-dangle": 0, "guard-for-in": 2, "no-extend-native": 2, "wrap-iife": 2, @@ -21,5 +22,8 @@ "no-multi-spaces": 2, "no-multiple-empty-lines": 2, "one-var": [2, "never"] + }, + "globals": { + "fetch": true } } diff --git a/lib/helpers/command-line.js b/lib/helpers/command-line.js index 4996f890..805dd30b 100644 --- a/lib/helpers/command-line.js +++ b/lib/helpers/command-line.js @@ -3,13 +3,13 @@ var childProcess = require('child_process'); var which = require('which'); var log = require('./log'); -var windows = (process.platform.indexOf("win32") >= 0 || process.platform.indexOf("win64") >= 0); +var windows = (process.platform.indexOf('win32') >= 0 || process.platform.indexOf('win64') >= 0); function run(command, args, options) { return new Promise(function(resolve, reject) { - var pro, - stdOut = "", - stdErr = ""; + var pro; + var stdOut = ''; + var stdErr = ''; if (windows) { args.unshift('/c', command); @@ -31,7 +31,7 @@ function run(command, args, options) { }); pro.on('close', function(code) { - var output = { "stderr": stdErr, "stdout": stdOut }; + var output = { 'stderr': stdErr, 'stdout': stdOut }; if (code !== 0) { output.err = code; diff --git a/lib/helpers/files.js b/lib/helpers/files.js index 83057da3..403e5cea 100644 --- a/lib/helpers/files.js +++ b/lib/helpers/files.js @@ -10,6 +10,30 @@ function getBuildFolderPath() { return path.join(process.cwd(), '/build/'); } +function requireIfExists(filePath) { + if (fs.existsSync(filePath)) { + return require(filePath); + } else { + return undefined; + } +} + +function getPackageJson() { + return requireIfExists(path.join(process.cwd(), '/package.json')); +} + +function packageJsonExists() { + return (typeof getPackageJson() !== 'undefined'); +} + +function getBowerJson() { + return requireIfExists(path.join(process.cwd(), '/bower.json')); +} + +function bowerJsonExists() { + return (typeof getBowerJson() !== 'undefined'); +} + function getMainSassPath() { var sassMainPath = path.join(process.cwd(), '/main.scss'); var bowerJson = getBowerJson(); @@ -23,9 +47,9 @@ function getMainSassPath() { } } if (isInBowerMain && !fileExists) { - log.primaryError("main.scss is listed in bower.json main, but file doesn't exist."); + log.primaryError('main.scss is listed in bower.json main, but file doesn\'t exist.'); } else if (!isInBowerMain && fileExists) { - log.primaryError("main.scss exists but is not listed in bower.json main."); + log.primaryError('main.scss exists but is not listed in bower.json main.'); } if (isInBowerMain && fileExists) { return sassMainPath; @@ -35,10 +59,10 @@ function getMainSassPath() { } function getMainJsPath() { - var jsMainPath = path.join(process.cwd(), '/main.js'), - bowerJson = getBowerJson(), - fileExists = fs.existsSync(jsMainPath), - isInBowerMain = false; + var jsMainPath = path.join(process.cwd(), '/main.js'); + var bowerJson = getBowerJson(); + var fileExists = fs.existsSync(jsMainPath); + var isInBowerMain = false; if (bowerJson) { if (bowerJson.main instanceof Array && bowerJson.main.indexOf('main.js') > -1) { isInBowerMain = true; @@ -47,9 +71,9 @@ function getMainJsPath() { } } if (isInBowerMain && !fileExists) { - log.primaryError("main.js is listed in bower.json main, but file doesn't exist."); + log.primaryError('main.js is listed in bower.json main, but file doesn\'t exist.'); } else if (!isInBowerMain && fileExists) { - log.primaryError("main.js exists but is not listed in bower.json main."); + log.primaryError('main.js exists but is not listed in bower.json main.'); } if (isInBowerMain && fileExists) { return jsMainPath; @@ -58,43 +82,19 @@ function getMainJsPath() { } } -function requireIfExists(path) { - if (fs.existsSync(path)) { - return require(path); - } else { - return undefined; - } -} - -function getPackageJson() { - return requireIfExists(path.join(process.cwd(), '/package.json')); -} - -function packageJsonExists() { - return (typeof getPackageJson() !== "undefined"); -} - -function getBowerJson() { - return requireIfExists(path.join(process.cwd(), '/bower.json')); -} - -function bowerJsonExists() { - return (typeof getBowerJson() !== "undefined"); -} - function getModuleName() { var bowerJson = getBowerJson(); if (bowerJson) { return bowerJson.name; } - return ""; + return ''; } function recursiveFileSearch(root, ext) { return new Promise(function(resolve) { - var excluded = ['.git', '.idea', 'bower_components', 'node_modules'], - finder = find(root), - files = []; + var excluded = ['.git', '.idea', 'bower_components', 'node_modules']; + var finder = find(root); + var files = []; finder.on('directory', function(dir, stat, stop) { var base = path.basename(dir); if (excluded.indexOf(base) > -1) { @@ -113,17 +113,17 @@ function recursiveFileSearch(root, ext) { } function getSassFilesList() { - return recursiveFileSearch(process.cwd(), ".scss"); + return recursiveFileSearch(process.cwd(), '.scss'); } function sassSupportsSilent(files) { return new Promise(function(resolve, reject) { - var supportsSilent = false, - moduleName = getModuleName(); + var supportsSilent = false; + var moduleName = getModuleName(); if (moduleName) { for (var c = 0; c < files.length; c++) { - var fileContents = fs.readFileSync(files[c], { encoding: "utf-8" }); - if (fileContents.indexOf(moduleName + "-is-silent") >= 0) { + var fileContents = fs.readFileSync(files[c], { encoding: 'utf-8' }); + if (fileContents.indexOf(moduleName + '-is-silent') >= 0) { supportsSilent = true; break; } @@ -146,14 +146,14 @@ function getNodeModulesDirectoryInUse() { if (err) { reject(err); } - conf.findPrefix(process.cwd(), function(err, pathPrefix) { - if (err) { - reject(err); + conf.findPrefix(process.cwd(), function(e, pathPrefix) { + if (e) { + reject(e); } var nodeModulesPath = pathPrefix; if (pathPrefix) { - nodeModulesPath = path.join(pathPrefix, "node_modules"); + nodeModulesPath = path.join(pathPrefix, 'node_modules'); } resolve(nodeModulesPath); diff --git a/lib/helpers/log.js b/lib/helpers/log.js index f86493dd..66c9627d 100644 --- a/lib/helpers/log.js +++ b/lib/helpers/log.js @@ -4,7 +4,7 @@ require('colors'); var debugLog = function() {}; -if (process.env.OBT_DEBUG === "true") { +if (process.env.OBT_DEBUG === 'true') { debugLog = function(text) { console.log(String(text).grey); }; diff --git a/lib/helpers/update-notifier.js b/lib/helpers/update-notifier.js index 99de7322..8ceedcd8 100644 --- a/lib/helpers/update-notifier.js +++ b/lib/helpers/update-notifier.js @@ -3,6 +3,7 @@ require('colors'); var https = require('https'); +var path = require('path'); var Configstore = require('configstore'); var semver = require('semver'); var log = require('./log'); @@ -39,7 +40,7 @@ function checkVersion() { } function getCurrentVersion() { - return require(__dirname + '/../../package.json').version; + return require(path.join(__dirname, '/../../package.json')).version; } function updateNotifier() { diff --git a/lib/origami-build-tools-cli.js b/lib/origami-build-tools-cli.js index a112feb2..3963886d 100755 --- a/lib/origami-build-tools-cli.js +++ b/lib/origami-build-tools-cli.js @@ -1,6 +1,6 @@ #! /usr/bin/env node -"use strict"; +'use strict'; var argv = require('minimist')(process.argv.slice(2)); var gulp = require('gulp'); @@ -60,8 +60,8 @@ if (argv.version) { argv._[0] = '--version'; } -var watch = !!argv.watch, - argument = argv._[0]; +var watch = !!argv.watch; +var argument = argv._[0]; function reportTaskError(error) { if (Array.isArray(error)) { @@ -69,7 +69,7 @@ function reportTaskError(error) { } else if (error) { log.primaryError(error); } - process.exit(1); + process.exit(1); // eslint-disable-line no-process-exit } function reportFinished() { @@ -106,5 +106,5 @@ if (tasks.isValid(argument)) { } printUsage(tasks.loadAll()); - process.exit(2); + process.exit(2); // eslint-disable-line no-process-exit } diff --git a/lib/origami-build-tools.js b/lib/origami-build-tools.js index 4652fa83..cb1be05b 100755 --- a/lib/origami-build-tools.js +++ b/lib/origami-build-tools.js @@ -37,7 +37,7 @@ TaskLoader.prototype.load = function(taskName) { var startTime = process.hrtime(); var module = require(this.tasks[taskName]); var timeTaken = process.hrtime(startTime); - log.debug("Loaded task: " + taskName + " in " + timeTaken.join(".") + "s"); + log.debug('Loaded task: ' + taskName + ' in ' + timeTaken.join('.') + 's'); this.taskCache[taskName] = module; return module; }; diff --git a/lib/plugins/babelRuntimePathResolver.js b/lib/plugins/babelRuntimePathResolver.js index 851364d8..ad7ee143 100644 --- a/lib/plugins/babelRuntimePathResolver.js +++ b/lib/plugins/babelRuntimePathResolver.js @@ -3,15 +3,20 @@ var path = require('path'); var through = require('through2'); var falafel = require('falafel'); -var fs = require('fs'); var prefix = /babel-runtime/; function create(config) { return function(file) { - if (!(/\.js$/).test(file)) return through(); + if (!(/\.js$/).test(file)) { + return through(); + } + + if (!config.rootDirectory) { + throw 'Missing \'rootDirectory\' config option to where the babel-runtime directory is'; + } - var rootDirectory = path.resolve(path.normalize(config.rootDirectory || './node_modules')); + var rootDirectory = path.normalize(config.rootDirectory); var tr = through(function(chunk, enc, callback) { try { @@ -39,7 +44,7 @@ function create(config) { return; } - node.update('require('+JSON.stringify(requirePath)+');'); + node.update('require(' + JSON.stringify(requirePath) + ');'); } })); } diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 529edc49..4d5e8bee 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -67,18 +67,18 @@ module.exports.js = function(gulp, config) { var destFolder = config.buildFolder || files.getBuildFolderPath(); var dest = config.buildJs || 'main.js'; - log.secondary("Browserifying " + src); + log.secondary('Browserifying ' + src); var bundle = browserify(config) .add(src) .require(src, { entry: true }); - bundle = transforms.reduce(function(bundle, transform) { + bundle = transforms.reduce(function(bundler, transform) { if (transform.options && transform.transform) { - return bundle.transform(transform.transform, transform.options); + return bundler.transform(transform.transform, transform.options); } - return bundle.transform(transform); + return bundler.transform(transform); }, bundle); var combinedStream = combine( @@ -115,7 +115,7 @@ module.exports.sass = function(gulp, config) { var destFolder = config.buildFolder || files.getBuildFolderPath(); var dest = config.buildCss || 'main.css'; - log.secondary("Compiling " + src); + log.secondary('Compiling ' + src); config.env = config.env || 'development'; var useSourceMaps = config.sourcemaps === true || config.env === 'development'; diff --git a/lib/tasks/demo.js b/lib/tasks/demo.js index b2795d59..145f0078 100644 --- a/lib/tasks/demo.js +++ b/lib/tasks/demo.js @@ -14,8 +14,8 @@ portfinder.basePort = 8080; var builtFiles = {}; var defaultDemoConfig = { - documentClasses: "", - description: "", + documentClasses: '', + description: '', expanded: true }; var server; @@ -26,16 +26,16 @@ function buildSass(gulp, demoConfig) { var dest = path.join(process.cwd(), '/demos/local/'); if (builtFiles.css.indexOf(src) === -1) { if (!fs.existsSync(src)) { - throw new Error("Sass file not found: " + src); + throw new Error('Sass file not found: ' + src); } - var bowerConfig = files.getBowerJson(), - prefixSass = ''; + var bowerConfig = files.getBowerJson(); + var prefixSass = ''; // If module has o-assets as a dependency, set local demos to use local assets if (bowerConfig.dependencies && bowerConfig.dependencies['o-assets']) { var moduleName = bowerConfig.name; - prefixSass = '@import "o-assets/main";\n'+ - '@include oAssetsSetModulePaths(('+moduleName+': ""));\n'; + prefixSass = '@import \'o-assets/main\';\n' + + '@include oAssetsSetModulePaths((' + moduleName + ': ""));\n'; } builtFiles.css.push(src); @@ -67,7 +67,7 @@ function buildJs(gulp, demoConfig) { var dest = path.basename(demoConfig.js); if (builtFiles.js.indexOf(src) === -1) { if (!fs.existsSync(src)) { - throw new Error("JavaScript file not found: " + src); + throw new Error('JavaScript file not found: ' + src); } builtFiles.js.push(src); @@ -115,7 +115,7 @@ function buildHtml(gulp, demoConfig, staticSource) { data.oDemoDocumentClasses = demoConfig.documentClasses || demoConfig.bodyClasses; data.oDemoTpl = fs.readFileSync(src, {encoding: 'utf8'}); - log.secondary("Rendering: " + dest + destName); + log.secondary('Rendering: ' + dest + destName); var origamiJsonPath = path.join(process.cwd(), 'origami.json'); var origamiJsonFile = fs.readFileSync(origamiJsonPath, { encoding: 'utf8' }); @@ -154,7 +154,7 @@ function getStylesheetTags(sassPath, dependencies, staticSource) { } stylesheets += ''; } else { - stylesheets += ''; + stylesheets += ''; } return stylesheets; } @@ -167,7 +167,7 @@ function getScriptTags(scriptPath, dependencies, staticSource) { } scripts += ''; } else { - scripts += ''; + scripts += ''; } return scripts; } @@ -227,7 +227,7 @@ module.exports = function(gulp, config) { config.local = config.runServer ? config.runServer : config.local; var configPath; - var configPaths = ["demos/src/config.json", "demos/src/config.js"]; + var configPaths = ['demos/src/config.json', 'demos/src/config.js']; if (config.demoConfig) { configPaths = [config.demoConfig]; @@ -241,7 +241,7 @@ module.exports = function(gulp, config) { } if (configPath) { - log.primary("Building" + (config.local ? " local and" : "") + " build service demos (config: " + configPath + ')'); + log.primary('Building' + (config.local ? ' local and' : '') + ' build service demos (config: ' + configPath + ')'); var demosConfig = require(path.join(process.cwd(), '/' + configPath)); var demos = []; @@ -252,7 +252,7 @@ module.exports = function(gulp, config) { log.primary('WARNING: Deprecated demo config format. Generating the new format...'); demosConfig.demos = convertToNewFormat(demosConfig.demos); log.secondary(JSON.stringify(demosConfig.demos, null, 2)); - log.primary('Copy and paste this config into the "demos" key in demos/src/config.json'); + log.primary('Copy and paste this config into the \'demos\' key in demos/src/config.json'); log.primary('Full documentation: http://origami.ft.com/docs/component-spec/modules/#demo-config-file'); } @@ -321,7 +321,7 @@ module.exports.runServer = function(gulp, config) { config = config || {}; - log.primary('Open http://localhost:'+port+'/demos/local/ in a browser to view the demos'); + log.primary('Open http://localhost:' + port + '/demos/local/ in a browser to view the demos'); server = gulp.src('.') .pipe(webserver({ diff --git a/lib/tasks/install.js b/lib/tasks/install.js index f7d7bb0c..cbc8f5d1 100644 --- a/lib/tasks/install.js +++ b/lib/tasks/install.js @@ -17,10 +17,36 @@ var bestGems = { }; var versions = { - scssLint: '>=0.27.0 <='+bestGems.scssLint, + scssLint: '>=0.27.0 <=' + bestGems.scssLint, bower: '^1.3.0' }; +function getCommandVersion(command, versionFlag) { + return new Promise(function(resolve, reject) { + commandLine.run(command, [versionFlag, '2>/dev/null']) + .then(function(output) { + var re = new RegExp(/\d+(\.\d+)+/); + var version = output.stdout.trim().match(re); + + if (version) { + resolve(version[0]); + } else { + // Craft an error message, although the command returned successfully, + // parsing of the version failed. + reject({ + stderr: 'Could not get version for command `' + + command + ' ' + versionFlag + + '`. Running command output: ' + + output.stderr + '\n' + output.stdout, + stdout: '' + }); + } + }, function() { + resolve(-1); + }); + }); +} + function getInstalledScssLintGemVersion() { return getCommandVersion('scss-lint', '--version'); } @@ -33,8 +59,8 @@ function getBowerCommand() { .then(function(modulespath) { var bowerCommand = path.join(modulespath, '/.bin/bower'); resolve(bowerCommand); - }, function(err) { - reject(err); + }, function(error) { + reject(error); }); } else { process.nextTick(function() { resolve(bowerPath); }); @@ -54,32 +80,6 @@ function getInstalledBowerVersion() { }); } -function getCommandVersion(command, versionFlag) { - return new Promise(function(resolve, reject) { - commandLine.run(command, [versionFlag, '2>/dev/null']) - .then(function(output) { - var re = new RegExp(/\d+(\.\d+)+/); - var version = output.stdout.trim().match(re); - - if (version) { - resolve(version[0]); - } else { - // Craft an error message, although the command returned successfully, - // parsing of the version failed. - reject({ - stderr: 'Could not get version for command `' + - command + ' ' + versionFlag + - '`. Running command output: ' + - output.stderr + '\n' + output.stdout, - stdout: '' - }); - } - }, function() { - resolve(-1); - }); - }); -} - function cliSuccess(output) { if (output && output.stderr) { console.log(output.stderr); @@ -196,7 +196,7 @@ module.exports.runNpmInstall = function(config) { return new Promise(function(resolve, reject) { var args = ['install']; if (config.registry) { - args.push(['--registry '+config.registry]); + args.push(['--registry ' + config.registry]); } // if (config.verbose) { @@ -242,13 +242,13 @@ module.exports.runBowerInstall = function(config) { // Try bower config var BowerConfig = require('bower-config'); - var loadedBowerConfig = new BowerConfig(process.cwd()).load(); + var loadedBowerConfig = new BowerConfig(process.cwd()).load(); // The registry key defaults to a string if the bowerrc is // not configured and an object with search key if it is // configured. This coerces the search key into an array // in order to filter the search registry by host. - var registrySearchConfig = Array.isArray(loadedBowerConfig._config.registry.search) ? + var registrySearchConfig = Array.isArray(loadedBowerConfig._config.registry.search) ? loadedBowerConfig._config.registry.search : [loadedBowerConfig._config.registry]; diff --git a/lib/tasks/test.js b/lib/tasks/test.js index 905e2dfc..e6c79725 100644 --- a/lib/tasks/test.js +++ b/lib/tasks/test.js @@ -48,6 +48,17 @@ function silentCompilationTest(gulp, silent) { }); } +function runSilentModeTest(gulp) { + return new Promise(function(resolve, reject) { + module.exports.silentCompilation(gulp) + .then(function() { + resolve(module.exports.nonSilentCompilation(gulp)); + }).catch(function(error) { + reject(error); + }); + }); +} + module.exports = function(gulp, config) { return new Promise(function(resolve, reject) { return Promise.all([ @@ -66,17 +77,6 @@ module.exports = function(gulp, config) { }); }; -function runSilentModeTest(gulp) { - return new Promise(function(resolve, reject) { - module.exports.silentCompilation(gulp) - .then(function() { - resolve(module.exports.nonSilentCompilation(gulp)); - }).catch(function(error) { - reject(error); - }); - }); -} - module.exports.silentCompilation = function(gulp) { return silentCompilationTest(gulp, true); }; @@ -142,7 +142,7 @@ module.exports._runBrowserTest = function(config) { } configContent = JSON.parse(configContent); - configContent.test_settings.default.launch_url = config.testUrl; + configContent.test_settings.default.launch_url = config.testUrl; // eslint-disable-line camelcase var tempNightwatchConfigPath = nightwatchConfigPath.replace('json', 'tmp.json'); diff --git a/lib/tasks/verify.js b/lib/tasks/verify.js index 9227b9f3..888320f3 100644 --- a/lib/tasks/verify.js +++ b/lib/tasks/verify.js @@ -88,12 +88,12 @@ function scsslintFailReporter() { * Custom fail reporter that doesn't fail on SCSS-Lint warnings */ function lintspacesFailReporter() { - var logLintspacesErrors = function(error, path) { + var logLintspacesErrors = function(error, errorPath) { console.error( '[%s] %s in (%s:%d)\n', gutil.colors.green('gulp-lintspaces'), gutil.colors.red(error.message), - path, + errorPath, error.line ); }; diff --git a/lib/tasks/version.js b/lib/tasks/version.js index 66720b16..ded6a32c 100644 --- a/lib/tasks/version.js +++ b/lib/tasks/version.js @@ -1,6 +1,8 @@ 'use strict'; +var path = require('path'); + module.exports = function() { - console.log("v"+require(path.join(__dirname, '/../../package.json')).version); + console.log('v' + require(path.join(__dirname, '/../../package.json')).version); }; module.exports.description = 'Print the installed version of Origami Build Tools'; diff --git a/test/fixtures/o-test/.eslintrc b/test/fixtures/o-test/.eslintrc index 0440d65d..4956f7af 100644 --- a/test/fixtures/o-test/.eslintrc +++ b/test/fixtures/o-test/.eslintrc @@ -17,7 +17,7 @@ "no-trailing-spaces": 2, "no-multi-str": 0, "dot-notation": 0, - "strict": [2, "global"], + "strict": [2, "function"], "quotes": [1, "single"], "valid-jsdoc": 1, "no-multi-spaces": 2, diff --git a/test/fixtures/o-test/src/js/test.js b/test/fixtures/o-test/src/js/test.js index 94ee0942..7c772287 100644 --- a/test/fixtures/o-test/src/js/test.js +++ b/test/fixtures/o-test/src/js/test.js @@ -1,3 +1,5 @@ +/* eslint-disable strict */ + function Test() { let name = 'test'; // eslint-disable-line } diff --git a/test/helpers/files.test.js b/test/helpers/files.test.js index ae1c9757..e17ddd8a 100644 --- a/test/helpers/files.test.js +++ b/test/helpers/files.test.js @@ -31,22 +31,22 @@ describe('Files helper', function() { it('should return module name', function() { expect(files.getModuleName()).to.be(''); - fs.writeFileSync('bower.json', JSON.stringify({ name: "o-test" }), 'utf8'); + fs.writeFileSync('bower.json', JSON.stringify({ name: 'o-test' }), 'utf8'); expect(files.getModuleName()).to.be('o-test'); fs.unlink(path.resolve(filesTestPath, 'bower.json')); }); it('should return a list of Sass files', function(done) { - files.getSassFilesList().then(function(files) { + files.getSassFilesList().then(function(sassFiles) { var testResults = [path.join(process.cwd() + '/main.scss'), path.join(process.cwd() + '/src/scss/_variables.scss')]; - expect(files).to.contain(testResults[0]); - expect(files).to.contain(testResults[1]); + expect(sassFiles).to.contain(testResults[0]); + expect(sassFiles).to.contain(testResults[1]); done(); }); }); it('should check if the module supports silent mode', function(done) { - fs.writeFileSync('bower.json', JSON.stringify({ name: "o-test" }), 'utf8'); + fs.writeFileSync('bower.json', JSON.stringify({ name: 'o-test' }), 'utf8'); files.getSassFilesList() .then(files.sassSupportsSilent) .then(function(supportsSilent) { @@ -58,7 +58,7 @@ describe('Files helper', function() { describe('Main files', function() { before(function() { - fs.writeFileSync('bower.json', JSON.stringify({ name: "o-test" }), 'utf8'); + fs.writeFileSync('bower.json', JSON.stringify({ name: 'o-test' }), 'utf8'); }); after(function() { @@ -98,7 +98,7 @@ describe('Files helper', function() { it('should get bower.json', function() { expect(typeof files.getBowerJson()).to.be('undefined'); fs.writeFileSync('bower.json', JSON.stringify({}), 'utf8'); - expect(typeof files.getBowerJson()).to.not.be("undefined"); + expect(typeof files.getBowerJson()).to.not.be('undefined'); }); it('should check if bower.json is present', function() { @@ -122,7 +122,7 @@ describe('Files helper', function() { it('should get package.json', function() { expect(typeof files.getPackageJson()).to.be('undefined'); fs.writeFileSync('package.json', JSON.stringify({}), 'utf8'); - expect(typeof files.getPackageJson()).to.not.be("undefined"); + expect(typeof files.getPackageJson()).to.not.be('undefined'); }); it('should check if package.json is present', function() { diff --git a/test/tasks/build.test.js b/test/tasks/build.test.js index d8188808..515312b5 100644 --- a/test/tasks/build.test.js +++ b/test/tasks/build.test.js @@ -26,8 +26,8 @@ describe('Build task', function() { process.chdir(buildTestPath); fs.writeFileSync('bower.json', JSON.stringify( { - name: "o-test", - main: "main.js" + name: 'o-test', + main: 'main.js' } ), 'utf8'); }); @@ -118,8 +118,8 @@ describe('Build task', function() { process.chdir(buildTestPath); fs.writeFileSync('bower.json', JSON.stringify( { - name: "o-test", - main: "main.scss" + name: 'o-test', + main: 'main.scss' } ), 'utf8'); }); diff --git a/test/tasks/demo.test.js b/test/tasks/demo.test.js index a4bd47ec..60990232 100644 --- a/test/tasks/demo.test.js +++ b/test/tasks/demo.test.js @@ -43,7 +43,7 @@ describe('Demo task', function() { it('should fail if there is not a bower.json file', function() { return demo(gulp) .then(function() { - throw new Error("No error thrown"); + throw new Error('No error thrown'); }, function(err) { setTimeout(function() { expect(err).to.be('Couldn\'t find a bower.json file. Please add one and try again'); @@ -56,7 +56,7 @@ describe('Demo task', function() { fs.writeFileSync('bower.json', '{"name":"o-test"}', 'utf8'); return demo(gulp) .then(function() { - throw new Error("No error thrown"); + throw new Error('No error thrown'); }, function(err) { setTimeout(function() { expect(err).to.be('Couldn\'t find demos config path, checked: demos/src/config.json,demos/src/config.js'); @@ -169,8 +169,8 @@ describe('Demo task', function() { var newOrigamiConfig = extend({}, JSON.parse(origamiConfig)); var updatedOrigamiConfig = JSON.parse(fs.readFileSync('origami.json', 'utf8')); var demosConfig = []; - demosConfig.push({"path": "/demos/test1.html", "expanded": true, "description": "First test"}); - demosConfig.push({"path": "/demos/test2.html", "expanded": false, "description": "Second test"}); + demosConfig.push({'path': '/demos/test1.html', 'expanded': true, 'description': 'First test'}); + demosConfig.push({'path': '/demos/test2.html', 'expanded': false, 'description': 'Second test'}); newOrigamiConfig.demos = demosConfig; expect(JSON.stringify(updatedOrigamiConfig)).to.be(JSON.stringify(newOrigamiConfig)); fs.writeFileSync('origami.json', origamiConfig, 'utf8'); From 08b17d1c856810cf61fba21628fdd47a7422d861 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Thu, 6 Aug 2015 13:51:55 +0100 Subject: [PATCH 04/29] Pushes eslint to v1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f94235a2..171135a3 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "findit": "^2.0.0", "gulp": "^3.9.0", "gulp-autoprefixer": "^2.3.1", - "gulp-eslint": "^0.15.0", + "gulp-eslint": "^1.0.0", "gulp-if-else": "^1.0.3", "gulp-lintspaces": "^0.3.0", "gulp-minify-css": "^1.1.6", From f6514013bb0d8b57fb49b8ab85df4b6e8490ccf7 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Thu, 6 Aug 2015 14:06:40 +0100 Subject: [PATCH 05/29] v4.0.0-beta.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 171135a3..704b91f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origami-build-tools", - "version": "3.3.0", + "version": "v4.0.0-beta.1", "description": "Origami component development tools.", "main": "./lib/origami-build-tools", "bin": { From 254d12aeafc17d77cb81e4b43642f27715e818c6 Mon Sep 17 00:00:00 2001 From: Matt Andrews Date: Thu, 6 Aug 2015 14:47:33 +0100 Subject: [PATCH 06/29] don't allow overwriting of globals [consistent with obt] --- config/.eslintrc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/.eslintrc b/config/.eslintrc index e8049373..02616e89 100644 --- a/config/.eslintrc +++ b/config/.eslintrc @@ -30,9 +30,9 @@ "prefer-const": 1 }, "globals": { - "require": true, - "module": true, - "exports": true, - "requireText": true + "require": false, + "module": false, + "exports": false, + "requireText": false } } From b0ae681ec1689895105760efeca36bd4a50a7578 Mon Sep 17 00:00:00 2001 From: Matt Andrews Date: Thu, 6 Aug 2015 14:57:18 +0100 Subject: [PATCH 07/29] let npm publish obt with `.eslintrc` --- .npmignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.npmignore b/.npmignore index 9b1e1180..5ad38d41 100644 --- a/.npmignore +++ b/.npmignore @@ -1,6 +1,5 @@ .idea/ test/ *.md -.eslintrc gulpfile.js .travis.yml From f26130e321745121e6441f650dc9584c4a854742 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Thu, 6 Aug 2015 15:44:07 +0100 Subject: [PATCH 08/29] v4.0.0-beta.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 704b91f1..0ccd0754 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origami-build-tools", - "version": "v4.0.0-beta.1", + "version": "v4.0.0-beta.2", "description": "Origami component development tools.", "main": "./lib/origami-build-tools", "bin": { From 575972bde338acc1d959a0bfeea455553f66245a Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Mon, 10 Aug 2015 15:58:25 +0100 Subject: [PATCH 09/29] Fixes eslint rules and babel path resolver --- .eslintrc | 4 +--- config/.eslintrc | 5 +--- lib/helpers/files.js | 8 +++---- lib/plugins/babelRuntimePathResolver.js | 2 +- lib/tasks/verify.js | 31 ++++++++++++------------- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/.eslintrc b/.eslintrc index e8b48093..c951e605 100644 --- a/.eslintrc +++ b/.eslintrc @@ -14,13 +14,11 @@ "wrap-iife": 2, "new-cap": 2, "no-caller": 2, - "no-irregular-whitespace": 1, - "no-trailing-spaces": 2, "strict": [2, "global"], "quotes": [1, "single"], "no-loop-func": 2, + "no-irregular-whitespace": 1, "no-multi-spaces": 2, - "no-multiple-empty-lines": 2, "one-var": [2, "never"] }, "globals": { diff --git a/config/.eslintrc b/config/.eslintrc index e8049373..99dd6d30 100644 --- a/config/.eslintrc +++ b/config/.eslintrc @@ -13,15 +13,12 @@ "wrap-iife": 2, "new-cap": 2, "no-caller": 2, - "no-irregular-whitespace": 1, - "no-trailing-spaces": 2, "no-multi-str": 0, "dot-notation": 0, "strict": [2, "global"], - "quotes": [1, "single"], "valid-jsdoc": 1, + "no-irregular-whitespace": 1, "no-multi-spaces": 2, - "no-multiple-empty-lines": 2, "one-var": [2, "never"], "constructor-super": 2, "no-this-before-super": 2, diff --git a/lib/helpers/files.js b/lib/helpers/files.js index 403e5cea..d1aea452 100644 --- a/lib/helpers/files.js +++ b/lib/helpers/files.js @@ -135,11 +135,9 @@ function sassSupportsSilent(files) { }); } -/** - * Get the node_modules directory that will be used when `npm install` is run - * in the current working directory (process.cwd()). This is necessary as npm walks up the - * directory tree until it finds a node_modules directory when npm installing. - */ +// Get the node_modules directory that will be used when `npm install` is run +// in the current working directory (process.cwd()). This is necessary as npm walks up the +// directory tree until it finds a node_modules directory when npm installing. function getNodeModulesDirectoryInUse() { return new Promise(function(resolve, reject) { npmconf.load({}, function(err, conf) { diff --git a/lib/plugins/babelRuntimePathResolver.js b/lib/plugins/babelRuntimePathResolver.js index ad7ee143..3bb4e187 100644 --- a/lib/plugins/babelRuntimePathResolver.js +++ b/lib/plugins/babelRuntimePathResolver.js @@ -44,7 +44,7 @@ function create(config) { return; } - node.update('require(' + JSON.stringify(requirePath) + ');'); + node.update('require(' + JSON.stringify(requirePath) + ')'); } })); } diff --git a/lib/tasks/verify.js b/lib/tasks/verify.js index 888320f3..fb88dd15 100644 --- a/lib/tasks/verify.js +++ b/lib/tasks/verify.js @@ -63,9 +63,9 @@ function pathsToGlob(paths) { return globPatterns; } -/** - * Custom fail reporter that doesn't fail on SCSS-Lint warnings - */ +// +// Custom fail reporter that doesn't fail on SCSS-Lint warnings +// function scsslintFailReporter() { var stream = through.obj(function(file, enc, cb) { var error; @@ -84,9 +84,9 @@ function scsslintFailReporter() { return stream; } -/** - * Custom fail reporter that doesn't fail on SCSS-Lint warnings - */ +// +// Custom fail reporter that doesn't fail on SCSS-Lint warnings +// function lintspacesFailReporter() { var logLintspacesErrors = function(error, errorPath) { console.error( @@ -124,9 +124,9 @@ function lintspacesFailReporter() { return stream; } -/** - * Run the SCSS gulp plugin. - */ +// +// Run the SCSS gulp plugin. +// module.exports.scssLint = function(gulp, config) { config = config || {}; var configPath = config.scssLintPath || path.join(__dirname, '/../../config/scss-lint.yml'); @@ -148,9 +148,9 @@ module.exports.scssLint = function(gulp, config) { return combinedStream.resume(); }; -/** - * Run the ESLint gulp plugin. - */ +// +// Run the ESLint gulp plugin. +// module.exports.esLint = function(gulp, config) { config = config || {}; var configPath = config.esLintPath || path.join(__dirname, '/../../config/.eslintrc'); @@ -161,7 +161,8 @@ module.exports.esLint = function(gulp, config) { var combinedStream = combine( gulp.src(['**/*.js'].concat(excludeFiles)), eslint({ - configFile: configPath + configFile: configPath, + quiet: true }), eslint.format('compact', process.stdout), eslint.failAfterError() @@ -185,10 +186,8 @@ module.exports.lintspaces = function(gulp, config) { var combinedStream = combine.obj( gulp.src(['**/*.scss', '**/*.js'].concat(excludeFiles)), lintspaces({ + newlineMaximum: 1, ignores: ['js-comments'], - newline: true, - trailingspaces: true, - indentation: 'tabs', editorconfig: editorconfigPath }), lintspacesFailReporter() From 774a95aab113ce898f23fe4756e4b0291b68de54 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Mon, 10 Aug 2015 16:05:56 +0100 Subject: [PATCH 10/29] v4.0.0-beta.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0ccd0754..d43a01bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origami-build-tools", - "version": "v4.0.0-beta.2", + "version": "v4.0.0-beta.3", "description": "Origami component development tools.", "main": "./lib/origami-build-tools", "bin": { From 0bb17d6ae8081921629e50fb04dd177c306721fe Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Fri, 14 Aug 2015 11:25:32 +0100 Subject: [PATCH 11/29] Linter now errors with undefined variables being used, like globals --- .eslintrc | 2 ++ config/.eslintrc | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index c951e605..7f4d7c2c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -7,6 +7,8 @@ "modules": false }, "rules": { + "no-unused-vars": 2, + "no-undef": 2, "eqeqeq": 2, "no-underscore-dangle": 0, "guard-for-in": 2, diff --git a/config/.eslintrc b/config/.eslintrc index 51444440..8c067232 100644 --- a/config/.eslintrc +++ b/config/.eslintrc @@ -7,6 +7,8 @@ "browser": true }, "rules": { + "no-unused-vars": 2, + "no-undef": 2, "eqeqeq": 2, "guard-for-in": 2, "no-extend-native": 2, @@ -23,7 +25,6 @@ "constructor-super": 2, "no-this-before-super": 2, "no-var": 2, - "no-unused-vars": 2, "prefer-const": 1 }, "globals": { From 7408015f3be7c61f114c716bbc044a3a3d6a4d84 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Fri, 14 Aug 2015 11:25:50 +0100 Subject: [PATCH 12/29] v4.0.0-beta.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d43a01bb..456bd7db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origami-build-tools", - "version": "v4.0.0-beta.3", + "version": "v4.0.0-beta.4", "description": "Origami component development tools.", "main": "./lib/origami-build-tools", "bin": { From ccef201e5965373f353f4e00bdfaedc390bdacfd Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Mon, 17 Aug 2015 11:27:17 +0100 Subject: [PATCH 13/29] Stop linting multiple new lines and adds no-const-assign rule --- config/.eslintrc | 3 ++- lib/tasks/verify.js | 1 - test/fixtures/o-test/.eslintrc | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config/.eslintrc b/config/.eslintrc index 8c067232..aae59c67 100644 --- a/config/.eslintrc +++ b/config/.eslintrc @@ -25,7 +25,8 @@ "constructor-super": 2, "no-this-before-super": 2, "no-var": 2, - "prefer-const": 1 + "prefer-const": 1, + "no-const-assign": 2 }, "globals": { "require": false, diff --git a/lib/tasks/verify.js b/lib/tasks/verify.js index fb88dd15..a8e0daaa 100644 --- a/lib/tasks/verify.js +++ b/lib/tasks/verify.js @@ -186,7 +186,6 @@ module.exports.lintspaces = function(gulp, config) { var combinedStream = combine.obj( gulp.src(['**/*.scss', '**/*.js'].concat(excludeFiles)), lintspaces({ - newlineMaximum: 1, ignores: ['js-comments'], editorconfig: editorconfigPath }), diff --git a/test/fixtures/o-test/.eslintrc b/test/fixtures/o-test/.eslintrc index 4956f7af..76e680bd 100644 --- a/test/fixtures/o-test/.eslintrc +++ b/test/fixtures/o-test/.eslintrc @@ -27,7 +27,8 @@ "no-this-before-super": 2, "no-var": 2, "no-unused-vars": 0, - "prefer-const": 1 + "prefer-const": 1, + "no-const-assign": 2 }, "globals": { "require": true, From d6535b4931fb2b1261746f250e22009d265eb883 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Mon, 17 Aug 2015 11:27:30 +0100 Subject: [PATCH 14/29] v4.0.0-beta.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 456bd7db..f696d5a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origami-build-tools", - "version": "v4.0.0-beta.4", + "version": "v4.0.0-beta.5", "description": "Origami component development tools.", "main": "./lib/origami-build-tools", "bin": { From 55efaaf653e15f7e3655dbd966361d637ca6bf45 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Mon, 17 Aug 2015 11:36:32 +0100 Subject: [PATCH 15/29] v4.0.0-beta.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f696d5a4..5f43a03e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origami-build-tools", - "version": "v4.0.0-beta.5", + "version": "v4.0.0-beta.6", "description": "Origami component development tools.", "main": "./lib/origami-build-tools", "bin": { From d4b2932fd00de7aae3dbcc171ef1d985e10d949e Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Wed, 19 Aug 2015 13:47:14 +0100 Subject: [PATCH 16/29] Removes destFolder test --- lib/tasks/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/build.js b/lib/tasks/build.js index a04962c1..454219e0 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -52,7 +52,7 @@ module.exports.js = function(gulp, config) { // rootDirectory: cwd // }) - var destFolder = path.resolve(process.cwd(), 'build/build/build') || config.buildFolder || files.getBuildFolderPath(); + var destFolder = config.buildFolder || files.getBuildFolderPath(); var dest = config.buildJs || 'main.js'; var webpackConfig = { From 542c597087a6438691753f878934cc4f9d8e4efe Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Thu, 20 Aug 2015 11:37:47 +0100 Subject: [PATCH 17/29] Sets cwd for bower resolver and fixes bug where bower plugin was trying to compile non .js files --- lib/tasks/build.js | 14 ++++++++------ package.json | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 454219e0..8c9f3de1 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -38,7 +38,7 @@ module.exports = function(gulp, config) { module.exports.js = function(gulp, config) { config = config || {}; var src = config.js || files.getMainJsPath() || null; - // var cwd = config.cwd || process.cwd(); + var cwd = config.cwd || process.cwd(); if (src) { var loaders = ['babel'].concat(config.loaders || []); @@ -55,16 +55,20 @@ module.exports.js = function(gulp, config) { var destFolder = config.buildFolder || files.getBuildFolderPath(); var dest = config.buildJs || 'main.js'; + log.secondary('Webpacking ' + src); + var webpackConfig = { - quiet: false, + quiet: true, resolve: { - root: [path.join(process.cwd(), 'bower_components')] + root: [path.join(cwd, 'bower_components')] }, resolveLoader: { root: path.join(__dirname, '../../node_modules') }, plugins: [ - new BowerPlugin() + new BowerPlugin({ + includes: /\.js$/ + }) ], module: { loaders: [ @@ -80,8 +84,6 @@ module.exports.js = function(gulp, config) { } }; - log.secondary('Webpacking ' + src); - return gulp.src(src) .pipe(webpack(webpackConfig)) .pipe(gulpif(useSourceMaps, function() { diff --git a/package.json b/package.json index b6c962f8..596980d3 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "stream-combiner2": "^1.0.2", "textrequireify": "^2.1.1", "through2": "^2.0.0", + "transform-loader": "^0.2.2", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", "webpack-stream": "^2.1.0", From 5ffbf468d3ba3ae2a7c28490bc559d2ebc4c98d2 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Mon, 31 Aug 2015 22:18:02 +0100 Subject: [PATCH 18/29] Adds custom loaders for babel runtime resolver and textrequirefy. The latter still does not work due to webpack issue --- lib/origami-build-tools-cli.js | 7 +-- lib/plugins/babelRuntimePathResolver.js | 60 ++++++------------------- lib/plugins/textrequireify-loader.js | 55 +++++++++++++++++++++++ lib/tasks/build.js | 32 ++++++++----- 4 files changed, 93 insertions(+), 61 deletions(-) create mode 100644 lib/plugins/textrequireify-loader.js diff --git a/lib/origami-build-tools-cli.js b/lib/origami-build-tools-cli.js index 3963886d..38382f75 100755 --- a/lib/origami-build-tools-cli.js +++ b/lib/origami-build-tools-cli.js @@ -65,7 +65,7 @@ var argument = argv._[0]; function reportTaskError(error) { if (Array.isArray(error)) { - log.primaryError(error.join('\n')); + log.primaryError(error.join('\n')); } else if (error) { log.primaryError(error); } @@ -84,6 +84,7 @@ if (tasks.isValid(argument)) { } else { var taskResult = task(gulp, argv); + if (typeof taskResult !== 'undefined' && taskResult !== null) { // Check if the function returns a Promise if (taskResult instanceof Promise) { @@ -95,8 +96,8 @@ if (tasks.isValid(argument)) { taskResult .on('error', reportTaskError) .on('end', reportFinished); - // Make sure it reaches 'end' - taskResult.resume(); + // Make sure it reaches 'end' + taskResult.resume(); } } } diff --git a/lib/plugins/babelRuntimePathResolver.js b/lib/plugins/babelRuntimePathResolver.js index 3bb4e187..7a0ca252 100644 --- a/lib/plugins/babelRuntimePathResolver.js +++ b/lib/plugins/babelRuntimePathResolver.js @@ -1,55 +1,23 @@ 'use strict'; var path = require('path'); -var through = require('through2'); var falafel = require('falafel'); var prefix = /babel-runtime/; - -function create(config) { - return function(file) { - if (!(/\.js$/).test(file)) { - return through(); - } - - if (!config.rootDirectory) { - throw 'Missing \'rootDirectory\' config option to where the babel-runtime directory is'; - } - - var rootDirectory = path.normalize(config.rootDirectory); - - var tr = through(function(chunk, enc, callback) { - try { - this.push(parse(chunk)); - } catch(err) { - err.debowerifyFile = file; - err.sourcecode = chunk; - this.emit('error', err); +var rootDirectory = path.resolve(__dirname, '../../node_modules'); + +module.exports = function babelRuntimePathResolver(file) { + this.cacheable = true; + + return String(falafel(file, { locations: true, ecmaVersion: 6 }, function(node) { + // Find require() calls + if (node.type === 'CallExpression' && node.callee.type === 'Identifier') { + if (node.callee.name === 'require' && prefix.test(node.arguments[0].value)) { // require("babel-runtime/*") + var requirePath = rootDirectory + '/' + node.arguments[0].value; + node.update('require(' + JSON.stringify(requirePath) + ')'); + } else {// none of the above, skip + return; } - - return callback(); - }); - - return tr; - - function parse(source) { - return String(falafel(source, { locations: true, ecmaVersion: 6 }, function(node) { - // Find require() calls - if (node.type === 'CallExpression' && node.callee.type === 'Identifier') { - var requirePath; - - if (node.callee.name === 'require' && prefix.test(node.arguments[0].value)) { // require("babel-runtime/*") - requirePath = rootDirectory + '/' + node.arguments[0].value; - } else {// none of the above, skip - return; - } - - node.update('require(' + JSON.stringify(requirePath) + ')'); - } - })); } - }; + })); } - -module.exports = create({}); -module.exports.create = create; diff --git a/lib/plugins/textrequireify-loader.js b/lib/plugins/textrequireify-loader.js new file mode 100644 index 00000000..e15dc39d --- /dev/null +++ b/lib/plugins/textrequireify-loader.js @@ -0,0 +1,55 @@ +'use strict'; + +var path = require('path'); +var falafel = require('falafel'); +var fs = require('fs'); + +var prefix = /^text!/; + +module.exports = function textrequirefy(file) { + this.cacheable = true; + var webpack = this; + var filePath = process.cwd(); + + // Gets the cwd param + var cwdParam = this.query.match(/(?:cwd=)(.*?)(?:&|$)/); + var rootDirectory = path.resolve(path.normalize(cwdParam[1] || './bower_components/')); + + return String(falafel(file, { locations: true, ecmaVersion: 6 }, function(node) { + // Find require() calls + if (node.type === 'CallExpression' && node.callee.type === 'Identifier') { + var requirePath; + + if(node.callee.name === 'requireText') { // requireText("file.txt") + requirePath = node.arguments[0].value; + } else if(node.callee.name === 'require' && prefix.test(node.arguments[0].value)) { // require("text!file.txt") + requirePath = node.arguments[0].value.replace(prefix, ''); + } else {// none of the above, skip + return; + } + +console.log(webpack); + var fsPath; + if (/^\.+\//.test(requirePath)) { + // this.resourcePath not working for some reason + fsPath = path.resolve(path.dirname(this.resourcePath), requirePath); // relative paths are relative to the current file + } else if (rootDirectory) { + fsPath = path.resolve(rootDirectory, requirePath); // absolute paths require rootDirectory setting + } + + if (fsPath.substring(0, rootDirectory.length) !== rootDirectory) { + throw new Error('Can\'t require "' + requirePath + '" in "' + file + ':' + node.loc.start.line + '", because the path points outside the root directory (too many "../"?)'); + } + + console.log(filePath); + if (!fs.existsSync(fsPath)) { + // console.log(2001000000, fsPath); + console.log(10000000000, webpack); + throw new Error('Can\'t require "' + requirePath + '" in "' + file + ':' + node.loc.start.line + '", because the file "' + fsPath + '" doesn\'t exist'); + } + + // JSON.stringify escapes the text as a JS string literal + node.update(JSON.stringify(fs.readFileSync(fsPath, {encoding:'utf-8'}))); + } + })); +} diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 8c9f3de1..69dc9027 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -15,10 +15,10 @@ var rename = require('gulp-rename'); var merge = require('merge-stream'); var gulpif = require('gulp-if-else'); var autoprefixer = require('gulp-autoprefixer'); +var gutil = require('gulp-util'); var prefixer = require('../plugins/gulp-prefixer'); var files = require('../helpers/files'); var log = require('../helpers/log'); -var babelRuntimePathResolver = require('../plugins/babelRuntimePathResolver'); module.exports = function(gulp, config) { var jsStream; @@ -40,17 +40,13 @@ module.exports.js = function(gulp, config) { var src = config.js || files.getMainJsPath() || null; var cwd = config.cwd || process.cwd(); if (src) { - var loaders = ['babel'].concat(config.loaders || []); + // Temporary fix as aliased loaders don't pass in queries due to webpack bug + var textrequireifyPath = path.join(__dirname, '../plugins/textrequireify-loader.js'); + var loaders = ['babel-runtime-path-loader', 'babel?optional[]=runtime', textrequireifyPath + '?cwd=' + cwd].concat(config.loaders || []).join('!'); config.env = config.env || 'development'; var useSourceMaps = config.sourcemaps === true || config.env === 'development'; - // babelRuntimePathResolver.create({ - // rootDirectory: path.resolve(__dirname, '../../node_modules') - // }), - // textrequireify.create({ - // rootDirectory: cwd - // }) var destFolder = config.buildFolder || files.getBuildFolderPath(); var dest = config.buildJs || 'main.js'; @@ -63,7 +59,11 @@ module.exports.js = function(gulp, config) { root: [path.join(cwd, 'bower_components')] }, resolveLoader: { - root: path.join(__dirname, '../../node_modules') + root: [path.join(__dirname, '../../node_modules')], + alias: { + 'babel-runtime-path-loader': path.join(__dirname, '../plugins/babelRuntimePathResolver'), + 'textrequireify-loader': path.join(__dirname, '../plugins/textrequireify-loader') + } }, plugins: [ new BowerPlugin({ @@ -75,7 +75,7 @@ module.exports.js = function(gulp, config) { { test: /\.js$/, exclude: /node_modules/, - loaders: loaders + loader: loaders } ] }, @@ -84,8 +84,14 @@ module.exports.js = function(gulp, config) { } }; - return gulp.src(src) - .pipe(webpack(webpackConfig)) + var stream = gulp.src(src) + .pipe(webpack(webpackConfig, null, function(err, stats) { + if (stats.compilation.errors) { + // Logs errors that don't break builds, need to figure out how to break them + // but the erros are thrown after the build is made anyway + console.log(stats.compilation.errors.toString()); + } + })) .pipe(gulpif(useSourceMaps, function() { return sourcemaps.init({loadMaps: true}) })) @@ -98,6 +104,8 @@ module.exports.js = function(gulp, config) { .pipe(gulpif(destFolder !== 'disabled', function() { return gulp.dest(destFolder) })); + + return stream; } }; From 1411367ef2a9e03db64948b4f87637296c8eb9d5 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Tue, 1 Sep 2015 13:12:40 +0100 Subject: [PATCH 19/29] Fixes tests and verify --- .travis.yml | 1 + lib/tasks/build.js | 2 -- test/tasks/build.test.js | 10 +++++----- test/tasks/demo.test.js | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 87778753..d557eead 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +sudo: false language: node_js node_js: - "0.12" diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 69dc9027..4fdd643c 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -1,7 +1,6 @@ 'use strict'; var path = require('path'); -var fs = require('fs'); var merge = require('merge-stream'); var BowerPlugin = require('bower-webpack-plugin'); var webpack = require('webpack-stream'); @@ -15,7 +14,6 @@ var rename = require('gulp-rename'); var merge = require('merge-stream'); var gulpif = require('gulp-if-else'); var autoprefixer = require('gulp-autoprefixer'); -var gutil = require('gulp-util'); var prefixer = require('../plugins/gulp-prefixer'); var files = require('../helpers/files'); var log = require('../helpers/log'); diff --git a/test/tasks/build.test.js b/test/tasks/build.test.js index 515312b5..2c97562c 100644 --- a/test/tasks/build.test.js +++ b/test/tasks/build.test.js @@ -47,7 +47,7 @@ describe('Build task', function() { var builtJs = fs.readFileSync('build/main.js', 'utf8'); expect(builtJs).to.contain('sourceMappingURL'); expect(builtJs).to.contain('var Test'); - expect(builtJs).to.contain('function Test() {\n\tvar name = \'test\';'); + expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); done(); }); }); @@ -61,7 +61,7 @@ describe('Build task', function() { var builtJs = fs.readFileSync('build/main.js', 'utf8'); expect(builtJs).to.not.contain('sourceMappingURL'); expect(builtJs).to.not.contain('var Test'); - expect(builtJs).to.not.contain('function Test() {\n\tvar name = \'test\';'); + expect(builtJs).to.not.contain('function Test() {\n\t\tvar name = \'test\';'); done(); }); }); @@ -75,7 +75,7 @@ describe('Build task', function() { var builtJs = fs.readFileSync('build/main.js', 'utf8'); expect(builtJs).to.contain('sourceMappingURL'); expect(builtJs).to.not.contain('var Test'); - expect(builtJs).to.contain('function Test() {\n\tvar name = \'test\';'); + expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); done(); }); }); @@ -89,7 +89,7 @@ describe('Build task', function() { var builtJs = fs.readFileSync('test-build/main.js', 'utf8'); expect(builtJs).to.contain('sourceMappingURL'); expect(builtJs).to.contain('var Test'); - expect(builtJs).to.contain('function Test() {\n\tvar name = \'test\';'); + expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); done(); }); }); @@ -103,7 +103,7 @@ describe('Build task', function() { var builtJs = fs.readFileSync('build/bundle.js', 'utf8'); expect(builtJs).to.contain('sourceMappingURL'); expect(builtJs).to.contain('var Test'); - expect(builtJs).to.contain('function Test() {\n\tvar name = \'test\';'); + expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); done(); }); }); diff --git a/test/tasks/demo.test.js b/test/tasks/demo.test.js index 60990232..fab0782c 100644 --- a/test/tasks/demo.test.js +++ b/test/tasks/demo.test.js @@ -152,7 +152,7 @@ describe('Demo task', function() { .then(function() { expect(fs.readFileSync('demos/local/test1.html', 'utf8')).to.contain('
test1
'); expect(fs.readFileSync('demos/local/test2.html', 'utf8')).to.contain('
test2
'); - expect(fs.readFileSync('demos/local/demo.js', 'utf8')).to.contain('function Test() {\n\tvar name = \'test\';'); + expect(fs.readFileSync('demos/local/demo.js', 'utf8')).to.contain('function Test() {\n\t\tvar name = \'test\';'); expect(fs.readFileSync('demos/local/demo.css', 'utf8')).to.contain('div {\n color: blue; }\n'); fs.unlink('demos/test1.html'); fs.unlink('demos/test2.html'); From 06edbe7c10aa7f5e74b7e69d72943ef3669222a5 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Tue, 8 Sep 2015 16:19:45 +0100 Subject: [PATCH 20/29] Adds hacky fix for textrequireify involving forked transform-loader to work with textrequireify and allowing to pass options to it --- lib/plugins/textrequireify-loader.js | 4 +--- lib/tasks/build.js | 8 +++++--- package.json | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/plugins/textrequireify-loader.js b/lib/plugins/textrequireify-loader.js index e15dc39d..d858927c 100644 --- a/lib/plugins/textrequireify-loader.js +++ b/lib/plugins/textrequireify-loader.js @@ -1,3 +1,4 @@ +// Not in use until the this.resourcePath issue is solved: https://github.com/webpack/webpack/issues/1410 'use strict'; var path = require('path'); @@ -28,7 +29,6 @@ module.exports = function textrequirefy(file) { return; } -console.log(webpack); var fsPath; if (/^\.+\//.test(requirePath)) { // this.resourcePath not working for some reason @@ -41,10 +41,8 @@ console.log(webpack); throw new Error('Can\'t require "' + requirePath + '" in "' + file + ':' + node.loc.start.line + '", because the path points outside the root directory (too many "../"?)'); } - console.log(filePath); if (!fs.existsSync(fsPath)) { // console.log(2001000000, fsPath); - console.log(10000000000, webpack); throw new Error('Can\'t require "' + requirePath + '" in "' + file + ':' + node.loc.start.line + '", because the file "' + fsPath + '" doesn\'t exist'); } diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 4fdd643c..6be3b0be 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -39,8 +39,10 @@ module.exports.js = function(gulp, config) { var cwd = config.cwd || process.cwd(); if (src) { // Temporary fix as aliased loaders don't pass in queries due to webpack bug - var textrequireifyPath = path.join(__dirname, '../plugins/textrequireify-loader.js'); - var loaders = ['babel-runtime-path-loader', 'babel?optional[]=runtime', textrequireifyPath + '?cwd=' + cwd].concat(config.loaders || []).join('!'); + // Currently using forked transform-loader with Browserify textrequireify + // until webpack bug mentioned in textrequireify-loader.js is fixed + var textrequireifyPath = path.join(__dirname, '../../node_modules/textrequireify/index.js'); + var loaders = ['transform?' + textrequireifyPath + '=>{rootDirectory: "' + cwd + '"}', 'babel-runtime-path-loader', 'babel?optional[]=runtime'].concat(config.loaders || []); config.env = config.env || 'development'; @@ -73,7 +75,7 @@ module.exports.js = function(gulp, config) { { test: /\.js$/, exclude: /node_modules/, - loader: loaders + loaders: loaders } ] }, diff --git a/package.json b/package.json index 596980d3..be11b08f 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "stream-combiner2": "^1.0.2", "textrequireify": "^2.1.1", "through2": "^2.0.0", - "transform-loader": "^0.2.2", + "transform-loader": "AlbertoElias/transform-loader", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", "webpack-stream": "^2.1.0", From 7fc0257b8151862632e29a34b30ddc9a698a3b57 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Wed, 9 Sep 2015 12:18:18 +0100 Subject: [PATCH 21/29] Removes hack for textrequireify as custom loader now works --- lib/plugins/textrequireify-loader.js | 7 ++----- lib/tasks/build.js | 7 +++---- package.json | 2 -- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/plugins/textrequireify-loader.js b/lib/plugins/textrequireify-loader.js index d858927c..1db25499 100644 --- a/lib/plugins/textrequireify-loader.js +++ b/lib/plugins/textrequireify-loader.js @@ -1,4 +1,3 @@ -// Not in use until the this.resourcePath issue is solved: https://github.com/webpack/webpack/issues/1410 'use strict'; var path = require('path'); @@ -9,8 +8,7 @@ var prefix = /^text!/; module.exports = function textrequirefy(file) { this.cacheable = true; - var webpack = this; - var filePath = process.cwd(); + var filePath = this.resourcePath; // Gets the cwd param var cwdParam = this.query.match(/(?:cwd=)(.*?)(?:&|$)/); @@ -31,8 +29,7 @@ module.exports = function textrequirefy(file) { var fsPath; if (/^\.+\//.test(requirePath)) { - // this.resourcePath not working for some reason - fsPath = path.resolve(path.dirname(this.resourcePath), requirePath); // relative paths are relative to the current file + fsPath = path.resolve(path.dirname(filePath), requirePath); // relative paths are relative to the current file } else if (rootDirectory) { fsPath = path.resolve(rootDirectory, requirePath); // absolute paths require rootDirectory setting } diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 6be3b0be..40e9cb85 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -39,10 +39,9 @@ module.exports.js = function(gulp, config) { var cwd = config.cwd || process.cwd(); if (src) { // Temporary fix as aliased loaders don't pass in queries due to webpack bug - // Currently using forked transform-loader with Browserify textrequireify - // until webpack bug mentioned in textrequireify-loader.js is fixed - var textrequireifyPath = path.join(__dirname, '../../node_modules/textrequireify/index.js'); - var loaders = ['transform?' + textrequireifyPath + '=>{rootDirectory: "' + cwd + '"}', 'babel-runtime-path-loader', 'babel?optional[]=runtime'].concat(config.loaders || []); + var textrequireifyPath = path.join(__dirname, '../plugins/textrequireify-loader.js'); + + var loaders = [textrequireifyPath + '?cwd=' + cwd, 'babel-runtime-path-loader', 'babel?optional[]=runtime'].concat(config.loaders || []); config.env = config.env || 'development'; diff --git a/package.json b/package.json index be11b08f..40fcd453 100644 --- a/package.json +++ b/package.json @@ -50,9 +50,7 @@ "portfinder": "^0.4.0", "semver": "^4.3.6", "stream-combiner2": "^1.0.2", - "textrequireify": "^2.1.1", "through2": "^2.0.0", - "transform-loader": "AlbertoElias/transform-loader", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", "webpack-stream": "^2.1.0", From 59ebed72c5d7744a8b78bf844daa918a2ca11977 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Wed, 9 Sep 2015 18:22:24 +0100 Subject: [PATCH 22/29] Disables AMD modules, it was breaking the use of ftscroller --- lib/origami-build-tools.js | 1 - lib/tasks/build.js | 2 +- package.json | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/origami-build-tools.js b/lib/origami-build-tools.js index cb1be05b..54cc3ad4 100755 --- a/lib/origami-build-tools.js +++ b/lib/origami-build-tools.js @@ -1,6 +1,5 @@ 'use strict'; -require('es6-promise').polyfill(); require('isomorphic-fetch'); var update = require('./helpers/update-notifier'); diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 40e9cb85..37eda2a2 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -41,7 +41,7 @@ module.exports.js = function(gulp, config) { // Temporary fix as aliased loaders don't pass in queries due to webpack bug var textrequireifyPath = path.join(__dirname, '../plugins/textrequireify-loader.js'); - var loaders = [textrequireifyPath + '?cwd=' + cwd, 'babel-runtime-path-loader', 'babel?optional[]=runtime'].concat(config.loaders || []); + var loaders = [textrequireifyPath + '?cwd=' + cwd, 'babel-runtime-path-loader', 'babel?optional[]=runtime', 'imports?define=>false'].concat(config.loaders || []); config.env = config.env || 'development'; diff --git a/package.json b/package.json index 40fcd453..41bd1984 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "gulp-util": "^3.0.6", "gulp-webserver": "^0.9.1", "haikro": "^1.14.1", + "imports-loader": "^0.6.4", "isomorphic-fetch": "^2.1.0", "merge-stream": "^0.1.7", "minimist": "^1.1.1", From a6c1e0f2a183b995eeda9c75c374da80debf52b2 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Thu, 17 Sep 2015 09:28:38 +0200 Subject: [PATCH 23/29] Adds proper webpack error logging. Now triggers error on dependency not found errors and syntax errors --- .gitignore | 2 +- lib/origami-build-tools-cli.js | 1 - lib/plugins/textrequireify-loader.js | 1 - lib/tasks/build.js | 33 ++++++++++++++-------------- package.json | 5 ++--- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 98610597..78774f59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .idea/ node_modules/ -npm-debug.log +npm-debug.log* .DS_Store .editorconfig diff --git a/lib/origami-build-tools-cli.js b/lib/origami-build-tools-cli.js index 38382f75..b2c700ce 100755 --- a/lib/origami-build-tools-cli.js +++ b/lib/origami-build-tools-cli.js @@ -84,7 +84,6 @@ if (tasks.isValid(argument)) { } else { var taskResult = task(gulp, argv); - if (typeof taskResult !== 'undefined' && taskResult !== null) { // Check if the function returns a Promise if (taskResult instanceof Promise) { diff --git a/lib/plugins/textrequireify-loader.js b/lib/plugins/textrequireify-loader.js index 1db25499..a7a1d6e3 100644 --- a/lib/plugins/textrequireify-loader.js +++ b/lib/plugins/textrequireify-loader.js @@ -39,7 +39,6 @@ module.exports = function textrequirefy(file) { } if (!fs.existsSync(fsPath)) { - // console.log(2001000000, fsPath); throw new Error('Can\'t require "' + requirePath + '" in "' + file + ':' + node.loc.start.line + '", because the file "' + fsPath + '" doesn\'t exist'); } diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 37eda2a2..4bc96932 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -83,28 +83,27 @@ module.exports.js = function(gulp, config) { } }; - var stream = gulp.src(src) - .pipe(webpack(webpackConfig, null, function(err, stats) { - if (stats.compilation.errors) { - // Logs errors that don't break builds, need to figure out how to break them - // but the erros are thrown after the build is made anyway - console.log(stats.compilation.errors.toString()); - } - })) - .pipe(gulpif(useSourceMaps, function() { + var combinedStream = combine.obj( + gulp.src(src), + webpack(webpackConfig), + gulpif(useSourceMaps, function() { return sourcemaps.init({loadMaps: true}) - })) - .pipe(gulpif(config.env === 'production', function() { + }), + gulpif(config.env === 'production', function() { return streamify(uglify()); - })) - .pipe(gulpif(useSourceMaps, function() { + }), + gulpif(useSourceMaps, function() { return sourcemaps.write(); - })) - .pipe(gulpif(destFolder !== 'disabled', function() { + }), + gulpif(destFolder !== 'disabled', function() { return gulp.dest(destFolder) - })); + }) + ); - return stream; + // Returns a combined stream so an error handler can be attached to the end of the pipeline, + // and it will have effects in all the steps. We need to resume() because stream-combiner2 + // seems to pause the stream and it doesn't reach the `end` event + return combinedStream.resume(); } }; diff --git a/package.json b/package.json index 41bd1984..88df7845 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "obt": "./lib/origami-build-tools-cli.js" }, "engines": { - "node": "^0.12.2", + "node": "^4.0.0", "npm": "^2.0.0" }, "scripts": { @@ -22,7 +22,6 @@ "colors": "^1.1.2", "configstore": "^1.1.0", "denodeify": "^1.2.1", - "es6-promise": "^2.3.0", "falafel": "^1.2.0", "findit": "^2.0.0", "gulp": "^3.9.0", @@ -54,7 +53,7 @@ "through2": "^2.0.0", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", - "webpack-stream": "^2.1.0", + "webpack-stream": "AlbertoElias/webpack-stream", "which": "^1.1.1" }, "devDependencies": { From 23bd4fb9ac7c642b7c7f100e5a931958d78721c7 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Fri, 18 Sep 2015 10:02:09 +0200 Subject: [PATCH 24/29] Adds a json loader to be able to require json files like in Node and Browserify --- lib/tasks/build.js | 4 ++++ package.json | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 4bc96932..42202f08 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -75,6 +75,10 @@ module.exports.js = function(gulp, config) { test: /\.js$/, exclude: /node_modules/, loaders: loaders + }, + { + test: /\.json$/, + loader: 'json' } ] }, diff --git a/package.json b/package.json index 88df7845..49a61fed 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "haikro": "^1.14.1", "imports-loader": "^0.6.4", "isomorphic-fetch": "^2.1.0", + "json-loader": "^0.5.3", "merge-stream": "^0.1.7", "minimist": "^1.1.1", "nightwatch": "^0.7.2", From 63d9b0cf801ca09d2babf7ec4cbdb880a00f6119 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Fri, 18 Sep 2015 12:35:54 +0200 Subject: [PATCH 25/29] v4.0.0-beta.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 49a61fed..72f1120f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origami-build-tools", - "version": "v4.0.0-beta.6", + "version": "v4.0.0-beta.7", "description": "Origami component development tools.", "main": "./lib/origami-build-tools", "bin": { From 016d73eddeeb63a840f7f280e8a376b4c25af331 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Mon, 21 Sep 2015 08:42:38 +0200 Subject: [PATCH 26/29] Removed promise polyfill from tests --- test/helpers/command-line.test.js | 1 - test/helpers/files.test.js | 1 - test/tasks/build.test.js | 1 - test/tasks/demo.test.js | 1 - 4 files changed, 4 deletions(-) diff --git a/test/helpers/command-line.test.js b/test/helpers/command-line.test.js index bda6b6b7..0005a432 100644 --- a/test/helpers/command-line.test.js +++ b/test/helpers/command-line.test.js @@ -2,7 +2,6 @@ 'use strict'; var expect = require('expect.js'); -require('es6-promise').polyfill(); var commandLine = require('../../lib/helpers/command-line'); diff --git a/test/helpers/files.test.js b/test/helpers/files.test.js index e17ddd8a..2040b219 100644 --- a/test/helpers/files.test.js +++ b/test/helpers/files.test.js @@ -2,7 +2,6 @@ 'use strict'; var expect = require('expect.js'); -require('es6-promise').polyfill(); var fs = require('fs-extra'); var path = require('path'); diff --git a/test/tasks/build.test.js b/test/tasks/build.test.js index 2c97562c..15f26d72 100644 --- a/test/tasks/build.test.js +++ b/test/tasks/build.test.js @@ -1,7 +1,6 @@ /* global describe, it, before, after, afterEach */ 'use strict'; -require('es6-promise').polyfill(); var denodeify = require('denodeify'); var exec = denodeify(require('child_process').exec, function(err, stdout) { return [err, stdout]; }); diff --git a/test/tasks/demo.test.js b/test/tasks/demo.test.js index fab0782c..b2e0420c 100644 --- a/test/tasks/demo.test.js +++ b/test/tasks/demo.test.js @@ -1,7 +1,6 @@ /* global describe, it, before, after */ 'use strict'; -require('es6-promise').polyfill(); var expect = require('expect.js'); var gulp = require('gulp'); var extend = require('node.extend'); From 7a6fc6b6740b2fffdb5f8d32be16ee803ac8488c Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Tue, 22 Sep 2015 08:13:18 +0200 Subject: [PATCH 27/29] Adds tests for requireText, requiring JSONs and syntax and missing dep errors --- lib/origami-build-tools-cli.js | 6 +-- test/fixtures/o-test/main.js | 6 ++- test/fixtures/o-test/src/js/json-test.json | 3 ++ test/fixtures/o-test/src/js/missing-dep.js | 1 + test/fixtures/o-test/src/js/require-text.txt | 1 + test/fixtures/o-test/src/js/syntax-error.js | 3 ++ test/tasks/build.test.js | 41 ++++++++++++++++++++ test/tasks/verify.test.js | 4 +- 8 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/o-test/src/js/json-test.json create mode 100644 test/fixtures/o-test/src/js/missing-dep.js create mode 100644 test/fixtures/o-test/src/js/require-text.txt create mode 100644 test/fixtures/o-test/src/js/syntax-error.js diff --git a/lib/origami-build-tools-cli.js b/lib/origami-build-tools-cli.js index b2c700ce..3963886d 100755 --- a/lib/origami-build-tools-cli.js +++ b/lib/origami-build-tools-cli.js @@ -65,7 +65,7 @@ var argument = argv._[0]; function reportTaskError(error) { if (Array.isArray(error)) { - log.primaryError(error.join('\n')); + log.primaryError(error.join('\n')); } else if (error) { log.primaryError(error); } @@ -95,8 +95,8 @@ if (tasks.isValid(argument)) { taskResult .on('error', reportTaskError) .on('end', reportFinished); - // Make sure it reaches 'end' - taskResult.resume(); + // Make sure it reaches 'end' + taskResult.resume(); } } } diff --git a/test/fixtures/o-test/main.js b/test/fixtures/o-test/main.js index f35e0b62..12953ab4 100644 --- a/test/fixtures/o-test/main.js +++ b/test/fixtures/o-test/main.js @@ -1 +1,5 @@ -var Test = require('./src/js/test'); // eslint-disable-line +/*eslint-disable */ +let Test = require('./src/js/test'); +let jsonTest = require('./src/js/json-test.json'); +let textTest = requireText('./src/js/require-text.txt'); +/*eslint-enable */ diff --git a/test/fixtures/o-test/src/js/json-test.json b/test/fixtures/o-test/src/js/json-test.json new file mode 100644 index 00000000..1d2b32c9 --- /dev/null +++ b/test/fixtures/o-test/src/js/json-test.json @@ -0,0 +1,3 @@ +{ + "test": true +} diff --git a/test/fixtures/o-test/src/js/missing-dep.js b/test/fixtures/o-test/src/js/missing-dep.js new file mode 100644 index 00000000..17a3a161 --- /dev/null +++ b/test/fixtures/o-test/src/js/missing-dep.js @@ -0,0 +1 @@ +let dep = require('dep'); // eslint-disable-line diff --git a/test/fixtures/o-test/src/js/require-text.txt b/test/fixtures/o-test/src/js/require-text.txt new file mode 100644 index 00000000..0527e6bd --- /dev/null +++ b/test/fixtures/o-test/src/js/require-text.txt @@ -0,0 +1 @@ +This is a test diff --git a/test/fixtures/o-test/src/js/syntax-error.js b/test/fixtures/o-test/src/js/syntax-error.js new file mode 100644 index 00000000..07725ee6 --- /dev/null +++ b/test/fixtures/o-test/src/js/syntax-error.js @@ -0,0 +1,3 @@ +/*eslint-disable */ +le test = 'wrong syntax'; +/*eslint-enable */ diff --git a/test/tasks/build.test.js b/test/tasks/build.test.js index 15f26d72..d50af00e 100644 --- a/test/tasks/build.test.js +++ b/test/tasks/build.test.js @@ -47,6 +47,8 @@ describe('Build task', function() { expect(builtJs).to.contain('sourceMappingURL'); expect(builtJs).to.contain('var Test'); expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); + expect(builtJs).to.contain('var textTest = "This is a test\\n";'); + expect(builtJs).to.contain('\tmodule.exports = {\n\t\t"test": true\n\t};') done(); }); }); @@ -61,6 +63,8 @@ describe('Build task', function() { expect(builtJs).to.not.contain('sourceMappingURL'); expect(builtJs).to.not.contain('var Test'); expect(builtJs).to.not.contain('function Test() {\n\t\tvar name = \'test\';'); + expect(builtJs).to.not.contain('"This is a test"'); + expect(builtJs).to.not.contain('function Test() {\n\t\tvar name = \'test\';'); done(); }); }); @@ -89,6 +93,8 @@ describe('Build task', function() { expect(builtJs).to.contain('sourceMappingURL'); expect(builtJs).to.contain('var Test'); expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); + expect(builtJs).to.contain('var textTest = "This is a test\\n";'); + expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); done(); }); }); @@ -103,6 +109,41 @@ describe('Build task', function() { expect(builtJs).to.contain('sourceMappingURL'); expect(builtJs).to.contain('var Test'); expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); + expect(builtJs).to.contain('var textTest = "This is a test\\n";'); + expect(builtJs).to.contain('function Test() {\n\t\tvar name = \'test\';'); + done(); + }); + }); + + it('should fail on syntax error', function(done) { + build + .js(gulp, { + js: './src/js/syntax-error.js' + }) + .on('error', function(e) { + expect(e.message).to.contain('SyntaxError'); + expect(e.message).to.contain('Unexpected token'); + done(); + }) + .on('end', function() { + // Fail quickly to not wait for test to timeout + expect(true).to.be(false); + done(); + }); + }); + + it('should fail when a dependency is not found', function(done) { + build + .js(gulp, { + js: './src/js/missing-dep.js' + }) + .on('error', function(e) { + expect(e.message).to.contain('ModuleNotFoundError: Module not found: Error: Cannot resolve module \'dep\''); + done(); + }) + .on('end', function() { + // Fail quickly to not wait for test to timeout + expect(true).to.be(false); done(); }); }); diff --git a/test/tasks/verify.test.js b/test/tasks/verify.test.js index 1418cf2c..64e4a99c 100644 --- a/test/tasks/verify.test.js +++ b/test/tasks/verify.test.js @@ -48,7 +48,7 @@ describe('Verify task', function() { it('should run esLint with default config', function(done) { verify.esLint(gulp) .on('error', function(error) { - expect(error.message).to.be('Failed with 1 error'); + expect(error.message).to.be('Failed with 2 errors'); done(); }); }); @@ -58,7 +58,7 @@ describe('Verify task', function() { esLintPath: '.eslintrc' }) .on('error', function(error) { - expect(error.message).to.be(undefined); + expect(error.message).to.be('Failed with 1 error'); }); stream.resume(); From 419cc1fe72356d8f55559363bcc7e1438b918470 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Tue, 22 Sep 2015 08:27:38 +0200 Subject: [PATCH 28/29] Fix linting errors --- test/fixtures/o-test/.eslintignore | 1 + test/fixtures/o-test/src/js/syntax-error.js | 2 -- test/tasks/verify.test.js | 13 +++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/o-test/.eslintignore diff --git a/test/fixtures/o-test/.eslintignore b/test/fixtures/o-test/.eslintignore new file mode 100644 index 00000000..953619bf --- /dev/null +++ b/test/fixtures/o-test/.eslintignore @@ -0,0 +1 @@ +./src/js/syntax-error.js diff --git a/test/fixtures/o-test/src/js/syntax-error.js b/test/fixtures/o-test/src/js/syntax-error.js index 07725ee6..dc75e0d5 100644 --- a/test/fixtures/o-test/src/js/syntax-error.js +++ b/test/fixtures/o-test/src/js/syntax-error.js @@ -1,3 +1 @@ -/*eslint-disable */ le test = 'wrong syntax'; -/*eslint-enable */ diff --git a/test/tasks/verify.test.js b/test/tasks/verify.test.js index 64e4a99c..a24aafe3 100644 --- a/test/tasks/verify.test.js +++ b/test/tasks/verify.test.js @@ -47,18 +47,19 @@ describe('Verify task', function() { it('should run esLint with default config', function(done) { verify.esLint(gulp) - .on('error', function(error) { - expect(error.message).to.be('Failed with 2 errors'); - done(); - }); + .on('error', function(error) { + expect(error.message).to.be('Failed with 1 error'); + done(); + }); }); it('should run esLint with custom config', function(done) { var stream = verify.esLint(gulp, { - esLintPath: '.eslintrc' + esLintPath: '.eslintrc', + excludeFiles: ['./src/js/syntax-error.js'] }) .on('error', function(error) { - expect(error.message).to.be('Failed with 1 error'); + expect(error.message).to.be(undefined); }); stream.resume(); From 2615f970f95821baf16b1fd41b796f79d6c10669 Mon Sep 17 00:00:00 2001 From: Alberto Elias Date: Tue, 22 Sep 2015 13:17:55 +0200 Subject: [PATCH 29/29] Adds comments, updates readme and adds support for having loaders in project's directory --- .travis.yml | 2 +- README.md | 7 +------ lib/plugins/babelRuntimePathResolver.js | 2 ++ lib/tasks/build.js | 20 +++++++++++++++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index d557eead..867a43cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ sudo: false language: node_js node_js: - - "0.12" + - "4" script: - gulp install - gulp verify diff --git a/README.md b/README.md index c9a33b90..0175c612 100644 --- a/README.md +++ b/README.md @@ -99,12 +99,7 @@ Runs: - env: `String` It can be either 'production' or 'development'. If it's 'production', it will run [uglify](https://github.com/mishoo/UglifyJS2). If it's 'development', it will generate a sourcemap. (Default: 'development') - cwd: `String` The path to the working directory, in which the code to be built exists. (Default: current working directory) - sourcemaps: `Boolean` Set to true to output sourcemaps, even if env is 'development'. (Default: false) - - transforms: `Array` Additional browserify transforms to run *after* babelify, debowerify and textrequireify. Each transform should be specified as a - - `Function` The transform function. e.g: `var brfs = require('brfs'); config.transform.push(brfs);` - - insertGlobals: See [browserify documentation](https://github.com/substack/node-browserify#usage) - - detectGlobals: See [browserify documentation](https://github.com/substack/node-browserify#usage) - - ignoreMissing: See [browserify documentation](https://github.com/substack/node-browserify#usage) - - standalone: See [browserify documentation](https://github.com/substack/node-browserify#usage) + - loaders: `Array` Additional Webpack loaders for JavaScript files to run *before* imports-loader (removes AMD module support), babel-loader (which adds babel-runtime polyfills) and textrequireify-loader. OBT will search for loaders in its `node_modules` directory, but also in the project's `node_modules` folder. This way, you can install your own loaders and pass them to the `loaders` array by their name. e.g. `[coffee-loader]` * __sass(gulp, config)__ Config accepts: - sass: `String` Path to your main Sass file. (Default: './main.scss' and checks your bower.json to see if it's in its main key) - autoprefixerBrowsers: `Array` An array of strings of [browser names for autoprefixer](https://github.com/postcss/autoprefixer#browsers) to check what prefixes it needs. (Default: `["> 1%", "last 2 versions", "ie > 6", "ff ESR"]`) diff --git a/lib/plugins/babelRuntimePathResolver.js b/lib/plugins/babelRuntimePathResolver.js index 7a0ca252..b3ee1c95 100644 --- a/lib/plugins/babelRuntimePathResolver.js +++ b/lib/plugins/babelRuntimePathResolver.js @@ -1,3 +1,5 @@ +// Makes paths to babel-runtime polyfills absolute as they're +// in OBT's node_modules directory and not the module's 'use strict'; var path = require('path'); diff --git a/lib/tasks/build.js b/lib/tasks/build.js index 42202f08..7a33aeda 100644 --- a/lib/tasks/build.js +++ b/lib/tasks/build.js @@ -41,7 +41,16 @@ module.exports.js = function(gulp, config) { // Temporary fix as aliased loaders don't pass in queries due to webpack bug var textrequireifyPath = path.join(__dirname, '../plugins/textrequireify-loader.js'); - var loaders = [textrequireifyPath + '?cwd=' + cwd, 'babel-runtime-path-loader', 'babel?optional[]=runtime', 'imports?define=>false'].concat(config.loaders || []); + // They're loaded right to left + var loaders = [ + textrequireifyPath + '?cwd=' + cwd, + // Makes paths to babel-runtime polyfills absolute as they're + // in OBT's node_modules directory and not the module's + 'babel-runtime-path-loader', + 'babel?optional[]=runtime', + // Disables AMD module loading + 'imports?define=>false' + ].concat(config.loaders || []); config.env = config.env || 'development'; @@ -58,7 +67,10 @@ module.exports.js = function(gulp, config) { root: [path.join(cwd, 'bower_components')] }, resolveLoader: { - root: [path.join(__dirname, '../../node_modules')], + root: [ + path.join(__dirname, '../../node_modules'), + path.join(process.cwd(), './node_modules') + ], alias: { 'babel-runtime-path-loader': path.join(__dirname, '../plugins/babelRuntimePathResolver'), 'textrequireify-loader': path.join(__dirname, '../plugins/textrequireify-loader') @@ -76,6 +88,8 @@ module.exports.js = function(gulp, config) { exclude: /node_modules/, loaders: loaders }, + // Node.JS, require.js and Browserify support requiring JSON files + // json-loader does this in webpack { test: /\.json$/, loader: 'json' @@ -100,7 +114,7 @@ module.exports.js = function(gulp, config) { return sourcemaps.write(); }), gulpif(destFolder !== 'disabled', function() { - return gulp.dest(destFolder) + return gulp.dest(destFolder); }) );