-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
executable file
·51 lines (51 loc) · 1.71 KB
/
cli.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
#!/usr/bin/env node
const core = require("./index.js");
const commander = require("commander");
const fs = require("fs");
const watch = require("node-watch");
const Path = require("path");
const cp = require("child_process");
commander.usage("[options] [targetpath]");
commander.option("-o --out <outfile>");
commander.option("-w --watch");
commander.parse(process.argv);
var thisPath = commander.args[0] ? commander.args[0] : process.cwd();
var jsFile = commander.js
? commander.js
: Path.join(thisPath, "RNSwiftBridge.js");
var outfile = commander.out;
if (!outfile) outfile = core.getRootIOSPath(thisPath);
if (fs.existsSync(outfile) && fs.lstatSync(outfile).isDirectory()) {
outfile = Path.join(outfile, "rn-swift-bridge.m");
}
if (commander.watch) {
try {
console.log("Watching for swift changes on " + thisPath);
watch(thisPath, { recursive: true, filter: /\.swift$/ }, () => {
const text = core.getBridgingModuleTextFromPath(thisPath);
console.log("Detected change");
if (core.writeIf(outfile, text)) {
core.addModuleToPBXProj(outfile, thisPath);
console.log("Updated " + outfile);
if (core.writeIf(jsFile, core.getJSFromPath(thisPath))) {
console.log("Updated " + jsFile);
}
}
});
} catch (e) {
console.log("Hit error ", e);
}
} else {
try {
const text = core.getBridgingModuleTextFromPath(thisPath);
if (core.writeIf(outfile, text)) {
core.addModuleToPBXProj(outfile, thisPath);
} else console.log("No changes to ", outfile);
console.log("Updated " + outfile);
if (core.writeIf(jsFile, core.getJSFromPath(thisPath))) {
console.log("Updated " + jsFile);
}
} catch (e) {
console.log("Hit error ", e);
}
}