forked from cocos-creator/fireball-engine-core-deprecated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
218 lines (189 loc) · 5.83 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
var Path = require('path');
var gulp = require('gulp');
var gutil = require('gulp-util');
var del = require('del');
var rename = require('gulp-rename');
var header = require('gulp-header');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var uglify = require('gulp-uglifyjs');
var concat = require('gulp-concat');
var qunit = require('gulp-qunit');
var preprocess = require('gulp-preprocess');
var fb = require('gulp-fb');
var paths = {
src: [
'src/__intro.js',
'src/editor/pre-define.js',
// javascript extends
'src/definition.js',
'src/core.js',
'src/math.js',
'src/intersection.js',
'src/callbacks-invoker.js',
// basic classes utility
'src/utils.js',
'src/attribute.js',
'src/class.js',
'src/class-new.js',
'src/path.js',
'src/object.js',
'src/hash-object.js',
'src/vec2.js',
'src/matrix23.js',
'src/rect.js',
'src/polygon.js',
'src/color.js',
'src/types.js',
'src/deserialize.js',
'src/instantiate.js',
// assets
'src/asset/asset.js',
'src/asset/custom-asset.js',
'src/asset/script-asset.js',
'src/asset/texture.js',
'src/asset/sprite.js',
'src/asset/atlas.js',
'src/asset/atlas-utils.js',
'src/asset/json-asset.js',
'src/asset/text-asset.js',
'src/asset/bitmap-font.js',
'src/asset/audio-clip.js',
// editor utils
'src/editor/serialize.js',
'src/editor/serialize-nicify.js',
'src/__outro.js'
],
player_dev: 'bin/core.player.dev.js',
player: 'bin/core.player.js',
test: {
src: 'test/unit/**/*.js',
runner: 'test/lib/runner.html',
lib_dev: [
'bin/dev/core.js',
],
lib_min: [
'bin/min/core.js',
],
},
ref: {
src: [
'test/lib/*.js',
'test/unit/_*.js',
],
dest: '_references.js',
},
};
// clean
gulp.task('clean', function() {
del('bin/');
});
// js-hint
gulp.task('jshint', function() {
return gulp.src(paths.src.concat( ['!**/__intro.js','!**/__outro.js'] ))
.pipe(jshint({
forin: false,
multistr: true,
loopfunc: true
}))
.pipe(jshint.reporter(stylish))
;
});
// js dev
gulp.task('js-dev', function() {
return gulp.src(paths.src)
.pipe(preprocess({context: { EDITOR: true, DEBUG: true, DEV: true }}))
.pipe(concat('core.js'))
.pipe(gulp.dest('bin/dev'))
;
});
// js min
gulp.task('js-min', function() {
return gulp.src(paths.src)
.pipe(preprocess({context: { EDITOR: true, DEV: true }}))
.pipe(concat('core.js'))
.pipe(uglify({
compress: {
dead_code: false,
unused: false
}
}))
.pipe(gulp.dest('bin/min'))
;
});
// player dev
gulp.task('js-player-dev', function() {
return gulp.src(paths.src.concat('!**/editor/**'))
.pipe(preprocess({context: { PLAYER: true, DEBUG: true, DEV: true }}))
.pipe(concat(Path.basename(paths.player_dev)))
.pipe(gulp.dest(Path.dirname(paths.player_dev)))
;
});
// player
gulp.task('js-player', function() {
return gulp.src(paths.src.concat('!**/editor/**'))
.pipe(preprocess({context: { PLAYER: true }}))
.pipe(concat(Path.basename(paths.player)))
.pipe(gulp.dest(Path.dirname(paths.player)))
;
});
gulp.task('dev', ['jshint', 'js-dev', 'js-player-dev', 'js-player']);
gulp.task('min', ['jshint', 'js-min', 'js-player-dev', 'js-player']);
gulp.task('default', ['dev', 'min']);
/////////////////////////////////////////////////////////////////////////////
// test
/////////////////////////////////////////////////////////////////////////////
gulp.task('unit-runner', function() {
var js = paths.test.src;
var dest = paths.test.src.split('*')[0];
return gulp.src(js, { read: false, base: './' })
.pipe(fb.toFileList())
.pipe(fb.generateRunner(paths.test.runner,
dest,
'Fireball Core Test Suite',
paths.test.lib_min,
paths.test.lib_dev,
paths.src))
.pipe(gulp.dest(dest))
;
});
gulp.task('test', ['js-min', 'js-dev', 'unit-runner'], function() {
var timeOutInSeconds = 5;
return gulp.src(['test/unit/**/*.html', '!**/*.dev.*'], { read: false })
.pipe(qunit({ timeout: timeOutInSeconds }))
;
});
gulp.task('export-api-syntax', function (done) {
// 默认所有 core 模块都在 Fire 下面
var DefaultModuleHeader = "/**\n" +
" * @module Fire\n" +
" * @class Fire\n" +
" */\n";
var dest = '../../utils/api/core';
del(dest + '/**/*', { force: true }, function (err) {
if (err) {
done(err);
return;
}
gulp.src(paths.src)
.pipe(header(DefaultModuleHeader))
.pipe(gulp.dest(dest))
.on('end', done);
});
});
/////////////////////////////////////////////////////////////////////////////
// tasks
/////////////////////////////////////////////////////////////////////////////
// ref
gulp.task('ref', function() {
var src = paths.src;//.concat(['!src/__intro.js', '!src/__outro.js']);
var files = paths.ref.src.concat(src);
var destPath = paths.ref.dest;
return fb.generateReference(files, destPath);
});
gulp.task('all', ['default', 'test', 'ref'] );
gulp.task('ci', ['jshint', 'test'] );
// watch
gulp.task('watch', function() {
gulp.watch(paths.src, ['dev']).on( 'error', gutil.log );
});