-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
118 lines (102 loc) · 3.56 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
var exec = require('child_process').exec,
del = require('del'),
gulp = require('gulp'),
babel = require('gulp-babel'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
gulpif = require('gulp-if'),
fs = require('fs-extra'),
yargs = require('yargs'),
cordova = require('cordova-lib').cordova,
cordovajs = require('cordova-js/tasks/lib/bundle');
var pjson = require('./package.json');
var argv = yargs.argv;
var env = argv.p ? 'prod' : 'dev';
gulp.task('clean', function () {
return del(['browser/index.js', 'tmp', 'renderer/js/cordova.js', 'node_modules/cordova-js/src/legacy-exec/simulator']);
});
gulp.task('app:transpile', function() {
return gulp.src('./**/*.es6.js')
.pipe(babel())
.pipe(rename(function (path) {
path.basename = path.basename.substr(0, path.basename.length - 4);
}))
.pipe(gulp.dest('./'));
});
gulp.task('app:run', ['app:transpile'], function(cb) {
exec('electron .', function(err) {
if (err) return cb(err);
cb();
});
});
gulp.task('app:debug', ['app:transpile'], function(cb) {
exec('electron --debug=5858 .', function(err) {
if (err) return cb(err);
cb();
});
});
gulp.task('plugin:add', function (cb) {
if (argv.n !== undefined && ((argv.i !== undefined && argv.v !== undefined) || argv.u !== undefined)) {
pjson.cordovaPlugins[argv.n] = {};
if (argv.i !== undefined) {
pjson.cordovaPlugins[argv.n].id = argv.i;
pjson.cordovaPlugins[argv.n].version = argv.v;
} else {
pjson.cordovaPlugins[argv.n].url = argv.u;
}
fs.writeJson('package.json', pjson, {spaces: 2}, function(err) {
cb(err);
});
}
});
gulp.task('cordova:create', ['clean'], function (cb) {
var plugins = [];
for (var key in pjson.cordovaPlugins) {
if(pjson.cordovaPlugins.hasOwnProperty(key)) {
var plugin = pjson.cordovaPlugins[key].id || pjson.cordovaPlugins[key].url;
if (pjson.cordovaPlugins[key].id !== undefined) {
plugin += "@" + pjson.cordovaPlugins[key].version;
}
plugins.push(plugin);
}
}
cordova.raw.create('tmp', 'ozsay.cordovaSimulator.simulator', 'simulator').done(function() {
var cwd = process.cwd();
process.chdir('tmp');
cordova.raw.platform('add', ['android']).done(function() {
if (plugins.length > 0) {
cordova.raw.plugin('add', plugins).done(function() {
process.chdir(cwd);
cb();
});
} else {
process.chdir(cwd);
cb();
}
});
});
});
gulp.task('cordovaJs:create', ['cordova:create'], function (done) {
fs.copy('cordova/simulator', 'node_modules/cordova-js/src/legacy-exec/simulator', function (err) {
if (!err) {
var cwd = process.cwd();
process.chdir('node_modules/cordova-js');
var cordovaJsFile = cordovajs('simulator', false, 'custom commit', '4.1.1');
process.chdir(cwd);
fs.outputFile('tmp/platforms/android/assets/www/cordova.js', cordovaJsFile, done);
} else {
done(err);
}
});
});
gulp.task('cordovaJs:copy', ['cordovaJs:create'], function () {
return gulp.src(['tmp/platforms/android/assets/www/cordova*.js',
'tmp/platforms/android/assets/www/plugins/**/*.js',
'cordova/proxy.js'])
.pipe(concat('cordova.js'))
.pipe(gulpif(env !== "dev", uglify()))
.pipe(gulp.dest('renderer/js/'));
});
gulp.task('build', ['cordovaJs:copy'], function() {
});