Skip to content

Commit

Permalink
KEY-20: Isoleted minify and concatenate
Browse files Browse the repository at this point in the history
  • Loading branch information
JP Osorio committed Oct 3, 2015
1 parent b011ae0 commit 11b4683
Show file tree
Hide file tree
Showing 11 changed files with 254 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/
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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:[email protected]:kenzanmedia/pipeline-minify-js.git`

_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 _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
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());
});
62 changes: 62 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[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-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://[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"
}
}
54 changes: 54 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
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 11b4683

Please sign in to comment.