Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Commit ed58db0

Browse files
committed
Merge pull request #6 from addyosmani/gulp-rework
First slice of new gulp file
2 parents 7391944 + 5d7c8f1 commit ed58db0

File tree

15 files changed

+568
-206
lines changed

15 files changed

+568
-206
lines changed

.eslintrc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"ecmaFeatures": { "modules": true },
3+
"rules": {
4+
"array-bracket-spacing": 2,
5+
"block-spacing": [2, "never"],
6+
"brace-style": [2, "1tbs", { "allowSingleLine": false }],
7+
"camelcase": [2, {"properties": "always"}],
8+
"curly": 2,
9+
"default-case": 2,
10+
"dot-notation": 2,
11+
"eqeqeq": 2,
12+
"indent": [
13+
2,
14+
2
15+
],
16+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
17+
"max-len": [2, 80, 2, {"ignoreUrls": true}],
18+
"new-cap": 2,
19+
"no-console": 0,
20+
"no-else-return": 2,
21+
"no-eval": 2,
22+
"no-multi-spaces": 2,
23+
"no-multiple-empty-lines": [2, {"max": 2}],
24+
"no-shadow": 2,
25+
"no-trailing-spaces": 2,
26+
"no-unused-expressions": 2,
27+
"object-curly-spacing": [2, "never"],
28+
"padded-blocks": [2, "never"],
29+
"quotes": [
30+
2,
31+
"single"
32+
],
33+
"semi": [
34+
2,
35+
"always"
36+
],
37+
"space-after-keywords": 2,
38+
"space-before-blocks": 2,
39+
"space-before-function-paren": [2, "never"],
40+
"spaced-comment": 2,
41+
"valid-typeof": 2,
42+
"no-unused-vars": [2, {"args": "none"}]
43+
},
44+
"env": {
45+
"es6": true,
46+
"browser": true,
47+
"node": true
48+
},
49+
"extends": "eslint:recommended",
50+
"globals": {
51+
"importScripts": true
52+
}
53+
}

gulp-tasks/bump.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
*
3+
* Copyright 2015 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
var gulp = require('gulp');
19+
var bump = require('gulp-bump');
20+
var fs = require('fs');
21+
22+
gulp.task('update-pkg', function() {
23+
return gulp.src('./package.json')
24+
.pipe(bump({type:'patch'}))
25+
.pipe(gulp.dest('./'));
26+
});
27+
28+
gulp.task('bump', ['update-pkg'], function(cb) {
29+
GLOBAL.config.version =
30+
JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
31+
cb();
32+
});

gulp-tasks/clean.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
*
3+
* Copyright 2015 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
var gulp = require('gulp');
19+
var del = require('del');
20+
21+
gulp.task('clean', function(cb) {
22+
del([GLOBAL.config.dest], {dot: true})
23+
.then(function() {
24+
cb();
25+
});
26+
});

gulp-tasks/copy.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
*
3+
* Copyright 2015 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
var gulp = require('gulp');
19+
var runSequence = require('run-sequence');
20+
var del = require('del');
21+
22+
gulp.task('copy:watch', function() {
23+
gulp.watch(GLOBAL.config.src + '/*.*', ['copy:root']);
24+
});
25+
26+
gulp.task('copy:cleanRoot', function(cb) {
27+
del([GLOBAL.config.dest + '/*.{json,txt,ico}'], {dot: true})
28+
.then(function() {
29+
cb();
30+
});
31+
});
32+
33+
gulp.task('copy:root', ['copy:cleanRoot'], function() {
34+
return gulp.src([
35+
GLOBAL.config.src + '/*.{json,txt,ico}',
36+
])
37+
.pipe(gulp.dest(GLOBAL.config.dest));
38+
});
39+
40+
gulp.task('copy', function(cb) {
41+
runSequence(
42+
'copy:root',
43+
cb);
44+
});

gulp-tasks/html.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
*
3+
* Copyright 2015 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the 'License');
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an 'AS IS' BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
var gulp = require('gulp');
19+
var gulpif = require('gulp-if');
20+
var minifyHtml = require('gulp-minify-html');
21+
var replace = require('gulp-replace');
22+
23+
gulp.task('html:watch', function() {
24+
gulp.watch(GLOBAL.config.src + '/**/*.html', ['html']);
25+
});
26+
27+
gulp.task('html', function() {
28+
return gulp.src([
29+
GLOBAL.config.src + '/**/*.html',
30+
])
31+
.pipe(gulpif(GLOBAL.config.env == 'prod', minifyHtml()))
32+
.pipe(replace(/@VERSION@/g, GLOBAL.config.version))
33+
.pipe(gulp.dest(config.dest));
34+
});

gulp-tasks/images.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
*
3+
* Copyright 2015 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the 'License');
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an 'AS IS' BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
var gulp = require('gulp');
18+
var del = require('del');
19+
var gulpif = require('gulp-if');
20+
var imagemin = require('gulp-imagemin');
21+
22+
gulp.task('images:watch', function() {
23+
gulp.watch(GLOBAL.config.src + '/images/**/*.*', ['images']);
24+
});
25+
26+
gulp.task('images:clean', function(cb) {
27+
del([GLOBAL.config.dest + '/*.{png,jpg,jpeg,gif,svg}'], {dot: true})
28+
.then(function() {
29+
cb();
30+
});
31+
});
32+
33+
gulp.task('images', ['images:clean'], function() {
34+
return gulp.src(GLOBAL.config.src + '/**/*.{png,jpg,jpeg,gif,svg}')
35+
.pipe(gulpif(GLOBAL.config.env == 'prod', imagemin({
36+
progressive: true,
37+
interlaced: true,
38+
svgoPlugins: [{removeViewBox: false}],
39+
})))
40+
.pipe(gulp.dest(GLOBAL.config.dest));
41+
});

gulp-tasks/scripts.js

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/**
2+
*
3+
* Copyright 2015 Google Inc. All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the 'License');
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an 'AS IS' BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
var gulp = require('gulp');
19+
var del = require('del');
20+
var runSequence = require('run-sequence');
21+
var eslint = require('gulp-eslint');
22+
var path = require('path');
23+
var glob = require('glob');
24+
var browserify = require('browserify');
25+
var babelify = require('babelify');
26+
var gutil = require('gulp-util');
27+
var source = require('vinyl-source-stream');
28+
var uglify = require('gulp-uglify');
29+
var gulpif = require('gulp-if');
30+
var streamify = require('gulp-streamify');
31+
var replace = require('gulp-replace');
32+
var license = require('gulp-license');
33+
34+
gulp.task('scripts:watch', function() {
35+
gulp.watch(GLOBAL.config.src + '/**/*.es6.js', ['scripts:es6']);
36+
});
37+
38+
// Takes a set of objects defining inputs of javascript files
39+
// to run through browserify and babelify
40+
function compileES6Bundles(browserifyBundles, minify) {
41+
browserifyBundles.forEach(function(bundle) {
42+
var browserifyBundle = browserify({
43+
entries: [bundle.srcPath],
44+
})
45+
.transform(babelify);
46+
47+
return browserifyBundle.bundle()
48+
.on('log', gutil.log.bind(gutil, 'Browserify Log'))
49+
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
50+
.pipe(source(bundle.outputFilename))
51+
.pipe(replace(/@VERSION@/g, GLOBAL.config.version))
52+
53+
// If this is a production build - minify JS
54+
.pipe(gulpif(GLOBAL.config.env == 'prod', streamify(uglify())))
55+
.pipe(license(GLOBAL.config.license, GLOBAL.config.licenseOptions))
56+
.pipe(gulp.dest(bundle.dest));
57+
});
58+
}
59+
60+
// This takes a source path and finds all files ending
61+
// with .es6.js and creates the bundles to run through browserify
62+
// and babelify
63+
function generateES6Bundles(srcPath) {
64+
if (!srcPath) {
65+
throw new Error('Invalid source path given to generateES6Bundles');
66+
}
67+
68+
var es6Filepaths = glob.sync(srcPath + '/**/*.es6.js');
69+
70+
var browserifyBundles = [];
71+
es6Filepaths.forEach(function(filepath) {
72+
var filename = path.basename(filepath);
73+
var directoryOfFile = path.dirname(filepath);
74+
var relativeDirectory = path.relative(
75+
srcPath,
76+
directoryOfFile);
77+
78+
// Replace .es6.js with .js for the final output
79+
var outputFilename =
80+
filename.substring(0, filename.length - '.es6.js'.length) + '.js';
81+
82+
browserifyBundles.push({
83+
srcPath: './' + filepath,
84+
outputFilename: outputFilename,
85+
dest: path.join(GLOBAL.config.dest, relativeDirectory),
86+
});
87+
});
88+
89+
compileES6Bundles(browserifyBundles);
90+
}
91+
92+
gulp.task('scripts:eslint', function() {
93+
return gulp.src([GLOBAL.config.src + '/**/*.es6.js'])
94+
95+
// eslint() attaches the lint output to the eslint property
96+
// of the file object so it can be used by other modules.
97+
.pipe(eslint())
98+
99+
// eslint.format() outputs the lint results to the console.
100+
// Alternatively use eslint.formatEach() (see Docs).
101+
.pipe(eslint.format())
102+
103+
// To have the process exit with an error code (1) on
104+
// lint error, return the stream and pipe to failOnError last.
105+
.pipe(eslint.failOnError());
106+
});
107+
108+
gulp.task('scripts:es6', ['scripts:eslint'], function(cb) {
109+
generateES6Bundles(GLOBAL.config.src);
110+
111+
cb();
112+
});
113+
114+
// Delete any files currently in the scripts destination path
115+
gulp.task('scripts:clean', function(cb) {
116+
del([GLOBAL.config.dest + '/**/*.js'], {dot: true})
117+
.then(function() {
118+
cb();
119+
});
120+
});
121+
122+
gulp.task('scripts', function(cb) {
123+
runSequence(
124+
'scripts:clean',
125+
['scripts:es6'],
126+
cb
127+
);
128+
});

0 commit comments

Comments
 (0)