-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
executable file
·75 lines (60 loc) · 2.06 KB
/
main.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
#!/usr/bin/env node
const argv = require('minimist')(process.argv.slice(2))
const chalk = require('chalk')
const json = require('format-json')
const { textSync } = require('figlet')
const { onCreate, onDelete, onRestore, onList, onInit } = require('./libs/actions')
const { textBox, printToscreen } = require('./libs/utils')
const { firebaseConfig, shortFireConfig } = require('./libs/config')
const header = chalk.yellow(textSync('Short Fire', {
font: 'Graceful',
horizontalLayout: 'default',
verticalLayout: 'default'
}))
const help = `
Usage: short-fire [command] <options>
Command:
init Init Short fire for create configulation.
create [url] <slug> <options> Create shorten URL defind slug is optional.
options:
-n, --new
Force the system to create a new random url when there is an existing destination.
list <q> List all available URL. defind q for searching.
dump Dump Firebase configulation for backup purpose.
restore <file> Restore configulation from file.
delete [slug] Delete URL by specific slug.
Examples:
$ short-fire create http://example.com/link
$ short-fire create http://example.com/link example
`
if (!argv['_'][0] || argv['_'][0] === '--help') {
printToscreen(header + '\n')
printToscreen(help)
}
if ((!shortFireConfig['project-id'] || !shortFireConfig['token'] || !shortFireConfig['domain']) && argv['_'][0] !== 'init') {
textBox(chalk.red('• Error') + ' Configulation not found. Please run `short-fire init`')
process.exit(0)
}
if (argv['_'][0] === 'init') {
printToscreen(header + '\n')
onInit()
}
if (argv['_'][0] === 'create') {
printToscreen(header + '\n')
onCreate(argv)
}
if (argv['_'][0] === 'list') {
printToscreen(header + '\n')
onList(argv)
}
if (argv['_'][0] === 'dump') {
printToscreen(json.diffy(firebaseConfig))
}
if (argv['_'][0] === 'restore') {
printToscreen(header + '\n')
onRestore(argv)
}
if (argv['_'][0] === 'delete') {
printToscreen(header + '\n')
onDelete(argv)
}