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

Commit e784b0d

Browse files
author
Chris Ferdinandi
committed
Add new task(s) for concatenating scripts.
DRYer code.
1 parent 9933ea2 commit e784b0d

File tree

11 files changed

+54
-22
lines changed

11 files changed

+54
-22
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ gulp-boilerplate/
5555
| | |—— # static assets
5656
|—— src/
5757
| |—— js/
58+
| | |—— bind-polyfill.js
59+
| | |—— classList.js
5860
| | |—— myplugin.js
5961
| |—— sass/
6062
| | |—— myplugin.sass
@@ -69,8 +71,10 @@ gulp-boilerplate/
6971
| | |—— spec-myplugin.js
7072
|—— .travis.yml
7173
|—— gulfile.js
74+
|—— index.html
7275
|—— package.json
7376
|—— README.md
77+
|—— STARTER-README.md
7478
```
7579

7680

@@ -89,6 +93,7 @@ Inside `gulpfile.js` you'll see a variable named `paths`. Adjust the paths to su
8993
```js
9094
var paths = {
9195
output : 'dist/',
96+
temp: 'src/temp/',
9297
scripts : {
9398
input : [ 'src/js/*' ],
9499
output : 'dist/js/'
@@ -99,7 +104,6 @@ var paths = {
99104
},
100105
static : 'src/static/**',
101106
test : {
102-
input : [ 'src/js/**/*.js' ],
103107
spec : [ 'test/spec/**/*.js' ],
104108
coverage: 'test/coverage/',
105109
results: 'test/results/'
@@ -125,6 +129,8 @@ Gulp Boilerplate is licensed under the [MIT License](http://gomakethings.com/mit
125129

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

132+
* v0.7.0 - August 24, 2014
133+
* Add new task(s) for concatenating scripts. DRYer code.
128134
* v0.6.0 - August 23, 2014
129135
* Updated to event bubbling setup.
130136
* v0.5.0 - August 23, 2014

dist/css/myplugin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.6.0
2+
* gulp-boilerplate v0.7.0
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/css/myplugin.min.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/** gulp-boilerplate v0.6.0, by Chris Ferdinandi | http://github.com/cferdinandi/Plugin | Licensed under MIT: http://gomakethings.com/mit/ */
1+
/** gulp-boilerplate v0.7.0, by Chris Ferdinandi | http://github.com/cferdinandi/Plugin | Licensed under MIT: http://gomakethings.com/mit/ */

dist/js/bind-polyfill.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.6.0
2+
* gulp-boilerplate v0.7.0
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/js/bind-polyfill.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/classList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.6.0
2+
* gulp-boilerplate v0.7.0
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/js/classList.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/myplugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* gulp-boilerplate v0.6.0
2+
* gulp-boilerplate v0.7.0
33
* My Gulp.js boilerplate for creating new web projects, by Chris Ferdinandi.
44
* http://github.com/cferdinandi/Plugin
55
*

dist/js/myplugin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Gulp Packages
12
var gulp = require('gulp');
23
var plumber = require('gulp-plumber');
34
var clean = require('gulp-clean');
@@ -15,8 +16,10 @@ var minify = require('gulp-minify-css');
1516
var karma = require('gulp-karma');
1617
var package = require('./package.json');
1718

19+
// Paths to project folders
1820
var paths = {
1921
output : 'dist/',
22+
temp: 'src/temp/',
2023
scripts : {
2124
input : [ 'src/js/*' ],
2225
output : 'dist/js/'
@@ -33,6 +36,7 @@ var paths = {
3336
}
3437
};
3538

39+
// Template for banner to add to file headers
3640
var banner = {
3741
full :
3842
'/**\n' +
@@ -51,23 +55,30 @@ var banner = {
5155
' */\n'
5256
};
5357

54-
gulp.task('scripts', ['clean'], function() {
58+
// Concatenate scripts in subfolders
59+
gulp.task('concatenate', function() {
5560
return gulp.src(paths.scripts.input)
5661
.pipe(plumber())
5762
.pipe(flatten())
63+
5864
.pipe(tap(function (file, t) {
5965
if ( file.stat.isDirectory() ) {
6066
var name = file.relative + '.js';
6167
return gulp.src(file.path + '/*.js')
6268
.pipe(concat(name))
63-
.pipe(header(banner.full, { package : package }))
64-
.pipe(gulp.dest(paths.scripts.output))
65-
.pipe(rename({ suffix: '.min' }))
66-
.pipe(uglify())
67-
.pipe(header(banner.min, { package : package }))
68-
.pipe(gulp.dest(paths.scripts.output));
69+
.pipe(gulp.dest(paths.temp));
6970
}
70-
}))
71+
}));
72+
});
73+
74+
// Lint and minify scripts
75+
gulp.task('scripts', ['clean', 'concatenate'], function() {
76+
return gulp.src([
77+
paths.scripts.input + '/../*.js',
78+
paths.temp + '/*.js'
79+
])
80+
.pipe(plumber())
81+
.pipe(flatten())
7182
.pipe(header(banner.full, { package : package }))
7283
.pipe(gulp.dest(paths.scripts.output))
7384
.pipe(rename({ suffix: '.min' }))
@@ -76,6 +87,7 @@ gulp.task('scripts', ['clean'], function() {
7687
.pipe(gulp.dest(paths.scripts.output));
7788
});
7889

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

105+
// Copy static files into output folder
93106
gulp.task('static', ['clean'], function() {
94107
return gulp.src(paths.static)
95108
.pipe(plumber())
96109
.pipe(gulp.dest(paths.output));
97110
});
98111

112+
// Lint scripts
99113
gulp.task('lint', function () {
100114
return gulp.src(paths.scripts.input)
101115
.pipe(plumber())
102116
.pipe(jshint())
103117
.pipe(jshint.reporter('jshint-stylish'));
104118
});
105119

120+
// Remove prexisting content from output and test folders
106121
gulp.task('clean', function () {
107122
return gulp.src([
108-
paths.output,
109-
paths.test.coverage,
110-
paths.test.results
123+
paths.output,
124+
paths.test.coverage,
125+
paths.test.results
111126
], { read: false })
112127
.pipe(plumber())
113128
.pipe(clean());
114129
});
115130

131+
// Remove temporary files
132+
gulp.task('cleanTemp', ['scripts'], function () {
133+
return gulp.src(paths.temp, { read: false })
134+
.pipe(plumber())
135+
.pipe(clean());
136+
});
137+
138+
// Run unit tests
116139
gulp.task('test', function() {
117140
return gulp.src([paths.scripts.input + '/../**/*.js'].concat(paths.test.spec))
118141
.pipe(plumber())
119142
.pipe(karma({ configFile: 'test/karma.conf.js' }))
120143
.on('error', function(err) { throw err; });
121144
});
122145

146+
// Combine tasks into runner
123147
gulp.task('default', [
124148
'lint',
125149
'clean',
150+
'static',
151+
'concatenate',
126152
'scripts',
127153
'styles',
128-
'static',
154+
'cleanTemp',
129155
'test'
130156
]);

0 commit comments

Comments
 (0)