-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
192 lines (149 loc) · 4.53 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
187
188
189
190
191
192
var lr = require('tiny-lr');
var gulp = require('gulp');
var gulputil = require('gulp-util');
var watch = require('gulp-watch');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var livereload = require('gulp-livereload');
var concat = require('gulp-concat');
var less = require('gulp-less');
var bower = require('gulp-bower');
var usemin = require('gulp-usemin');
var rename = require("gulp-rename");
var rjs = require('gulp-requirejs');
var uglify = require('gulp-uglify');
var rev = require('gulp-rev');
var clean = require('gulp-clean');
var rjsConfig = require('./public/scripts/requirejsConfig');
var es = require('event-stream');
var deploy = require('gulp-gh-pages');
var server = lr();
// gulp.task('default', function(){
// // place code for your default task here
// });
var ngConstant = require('gulp-ng-constant');
gulp.task('translations', function(done) {
var locales = ['en', 'zh-TW'];
locales.forEach(function(locale) {
var translations = require('./public/locale/' + locale + '.json');
var translationFile = {};
console.log(translations);
var localeKey = 'taxCalculator.translations.' + locale;
translationFile[localeKey] = translations;
//gulp.src()
//get file
var count = 0;
var stream = ngConstant({
name: localeKey,
deps: [],
constants: translationFile,
wrap: 'amd',
stream: true
})
// Writes config.js to dist/ folder
.pipe(rename("translations.js"))
.pipe(gulp.dest('dist/scripts/' + locale))
.pipe(gulp.dest('public/scripts/' + locale));
stream.on('end', function() {
if (count == locales.length) {
done();
}
});
});
//quick hack
});
var deployIEScripts = function() {
gulp.src(['public/bower_components/es5-shim/es5-shim.min.js',
'public/bower_components/json3/lib/json3.min.js'
])
.pipe(gulp.dest('public/scripts/'))
.pipe(gulp.dest('dist/scripts/'));
};
// https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-tasks-in-series.md#running-tasks-in-series
var concatJs = function() {
console.log(rjsConfig);
rjsConfig.baseUrl = "public/scripts";
rjsConfig.out = 'concat.js';
rjsConfig.name = "main";
return rjs(rjsConfig).pipe(uglify({
outSourceMap: true,
output: {
ascii_only: false
}
}))
.pipe(gulp.dest('dist/scripts/')); // pipe it to the output DIR
};
gulp.task('less', function() {
gulp.src('less/*.less')
.pipe(less())
.pipe(gulp.dest('public/css/'))
})
gulp.task('build2', ['build'], function(cb) {
//smell of bad design but works
//trick let this two overwite the concated js file
//simple overwrite wont do as it just stream to same files ignoring existing content length
es.concat(
gulp.src('pre-dist/index.html')
.pipe(gulp.dest('dist/')),
gulp.src('CNAME')
.pipe(gulp.dest('dist/')),
gulp.src(['public/scripts/require.min.js'])
.pipe(gulp.dest('dist/scripts/')),
concatJs()
).on('end', cb);
});
gulp.task('pre-dist-clean', ['build', 'build2'], function() {
// //ok remove folder not scripts
// console.log('clean');
gulp.src('pre-dist/', {
read: true
}).pipe(clean({
force: true
}));
});
gulp.task('dist', ['build', 'build2', 'pre-dist-clean']);
gulp.task('build', function(cb) {
deployIEScripts();
var lessStream = gulp.src('less/*.less')
.pipe(less())
.pipe(gulp.dest('dist/css/'));
var templatesStream = gulp.src(['public/templates/**.html'])
.pipe(gulp.dest('dist/templates/'));
var htmlMinStream = gulp.src('public/index.html')
.pipe(usemin({
// css: [minifyCss(), 'concat'],
// html: [minifyHtml({empty: true})],
js: []
}))
.pipe(gulp.dest('pre-dist/'));
//discard it as concat may run before above
es.concat(
lessStream, templatesStream, htmlMinStream
).on('end', cb);
});
gulp.task('default', ['listen', 'translations'], function() {
bower()
.pipe(gulp.dest('public/bower_components/'));
//TODO ensure bower end
deployIEScripts();
gulp.src(['public/*', 'public/templates/*', 'public/scripts/*',
'public/locale/*'
])
.pipe(watch())
.pipe(livereload(server))
gulp.watch('public/locale/*', ['translations']);
gulp.src('less/*.less')
.pipe(less())
.pipe(gulp.dest('public/css/'))
concatJs();
});
gulp.task('deploy', function() {
return gulp.src('./dist/**/*')
.pipe(deploy());
});
gulp.task('listen', function(next) {
server.listen(35729, function(err) {
if (err) return console.error(err);
next();
});
});