From 11b4683e1eaaceddfa27e00a4eff68bcae3a7251 Mon Sep 17 00:00:00 2001 From: JP Osorio Date: Fri, 2 Oct 2015 20:10:16 -0400 Subject: [PATCH] KEY-20: Isoleted minify and concatenate --- .editorconfig | 12 ++++++++ .gitattributes | 4 +++ .gitignore | 2 ++ README.md | 60 +++++++++++++++++++++++++++++++++++- bin/build.sh | 9 ++++++ gulpfile.js | 20 ++++++++++++ package.json | 62 ++++++++++++++++++++++++++++++++++++++ src/index.js | 54 +++++++++++++++++++++++++++++++++ test/fixtures/testFile1.js | 1 + test/fixtures/testFile2.js | 1 + test/index.spec.js | 30 ++++++++++++++++++ 11 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 bin/build.sh create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/index.js create mode 100644 test/fixtures/testFile1.js create mode 100644 test/fixtures/testFile2.js create mode 100644 test/index.spec.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2a006fd --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = false +indent_size = 2 +indent_style = space +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..4307127 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +* text eol=lf + +.bat text eol=crlf +.sh text eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..78f2710 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +.idea/ diff --git a/README.md b/README.md index 4035803..440ff91 100644 --- a/README.md +++ b/README.md @@ -1 +1,59 @@ -# pipeline-minify-js +## Pipeline-minify-js + + +## Information + +| Package | Description | Version| +| ------------- |:-------------:| -----:| +| Pipeline-minify-js| This pipeline concatenates and minifies js files | 0.1.0 | + +# Overview + + +_repo_: `ssh:git@github.com:kenzanmedia/pipeline-minify-js.git` + +_jenkins_: `TODO` + +## Install +`npm install git+ssh:git@github.com:kenzanmedia/pipeline-minify-js.git` + +## Usage +```javascript +var gulp = require('gulp'); +var minifyPipeline = require('pipeline-minify-js')(); + + +gulp.task('default', function() { + return gulp + .src(['src/**/*.js']) + .pipe(minifyPipeline.minifyJS()); +}); +``` + +## Options + +Pipeline options: +* _config_ -> Object that contains the configuration. + + + __config.concatenate:__ If _false_ the pipelene won't concatenate the files, hence it won't generate a js file e the files using `jscsrc`. You might want to disable JSCS if working on a legacy project. Otherwise this option should _false_. + + + __config.output:__ Sets the path to output the concatenate and minify files. + + + Default: + ```javascript + config = { + concatenate: true, + output: 'dist/' + } + ``` + + + +## Results + + + + + +## LICENSE diff --git a/bin/build.sh b/bin/build.sh new file mode 100644 index 0000000..dbd0ea5 --- /dev/null +++ b/bin/build.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +echo "installing npm dependencies" +rm -rf node_modules > /dev/null 2>&1 + +npm install + +echo "running build task" +gulp \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..1b58972 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,20 @@ + +'use strict'; + +var gulp = require('gulp'); +var buildPipeline = require('./src/index.js')(); +var validatePipeline = require('pipeline-validate-js')(); + +var config = { + files: [ + 'src/**/*.js', + 'test/**/*.js' + ] +}; + +gulp.task('default', function() { + return gulp + .src(config.files) + .pipe(validatePipeline.validateJS()) + .pipe(buildPipeline.minifyJS()); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..96c87cd --- /dev/null +++ b/package.json @@ -0,0 +1,62 @@ +{ + "name": "pipeline-build-js", + "version": "0.1.0-SNAPSHOT", + "description": "Gulp pipeline to run tests locally using node and mocha", + "author": "Juan P. Osorio (https://github.com/jpoo90)", + "contributors": [ + { + "name": "Owen Buckley", + "email": "obuckley@kenzan.com" + }, + { + "name": "Chris Sharon", + "email": "csharon@kenzan.com" + } + ], + "scripts": { + "test": "mocha test/index.spec.js -w" + }, + "main": "src/index.js", + "repository": { + "type": "git", + "url": "ssh://git@github.com:kenzanmedia/pipeline-build-js.git" + }, + "keywords": [ + "Gulp", + "Tools", + "Keystone", + "Pipeline" + ], + "preferGlobal": false, + "private": false, + "publishConfig": { + "registry": "" + }, + "engines": { + "node": ">=0.10.3", + "npm": ">=1.0.20" + }, + "analyze": true, + "license": "ISC", + "dependencies": { + "chai": "3.3.0", + "gulp": "3.9.0", + "gulp-concat": "2.6.0", + "gulp-if": "2.0.0", + "gulp-load-plugins": "0.10.0", + "gulp-plumber": "1.0.1", + "gulp-print": "2.0.1", + "gulp-rename": "1.2.2", + "gulp-sourcemaps": "1.6.0", + "gulp-uglify": "1.4.1", + "lazypipe": "1.0.1", + "mocha": "2.3.3", + "pipeline-handyman": "git+ssh://git@github.com/kenzanmedia/pipeline-handyman.git#aeb41b4423ca07d5bab17ce28e6bdfb1b4e7b364", + "pipeline-validate-js": "git+ssh://git@github.com/kenzanmedia/pipeline-validate-js.git#55c0ec3a51799e83d4748ffbb700687fb818b8f5", + "yargs": "3.26.0" + }, + "devDependencies": { + "path": "0.12.7", + "stream-assert": "2.0.3" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..9184da5 --- /dev/null +++ b/src/index.js @@ -0,0 +1,54 @@ +/*global require, module */ + +'use strict'; + +var args = require('yargs').argv; +var handyman = require('pipeline-handyman'); +var gulp = require('gulp'); +var lazypipe = require('lazypipe'); +var plugins = require('gulp-load-plugins')({lazy: true}); + +var config = { + concatenate: true, + output: 'dist/' +}; + +module.exports = buildPipeline; + +function buildPipeline(options) { + + if (config) { + config = handyman.updateConf(config, options); + } + + var pipeline = { + minifyJS: minifyJS() + }; + + return pipeline; + + function minifyJS() { + + return lazypipe() + .pipe(function() { + return plugins.if(args.verbose, plugins.print()); + }) + .pipe(plugins.plumber) + .pipe(plugins.sourcemaps.init) + .pipe(concatJS()) + .pipe(plugins.uglify) + .pipe(plugins.rename, 'build.min.js') + .pipe(plugins.sourcemaps.write, './') + .pipe(gulp.dest, config.output); + } + + function concatJS() { + console.log(config.concatenate); + var bypass = lazypipe(); + var concat = lazypipe() + .pipe(plugins.concat, 'build.js') + .pipe(gulp.dest, config.output); + + return config.concatenate ? concat : bypass; + } +} diff --git a/test/fixtures/testFile1.js b/test/fixtures/testFile1.js new file mode 100644 index 0000000..be31052 --- /dev/null +++ b/test/fixtures/testFile1.js @@ -0,0 +1 @@ +console.log('FILE 1'); diff --git a/test/fixtures/testFile2.js b/test/fixtures/testFile2.js new file mode 100644 index 0000000..5a4a25c --- /dev/null +++ b/test/fixtures/testFile2.js @@ -0,0 +1 @@ +console.log('FILE 2'); diff --git a/test/index.spec.js b/test/index.spec.js new file mode 100644 index 0000000..76424ff --- /dev/null +++ b/test/index.spec.js @@ -0,0 +1,30 @@ +/*global require */ +'use strict'; + +var minifyPipeline = require('../'); +var gulp = require('gulp'); +var path = require('path'); +var assert = require('stream-assert'); + +var fixtures = function (glob) { return path.join(__dirname, 'fixtures', glob); }; + +describe('pipeline-minify-js', function() { + describe('Pipeline functionality', function() { + it('Should output two files if concatenate is true', function (done) { + gulp + .src(fixtures('*')) + .pipe(minifyPipeline().minifyJS()) + .pipe(assert.length(2)) + .pipe(assert.end(done)); + + }); + + it('Should output one file if concatenate is false', function (done) { + gulp + .src(fixtures('*')) + .pipe(minifyPipeline({concatenate: false}).minifyJS()) + .pipe(assert.length(4)) + .pipe(assert.end(done)); + }); + }); +});