forked from Neat-Pagos/android-package-name-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
63 lines (57 loc) · 2.74 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
const core = require('@actions/core');
const fs = require('fs');
try {
const androidManifestPath = core.getInput('androidManifestPath');
const buildGradlePath = core.getInput('buildGradlePath');
const stringsPath = core.getInput('stringsPath');
const mainActivityPath = core.getInput('mainActivityPath');
const mainApplicationPath = core.getInput('mainApplicationPath');
const reactNativeFlipperPath = core.getInput('reactNativeFlipperPath');
const newPackageName = core.getInput('newPackageName');
const oldPackageName = core.getInput('oldPackageName');
console.log(`newPackageName: ${newPackageName}`);
console.log(`oldPackageName: ${oldPackageName}`);
console.log(`androidManifestPath: ${androidManifestPath}`);
console.log(`buildGradlePath: ${buildGradlePath}`);
console.log(`stringsPath: ${stringsPath}`);
console.log(`mainActivityPath: ${mainActivityPath}`);
console.log(`mainApplicationPath: ${mainApplicationPath}`);
console.log(`reactNativeFlipperPath: ${reactNativeFlipperPath}`);
const searchRegExp = new RegExp(oldPackageName, 'g');
const paths = [androidManifestPath, buildGradlePath, stringsPath, mainActivityPath, mainApplicationPath, reactNativeFlipperPath];
let manifestOK = false;
let gradleOK = false;
let stringsOK = false;
let mainActivityOK = false;
let mainApplicationOK = false;
let reactNativeFlipperOK = false;
paths.forEach((path) => {
fs.readFile(path, 'utf8', function (err, data) {
console.log(`Processing ${path}`);
const newData = data.replace(searchRegExp, newPackageName);
fs.writeFile(path, newData, function (err) {
if (err) throw err;
console.log(`Successfully override package name ${newPackageName} on ${path}`);
if(path === androidManifestPath){
manifestOK = true
} else if(path === buildGradlePath){
gradleOK = true
} else if(path === stringsPath){
stringsOK = true
} else if(path === mainActivityPath){
mainActivityOK = true
} else if(path === mainApplicationPath){
mainApplicationOK = true
} else if(path === reactNativeFlipperPath){
reactNativeFlipperOK = true
}
if (manifestOK && gradleOK && stringsOK && mainActivityOK && mainApplicationOK && reactNativeFlipperOK) {
console.log('All files have been processed');
core.setOutput("result", `Done`);
}
});
});
});
} catch (error) {
core.setFailed(error.message);
}