Skip to content

Commit 11b4683

Browse files
author
JP Osorio
committed
KEY-20: Isoleted minify and concatenate
1 parent b011ae0 commit 11b4683

11 files changed

+254
-1
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = false
7+
indent_size = 2
8+
indent_style = space
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitattributes

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
* text eol=lf
2+
3+
.bat text eol=crlf
4+
.sh text eol=lf

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
.idea/

README.md

+59-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,59 @@
1-
# pipeline-minify-js
1+
## Pipeline-minify-js
2+
3+
4+
## Information
5+
6+
| Package | Description | Version|
7+
| ------------- |:-------------:| -----:|
8+
| Pipeline-minify-js| This pipeline concatenates and minifies js files | 0.1.0 |
9+
10+
# Overview
11+
12+
13+
_repo_: `ssh:[email protected]:kenzanmedia/pipeline-minify-js.git`
14+
15+
_jenkins_: `TODO`
16+
17+
## Install
18+
`npm install git+ssh:[email protected]:kenzanmedia/pipeline-minify-js.git`
19+
20+
## Usage
21+
```javascript
22+
var gulp = require('gulp');
23+
var minifyPipeline = require('pipeline-minify-js')();
24+
25+
26+
gulp.task('default', function() {
27+
return gulp
28+
.src(['src/**/*.js'])
29+
.pipe(minifyPipeline.minifyJS());
30+
});
31+
```
32+
33+
## Options
34+
35+
Pipeline options:
36+
* _config_ -> Object that contains the configuration.
37+
38+
+ __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_.
39+
40+
+ __config.output:__ Sets the path to output the concatenate and minify files.
41+
42+
43+
Default:
44+
```javascript
45+
config = {
46+
concatenate: true,
47+
output: 'dist/'
48+
}
49+
```
50+
51+
52+
53+
## Results
54+
55+
56+
57+
58+
59+
## LICENSE

bin/build.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
echo "installing npm dependencies"
4+
rm -rf node_modules > /dev/null 2>&1
5+
6+
npm install
7+
8+
echo "running build task"
9+
gulp

gulpfile.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
'use strict';
3+
4+
var gulp = require('gulp');
5+
var buildPipeline = require('./src/index.js')();
6+
var validatePipeline = require('pipeline-validate-js')();
7+
8+
var config = {
9+
files: [
10+
'src/**/*.js',
11+
'test/**/*.js'
12+
]
13+
};
14+
15+
gulp.task('default', function() {
16+
return gulp
17+
.src(config.files)
18+
.pipe(validatePipeline.validateJS())
19+
.pipe(buildPipeline.minifyJS());
20+
});

package.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "pipeline-build-js",
3+
"version": "0.1.0-SNAPSHOT",
4+
"description": "Gulp pipeline to run tests locally using node and mocha",
5+
"author": "Juan P. Osorio <[email protected]> (https://github.com/jpoo90)",
6+
"contributors": [
7+
{
8+
"name": "Owen Buckley",
9+
"email": "[email protected]"
10+
},
11+
{
12+
"name": "Chris Sharon",
13+
"email": "[email protected]"
14+
}
15+
],
16+
"scripts": {
17+
"test": "mocha test/index.spec.js -w"
18+
},
19+
"main": "src/index.js",
20+
"repository": {
21+
"type": "git",
22+
"url": "ssh://[email protected]:kenzanmedia/pipeline-build-js.git"
23+
},
24+
"keywords": [
25+
"Gulp",
26+
"Tools",
27+
"Keystone",
28+
"Pipeline"
29+
],
30+
"preferGlobal": false,
31+
"private": false,
32+
"publishConfig": {
33+
"registry": ""
34+
},
35+
"engines": {
36+
"node": ">=0.10.3",
37+
"npm": ">=1.0.20"
38+
},
39+
"analyze": true,
40+
"license": "ISC",
41+
"dependencies": {
42+
"chai": "3.3.0",
43+
"gulp": "3.9.0",
44+
"gulp-concat": "2.6.0",
45+
"gulp-if": "2.0.0",
46+
"gulp-load-plugins": "0.10.0",
47+
"gulp-plumber": "1.0.1",
48+
"gulp-print": "2.0.1",
49+
"gulp-rename": "1.2.2",
50+
"gulp-sourcemaps": "1.6.0",
51+
"gulp-uglify": "1.4.1",
52+
"lazypipe": "1.0.1",
53+
"mocha": "2.3.3",
54+
"pipeline-handyman": "git+ssh://[email protected]/kenzanmedia/pipeline-handyman.git#aeb41b4423ca07d5bab17ce28e6bdfb1b4e7b364",
55+
"pipeline-validate-js": "git+ssh://[email protected]/kenzanmedia/pipeline-validate-js.git#55c0ec3a51799e83d4748ffbb700687fb818b8f5",
56+
"yargs": "3.26.0"
57+
},
58+
"devDependencies": {
59+
"path": "0.12.7",
60+
"stream-assert": "2.0.3"
61+
}
62+
}

src/index.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*global require, module */
2+
3+
'use strict';
4+
5+
var args = require('yargs').argv;
6+
var handyman = require('pipeline-handyman');
7+
var gulp = require('gulp');
8+
var lazypipe = require('lazypipe');
9+
var plugins = require('gulp-load-plugins')({lazy: true});
10+
11+
var config = {
12+
concatenate: true,
13+
output: 'dist/'
14+
};
15+
16+
module.exports = buildPipeline;
17+
18+
function buildPipeline(options) {
19+
20+
if (config) {
21+
config = handyman.updateConf(config, options);
22+
}
23+
24+
var pipeline = {
25+
minifyJS: minifyJS()
26+
};
27+
28+
return pipeline;
29+
30+
function minifyJS() {
31+
32+
return lazypipe()
33+
.pipe(function() {
34+
return plugins.if(args.verbose, plugins.print());
35+
})
36+
.pipe(plugins.plumber)
37+
.pipe(plugins.sourcemaps.init)
38+
.pipe(concatJS())
39+
.pipe(plugins.uglify)
40+
.pipe(plugins.rename, 'build.min.js')
41+
.pipe(plugins.sourcemaps.write, './')
42+
.pipe(gulp.dest, config.output);
43+
}
44+
45+
function concatJS() {
46+
console.log(config.concatenate);
47+
var bypass = lazypipe();
48+
var concat = lazypipe()
49+
.pipe(plugins.concat, 'build.js')
50+
.pipe(gulp.dest, config.output);
51+
52+
return config.concatenate ? concat : bypass;
53+
}
54+
}

test/fixtures/testFile1.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('FILE 1');

test/fixtures/testFile2.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('FILE 2');

test/index.spec.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*global require */
2+
'use strict';
3+
4+
var minifyPipeline = require('../');
5+
var gulp = require('gulp');
6+
var path = require('path');
7+
var assert = require('stream-assert');
8+
9+
var fixtures = function (glob) { return path.join(__dirname, 'fixtures', glob); };
10+
11+
describe('pipeline-minify-js', function() {
12+
describe('Pipeline functionality', function() {
13+
it('Should output two files if concatenate is true', function (done) {
14+
gulp
15+
.src(fixtures('*'))
16+
.pipe(minifyPipeline().minifyJS())
17+
.pipe(assert.length(2))
18+
.pipe(assert.end(done));
19+
20+
});
21+
22+
it('Should output one file if concatenate is false', function (done) {
23+
gulp
24+
.src(fixtures('*'))
25+
.pipe(minifyPipeline({concatenate: false}).minifyJS())
26+
.pipe(assert.length(4))
27+
.pipe(assert.end(done));
28+
});
29+
});
30+
});

0 commit comments

Comments
 (0)