Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Add new task(s) for concatenating scripts.
Browse files Browse the repository at this point in the history
DRYer code.
  • Loading branch information
Chris Ferdinandi committed Aug 25, 2014
1 parent 9933ea2 commit e784b0d
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 22 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ gulp-boilerplate/
| | |—— # static assets
|—— src/
| |—— js/
| | |—— bind-polyfill.js
| | |—— classList.js
| | |—— myplugin.js
| |—— sass/
| | |—— myplugin.sass
Expand All @@ -69,8 +71,10 @@ gulp-boilerplate/
| | |—— spec-myplugin.js
|—— .travis.yml
|—— gulfile.js
|—— index.html
|—— package.json
|—— README.md
|—— STARTER-README.md
```


Expand All @@ -89,6 +93,7 @@ Inside `gulpfile.js` you'll see a variable named `paths`. Adjust the paths to su
```js
var paths = {
output : 'dist/',
temp: 'src/temp/',
scripts : {
input : [ 'src/js/*' ],
output : 'dist/js/'
Expand All @@ -99,7 +104,6 @@ var paths = {
},
static : 'src/static/**',
test : {
input : [ 'src/js/**/*.js' ],
spec : [ 'test/spec/**/*.js' ],
coverage: 'test/coverage/',
results: 'test/results/'
Expand All @@ -125,6 +129,8 @@ Gulp Boilerplate is licensed under the [MIT License](http://gomakethings.com/mit

Gulp Boilerplate uses [semantic versioning](http://semver.org/).

* v0.7.0 - August 24, 2014
* Add new task(s) for concatenating scripts. DRYer code.
* v0.6.0 - August 23, 2014
* Updated to event bubbling setup.
* v0.5.0 - August 23, 2014
Expand Down
2 changes: 1 addition & 1 deletion dist/css/myplugin.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* gulp-boilerplate v0.6.0
* gulp-boilerplate v0.7.0
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
* http://github.com/cferdinandi/Plugin
*
Expand Down
2 changes: 1 addition & 1 deletion dist/css/myplugin.min.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/** gulp-boilerplate v0.6.0, by Chris Ferdinandi | http://github.com/cferdinandi/Plugin | Licensed under MIT: http://gomakethings.com/mit/ */
/** gulp-boilerplate v0.7.0, by Chris Ferdinandi | http://github.com/cferdinandi/Plugin | Licensed under MIT: http://gomakethings.com/mit/ */
2 changes: 1 addition & 1 deletion dist/js/bind-polyfill.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* gulp-boilerplate v0.6.0
* gulp-boilerplate v0.7.0
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
* http://github.com/cferdinandi/Plugin
*
Expand Down
2 changes: 1 addition & 1 deletion dist/js/bind-polyfill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/classList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* gulp-boilerplate v0.6.0
* gulp-boilerplate v0.7.0
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
* http://github.com/cferdinandi/Plugin
*
Expand Down
2 changes: 1 addition & 1 deletion dist/js/classList.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/js/myplugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* gulp-boilerplate v0.6.0
* gulp-boilerplate v0.7.0
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
* http://github.com/cferdinandi/Plugin
*
Expand Down
2 changes: 1 addition & 1 deletion dist/js/myplugin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 38 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Gulp Packages
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var clean = require('gulp-clean');
Expand All @@ -15,8 +16,10 @@ var minify = require('gulp-minify-css');
var karma = require('gulp-karma');
var package = require('./package.json');

// Paths to project folders
var paths = {
output : 'dist/',
temp: 'src/temp/',
scripts : {
input : [ 'src/js/*' ],
output : 'dist/js/'
Expand All @@ -33,6 +36,7 @@ var paths = {
}
};

// Template for banner to add to file headers
var banner = {
full :
'/**\n' +
Expand All @@ -51,23 +55,30 @@ var banner = {
' */\n'
};

gulp.task('scripts', ['clean'], function() {
// Concatenate scripts in subfolders
gulp.task('concatenate', function() {
return gulp.src(paths.scripts.input)
.pipe(plumber())
.pipe(flatten())

.pipe(tap(function (file, t) {
if ( file.stat.isDirectory() ) {
var name = file.relative + '.js';
return gulp.src(file.path + '/*.js')
.pipe(concat(name))
.pipe(header(banner.full, { package : package }))
.pipe(gulp.dest(paths.scripts.output))
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(header(banner.min, { package : package }))
.pipe(gulp.dest(paths.scripts.output));
.pipe(gulp.dest(paths.temp));
}
}))
}));
});

// Lint and minify scripts
gulp.task('scripts', ['clean', 'concatenate'], function() {
return gulp.src([
paths.scripts.input + '/../*.js',
paths.temp + '/*.js'
])
.pipe(plumber())
.pipe(flatten())
.pipe(header(banner.full, { package : package }))
.pipe(gulp.dest(paths.scripts.output))
.pipe(rename({ suffix: '.min' }))
Expand All @@ -76,6 +87,7 @@ gulp.task('scripts', ['clean'], function() {
.pipe(gulp.dest(paths.scripts.output));
});

// Process, lint, and minify Sass files
gulp.task('styles', ['clean'], function() {
return gulp.src(paths.styles.input)
.pipe(plumber())
Expand All @@ -90,41 +102,55 @@ gulp.task('styles', ['clean'], function() {
.pipe(gulp.dest(paths.styles.output));
});

// Copy static files into output folder
gulp.task('static', ['clean'], function() {
return gulp.src(paths.static)
.pipe(plumber())
.pipe(gulp.dest(paths.output));
});

// Lint scripts
gulp.task('lint', function () {
return gulp.src(paths.scripts.input)
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});

// Remove prexisting content from output and test folders
gulp.task('clean', function () {
return gulp.src([
paths.output,
paths.test.coverage,
paths.test.results
paths.output,
paths.test.coverage,
paths.test.results
], { read: false })
.pipe(plumber())
.pipe(clean());
});

// Remove temporary files
gulp.task('cleanTemp', ['scripts'], function () {
return gulp.src(paths.temp, { read: false })
.pipe(plumber())
.pipe(clean());
});

// Run unit tests
gulp.task('test', function() {
return gulp.src([paths.scripts.input + '/../**/*.js'].concat(paths.test.spec))
.pipe(plumber())
.pipe(karma({ configFile: 'test/karma.conf.js' }))
.on('error', function(err) { throw err; });
});

// Combine tasks into runner
gulp.task('default', [
'lint',
'clean',
'static',
'concatenate',
'scripts',
'styles',
'static',
'cleanTemp',
'test'
]);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-boilerplate",
"version": "0.6.0",
"version": "0.7.0",
"description": "My Gulp.js boilerplate for creating new web projects",
"author": {
"name": "Chris Ferdinandi",
Expand Down

0 comments on commit e784b0d

Please sign in to comment.