-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
76 lines (72 loc) · 2.18 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
74
75
76
#!/usr/bin/env node
/**
* @copyright 2020 John Wiley & Sons, Inc.
* @license MIT
*/
import * as fs from 'node:fs';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import * as describe from './commands/describe.js';
import * as check from './commands/check.js';
import * as dash from './commands/dash.js';
import * as dns from './commands/dns.js';
import * as compare from './commands/compare.js';
import * as domains from './commands/domains.js';
import * as show from './commands/show.js';
import * as worker from './commands/worker.js';
import * as sync from './commands/sync.js';
// load environment variables from `.env` file (if any)
import 'dotenv/config';
/**
* Command handler of awesomeness.
*/
yargs(hideBin(process.argv))
.scriptName('redirects')
.env('WR')
.usage('$0 <cmd> [args]')
// these options apply to all the commands
.option('cloudflareToken', {
describe: 'API (Bearer) token for the Cloudflare API (WR_CLOUDFLARE_TOKEN)',
demandOption: true,
type: 'string'
})
.option('accountId', {
describe: 'ID of the account for which you are managing redirects',
demandOption: true,
type: 'string'
})
.option('configDir', {
type: 'string',
describe: 'directory containing the `.settings.yaml` default configuration (WR_CONFIG_DIR)',
demandOption: true,
coerce(v) {
return {
name: v,
contents: fs.readdirSync(v, 'utf8')
};
}
})
// Describe a redirect as a YAML file
.command(describe)
// List zones in current Cloudflare account, and prompt to add missing zones
.command(domains)
// Show current redirects for [domain]
.command(show)
// Check [domain]'s settings with Cloudflare's
.command(check)
// Compare [dir]'s local redirect descriptions for [domain] with Cloudflare's
.command(compare)
// Manage the DNS records for [domain]
.command(dns)
// Output a link to the Cloudflare Dashboard
.command(dash)
// Setup Worker and KV stuff for large redirects
.command(worker)
// WIP Synchronize zones with YAML
.command(sync)
.demandCommand(1, '')
.alias('h', 'help')
.alias('v', 'version')
.default('cacheDir', '.cache')
.default('cacheId', 'zones')
.argv;