-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kenzanmedia/KEY-20-minify-js-pipeline
Key 20 minify js pipeline
- Loading branch information
Showing
11 changed files
with
253 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('FILE 1'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('FILE 2'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); | ||
}); |