forked from play-co/devkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgradeTargets
83 lines (76 loc) · 2.11 KB
/
upgradeTargets
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
var fs = require('fs');
var walk = function(dir, done) {
var results = [];
fs.readdir(dir, function(err, list) {
if (err) return done(err);
var pending = list.length;
if (!pending) return done(null, results);
list.forEach(function(file) {
file = dir + '/' + file;
fs.stat(file, function(err, stat) {
if (stat && stat.isDirectory()) {
walk(file, function(err, res) {
results = results.concat(res);
if (!--pending) done(null, results);
});
} else {
results.push(file);
if (!--pending) done(null, results);
}
});
});
});
};
walk('resources/', function (err, files) {
files.forEach(function (file) {
if (/metadata.json$/.test(file)) {
var contents = fs.readFileSync(file);
try {
contents = JSON.parse(contents);
} catch (e) {
console.error('Could not rewrite', file);
return;
}
var newContents = {};
var keys = Object.keys(contents);
keys.forEach(function (key) {
switch (key) {
case 'targets':
var targets = {};
contents.targets.forEach(function (target) {
if (target == 'android' || target == 'ios') {
targets['browser-mobile'] = true;
} else if (target == 'desktop') {
targets['browser-desktop'] = true;
} else if (target == 'native-mobile' || target == 'native-tablet') {
targets['native-android'] = true;
targets['native-ios'] = true;
} else {
targets[target] = true;
}
});
newContents.targets = Object.keys(targets);
break;
case 'native-tablet':
case 'native-mobile':
newContents['native-android'] = newContents['native-ios'] = contents[key];
break;
case 'ios':
case 'android':
newContents['browser-mobile'] = contents[key];
break;
case 'desktop':
newContents['browser-desktop'] = contents[key];
break;
default:
newContents[key] = contents[key];
break;
}
});
console.log('======', file);
console.log(contents);
console.log(JSON.stringify(newContents, null, '\t'));
fs.writeFileSync(file, JSON.stringify(newContents, null, '\t'));
}
});
});