forked from Acode-Foundation/Acode
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrestore-cordova-resources.js
More file actions
49 lines (38 loc) · 1.29 KB
/
restore-cordova-resources.js
File metadata and controls
49 lines (38 loc) · 1.29 KB
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
const fs = require("fs");
const path = require("path");
const templateResPath = path.resolve(
__dirname,
"../node_modules/cordova-android/templates/project/res",
);
const androidResPath = path.resolve(
__dirname,
"../platforms/android/app/src/main/res",
);
if (!fs.existsSync(templateResPath) || !fs.existsSync(androidResPath)) {
process.exit(0);
}
restoreCordovaResourceFiles(templateResPath);
function restoreCordovaResourceFiles(currentPath) {
for (const entry of fs.readdirSync(currentPath, { withFileTypes: true })) {
const absolutePath = path.join(currentPath, entry.name);
if (entry.isDirectory()) {
restoreCordovaResourceFiles(absolutePath);
continue;
}
if (!shouldRestore(absolutePath)) {
continue;
}
const relativePath = path.relative(templateResPath, absolutePath);
const destinationPath = path.join(androidResPath, relativePath);
if (fs.existsSync(destinationPath)) {
continue;
}
fs.mkdirSync(path.dirname(destinationPath), { recursive: true });
fs.copyFileSync(absolutePath, destinationPath);
console.log(`[Cordova Hook] Restored ${relativePath}`);
}
}
function shouldRestore(filePath) {
const fileName = path.basename(filePath);
return fileName.startsWith("cdv_") || fileName === "ic_cdv_splashscreen.xml";
}