1 | const fs = require('fs');
|
2 | const utils = require("./index");
|
3 |
|
4 | module.exports = {
|
5 | androidGradle(name, newValue) {
|
6 | let file = process.cwd() + '/platforms/android/eeuiApp/build.gradle';
|
7 | if (!fs.existsSync(file)) {
|
8 | return "";
|
9 | }
|
10 |
|
11 | let value = "";
|
12 | let result = fs.readFileSync(file, 'utf8');
|
13 | let reg = new RegExp(`${name}\\s*=\\s*("*|'*)(.+?)\\1\\r*\\n`);
|
14 | let match = result.match(reg);
|
15 | if (utils.count(match) > 2) {
|
16 | value = match[2].trim();
|
17 | if (typeof newValue !== "undefined") {
|
18 | let newResult = result.replace(new RegExp(match[0], "g"), `${name} = ${match[1]}${newValue}${match[1]}\n`);
|
19 | fs.writeFileSync(file, newResult, 'utf8');
|
20 | value = newValue;
|
21 | }
|
22 | }
|
23 | return value;
|
24 | },
|
25 |
|
26 | iosInfo(name, newValue) {
|
27 | let file = process.cwd() + '/platforms/ios/eeuiApp/eeuiApp/Info.plist';
|
28 | if (!fs.existsSync(file)) return "";
|
29 |
|
30 | let value = "";
|
31 | let result = fs.readFileSync(file, 'utf8');
|
32 | let reg = new RegExp(`<key>${name}</key>(\\s*\\r*\\n*\\s*)<string>(.+?)</string>`);
|
33 | let match = result.match(reg);
|
34 | if (utils.count(match) > 2) {
|
35 | value = match[2].trim();
|
36 | if (typeof newValue !== "undefined") {
|
37 | let newResult = result.replace(match[0], `<key>${name}</key>${match[1]}<string>${newValue}</string>`);
|
38 | fs.writeFileSync(file, newResult, 'utf8');
|
39 | value = newValue;
|
40 | }
|
41 | }
|
42 |
|
43 | ['CURRENT_PROJECT_VERSION', 'MARKETING_VERSION'].some((pName) => {
|
44 | if (value === "$(" + pName + ")") {
|
45 | file = process.cwd() + '/platforms/ios/eeuiApp/eeuiApp.xcodeproj/project.pbxproj';
|
46 | if (fs.existsSync(file)) {
|
47 | result = fs.readFileSync(file, 'utf8');
|
48 | reg = new RegExp(`${pName}\\s*=\\s*(.+?);`);
|
49 | match = result.match(reg);
|
50 | if (utils.count(match) > 1) {
|
51 | value = match[1].trim();
|
52 | }
|
53 | }
|
54 | return true;
|
55 | }
|
56 | });
|
57 | return value;
|
58 | }
|
59 | };
|