-
Notifications
You must be signed in to change notification settings - Fork 1
/
clearSplashAndIcons.js
52 lines (48 loc) · 2.1 KB
/
clearSplashAndIcons.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
module.exports = function(ctx) {
var fs = ctx.requireCordovaModule('fs');
var path = ctx.requireCordovaModule('path');
var events = ctx.requireCordovaModule('cordova-common').events;
var is_android = ctx.opts.platforms.length === 1 && ctx.opts.platforms[0] === 'android';
var res_dir;
if (is_android) {
res_dir = path.join(ctx.opts.projectRoot, 'platforms/android/app/src/main/res');
}
else {
folders = fs.readdirSync(path.join(ctx.opts.projectRoot, 'platforms/ios'));
for (const folder of folders) {
events.emit('verbose', 'cleanSplashAndIcons.js hook, folder: ' + folder);
/* Find {appname}.xcworkspace folder and extract app name from it */
if (folder.endsWith('.xcworkspace')) {
var appname = folder.split('.')[0];
res_dir = path.join(ctx.opts.projectRoot, 'platforms/ios/' + appname + '/Images.xcassets');
break;
}
}
if (!res_dir) {
throw 'did not find res_dir for ios platform';
}
}
/* Loop over res folders deleting png files from subfolders */
fs.readdir(res_dir, (err, subfolders) => {
if (err) throw err;
for (const subfolder of subfolders) {
let curr_subfolder_path = path.join(res_dir, subfolder);
/* Make sure its a folder and not a file */
if (fs.lstatSync(curr_subfolder_path).isDirectory()) {
fs.readdir(curr_subfolder_path, (err, files) => {
if (err) throw err;
for (const file of files) {
/* Delete png files */
if (file.endsWith('.png')) {
let file_path = path.join(curr_subfolder_path, file);
events.emit('verbose', 'cleanSplashAndIcons.js hook, deleting: ' + file_path);
fs.unlink(file_path, err => {
if (err) throw err;
});
}
}
});
}
}
});
}