-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathupdate.js
executable file
·42 lines (31 loc) · 1.12 KB
/
update.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
#!/usr/bin/env node
const fs = require('fs')
, path = require('path')
, updateAliases = require('./update-aliases')
require('http').globalAgent.maxSockets = 20
if (process.argv.length < 3) {
console.error('Usage: update [--dry-run] <domain>')
return process.exit(1)
}
const dryRun = process.argv.includes('--dry-run')
, domain = process.argv.filter((a) => a !== '--dry-run')[2].replace(/\/$/, '')
, dir = path.join(__dirname, '..', domain)
, credsFile = path.join(dir, 'credentials.json')
if (!fs.statSync(dir).isDirectory()) {
console.error(`Usage: update <domain> ("domain" must be a directory above ${__dirname}`)
return process.exit(1)
}
if (!fs.existsSync(credsFile)) {
console.error(`Error: ${dir} does not have a credentials.json file`)
return process.exit(1)
}
const creds = require(credsFile)
if (typeof creds['api-key'] != 'string') {
console.error(`Error: ${credsFile} does not have an "api-key" property`)
return process.exit(1)
}
const aliases = require(path.join(dir, 'aliases.json'))
updateAliases(domain, creds, aliases, dryRun, function (err) {
if (err)
throw err
})