1 | import * as CliTable from 'cli-table2';
|
2 | import { ui, Command, Project, unwrap } from 'denali-cli';
|
3 | import Application from '../lib/runtime/application';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export default class RoutesCommand extends Command {
|
11 |
|
12 |
|
13 | static commandName = 'routes';
|
14 | static description = 'Display all defined routes within your application.';
|
15 | static longDescription = unwrap`
|
16 | Displays routes from your application and any routes added by addons.
|
17 | Display shows the method, endpoint, and the action associated to that
|
18 | route.`;
|
19 |
|
20 | static runsInApp = true;
|
21 |
|
22 | static flags = {
|
23 | environment: {
|
24 | description: 'The target environment to build for.',
|
25 | default: process.env.NODE_ENV || 'development',
|
26 | type: <any>'string'
|
27 | },
|
28 | 'print-slow-trees': {
|
29 | description: 'Print out an analysis of the build process, showing the slowest nodes.',
|
30 | default: false,
|
31 | type: <any>'boolean'
|
32 | }
|
33 | };
|
34 |
|
35 | async run(argv: any) {
|
36 | let project = new Project({
|
37 | environment: argv.environment,
|
38 | printSlowTrees: argv.printSlowTrees,
|
39 | buildDummy: true
|
40 | });
|
41 | let application: Application = await project.createApplication();
|
42 | await application.runInitializers();
|
43 | let routes = application.router.routes;
|
44 | let methods = Object.keys(routes);
|
45 | let table = new CliTable({
|
46 | head: [ 'URL', 'ACTION' ]
|
47 | });
|
48 |
|
49 | methods.forEach((method) => {
|
50 | let methodRoutes = routes[method];
|
51 |
|
52 | methodRoutes.forEach((route) => {
|
53 | table.push([ `${ method.toUpperCase() } ${ route.spec.replace(/\(\/\)$/, '/') }`, route.actionPath ]);
|
54 | });
|
55 | });
|
56 |
|
57 | ui.info(table.toString());
|
58 | }
|
59 |
|
60 | }
|