-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcli.ts
95 lines (80 loc) · 3.02 KB
/
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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// @ts-check
require("dotenv").config();
// @ts-ignore
import pkg from "../package.json";
import { Command } from "commander";
import { del, down, loadConfig, typescript, up } from "./index";
main().catch((error) => {
console.error("Error: " + error.message);
process.exit(1);
});
async function main() {
const program = new Command();
program.version(pkg.version);
program.option("--configPath <path>", "Path to .js(on) config file");
program
.command("down <schemaPath>")
.option(
"--prefix <prefix>",
"Only classes with the given prefix will be pulled",
""
)
.option("--ignore <ignore...>", "Class(es) to ignore", "")
.description("Fetch the schema from Parse Server")
.action(async (schemaPath, options) => {
const cfg = await loadConfig(program.opts().configPath, {
operation: "down",
});
await down(cfg, schemaPath, options);
});
program
.command("up <schemaPath>")
.option(
"--prefix <prefix>",
"Only classes with the given prefix will be pushed or removed",
""
)
.option("--ignore <ignore...>", "Class(es) to ignore", "")
.option("--safe", "This will prevent destructive operations", "")
.option("--deleteNonEmptyClass", "Delete non-empty classes", false)
.description("Upload the local schema to Parse Server")
.action(async (schemaPath, options) => {
const cfg = await loadConfig(program.opts().configPath, {
operation: "up",
});
await up(cfg, schemaPath, {
prefix: options.prefix,
ignore: options.ignore,
deleteClasses: !options.safe,
deleteFields: !options.safe,
deleteNonEmptyClass: options.deleteNonEmptyClass,
});
});
program
.command("delete <schemaPath>")
.option(
"--prefix <prefix>",
"Only classes with the given prefix will be deleted",
""
)
.option("--deleteNonEmptyClass", "Delete non-empty classes", false)
.description("Delete the local schema from Parse Server")
.action(async (schemaPath, options) => {
const cfg = await loadConfig(program.opts().configPath);
await del(cfg, schemaPath, options);
});
program
.command("typescript <typescriptPath>")
.description("Transform the local schema to Typescript definitions")
.option("--prefix <prefix>", "Prefix will be stripped from class names", "")
.option("--ignore <ignore...>", "Class(es) to ignore", "")
.option("--no-class", "Don't create and register custom Parse.Object")
.option("--no-sdk", "Don't use Parse JS SDK, just TS without dependencies")
.option("--global-sdk", "Use a global Parse JS SDK", false)
.option("--is_esm", "Use ES module imports in generated files.", false)
.action(async (typescriptPath, options) => {
const cfg = await loadConfig(program.opts().configPath);
await typescript(cfg, typescriptPath, options);
});
await program.parseAsync(process.argv);
}