forked from boundstate/cordova-android-res
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (66 loc) · 1.56 KB
/
index.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
var androidRes = require('android-res');
var colors = require('colors');
var glob = require("glob")
var Q = require('q');
/**
* @var {Object} console utils
*/
var display = {
success: function (str) {
str = '✓ '.green + str;
console.log(' ' + str);
},
error: function (str) {
str = '✗ '.red + str;
console.log(' ' + str);
},
header: function (str) {
console.log('');
console.log(' ' + str.cyan.underline);
console.log('');
}
};
/**
* Generates Android resources from the android-res folder.
*/
function run() {
var completeDeferred = Q.defer();
var promises = [];
var options = {
dest: 'platforms/android/res/'
};
display.header('Generating Android resources');
glob('android-res/**/*', function (err, files) {
if (err) {
display.error(err);
return;
}
if (files.length === 0) {
display.error('No resources found at "android-res/"');
return;
}
files.forEach(function (file) {
var promise = androidRes(file, options);
promise
.catch(function (err) {
display.error(err);
})
.progress(function (data) {
display.success(data.dest + ' (' + data.width + 'x' + data.height + ')');
});
promises.push(promise);
});
Q.all(promises)
.catch(function (err) {
completeDeferred.reject(err);
})
.then(function() {
completeDeferred.resolve();
})
.finally(function() {
console.log('');
});
});
return completeDeferred.promise;
}
module.exports = run;