Skip to content

Commit

Permalink
Merge pull request #1 from kenzanmedia/KEY-20-minify-js-pipeline
Browse files Browse the repository at this point in the history
Key 20 minify js pipeline
  • Loading branch information
thescientist13 committed Oct 6, 2015
2 parents b011ae0 + 7cc5cdd commit b25241c
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* text eol=lf

.bat text eol=crlf
.sh text eol=lf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.idea/
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,58 @@
# pipeline-minify-js
## Pipeline-minify-js


## Information

| Package | Description | Version|
| ------------- |:-------------:| -----:|
| Pipeline-minify-js| This pipeline minifies and optionally concatenates js files | 0.1.0 |

# Overview


_repo_: `https://github.com/kenzanmedia/pipeline-minify-js/`

_jenkins_: `TODO`

## Install
`npm install git+ssh:[email protected]: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 _true_ the pipeline will concatenate the files, hence it will generate a js file with all of the files concatenated.

+ __config.output:__ Sets the path to output the concatenate and minify files.


Default:
```javascript
config = {
concatenate: false,
output: 'dist/'
}
```

## Results

This pipeline returns an object. This object receives a stream with the files to minify, and you can call the _minifyJS_ method to execute the minification. Based on the configuration provided in _config.concatenate_, the pipeline will concatenate the files or no. After finishing the process you will have a folder named as _config.output_ . In this folder you can find the .min.js file, the source map, and a plain js file if the concatenation was executed.




## LICENSE
9 changes: 9 additions & 0 deletions bin/build.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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());
});
63 changes: 63 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "pipeline-minify-js",
"version": "0.1.0-SNAPSHOT",
"description": "Gulp pipeline to minify and optionally concatenate js files",
"author": "Juan P. Osorio <[email protected]> (https://github.com/jpoo90)",
"contributors": [
{
"name": "Owen Buckley",
"email": "[email protected]"
},
{
"name": "Chris Sharon",
"email": "[email protected]"
}
],
"scripts": {
"test": "mocha test/index.spec.js -w"
},
"main": "src/index.js",
"repository": {
"type": "git",
"url": "ssh://[email protected]:kenzanmedia/pipeline-minify-js.git"
},
"keywords": [
"Gulp",
"Tools",
"Keystone",
"Pipeline",
"Minify"
],
"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://[email protected]/kenzanmedia/pipeline-handyman.git#aeb41b4423ca07d5bab17ce28e6bdfb1b4e7b364",
"pipeline-validate-js": "git+ssh://[email protected]/kenzanmedia/pipeline-validate-js.git#55c0ec3a51799e83d4748ffbb700687fb818b8f5",
"yargs": "3.26.0"
},
"devDependencies": {
"path": "0.12.7",
"stream-assert": "2.0.3"
}
}
53 changes: 53 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*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: false,
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() {
var bypass = lazypipe();
var concat = lazypipe()
.pipe(plugins.concat, 'build.js')
.pipe(gulp.dest, config.output);

return config.concatenate ? concat : bypass;
}
}
1 change: 1 addition & 0 deletions test/fixtures/testFile1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('FILE 1');
1 change: 1 addition & 0 deletions test/fixtures/testFile2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('FILE 2');
30 changes: 30 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -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));
});
});
});

0 comments on commit b25241c

Please sign in to comment.