-
Notifications
You must be signed in to change notification settings - Fork 15
/
react-native.config.js
executable file
·70 lines (68 loc) · 1.96 KB
/
react-native.config.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
64
65
66
67
68
69
70
#!/usr/bin/env node
var pbxproj = require("@raydeck/xcode");
var fs = require("fs");
var path = require("path");
var glob = require("glob");
var cp = require("child_process");
function swiftify() {
//Get my directory
//Work with current dir
var thisPath = process.cwd();
//Look for dependency
var iosPath = path.join(thisPath, "ios");
if (!fs.existsSync(iosPath)) {
console.log("Could not find ios in ", thisPath, iosPath);
console.log(fs.readdirSync(thisPath));
process.exit();
}
const globs = glob.sync(path.join(iosPath, "*.xcodeproj"));
if (!globs || globs.length == 0) {
console.log("Could not find xcodeproj directory");
process.exit();
}
const xpdir = globs[0];
if (xpdir.length === 0) {
console.log("Could not find xcodeproj directory inside: ", iosPath);
process.exit();
}
let filename = xpdir + "/project.pbxproj";
let properties = {
SWIFT_VERSION: "4.0"
};
if (!fs.existsSync(filename)) {
console.log("Could not find pbxproj file:", filename);
process.exit();
}
const placeholder = "RNPlaceholder.swift";
const placeholderPath = iosPath + "/" + placeholder;
if (!fs.existsSync(placeholderPath)) {
console.log("Writing to ", placeholderPath);
fs.writeFileSync(placeholderPath, "");
}
var proj = pbxproj.project(filename);
proj.parseSync();
proj.addSourceFileNew(placeholder);
for (var key in properties) {
proj.addBuildProperty(key, properties[key]);
}
const out = proj.writeSync();
fs.writeFileSync(filename, out);
const packagePath = path.join(thisPath, "package.json");
if (fs.existsSync(packagePath)) {
var package = require(packagePath);
if (!package.isSwift) {
package.isSwift = true;
fs.writeFileSync(packagePath, JSON.stringify(package, null, 2));
cp.spawnSync("react-native", ["fixpods"]);
}
}
}
module.exports = {
commands: [
{
name: "swiftify",
description: "Enable swift on the iOS app",
func: swiftify
}
]
};