forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
196 lines (156 loc) · 6.25 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
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
'use strict';
const Path = require('path');
const gulp = require('gulp');
const Del = require('del');
const Shell = require('gulp-shell');
const Engine = require('./gulp/tasks/engine');
const Test = require('./gulp/tasks/test');
const Watch = require('./gulp/tasks/watch');
/////////////
// engine //
/////////////
gulp.task('build-debug-infos', function () {
Engine.buildDebugInfos();
});
gulp.task('build-html5-dev', ['clean-cache', 'build-debug-infos'], function (done) {
Engine.buildCocosJs('./index.js', './bin/cocos2d-js.js', [], done);
});
gulp.task('build-html5-min', ['clean-cache', 'build-debug-infos'], function (done) {
Engine.buildCocosJsMin('./index.js', './bin/cocos2d-js-min.js', [], done);
});
gulp.task('build-html5-preview', ['build-debug-infos'], function (done) {
Engine.buildPreview('./index.js', './bin/cocos2d-js-for-preview.js', done);
});
gulp.task('build-html5-preview-dev', ['build-debug-infos'], function (done) {
Engine.buildPreview('./index.js', './bin/cocos2d-js-for-preview.js', done, true);
});
gulp.task('build-html5', ['build-html5-preview', 'build-html5-dev', 'build-html5-min']);
gulp.task('build-jsb-dev', ['clean-cache', 'build-debug-infos'], function (done) {
var args = process.argv.slice(3); // strip task name
var opts = {};
if (args.indexOf('--native-renderer') !== -1) {
opts.nativeRenderer = true;
}
Engine.buildJsb([
'./index.js',
], './bin/cocos2d-jsb.js', [], opts, done);
});
gulp.task('build-jsb-min', ['clean-cache', 'build-debug-infos'], function (done) {
var args = process.argv.slice(3); // strip task name
var opts = {};
if (args.indexOf('--native-renderer') !== -1) {
opts.nativeRenderer = true;
}
Engine.buildJsbMin([
'./index.js',
], './bin/cocos2d-jsb-min.js', [], opts, done);
});
gulp.task('build-jsb-preview', ['build-debug-infos'], function (done) {
Engine.buildJsbPreview([
'./index.js',
], './bin/cocos2d-jsb-for-preview.js', [], done);
});
gulp.task('build-jsb', ['build-jsb-preview', 'build-jsb-dev', 'build-jsb-min']);
/////////
// test //
/////////
gulp.task('clean-test', ['clean-test-cases'], function () {
return Del([
'./bin/cocos2d-js-extends-for-test.js',
'./bin/cocos2d-js-for-test.js',
]);
});
gulp.task('clean-test-cases', function () {
return Del('./bin/test/**/*');
});
gulp.task('build-test-cases', ['clean-test-cases'], function (done) {
Test.buildTestCase('./bin/test/', done);
});
gulp.task('build-test', ['clean-test', 'build-test-cases', 'build-debug-infos'], function (done) {
Test.build('./index.js', './bin/cocos2d-js-for-test.js',
'../editor/test-utils/engine-extends-entry.js', './bin/cocos2d-js-extends-for-test.js',
false, done);
});
gulp.task('build-test-sm', ['clean-test', 'build-test-cases', 'build-debug-infos'], function (done) {
Test.build('./index.js', './bin/cocos2d-js-for-test.js',
'../editor/test-utils/engine-extends-entry.js', './bin/cocos2d-js-extends-for-test.js',
true, done);
});
gulp.task('unit-runner', ['build-test'], function (done) {
Test.unit('./bin', [
'./bin/cocos2d-js-for-test.js'
], done);
});
gulp.task('test', ['build-test', 'unit-runner'], function (done) {
Test.test(done);
});
gulp.task('visual-test', ['build-test'], Shell.task([
'sh ./test/visual-tests/run.sh'
]));
gulp.task('test-no-build', function (done) {
Test.test(done);
});
////////////
// global //
////////////
gulp.task('clean-cache', function () {
return Del(['./bin/.cache/*', '!./bin/.cache/dev/**']);
});
// fast build, only for develop
gulp.task('build-dev', ['clean-cache', 'build-html5-preview', 'build-jsb-preview'], function () {
return Del(['./bin/cocos2d-jsb-min.js', './bin/cocos2d-jsb.js']);
});
// only build preview for html5 since it will built by editor
gulp.task('build', ['clean-cache', 'build-html5-preview', 'build-jsb']);
// default task
gulp.task('default', ['build']);
gulp.task('clean', function () {
return Del('./bin/**/*');
});
////////////
// watch //
////////////
gulp.task('watch-preview', function () {
Watch.preview('./index.js', './bin/cocos2d-js-for-preview.js');
});
gulp.task('watch-jsb-polyfill', function () {
Watch.jsbPolyfill([
'./index.js',
], './bin/cocos2d-jsb.js');
});
gulp.task('watch-dev-files', ['watch-preview', 'watch-jsb-polyfill']);
gulp.task('test-in-ci', function () {
const { spawn } = require('child_process');
var gulp = process.platform === 'win32' ? 'gulp.cmd' : 'gulp';
var child = spawn(gulp, ['test'], {
stdio: [0, 'pipe', 2]
});
child.stdout.on('data', function (data) {
process.stdout.write(data);
if (data.toString().indexOf(' assertions failed ') !== -1) {
process.exitCode = 1;
process.exit();
}
});
});