-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
186 lines (168 loc) · 5.74 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
var gulp = require('gulp');
var ngAnnotate = require('gulp-ng-annotate');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var size = require('gulp-size');
//var clean = require('gulp-clean');
var rename = require('gulp-rename');
var minifyCSS = require('gulp-minify-css');
var minifyHTML = require('gulp-minify-html');
//var changed = require('gulp-changed');
var compass = require('gulp-compass');
var bowerFiles = require('main-bower-files');
var ignore = require('gulp-ignore');
var filelog = require('gulp-filelog');
var rev = require('gulp-rev');
var ngHtml2Js = require("gulp-ng-html2js");
var merge = require('merge-stream');
var lazypipe = require('lazypipe');
//var open = require('open');
//var runSequence = require('run-sequence');
//var connect = require('gulp-connect');
var shell = require('gulp-shell');
process.env.GOPATH = process.cwd();
var paths = {
appjs: {
src: './src/example.com/frontend/scripts/**/*.js',
dest: './src/example.com/frontend/build/'
},
libjs: {
dest: './src/example.com/frontend/build/'
},
views: {
src: './src/example.com/frontend/views/*.html',
base: './src/example.com/frontend/views/',
dest: './src/example.com/frontend/build/'
},
styles: {
src: './src/example.com/frontend/styles/*.scss',
dest: './src/example.com/frontend/build/',
sass: 'src/example.com/frontend/styles/',
import_path: ['./src/example.com/frontend/vendor/bootstrap-sass-official/assets/stylesheets']
},
ae_extra: './src/example.com/frontend/',
ae_yaml: {
dispatch: ['./src/example.com/frontend/dispatch.yaml'],
prod: ['./src/example.com/frontend/app-prod.yaml'],
qa: ['./src/example.com/frontend/app-qa.yaml'],
dev: ['./src/example.com/frontend/app-dev.yaml'],
},
};
var options = {
open: true,
httpPort: 4400,
devserver_port: 8080,
admin_port: 8000
};
// Helper function to generate a pipe that does the common file revisions
function revFiles(name, dest) {
return lazypipe()
.pipe(size, {title: name})
.pipe(rename, { suffix: '.min' })
.pipe(rev)
.pipe(gulp.dest, dest)
.pipe(rev.manifest)
.pipe(rename, name + "-manifest.json")
.pipe(gulp.dest, dest);
}
// process the compass files
gulp.task('styles', function () {
return gulp.src(paths.styles.src)
.pipe(compass({
css: paths.styles.dest,
sass: paths.styles.sass,
import_path: paths.styles.import_path
}))
.pipe(gulp.dest(paths.styles.dest))
.pipe(minifyCSS())
.pipe(size({title:"styles"}))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.styles.dest))
.pipe(rev())
.pipe(gulp.dest(paths.styles.dest))
.pipe(rev.manifest())
.pipe(rename("css-manifest.json"))
.pipe(gulp.dest(paths.styles.dest));
});
gulp.task('minify-appjs', function () {
var appjs = gulp.src(paths.appjs.src);
var viewjs = gulp.src(paths.views.src)
.pipe(minifyHTML({
empty: true,
quotes: true
}))
.pipe(ngHtml2Js({
moduleName: "app",
stripPrefix: paths.views.base,
prefix: "/_/views/"
}));
return merge(appjs, viewjs)
.pipe(ngAnnotate())
.pipe(concat("app.js"))
.pipe(gulp.dest(paths.appjs.dest))
.pipe(uglify())
.pipe(revFiles("appjs", paths.appjs.dest)());
});
gulp.task('minify-libjs', function () {
return gulp.src(bowerFiles())
.pipe(ignore.include('**/*.js'))
.pipe(ignore.exclude([
'**/angular.js',
'**/jquery.js',
'**/bootstrap/*.js',
]))
// .pipe(filelog())
.pipe(concat("lib.js"))
.pipe(gulp.dest(paths.libjs.dest))
.pipe(uglify())
.pipe(revFiles("libjs", paths.libjs.dest)());
});
gulp.task('build', ['styles', 'minify-appjs', 'minify-libjs']);
gulp.task('watch', ['build'], function() {
gulp.watch(paths.styles.src, ['styles']);
gulp.watch(paths.views.src, ['minify-appjs']);
gulp.watch(paths.appjs.src, ['minify-appjs']);
gulp.watch('./bower.json', ['minify-libjs']);
});
gulp.task('server', ['watch'], function(){
var cfg = [].concat(paths.ae_yaml.dev, paths.ae_yaml.dispatch);
gulp.src('').pipe(shell([
'goapp serve --port='+options.devserver_port+' --admin_port='+options.admin_port+' ' + cfg.join(' ')
]));
});
gulp.task('deploy:qa', ['build'], function(){
var appcfg = 'appcfg.py --oauth2 -A example-qa ';
gulp.src('').pipe(shell([
appcfg + 'update_queues ' + paths.ae_extra,
appcfg + 'update_cron ' + paths.ae_extra,
appcfg + 'update ' + paths.ae_yaml.qa.join(' '),
appcfg + 'update_dispatch ' + paths.ae_extra,
]));
});
gulp.task('deploy:prod', ['build'], function(){
var appcfg = 'appcfg.py --oauth2 -A example-prod ';
gulp.src('').pipe(shell([
appcfg + 'update_queues ' + paths.ae_extra,
appcfg + 'update_cron ' + paths.ae_extra,
appcfg + 'update ' + paths.ae_yaml.prod.join(' '),
appcfg + 'update_dispatch ' + paths.ae_extra,
]));
});
gulp.task('vet', shell.task([
'go vet `go list example.com/... | grep -v third_party`',
],{ignoreErrors:true}));
gulp.task('goget', shell.task([
'goapp get example.com/...',
], {ignoreErrors: true}));
gulp.task('test', shell.task([
'goapp test -parallel 4 `go list example.com/... | grep -v third_party`',
],{ignoreErrors:true}));
gulp.task('install', ['goget'], function() {
return bower.commands.install()
.on('log', function(data) {
gutil.log('bower', gutil.colors.cyan(data.id), data.message);
});
});
// default gulp task
gulp.task('default', ['server'], function() {
});