-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
73 lines (62 loc) · 2.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
var gulp = require('gulp'),
os = require('os'),
fs = require('fs-extra'),
concat = require('gulp-concat'),
replace = require('gulp-replace'),
unzip = require('gulp-unzip'),
remoteSrc = require('gulp-remote-src');
var pkg = require('./package.json');
function removeResource() {
var files = [
'./mobile_android_lib/src/main/res/raw',
'./mobile_android_sample/app/src/main/assets/maps',
'./mobile_android_sample/app/src/main/assets/tiles',
'./mobile_android_sample_kotlin/app/src/main/assets/maps',
'./mobile_android_sample_kotlin/app/src/main/assets/tiles'
];
for (var i=0; i<files.length; i++) {
var file = files[i];
try {
fs.removeSync(file);
} catch (e) {
}
}
}
function copyResource() {
['dist', 'parts', 'mobile.html'].forEach(function(res1) {
['core', 'mobile_gw'].forEach(function(mod) {
var check = 'node_modules/@maplat/' + mod + '/' + res1;
if (!fs.existsSync(check)) return;
if (fs.statSync(check).isDirectory()) {
fs.readdirSync(check).forEach(function(res) {
fs.copySync(check + '/' + res, './mobile_android_lib/src/main/res/raw/' + calcCopyTo(res1 + '/' + res));
});
} else {
fs.copySync(check, './mobile_android_lib/src/main/res/raw/' + calcCopyTo(res1));
}
});
});
}
function calcCopyTo(copy) {
return copy.replace(/[\/\.\-]/g, '_').toLowerCase();
}
function copyAssets() {
remoteSrc(['assets.zip'], {
base: 'http://code4history.github.io/MaplatMobileGw/'
}).pipe(unzip())
.pipe(gulp.dest('./mobile_android_sample/app/src/main'))
.pipe(gulp.dest('./mobile_android_sample_kotlin/app/src/main'));
}
gulp.task('init', function() {
removeResource();
copyResource();
copyAssets();
return new Promise(function(resolve, reject) {
gulp.src(['./mobile_android_lib/build.gradle'])
.pipe(concat('build.gradle'))
.pipe(replace(/def VERSION_NAME = ".+"/g, 'def VERSION_NAME = "' + pkg.version + '"'))
.on('error', reject)
.pipe(gulp.dest('./mobile_android_lib/'))
.on('end', resolve);
});
});