UNPKG

1.39 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3/**
4 * Yes, this is totally copied from
5 * https://github.com/zeit/now-cli/blob/b1663954fe935beb0244002625e05402f59bd20e/bin/now.js
6 */
7
8import 'babel-polyfill';
9
10// Native
11import { resolve } from 'path';
12
13// This command will be run if no other sub command is specified
14const defaultCommand = 'collective';
15
16const commands = new Set([
17 'help',
18 'info',
19 'stats',
20 'list',
21 'donate',
22 'ls',
23 'rm',
24 'remove',
25 'cc',
26 'billing',
27 'show',
28 'open',
29 'postinstall',
30 'setup',
31 'slack',
32 'support',
33 'email',
34 'twitter'
35]);
36
37const aliases = new Map([
38 ['ls', 'list'],
39 ['rm', 'remove'],
40 ['cc', 'billing'],
41 ['info', 'collective'],
42 ['stats', 'collective']
43]);
44
45let cmd = defaultCommand;
46const args = process.argv.slice(2);
47const index = args.findIndex(a => commands.has(a));
48
49if (index > -1) {
50 cmd = args[index];
51 args.splice(index, 1);
52
53 if (cmd === 'help') {
54 if (index < args.length && commands.has(args[index])) {
55 cmd = args[index];
56 args.splice(index, 1);
57 } else {
58 cmd = defaultCommand;
59 }
60
61 args.unshift('--help');
62 }
63
64 cmd = aliases.get(cmd) || cmd;
65}
66
67const bin = resolve(__dirname, '../commands/', cmd + '.js');
68
69// Prepare process.argv for subcommand
70process.argv = process.argv.slice(0, 2).concat(args);
71
72// Load sub command
73// With custom parameter to make "pkg" happy
74require(bin, 'may-exclude');