forked from cocos/engine-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
214 lines (191 loc) · 5.8 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
'use strict';
var gulp = require('gulp');
var gulpSequence = require('gulp-sequence');
var zip = require('gulp-zip');
var Ftp = require('ftp');
var ExecSync = require('child_process').execSync;
var spawn = require('child_process').spawn;
var Path = require('path');
var fs = require('fs');
gulp.task('make-cocos2d-x', gulpSequence('gen-cocos2d-x', 'upload-cocos2d-x'));
gulp.task('make-prebuilt', gulpSequence('gen-libs', 'collect-prebuilt-mk', 'archive-prebuilt-mk', 'archive-prebuilt', 'upload-prebuilt', 'upload-prebuilt-mk'));
gulp.task('make-simulator', gulpSequence('update-simulator-config', 'archive-simulator', 'upload-simulator'));
function execSync(cmd, workPath) {
var execOptions = {
cwd : workPath,
stdio : 'inherit'
};
ExecSync(cmd, execOptions);
}
function downloadSimulatorDLL(callback) {
var Download = require('download');
var destPath = Path.join('simulator', 'win32');
new Download({
mode: '755',
extract: true,
strip: 0
})
.get('http://192.168.52.109/TestBuilds/Fireball/simulator/dlls/dll.zip')
.dest(destPath)
.run(function(err, files) {
if (err) throw err;
else callback();
});
}
function upload2Ftp(localPath, ftpPath, config, cb) {
var ftpClient = new Ftp();
ftpClient.on('error', function(err) {
if (err) {
cb(err);
}
});
ftpClient.on('ready', function() {
var dirName = Path.dirname(ftpPath);
ftpClient.mkdir(dirName, true, function(err) {
if (err) {
cb(err);
}
});
ftpClient.put(localPath, ftpPath, function(err) {
if (err) {
cb(err);
}
ftpClient.end();
cb();
});
});
// connect to ftp
ftpClient.connect(config);
}
function uploadZipFile (zipFileName, path, cb) {
var remotePath = Path.join('TestBuilds','Fireball', 'cocos2d-x', zipFileName);
var zipFilePath = Path.join(path, zipFileName);
upload2Ftp(zipFilePath, remotePath, {
host: '192.168.52.109',
user: process.env.ftpUser,
password: process.env.ftpPass
},function(err) {
if (err) {
throw err;
}
cb();
});
}
gulp.task('init', function(cb) {
execSync('python download-deps.py', '.');
execSync('git submodule update --init', '.');
cb();
});
gulp.task('gen-libs', function(cb) {
execSync('./tools/cocos2d-console/bin/cocos gen-libs -m release', '.');
cb();
});
gulp.task('gen-cocos2d-x', function (cb) {
execSync('./git-archive-all cocos2d-x.zip', './tools/make-package');
cb();
});
gulp.task('gen-simulator', function (cb) {
var cocosConsoleRoot = './tools/cocos2d-console/bin';
var cocosConsoleBin;
if (process.platform === 'darwin') {
cocosConsoleBin = Path.join(cocosConsoleRoot, 'cocos');
}
else {
cocosConsoleBin = Path.join(cocosConsoleRoot, 'cocos.bat');
}
var args;
if (process.platform === 'darwin') {
args = ['gen-simulator', '-m', 'debug', '-p', 'mac'];
}
else {
args = ['gen-simulator', '-m', 'debug', '-p', 'win32', '--vs', '2013', '--ol', 'en'];
}
try {
var child = spawn(cocosConsoleBin, args);
child.stdout.on('data', function (data) {
console.log(data.toString());
});
child.stderr.on('data', function (data) {
console.error(data.toString());
});
child.on('close', (code) => {
if (code !== 0) {
console.error('Generate simulator failed');
cb();
return;
}
});
child.on('error', function () {
console.error('Generate simulator failed');
cb();
});
}
catch (err) {
console.error(err);
cb();
return;
}
});
gulp.task('collect-prebuilt-mk', function () {
return gulp.src([
'**/prebuilt-mk/Android.mk',
], {
base: './',
ignore: 'prebuilt_mk/**/*'
}).pipe(gulp.dest('prebuilt_mk'));
});
gulp.task('update-simulator-config', ['update-simulator-script'], function () {
var destPath = process.platform === 'win32' ? './simulator/win32' : './simulator/mac/Simulator.app/Contents/Resources';
return gulp.src('./tools/simulator/config.json')
.pipe(gulp.dest(destPath));
});
gulp.task('update-simulator-script', function () {
var destPath = process.platform === 'win32' ? './simulator/win32' : './simulator/mac/Simulator.app/Contents/Resources';
var updateScript = function () {
// scripts
return gulp.src(['./cocos/scripting/js-bindings/script/**/*', '!**/.DS_Store'], {
base: './cocos/scripting/js-bindings'
}).pipe(gulp.dest(destPath));
};
if (!fs.existsSync(destPath)) {
console.error(`Cant\'t find simulator dir [${destPath}]`);
} else {
if (process.platform === 'win32') {
downloadSimulatorDLL(updateScript);
} else {
updateScript();
}
}
});
gulp.task('archive-prebuilt-mk', function () {
return gulp.src('./prebuilt_mk/**/*')
.pipe(zip('prebuilt_mk_' + process.platform + '.zip'))
.pipe(gulp.dest('./'));
});
gulp.task('archive-simulator', function () {
return gulp.src('./simulator/**/*')
.pipe(zip('simulator_' + process.platform + '.zip'))
.pipe(gulp.dest('./'));
});
gulp.task('archive-prebuilt', function () {
return gulp.src('./prebuilt/**/*', {
base: './'
}).pipe(zip('prebuilt_' + process.platform + '.zip'))
.pipe(gulp.dest('./'));
});
gulp.task('upload-prebuilt-mk', function (cb) {
var zipFileName = 'prebuilt_mk_' + process.platform + '.zip';
uploadZipFile(zipFileName, '.', cb);
});
gulp.task('upload-prebuilt', function (cb) {
var zipFileName = 'prebuilt_' + process.platform + '.zip';
uploadZipFile(zipFileName, '.', cb);
});
gulp.task('upload-cocos2d-x', function (cb) {
var zipFileName = 'cocos2d-x.zip';
uploadZipFile(zipFileName, './tools/make-package', cb);
});
gulp.task('upload-simulator', function (cb) {
var zipFileName = 'simulator_' + process.platform + '.zip';
uploadZipFile(zipFileName, '.', cb);
});