This repository has been archived by the owner on Feb 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
157 lines (134 loc) · 3.61 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
/**
* PravitelstvoBG Build Script
*/
var gulp = require('gulp')
, concat = require('gulp-concat')
//, sass = require('gulp-sass')
, minifyCss = require('gulp-minify-css')
, rename = require('gulp-rename')
, exec = require('child_process').exec
, Q = require('q')
, fs = require('fs')
, argv = require('yargs').argv
, jshint = require('gulp-jshint')
, localprops = require('./localprops.json')
, pkg = require('./package.json');
var Consts = {
RELEASE_NAME: 'PravitelstvoBG-' + pkg.version + '.apk'
};
var paths = {
sass: ['./scss/**/*.scss']
};
gulp.task('sass', function(done) {
gulp.src('./scss/ionic.app.scss')
.pipe(sass())
.pipe(gulp.dest('./www/css/'))
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('./www/css/'))
.on('end', done);
});
gulp.task('watch', function() {
gulp.watch(paths.sass, ['sass']);
});
/**
* Remove built APK
*/
gulp.task('debug', function() {
var deferred = Q.defer();
var child = exec('cordova run --debug android', function(err, stdout, stderr) {
console.log(stdout);
if (err) {
console.error(stderr);
deferred.reject('[ERROR] Cordova build failed!');
} else {
deferred.resolve();
}
});
return deferred.promise;
});
/**
* Remove built APK
*/
gulp.task('clean', function() {
try {
fs.unlinkSync(Consts.RELEASE_NAME);
} catch (e) {};
});
/**
* Build release APK package
*/
gulp.task('build', ['clean'], function() {
var deferred = Q.defer();
var child = exec('cordova build --release android', function(err, stdout, stderr) {
console.log(stdout);
if (err) {
console.error(stderr);
deferred.reject('[ERROR] Cordova build failed!');
} else {
deferred.resolve();
}
});
return deferred.promise;
});
/**
* Sign release APK package
*/
gulp.task('sign', ['build'], function() {
var deferred = Q.defer();
var ksPath = localprops.ksPath || argv.ks;
if (ksPath) {
if (!fs.existsSync(ksPath)) {
console.error('[ERROR] Keystore not found at ' + ksPath + '!');
process.exit(-2);
}
} else {
console.error('[ERROR] Keystore path not specified! Use --ks <path>');
process.exit(-2);
}
var ksPass = localprops.ksPass || argv.ksPass;
if (!ksPass) {
console.error('[ERROR] Keystore password not specified! use --ksPass <password>');
process.exit(-3);
}
var apkPath = 'platforms/android/build/outputs/apk';
var cmdline = 'jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 '
+ ' -keystore ' + ksPath
+ ' -storepass ' + ksPass
+ ' -signedjar ' + apkPath + '/android-release-signed.apk'
+ ' ' + apkPath + '/android-release-unsigned.apk pravitelstvobg';
console.log(cmdline);
var child = exec(cmdline, function(err, stdout, stderr) {
console.log(stdout);
if (err) {
console.error(stderr);
deferred.reject('[ERROR] Cordova sign failed!');
} else {
//TODO: align
var zcmd = localprops.sdk_path + '/zipalign -v 4 ' + apkPath + '/android-release-signed.apk ' + Consts.RELEASE_NAME;
var zchild = exec(zcmd, function(err, stdout, stderr) {
console.log(stdout);
if (err) {
console.error(stderr);
deferred.reject('[ERROR] Cordova sign failed!');
} else {
// All OK!
deferred.resolve();
}
});
}
});
return deferred.promise;
});
gulp.task('lint', function() {
return gulp.src('./www/js/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
/**
* Default
*/
gulp.task('default', ['sass']);
gulp.task('release', ['build', 'sign']);