-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
cli.ts
36 lines (33 loc) · 798 Bytes
/
cli.ts
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
#!/usr/bin/env node
import * as fs from "fs";
import { migrate } from "./index";
function getSettings() {
let data;
try {
data = fs.readFileSync(`${process.cwd()}/.gmrc`, "utf8");
} catch (e) {
throw new Error(
"No .gmrc file found; please run `graphile-migrate init` first."
);
}
try {
return JSON.parse(data);
} catch (e) {
throw new Error("Failed to parse .gmrc file: " + e.message);
}
}
async function main() {
const argv = process.argv.slice(2);
const [cmd] = argv;
if (cmd === "migrate") {
await migrate(getSettings().connectionString);
} else {
console.error(`Command '${cmd || ""}' not understood`);
process.exit(1);
}
}
main().catch(e => {
// tslint:disable-next-line no-console
console.error(e);
process.exit(1);
});