-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcli.js
More file actions
63 lines (55 loc) · 1.76 KB
/
cli.js
File metadata and controls
63 lines (55 loc) · 1.76 KB
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
require('yargonaut')
.helpStyle('green.underline')
.errorsStyle('red.bold');
import 'colors';
import 'fetch-everywhere';
import yargs from 'yargs';
import { version } from '../package.json';
import apiUrls from './config/services';
import autoUpdate from './commands/update-cli';
import * as analytics from './services/analytics';
import { isAscii, containsSpace } from './services/validation';
import getHomeDir from './home-dir';
import { authorizeRequests, getRefreshToken } from './clients/auth-service';
const cliReferenceUrl =
'https://shoutem.github.io/docs/extensions/reference/cli';
const homeDir = getHomeDir();
if (!isAscii(homeDir) || containsSpace(homeDir)) {
console.log(
`ERROR: shoutem CLI homedir (currently \`${homeDir}\`) contains non-ascii characters or a space`
.red.bold,
);
console.log(
'Change it by setting SHOUTEM_CLI_HOME environmental variable'.red.bold,
);
console.log(`Check ${cliReferenceUrl} for more info`.red.bold);
process.exit(1);
}
analytics.setArgv(process.argv);
(async () => {
if (await autoUpdate()) {
return;
}
await authorizeRequests(await getRefreshToken());
const cli = yargs
.usage('Usage: shoutem [command] [-h]')
.option('version', {
alias: 'v',
description: 'Shows version number.',
})
.commandDir('cli')
.strict()
.help()
.epilog(
`If you don't have a developer account, you can register at ${apiUrls.appBuilder.bold}.\n\n` +
`A more detailed reference on how to use CLI can be found on the Developer Portal: ${cliReferenceUrl.bold}.`,
)
.alias('help', 'h');
const argv = cli.argv;
if (argv.version) {
console.log(version);
} else if (argv._.length === 0) {
cli.showHelp();
}
analytics.setCommandName(argv._[0]);
})();