Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 618e543

Browse files
author
Nick Litwin
committedDec 1, 2015
Move remaining tasks out
1 parent 223918a commit 618e543

File tree

4 files changed

+255
-0
lines changed

4 files changed

+255
-0
lines changed
 

‎gulp-tasks/build.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var runSequence = require('run-sequence');
2+
3+
module.exports = function(gulp, $, config, utilities) {
4+
'use strict';
5+
6+
gulp.task('build', function(done) {
7+
utilities.log('Building everything');
8+
9+
runSequence(
10+
'clean',
11+
['optimize', 'fonts']
12+
);
13+
14+
utilities.clean(config.temp, done);
15+
});
16+
17+
gulp.task('build-specs', ['templatecache', 'ngConstants'], function() {
18+
utilities.log('Building the spec runner');
19+
20+
var wiredep = require('wiredep').stream;
21+
var options = config.getWiredepDefaultOptions();
22+
options.devDependencies = true;
23+
24+
return gulp
25+
.src(config.specRunner)
26+
.pipe(wiredep(options))
27+
.pipe($.inject(gulp.src(config.testlibraries),
28+
{name: 'inject:testlibraries', read: false}))
29+
.pipe($.inject(gulp.src(config.nonBowerScripts),
30+
{name: 'inject:nonBowerScripts', read: false}))
31+
.pipe($.inject(
32+
gulp.src(config.js)
33+
.pipe($.naturalSort())
34+
.pipe($.angularFilesort())
35+
))
36+
.pipe($.inject(gulp.src(config.specHelpers),
37+
{name: 'inject:spechelpers', read: false}))
38+
.pipe($.inject(gulp.src(config.specs),
39+
{name: 'inject:specs', read: false}))
40+
.pipe($.inject(gulp.src(config.temp + config.templateCache.file),
41+
{name: 'inject:templates', read: false}))
42+
.pipe(gulp.dest(config.app));
43+
});
44+
};

‎gulp-tasks/deploy.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
var merge = require('merge-stream');
2+
var awspublishRouter = require('gulp-awspublish-router');
3+
4+
module.exports = function(gulp, $, config, utilities) {
5+
'use strict';
6+
7+
gulp.task('deploy', ['build'], function() {
8+
var awsConfig = {
9+
params: {
10+
Bucket: config.aws.bucket
11+
},
12+
"accessKeyId": config.aws.key,
13+
"secretAccessKey": config.aws.secret
14+
};
15+
16+
// create a new publisher
17+
var publisher = $.awspublish.create(awsConfig);
18+
19+
utilities.log('Deploying to S3');
20+
21+
var gzip = gulp.src(['build/**/*.js', 'build/**/*.css']).pipe($.awspublish.gzip())
22+
.pipe(awspublishRouter({
23+
cache: {
24+
cacheTime: 94608000,
25+
allowTransform: false,
26+
public: true
27+
},
28+
routes: {
29+
"^.+$": "$&"
30+
}
31+
}));
32+
33+
var plain = gulp.src(['build/**/*', '!build/**/*.js', '!build/**/*.css'])
34+
.pipe(awspublishRouter({
35+
cache: {
36+
cacheTime: 94608000,
37+
allowTransform: false,
38+
public: true
39+
},
40+
routes: {
41+
"^.+\\.html": {
42+
cacheTime: 0
43+
},
44+
"^.+$": "$&"
45+
}
46+
}));
47+
48+
return merge(gzip, plain)
49+
.pipe(publisher.cache())
50+
.pipe(publisher.publish())
51+
.pipe($.if(!config.production, publisher.sync()))
52+
.pipe($.awspublish.reporter());
53+
});
54+
};

‎gulp-tasks/optimize.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
var envFile = require('../config.js')();
2+
var envConfig = envFile[process.env.ENVIRONMENT || 'development'];
3+
var RevAll = require('gulp-rev-all');
4+
var merge = require('merge-stream');
5+
6+
module.exports = function(gulp, $, config, utilities) {
7+
'use strict';
8+
9+
gulp.task('optimize', ['inject', 'test', 'ngConstants', 'images'], function() {
10+
utilities.log('Optimizing the JavaScript, CSS, and HTML');
11+
12+
var assets = $.useref.assets({searchPath: ['.tmp', 'app', 'assets']});
13+
var templateCache = config.temp + config.templateCache.file;
14+
var cssFilter = $.filter('**/*.css');
15+
var jsLibFilter = $.filter('**/' + config.optimized.vendor);
16+
var jsAppFilter = $.filter('**/' + config.optimized.app);
17+
18+
var imageStream = gulp.src(config.temp + '/**/*.{svg,png,jpg,jpeg,gif}');
19+
var userefStream = gulp
20+
.src(config.indexHtml)
21+
.pipe($.plumber())
22+
.pipe($.inject(gulp.src(templateCache, {read: false}), {
23+
starttag: '<!-- inject:templates.js -->',
24+
endtag: '<!-- endinject -->',
25+
relative: true
26+
}))
27+
.pipe(assets)
28+
.pipe(cssFilter)
29+
.pipe($.csso())
30+
.pipe(cssFilter.restore())
31+
.pipe(jsLibFilter)
32+
.pipe($.uglify())
33+
.pipe(jsLibFilter.restore())
34+
.pipe(jsAppFilter)
35+
.pipe($.if(!config.production && !config.qa, $.sourcemaps.init()))
36+
.pipe($.ngAnnotate())
37+
.pipe($.uglify())
38+
.pipe(jsAppFilter.restore())
39+
.pipe(assets.restore())
40+
.pipe($.useref())
41+
42+
var revAll = new RevAll({
43+
prefix: envConfig.CONSTANTS.ASSET_PREFIX,
44+
dontRenameFile: [/^\/index.html/g]
45+
});
46+
47+
return merge(userefStream, imageStream)
48+
.pipe(revAll.revision())
49+
.pipe($.if(!config.production && !config.qa, $.sourcemaps.write()))
50+
// Uncomment if you want to see the JSON file containing
51+
// the file mapping (e.g., "{"js/app.js": "js/app-a9bae026bc.js"}")
52+
// .pipe(gulp.dest(config.build))
53+
// .pipe(revAll.manifestFile())
54+
.pipe(gulp.dest(config.build));
55+
});
56+
};

‎gulp-tasks/serve.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
var browserSync = require('browser-sync');
2+
var histFallback = require('connect-history-api-fallback');
3+
4+
module.exports = function(gulp, $, config, utilities) {
5+
'use strict';
6+
7+
gulp.task('serve', ['inject', 'ngConstants'], function() {
8+
gulp.watch(config.sass, ['styles'])
9+
.on('change', function(event) { utilities.changeEvent(event); });
10+
11+
gulp.watch(config.jade, ['templatecache'])
12+
.on('change', function(event) { utilities.changeEvent(event); });
13+
14+
var options = {
15+
server: {
16+
baseDir: [config.temp, config.app, config.assets],
17+
// Enables serving index.html for Angular HTML5 mode
18+
middleware: [histFallback()],
19+
routes: {
20+
'/bower_components': 'bower_components'
21+
}
22+
},
23+
files: config.watchFiles,
24+
ghostMode: {
25+
clicks: true,
26+
location: false,
27+
forms: true,
28+
scroll: true
29+
},
30+
logPrefix: 'Topcoder-Account',
31+
notify: false,
32+
port: 3000,
33+
reloadDelay: 1000
34+
};
35+
36+
browserSync(options);
37+
38+
});
39+
40+
gulp.task('serve-specs', ['build-specs'], function() {
41+
utilities.log('Run the spec runner');
42+
43+
gulp.watch(config.sass, ['styles'])
44+
.on('change', function(event) { utilities.changeEvent(event); });
45+
46+
gulp.watch(config.jade, ['templatecache'])
47+
.on('change', function(event) { utilities.changeEvent(event); });
48+
49+
var options = {
50+
server: {
51+
baseDir: ['./'],
52+
// Enables serving index.html for Angular HTML5 mode
53+
middleware: [histFallback()],
54+
routes: {
55+
'/bower_components': 'bower_components'
56+
}
57+
},
58+
files: config.watchFiles,
59+
ghostMode: {
60+
clicks: true,
61+
location: false,
62+
forms: true,
63+
scroll: true
64+
},
65+
logPrefix: 'Topcoder-Account',
66+
notify: false,
67+
reloadDelay: 1000,
68+
startPath: config.app + config.specRunnerFile
69+
};
70+
71+
browserSync(options);
72+
});
73+
74+
gulp.task('serve-build', ['build'], function() {
75+
// TODO: Figure out why watch doesn't work. Jade running before wiredep?
76+
77+
gulp.watch([config.sass, config.js, config.jade], ['optimize', browserSync.reload])
78+
.on('change', function(event) { utilities.changeEvent(event); });
79+
80+
var options = {
81+
server: {
82+
baseDir: config.build,
83+
// Enables serving index.html for Angular HTML5 mode
84+
middleware: [histFallback()]
85+
},
86+
files: [],
87+
ghostMode: {
88+
clicks: true,
89+
location: false,
90+
forms: true,
91+
scroll: true
92+
},
93+
logPrefix: 'Topcoder-Account',
94+
notify: false,
95+
reloadDelay: 1000
96+
};
97+
98+
browserSync(options);
99+
100+
});
101+
};

0 commit comments

Comments
 (0)
This repository has been archived.