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

Commit 9488f0c

Browse files
author
Nick Litwin
committed
Move tasks out of gulpfile into individual files
1 parent 618e543 commit 9488f0c

File tree

1 file changed

+5
-280
lines changed

1 file changed

+5
-280
lines changed

gulpfile.js

Lines changed: 5 additions & 280 deletions
Original file line numberDiff line numberDiff line change
@@ -1,294 +1,19 @@
11
'use strict';
22

33
var gulp = require('gulp');
4-
// rename to plugins once everything is modularized
5-
var $ = require('gulp-load-plugins')({lazy: true});
4+
var plugins = require('gulp-load-plugins')({lazy: true});
5+
66
var config = require('./gulp.config')();
77
var taskPath = './gulp-tasks/';
88
var taskList = require('fs').readdirSync(taskPath);
9+
910
var utilities = require(taskPath + 'utilities');
10-
var envFile = require('./config.js')();
11-
var envConfig = envFile[process.env.ENVIRONMENT || 'development'];
1211

1312
taskList.forEach(function(taskFile) {
1413
if (taskFile !== 'utilities.js') {
15-
require(taskPath + taskFile)(gulp, $, config, utilities);
14+
require(taskPath + taskFile)(gulp, plugins, config, utilities);
1615
}
1716
});
1817

19-
gulp.task('help', $.taskListing);
18+
gulp.task('help', plugins.taskListing);
2019
gulp.task('default', ['help']);
21-
22-
var browserSync = require('browser-sync');
23-
var histFallback = require('connect-history-api-fallback');
24-
var merge = require('merge-stream');
25-
var RevAll = require('gulp-rev-all');
26-
27-
var awspublishRouter = require('gulp-awspublish-router');
28-
29-
gulp.task('wiredep', ['jade'], function() {
30-
utilities.log('Injecting bower css/js and app js files into index.jade');
31-
var options = config.getWiredepDefaultOptions();
32-
var wiredep = require('wiredep').stream;
33-
34-
return gulp
35-
.src(config.index)
36-
.pipe(wiredep(options))
37-
.pipe($.inject(
38-
gulp.src(config.js)
39-
.pipe($.naturalSort('desc'))
40-
.pipe($.angularFilesort()),
41-
{relative: true}))
42-
.pipe($.inject(gulp.src(config.nonBowerScripts, {read: false}), {
43-
starttag: '//- inject:nonBowerScripts',
44-
endtag: '//- endinject',
45-
ignorePath: 'assets/'
46-
}))
47-
.pipe(gulp.dest(config.app));
48-
});
49-
50-
gulp.task('inject', ['wiredep', 'styles', 'templatecache'], function() {
51-
utilities.log('Injecting app css into index.jade');
52-
53-
return gulp
54-
.src(config.index)
55-
.pipe($.inject( // Sort the css (reset.css, then topcoder.css, then everything else)
56-
gulp.src([config.temp + 'assets/css/reset.css', config.css], {read: false})
57-
.pipe($.naturalSort('desc')),
58-
{ignorePath: '.tmp', addRootSlash: false}))
59-
.pipe(gulp.dest(config.app));
60-
});
61-
62-
gulp.task('optimize', ['inject', 'test', 'ngConstants', 'images'], function() {
63-
utilities.log('Optimizing the JavaScript, CSS, and HTML');
64-
65-
var assets = $.useref.assets({searchPath: ['.tmp', 'app', 'assets']});
66-
var templateCache = config.temp + config.templateCache.file;
67-
var cssFilter = $.filter('**/*.css');
68-
var jsLibFilter = $.filter('**/' + config.optimized.vendor);
69-
var jsAppFilter = $.filter('**/' + config.optimized.app);
70-
71-
var imageStream = gulp.src(config.temp + '/**/*.{svg,png,jpg,jpeg,gif}');
72-
var userefStream = gulp
73-
.src(config.indexHtml)
74-
.pipe($.plumber())
75-
.pipe($.inject(gulp.src(templateCache, {read: false}), {
76-
starttag: '<!-- inject:templates.js -->',
77-
endtag: '<!-- endinject -->',
78-
relative: true
79-
}))
80-
.pipe(assets)
81-
.pipe(cssFilter)
82-
.pipe($.csso())
83-
.pipe(cssFilter.restore())
84-
.pipe(jsLibFilter)
85-
.pipe($.uglify())
86-
.pipe(jsLibFilter.restore())
87-
.pipe(jsAppFilter)
88-
.pipe($.if(!config.production && !config.qa, $.sourcemaps.init()))
89-
.pipe($.ngAnnotate())
90-
.pipe($.uglify())
91-
.pipe(jsAppFilter.restore())
92-
.pipe(assets.restore())
93-
.pipe($.useref())
94-
95-
var revAll = new RevAll({
96-
prefix: envConfig.CONSTANTS.ASSET_PREFIX,
97-
dontRenameFile: [/^\/index.html/g]
98-
});
99-
100-
return merge(userefStream, imageStream)
101-
.pipe(revAll.revision())
102-
.pipe($.if(!config.production && !config.qa, $.sourcemaps.write()))
103-
// Uncomment if you want to see the JSON file containing
104-
// the file mapping (e.g., "{"js/app.js": "js/app-a9bae026bc.js"}")
105-
// .pipe(gulp.dest(config.build))
106-
// .pipe(revAll.manifestFile())
107-
.pipe(gulp.dest(config.build));
108-
});
109-
110-
gulp.task('build', ['optimize', 'fonts'], function(done) {
111-
utilities.log('Building everything');
112-
utilities.clean(config.temp, done);
113-
});
114-
115-
gulp.task('build-specs', ['templatecache', 'ngConstants'], function() {
116-
utilities.log('Building the spec runner');
117-
118-
var wiredep = require('wiredep').stream;
119-
var options = config.getWiredepDefaultOptions();
120-
options.devDependencies = true;
121-
122-
return gulp
123-
.src(config.specRunner)
124-
.pipe(wiredep(options))
125-
.pipe($.inject(gulp.src(config.testlibraries),
126-
{name: 'inject:testlibraries', read: false}))
127-
.pipe($.inject(gulp.src(config.nonBowerScripts),
128-
{name: 'inject:nonBowerScripts', read: false}))
129-
.pipe($.inject(
130-
gulp.src(config.js)
131-
.pipe($.naturalSort())
132-
.pipe($.angularFilesort())
133-
))
134-
.pipe($.inject(gulp.src(config.specHelpers),
135-
{name: 'inject:spechelpers', read: false}))
136-
.pipe($.inject(gulp.src(config.specs),
137-
{name: 'inject:specs', read: false}))
138-
.pipe($.inject(gulp.src(config.temp + config.templateCache.file),
139-
{name: 'inject:templates', read: false}))
140-
.pipe(gulp.dest(config.app));
141-
});
142-
143-
gulp.task('serve', ['inject', 'ngConstants'], function() {
144-
145-
gulp.watch(config.sass, ['styles'])
146-
.on('change', function(event) { changeEvent(event); });
147-
148-
gulp.watch(config.jade, ['jade'])
149-
.on('change', function(event) { changeEvent(event); });
150-
151-
var options = {
152-
server: {
153-
baseDir: [config.temp, config.app, config.assets],
154-
// Enables serving index.html for Angular HTML5 mode
155-
middleware: [histFallback()],
156-
routes: {
157-
'/bower_components': 'bower_components'
158-
}
159-
},
160-
files: config.watchFiles,
161-
ghostMode: {
162-
clicks: true,
163-
location: false,
164-
forms: true,
165-
scroll: true
166-
},
167-
logPrefix: 'Topcoder-Account',
168-
notify: false,
169-
port: 3000,
170-
reloadDelay: 1000
171-
};
172-
173-
browserSync(options);
174-
175-
});
176-
177-
gulp.task('serve-specs', ['build-specs'], function() {
178-
utilities.log('Run the spec runner');
179-
180-
gulp.watch(config.sass, ['styles'])
181-
.on('change', function(event) { changeEvent(event); });
182-
183-
gulp.watch(config.jade, ['jade'])
184-
.on('change', function(event) { changeEvent(event); });
185-
186-
var options = {
187-
server: {
188-
baseDir: ['./'],
189-
// Enables serving index.html for Angular HTML5 mode
190-
middleware: [histFallback()],
191-
routes: {
192-
'/bower_components': 'bower_components'
193-
}
194-
},
195-
files: config.watchFiles,
196-
ghostMode: {
197-
clicks: true,
198-
location: false,
199-
forms: true,
200-
scroll: true
201-
},
202-
logPrefix: 'Topcoder-Account',
203-
notify: false,
204-
reloadDelay: 1000,
205-
startPath: config.app + config.specRunnerFile
206-
};
207-
208-
browserSync(options);
209-
});
210-
211-
gulp.task('serve-build', ['build'], function() {
212-
// TODO: Figure out why watch doesn't work. Jade running before wiredep?
213-
214-
gulp.watch([config.sass, config.js, config.jade], ['optimize', browserSync.reload])
215-
.on('change', function(event) { changeEvent(event); });
216-
217-
var options = {
218-
server: {
219-
baseDir: config.build,
220-
// Enables serving index.html for Angular HTML5 mode
221-
middleware: [histFallback()]
222-
},
223-
files: [],
224-
ghostMode: {
225-
clicks: true,
226-
location: false,
227-
forms: true,
228-
scroll: true
229-
},
230-
logPrefix: 'Topcoder-Account',
231-
notify: false,
232-
reloadDelay: 1000
233-
};
234-
235-
browserSync(options);
236-
237-
});
238-
239-
// gulp.task('test', ['vet', 'templatecache'], function(done) {
240-
gulp.task('test', ['templatecache', 'ngConstants'], function(done) {
241-
utilities.startTests(true /* singleRun */, done);
242-
});
243-
244-
gulp.task('autotest', ['vet', 'templatecache'], function(done) {
245-
utilities.startTests(false /* singleRun */, done);
246-
});
247-
248-
gulp.task('deploy', ['build'], function() {
249-
var awsConfig = {
250-
params: {
251-
Bucket: config.aws.bucket
252-
},
253-
"accessKeyId": config.aws.key,
254-
"secretAccessKey": config.aws.secret
255-
};
256-
257-
// create a new publisher
258-
var publisher = $.awspublish.create(awsConfig);
259-
260-
utilities.log('Deploying to S3');
261-
262-
var gzip = gulp.src(['build/**/*.js', 'build/**/*.css']).pipe($.awspublish.gzip())
263-
.pipe(awspublishRouter({
264-
cache: {
265-
cacheTime: 94608000,
266-
allowTransform: false,
267-
public: true
268-
},
269-
routes: {
270-
"^.+$": "$&"
271-
}
272-
}));
273-
274-
var plain = gulp.src(['build/**/*', '!build/**/*.js', '!build/**/*.css'])
275-
.pipe(awspublishRouter({
276-
cache: {
277-
cacheTime: 94608000,
278-
allowTransform: false,
279-
public: true
280-
},
281-
routes: {
282-
"^.+\\.html": {
283-
cacheTime: 0
284-
},
285-
"^.+$": "$&"
286-
}
287-
}));
288-
289-
return merge(gzip, plain)
290-
.pipe(publisher.cache())
291-
.pipe(publisher.publish())
292-
.pipe($.if(!config.production, publisher.sync()))
293-
.pipe($.awspublish.reporter());
294-
});

0 commit comments

Comments
 (0)