-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
118 lines (98 loc) · 3.21 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var fs = require('fs');
var path = require('path');
var Nash = require('nash');
var homeDir = require('home-dir');
var Divshot = require('divshot-api');
var format = require('chalk');
var format = require('chalk');
var dumper = require('divshot-dumper');
var User = require('./lib/user');
var Cwd = require('./lib/cwd');
var environments = require('./lib/environments');
var commands = require('./lib/commands');
var errors = require('./lib/errors');
var CLIENT_ID = '526753cf2f55bd0002000006';
var API_HOST = process.env.API_HOST || 'https://api.divshot.com';
process.env.DIVSHOT_HASHED_BUCKET || (process.env.DIVSHOT_HASHED_BUCKET = "divshot-io-hashed-production");
var cliConfigDirectory = path.join(homeDir(), '.divshot');
var user = new User(cliConfigDirectory);
var cwd = new Cwd();
var title = fs.readFileSync(__dirname + '/lib/logo.txt')
var description = [
'Application-Grade Static Web Hosting\n ',
' Host single-page apps and static sites with',
' all the power of a modern application platform.'
].join('\n');
// Set up CLI
var cli = Nash.createCli({
title: title,
description: description,
color: 'yellow',
api: Divshot.createClient({
token: user.get('token'),
host: API_HOST,
client_id: CLIENT_ID
}),
user: user,
cwd: cwd,
errors: errors,
environments: environments,
timeout: 30000
});
// Set up process watching dumping machine
dumper(cli.api.events);
// Flags
cli.flag('-a', '--app')
.description('override the directory\'s app name')
.handler(function (appName) {
cwd.overrideAppName(appName);
});
cli.flag('-t', '--token')
.description('override your current user authentication token')
.handler(function (token) {
cli.user.set('token', token, false);
cli.api.setToken(token);
});
cli.flag('-v', '--version')
.description('show the CLI version number')
.exit(true)
.handler(function () {
var package = require(path.resolve(__dirname, './package.json'));
cli.log(package.version);
});
cli.flag('-c', '--config')
.description('use a different config file')
.handler(function (filename) {
cli.cwd.setConfigFilename(filename)
});
cli.flag('--timeout')
.description('set command timeout, in milliseconds')
.handler(function (timeout) {
cli.timeout = timeout;
});
cli.flag('-o', '--org')
.description('set command to operate on the given organization')
.handler(function (org) {
cli.org = org;
});
// Helpers
cli.method('authenticate', function (cli, command, done) {
if (!cli.user.authenticated()) return done(cli.errors.NOT_AUTHENTICATED);
done();
});
cli.method('isApp', function (cli, command, next) {
if(!cli.cwd.getConfig().name) return next(cli.errors.DIRECTORY_NOT_APP);
next();
});
cli.catchAll(function (type, attemptedCommand) {
// Undefined command
if (!attemptedCommand) return cli.commands.help({debug: true});
cli.log();
cli.log(format.bold('"' + attemptedCommand + '"') + ' is not a Divshot ' + type + '.');
cli.log('Please use ' + format.bold('"divshot help"') + ' for a list of Divshot commands.');
cli.log();
cli.log('Note: you may need to update Divshot in order to use that command: ' + format.bold('npm install -g divshot-cli'));
});
// Add commands
commands.connect(cli);
module.exports = cli;