-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
73 lines (69 loc) · 1.9 KB
/
index.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
71
72
73
#!/usr/bin/env node
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const handlers = require("./handlers");
const web2 = require("./server");
const commands = {
test: {
command: "status",
desc: "Test the connection to the datalayer and file propagation server",
handler: handlers.runConnectionCheckHandler,
},
deploy: {
command: "deploy",
desc: "Deploy files to the datalayer",
handler: handlers.deployHandler,
},
web2: {
command: "web2",
desc: "Run a web2 gateway server to view your datalayer files",
handler: web2.start,
},
init: {
command: "init",
desc: "Initialize a new config file",
handler: handlers.initHandler,
},
store: {
command: "store <action>",
desc: "Manage your datalayer store",
builder: (yargs) => {
yargs
.positional("action", {
describe: "Action to perform on the store",
type: "string",
choices: ["create", "clean", "mirror"],
})
.option("new", {
alias: "n",
description:
"Create a new store even if a store_id already exists in the config",
type: "boolean",
});
},
handler: async (argv) => {
if (argv.action === "create") {
await handlers.createStoreHandler(argv.new);
} else if (argv.action === "clean") {
await handlers.cleanStoreHandler();
} else if (argv.action === "mirror") {
await handlers.mirrorStoreHandler();
} else {
console.error("Unknown store action");
}
},
},
};
async function run() {
const argv = yargs(hideBin(process.argv))
.command(commands.deploy)
.command(commands.init)
.command(commands.store)
.command(commands.web2)
.command(commands.test)
.demandCommand(1, "You need at least one command before moving on")
.help()
.alias("h", "help")
.parse();
}
run();