This repository has been archived by the owner on Jul 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
android_ignore_translation_errors.js
executable file
·98 lines (88 loc) · 3.3 KB
/
android_ignore_translation_errors.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
// add additional build-extras.gradle file to instruct android's lint to ignore translation errors
// v0.2.0
// New version is a compatible Node module and only appends/write to file if it is
// empty or does not exist.
// causing error in the build --release
// Issue: https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/80
//
// Warning: This solution does not solve the problem only makes it possible to build --release
function handleErr(err, defer){
console.log('ERR : '+err);
return defer.reject(err);
}
function cb(err, data){
if(err){
handleErr(err, promise);
}
console.log('Successfully added/updated build-extra.gradle');
return data;
}
module.exports = ignoreTranslationErrors;
function ignoreTranslationErrors(ctx){
if(ctx.opts.platforms.indexOf('android') < 0){
return;
}
var fs = ctx.requireCordovaModule('fs'),
path = ctx.requireCordovaModule('path'),
deferral = ctx.requireCordovaModule('q').defer();
var rootdir = path.join(ctx.opts.projectRoot, 'platforms/android');
//
// Partial file appending still doesn't work.
// Needs some tweaking to append the lintOptions
// within the actual android{ lintOptions{}} Objects
//
function appendFile(data, file, promise){
var hasMissingTranslation = (data.indexOf('disable \'MissingTranslation\'') > -1);
var hasExtraTranslation = (data.indexOf('disable \'ExtraTranslation\'') > -1);
var lintOptions = 'android { \nlintOptions {\ndisable \'MissingTranslation\' \ndisable \'ExtraTranslation\' \n} \n}';
var write;
if(!hasMissingTranslation && !hasExtraTranslation){
write = fs.appendFile(file, lintOptions, 'UTF-8', cb);
}
else if(!hasMissingTranslation && hasExtraTranslation){
lintOptions = 'android { \nlintOptions {\ndisable \'MissingTranslation\' \n} \n}';
//write = fs.appendFile(file, lintOptions, 'UTF-8', cb);
}
else if(hasMissingTranslation && !hasExtraTranslation){
lintOptions = 'android { \nlintOptions {\ndisable \'ExtraTranslation\' \n} \n}';
//write = fs.appendFile(file, lintOptions, 'UTF-8', cb);
}
else{
console.log('SKIPPING : File already exists and contains exception settings.');
}
return promise.resolve(write);
}
function writeFile(file, promise){
var lintOptions = 'android { \nlintOptions {\ndisable \'MissingTranslation\' \ndisable \'ExtraTranslation\' \n} \n}';
var write = fs.appendFile(file, lintOptions, 'UTF-8', cb);
return promise.resolve(write);
}
if(rootdir){
var platforms = ctx.opts.platforms;
for(var x = 0; x < platforms.length; x++){
var platform = platforms[x].trim().toLowerCase();
try{
if(platform == 'android'){
fs.stat('platforms/android/build-extras.gradle', function(err, stat){
if(err){
console.log('File does not exist yet. Adding build-extra.gradle...');
return writeFile('platforms/android/build-extras.gradle',deferral);
}
if(stat && stat.isFile()){
console.log('File exists. Reading build-extra.gradle...');
return fs.readFile('platforms/android/build-extras.gradle','UTF-8',function(err,data){
console.log('Appending build-extra.gradle...');
return appendFile(data, 'platforms/android/build-extras.gradle', deferral);
});
}
});
}
}
catch(e){
handleErr(e,deferral);
console.log(e);
}
}
}
return deferral.promise;
}