1 | #!/usr/bin/env node
|
2 |
|
3 | const chalk = require('chalk');
|
4 | const clear = require('clear');
|
5 | const commander = require('commander');
|
6 | const figlet = require('figlet');
|
7 | const yeoman = require('yeoman-environment');
|
8 | const { argv, cwd } = require('process');
|
9 | const { parse } = require('path');
|
10 |
|
11 | const packageJson = require('../package.json');
|
12 | const audit = require('./audit');
|
13 |
|
14 | const program = commander;
|
15 | const yeomanEnv = yeoman.createEnv();
|
16 |
|
17 | const generators = {
|
18 | all: 'Regenerate entire application',
|
19 | app: 'Create a new Feathers application in the current folder',
|
20 | authentication: 'Set up authentication for the current application',
|
21 | connection: 'Initialize a new database connection',
|
22 | codelist: 'List custom code in generated modules',
|
23 | hook: 'Create a new hook',
|
24 | middleware: 'Create an Express middleware',
|
25 | options: 'Set options for generating the project',
|
26 | secret: 'Generate a new authentication secret',
|
27 | service: 'Generate a new service',
|
28 | graphql: 'Generate GraphQL service',
|
29 | fakes: 'Generate fake data',
|
30 | test: 'Generate a test for a hook, a service, or auth.'
|
31 |
|
32 | };
|
33 |
|
34 | Object.keys(generators).forEach(name => {
|
35 | const generator = `@feathers-plus/generator-feathers-plus/generators/${name}`;
|
36 | yeomanEnv.register(require.resolve(generator), `${name}`);
|
37 | });
|
38 |
|
39 | const blanks16 = ' ';
|
40 | const genDesc = Object.keys(generators).sort()
|
41 | .map(name => ` ${name}:${blanks16.substr(0, 16 - name.length)}${generators[name]}`).join('\n');
|
42 |
|
43 | clear();
|
44 | console.log(
|
45 | chalk.yellow(figlet.textSync('Feathers+', { horizontalLayout: 'full' }))
|
46 | );
|
47 | console.log('');
|
48 | console.log('With contributions from: j2L4e, NickBolles, lukeburpee, Matt & Marshall');
|
49 | console.log('');
|
50 | console.log('New features recently added:');
|
51 | console.log([
|
52 | '- ',
|
53 | chalk.yellow.bold('generate app'),
|
54 | ': new prompts for test environments and seeding data.'
|
55 | ].join(''));
|
56 | console.log([
|
57 | '- ',
|
58 | chalk.yellow.bold('generate fakes'),
|
59 | ': generate fake data for your services. Very powerful.'
|
60 | ].join(''));
|
61 | console.log([
|
62 | '- ',
|
63 | chalk.yellow.bold('generate hook'),
|
64 | ': generate a hook for one or more services.'
|
65 | ].join(''));
|
66 | console.log([
|
67 | '- ',
|
68 | chalk.yellow.bold('generate test'),
|
69 | ': generate a test for a hook, service or authentication.'
|
70 | ].join(''));
|
71 |
|
72 | console.log('');
|
73 | console.log([
|
74 | 'Migrating app in dir ',
|
75 | chalk.yellow.bold(parse(cwd()).base),
|
76 | ' to latest cli+ version:',
|
77 | ].join(''));
|
78 | console.log([
|
79 | '- ',
|
80 | 'Run ',
|
81 | chalk.red.bold('npm update'),
|
82 | '.',
|
83 | ].join(''));
|
84 | console.log('');
|
85 |
|
86 |
|
87 |
|
88 | const args = argv;
|
89 | args[2] = args[2] || '-h';
|
90 |
|
91 | program
|
92 | .version(packageJson.version)
|
93 | .description('The command line interface for managing Feathers applications.');
|
94 |
|
95 | program
|
96 | .command('audit')
|
97 | .alias('a')
|
98 | .description('Audit the current project.')
|
99 | .action(() => {
|
100 | audit();
|
101 | });
|
102 |
|
103 | program
|
104 | .command('generate <what>')
|
105 | .alias('g')
|
106 | .description(`(Re)generate code. <what> options:\n${genDesc}`)
|
107 | .action(what => {
|
108 | if (Object.keys(generators).indexOf(what) === -1) {
|
109 | program.help();
|
110 | } else {
|
111 | yeomanEnv.run(what, {});
|
112 | }
|
113 | });
|
114 |
|
115 | program
|
116 | .command('*')
|
117 | .action(() => program.help());
|
118 |
|
119 | program.parse(args);
|