@adonisjs/core 6.1.5-1 → 6.1.5-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/commands.json +1 -1
- package/build/commands/list/routes.d.ts +13 -0
- package/build/commands/list/routes.js +78 -0
- package/build/modules/ace/main.d.ts +1 -1
- package/build/modules/ace/main.js +1 -1
- package/build/src/cli_formatters/routes_list.d.ts +40 -0
- package/build/src/cli_formatters/routes_list.js +258 -0
- package/build/src/helpers/main.d.ts +2 -0
- package/build/src/helpers/main.js +2 -0
- package/build/src/helpers/parse_binding_reference.d.ts +5 -0
- package/build/src/helpers/parse_binding_reference.js +23 -0
- package/build/src/internal_helpers.js +3 -3
- package/package.json +21 -23
|
@@ -1 +1 @@
|
|
|
1
|
-
{"commands":[{"commandName":"build","description":"Build application for production by compiling frontend assets and TypeScript source to JavaScript","help":"","namespace":null,"aliases":[],"flags":[{"name":"watch","flagName":"watch","required":false,"type":"boolean","description":"Watch filesystem and restart the HTTP server on file change"},{"name":"ignoreTsErrors","flagName":"ignore-ts-errors","required":false,"type":"boolean","description":"Ignore TypeScript errors and continue with the build process"},{"name":"packageManager","flagName":"package-manager","required":false,"type":"string","description":"Select the package manager you want to use to install production dependencies"},{"name":"assets","flagName":"assets","required":false,"type":"boolean","description":"Build frontend assets","showNegatedVariantInHelp":true,"default":true}],"args":[],"options":{},"filePath":"build.js"},{"commandName":"configure","description":"Configure a package post installation","help":"","namespace":null,"aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Package name","type":"string"}],"options":{},"filePath":"configure.js"},{"commandName":"eject","description":"Eject scaffolding stubs to your application root","help":"","namespace":null,"aliases":[],"flags":[{"name":"pkg","flagName":"pkg","required":false,"type":"string","description":"Mention package name for searching stubs","default":"@adonisjs/core"}],"args":[{"name":"stubPath","argumentName":"stub-path","required":true,"description":"Path to the stubs directory or a single stub file","type":"string"}],"options":{},"filePath":"eject.js"},{"commandName":"generate:key","description":"Generate a secure random application key","help":"","namespace":"generate","aliases":[],"flags":[{"name":"show","flagName":"show","required":false,"type":"boolean","description":"Display the key on the terminal, instead of writing it to .env file"},{"name":"force","flagName":"force","required":false,"type":"boolean","description":"Force update .env file in production environment"}],"args":[],"options":{},"filePath":"generate_key.js"},{"commandName":"make:command","description":"Create a new ace command class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the command","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/command.js"},{"commandName":"make:controller","description":"Create a new HTTP controller class","help":"","namespace":"make","aliases":[],"flags":[{"name":"singular","flagName":"singular","required":false,"type":"boolean","description":"Convert controller class and file name to its singular form","alias":"r"},{"name":"resource","flagName":"resource","required":false,"type":"boolean","description":"Generate controller with resource actions","alias":"r"},{"name":"api","flagName":"api","required":false,"type":"boolean","description":"Generate controller with api resource actions","alias":"a"}],"args":[{"name":"name","argumentName":"name","required":true,"description":"The name of the controller","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/controller.js"},{"commandName":"make:event","description":"Create a new event class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the event","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/event.js"},{"commandName":"make:listener","description":"Create a new event listener class","help":"","namespace":"make","aliases":[],"flags":[{"name":"event","flagName":"event","required":false,"type":"string","description":"Generate an event class alongside the listener","alias":"e"}],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the listener","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/listener.js"},{"commandName":"make:middleware","description":"Create a new middleware class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the middleware","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/middleware.js"},{"commandName":"make:provider","description":"Create a new service provider class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the provider","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/provider.js"},{"commandName":"make:test","description":"Create a new Japa test file","help":"","namespace":"make","aliases":[],"flags":[{"name":"suite","flagName":"suite","required":false,"type":"string","description":"The suite for which to create the test file"}],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the test file","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/test.js"},{"commandName":"serve","description":"Start the development HTTP server along with the file watcher to perform restarts on file change","help":"","namespace":null,"aliases":[],"flags":[{"name":"watch","flagName":"watch","required":false,"type":"boolean","description":"Watch filesystem and restart the HTTP server on file change"},{"name":"poll","flagName":"poll","required":false,"type":"boolean","description":"Use polling to detect filesystem changes"},{"name":"clear","flagName":"clear","required":false,"type":"boolean","description":"Clear the terminal for new logs after file change","showNegatedVariantInHelp":true,"default":true},{"name":"assets","flagName":"assets","required":false,"type":"boolean","description":"Start assets bundler dev server","showNegatedVariantInHelp":true,"default":true}],"args":[],"options":{"staysAlive":true},"filePath":"serve.js"}],"version":1}
|
|
1
|
+
{"commands":[{"commandName":"build","description":"Build application for production by compiling frontend assets and TypeScript source to JavaScript","help":"","namespace":null,"aliases":[],"flags":[{"name":"watch","flagName":"watch","required":false,"type":"boolean","description":"Watch filesystem and restart the HTTP server on file change"},{"name":"ignoreTsErrors","flagName":"ignore-ts-errors","required":false,"type":"boolean","description":"Ignore TypeScript errors and continue with the build process"},{"name":"packageManager","flagName":"package-manager","required":false,"type":"string","description":"Select the package manager you want to use to install production dependencies"},{"name":"assets","flagName":"assets","required":false,"type":"boolean","description":"Build frontend assets","showNegatedVariantInHelp":true,"default":true}],"args":[],"options":{},"filePath":"build.js"},{"commandName":"configure","description":"Configure a package post installation","help":"","namespace":null,"aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Package name","type":"string"}],"options":{},"filePath":"configure.js"},{"commandName":"eject","description":"Eject scaffolding stubs to your application root","help":"","namespace":null,"aliases":[],"flags":[{"name":"pkg","flagName":"pkg","required":false,"type":"string","description":"Mention package name for searching stubs","default":"@adonisjs/core"}],"args":[{"name":"stubPath","argumentName":"stub-path","required":true,"description":"Path to the stubs directory or a single stub file","type":"string"}],"options":{},"filePath":"eject.js"},{"commandName":"generate:key","description":"Generate a secure random application key","help":"","namespace":"generate","aliases":[],"flags":[{"name":"show","flagName":"show","required":false,"type":"boolean","description":"Display the key on the terminal, instead of writing it to .env file"},{"name":"force","flagName":"force","required":false,"type":"boolean","description":"Force update .env file in production environment"}],"args":[],"options":{},"filePath":"generate_key.js"},{"commandName":"list:routes","description":"List application routes. This command will boot the application in the console environment","help":"","namespace":"list","aliases":[],"flags":[{"name":"middleware","flagName":"middleware","required":false,"type":"array","description":"View routes that includes all the mentioned middleware names. Use * to see routes that are using one or more middleware"},{"name":"ignoreMiddleware","flagName":"ignore-middleware","required":false,"type":"array","description":"View routes that does not include all the mentioned middleware names. Use * to see routes that are using zero middleware"},{"name":"json","flagName":"json","required":false,"type":"boolean","description":"Get routes list as a JSON string"},{"name":"table","flagName":"table","required":false,"type":"boolean","description":"View list of routes as a table"}],"args":[{"name":"match","argumentName":"match","required":false,"description":"Find routes matching the given keyword. Route name, pattern and controller name will be searched against the keyword","type":"string"}],"options":{"startApp":true},"filePath":"list/routes.js"},{"commandName":"make:command","description":"Create a new ace command class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the command","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/command.js"},{"commandName":"make:controller","description":"Create a new HTTP controller class","help":"","namespace":"make","aliases":[],"flags":[{"name":"singular","flagName":"singular","required":false,"type":"boolean","description":"Convert controller class and file name to its singular form","alias":"r"},{"name":"resource","flagName":"resource","required":false,"type":"boolean","description":"Generate controller with resource actions","alias":"r"},{"name":"api","flagName":"api","required":false,"type":"boolean","description":"Generate controller with api resource actions","alias":"a"}],"args":[{"name":"name","argumentName":"name","required":true,"description":"The name of the controller","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/controller.js"},{"commandName":"make:event","description":"Create a new event class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the event","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/event.js"},{"commandName":"make:listener","description":"Create a new event listener class","help":"","namespace":"make","aliases":[],"flags":[{"name":"event","flagName":"event","required":false,"type":"string","description":"Generate an event class alongside the listener","alias":"e"}],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the listener","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/listener.js"},{"commandName":"make:middleware","description":"Create a new middleware class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the middleware","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/middleware.js"},{"commandName":"make:provider","description":"Create a new service provider class","help":"","namespace":"make","aliases":[],"flags":[],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the provider","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/provider.js"},{"commandName":"make:test","description":"Create a new Japa test file","help":"","namespace":"make","aliases":[],"flags":[{"name":"suite","flagName":"suite","required":false,"type":"string","description":"The suite for which to create the test file"}],"args":[{"name":"name","argumentName":"name","required":true,"description":"Name of the test file","type":"string"}],"options":{"allowUnknownFlags":true},"filePath":"make/test.js"},{"commandName":"serve","description":"Start the development HTTP server along with the file watcher to perform restarts on file change","help":"","namespace":null,"aliases":[],"flags":[{"name":"watch","flagName":"watch","required":false,"type":"boolean","description":"Watch filesystem and restart the HTTP server on file change"},{"name":"poll","flagName":"poll","required":false,"type":"boolean","description":"Use polling to detect filesystem changes"},{"name":"clear","flagName":"clear","required":false,"type":"boolean","description":"Clear the terminal for new logs after file change","showNegatedVariantInHelp":true,"default":true},{"name":"assets","flagName":"assets","required":false,"type":"boolean","description":"Start assets bundler dev server","showNegatedVariantInHelp":true,"default":true}],"args":[],"options":{"staysAlive":true},"filePath":"serve.js"}],"version":1}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CommandOptions } from '../../types/ace.js';
|
|
2
|
+
import { BaseCommand } from '../../modules/ace/main.js';
|
|
3
|
+
export default class ListRoutes extends BaseCommand {
|
|
4
|
+
static commandName: string;
|
|
5
|
+
static description: string;
|
|
6
|
+
static options: CommandOptions;
|
|
7
|
+
match: string;
|
|
8
|
+
middleware: string[];
|
|
9
|
+
ignoreMiddleware: string[];
|
|
10
|
+
json: boolean;
|
|
11
|
+
table: boolean;
|
|
12
|
+
run(): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { args, BaseCommand, flags } from '../../modules/ace/main.js';
|
|
11
|
+
import { RoutesListFormatter } from '../../src/cli_formatters/routes_list.js';
|
|
12
|
+
export default class ListRoutes extends BaseCommand {
|
|
13
|
+
static commandName = 'list:routes';
|
|
14
|
+
static description = 'List application routes. This command will boot the application in the console environment';
|
|
15
|
+
static options = {
|
|
16
|
+
startApp: true,
|
|
17
|
+
};
|
|
18
|
+
async run() {
|
|
19
|
+
const router = await this.app.container.make('router');
|
|
20
|
+
const formatter = new RoutesListFormatter(router, this.ui, {}, {
|
|
21
|
+
ignoreMiddleware: this.ignoreMiddleware,
|
|
22
|
+
middleware: this.middleware,
|
|
23
|
+
match: this.match,
|
|
24
|
+
});
|
|
25
|
+
if (this.json) {
|
|
26
|
+
this.logger.log(JSON.stringify(await formatter.formatAsJSON(), null, 2));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (this.table) {
|
|
30
|
+
const tables = await formatter.formatAsAnsiTable();
|
|
31
|
+
tables.forEach((table) => {
|
|
32
|
+
this.logger.log('');
|
|
33
|
+
if (table.heading) {
|
|
34
|
+
this.logger.log(table.heading);
|
|
35
|
+
this.logger.log('');
|
|
36
|
+
}
|
|
37
|
+
table.table.render();
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const list = await formatter.formatAsAnsiList();
|
|
42
|
+
list.forEach((item) => {
|
|
43
|
+
this.logger.log('');
|
|
44
|
+
if (item.heading) {
|
|
45
|
+
this.logger.log(item.heading);
|
|
46
|
+
this.logger.log('');
|
|
47
|
+
}
|
|
48
|
+
this.logger.log(item.rows.join('\n'));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
__decorate([
|
|
53
|
+
args.string({
|
|
54
|
+
description: 'Find routes matching the given keyword. Route name, pattern and controller name will be searched against the keyword',
|
|
55
|
+
required: false,
|
|
56
|
+
}),
|
|
57
|
+
__metadata("design:type", String)
|
|
58
|
+
], ListRoutes.prototype, "match", void 0);
|
|
59
|
+
__decorate([
|
|
60
|
+
flags.array({
|
|
61
|
+
description: 'View routes that includes all the mentioned middleware names. Use * to see routes that are using one or more middleware',
|
|
62
|
+
}),
|
|
63
|
+
__metadata("design:type", Array)
|
|
64
|
+
], ListRoutes.prototype, "middleware", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
flags.array({
|
|
67
|
+
description: 'View routes that does not include all the mentioned middleware names. Use * to see routes that are using zero middleware',
|
|
68
|
+
}),
|
|
69
|
+
__metadata("design:type", Array)
|
|
70
|
+
], ListRoutes.prototype, "ignoreMiddleware", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
flags.boolean({ description: 'Get routes list as a JSON string' }),
|
|
73
|
+
__metadata("design:type", Boolean)
|
|
74
|
+
], ListRoutes.prototype, "json", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
flags.boolean({ description: 'View list of routes as a table' }),
|
|
77
|
+
__metadata("design:type", Boolean)
|
|
78
|
+
], ListRoutes.prototype, "table", void 0);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Kernel } from './kernel.js';
|
|
2
2
|
export { BaseCommand, ListCommand } from './commands.js';
|
|
3
|
-
export { args, flags, errors, Parser, FsLoader, ListLoader, HelpCommand, IndexGenerator, } from '@adonisjs/ace';
|
|
3
|
+
export { args, flags, errors, Parser, FsLoader, ListLoader, cliHelpers, HelpCommand, IndexGenerator, } from '@adonisjs/ace';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Kernel } from './kernel.js';
|
|
2
2
|
export { BaseCommand, ListCommand } from './commands.js';
|
|
3
|
-
export { args, flags, errors, Parser, FsLoader, ListLoader, HelpCommand, IndexGenerator, } from '@adonisjs/ace';
|
|
3
|
+
export { args, flags, errors, Parser, FsLoader, ListLoader, cliHelpers, HelpCommand, IndexGenerator, } from '@adonisjs/ace';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Router } from '../../modules/http.js';
|
|
2
|
+
import type { UIPrimitives } from '../../types/ace.js';
|
|
3
|
+
type SerializedRoute = {
|
|
4
|
+
name: string;
|
|
5
|
+
pattern: string;
|
|
6
|
+
methods: string[];
|
|
7
|
+
middleware: string[];
|
|
8
|
+
handler: {
|
|
9
|
+
type: 'closure';
|
|
10
|
+
name: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: 'controller';
|
|
13
|
+
moduleNameOrPath: string;
|
|
14
|
+
method: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare class RoutesListFormatter {
|
|
18
|
+
#private;
|
|
19
|
+
constructor(router: Router, ui: UIPrimitives, options: {
|
|
20
|
+
displayHeadRoutes?: boolean;
|
|
21
|
+
maxPrettyPrintWidth?: number;
|
|
22
|
+
}, filters: {
|
|
23
|
+
match?: string;
|
|
24
|
+
middleware?: string[];
|
|
25
|
+
ignoreMiddleware?: string[];
|
|
26
|
+
});
|
|
27
|
+
formatAsJSON(): Promise<{
|
|
28
|
+
domain: string;
|
|
29
|
+
routes: SerializedRoute[];
|
|
30
|
+
}[]>;
|
|
31
|
+
formatAsAnsiList(): Promise<{
|
|
32
|
+
heading: string;
|
|
33
|
+
rows: string[];
|
|
34
|
+
}[]>;
|
|
35
|
+
formatAsAnsiTable(): Promise<{
|
|
36
|
+
heading: string;
|
|
37
|
+
table: ReturnType<UIPrimitives['table']>;
|
|
38
|
+
}[]>;
|
|
39
|
+
}
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import stringWidth from 'string-width';
|
|
2
|
+
import { cliHelpers } from '../../modules/ace/main.js';
|
|
3
|
+
import { parseBindingReference } from '../../src/helpers/main.js';
|
|
4
|
+
export class RoutesListFormatter {
|
|
5
|
+
#router;
|
|
6
|
+
#colors;
|
|
7
|
+
#table;
|
|
8
|
+
#options;
|
|
9
|
+
#filters;
|
|
10
|
+
constructor(router, ui, options, filters) {
|
|
11
|
+
this.#router = router;
|
|
12
|
+
this.#colors = ui.colors;
|
|
13
|
+
this.#table = ui.table;
|
|
14
|
+
this.#filters = filters;
|
|
15
|
+
this.#options = options;
|
|
16
|
+
this.#router.commit();
|
|
17
|
+
}
|
|
18
|
+
#isAllowedByFilters(route) {
|
|
19
|
+
let allowRoute = true;
|
|
20
|
+
if (this.#filters.middleware) {
|
|
21
|
+
allowRoute = this.#filters.middleware.every((name) => {
|
|
22
|
+
if (name === '*') {
|
|
23
|
+
return route.middleware.length > 0;
|
|
24
|
+
}
|
|
25
|
+
return route.middleware.includes(name);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (allowRoute && this.#filters.ignoreMiddleware) {
|
|
29
|
+
allowRoute = this.#filters.ignoreMiddleware.every((name) => {
|
|
30
|
+
if (name === '*') {
|
|
31
|
+
return route.middleware.length === 0;
|
|
32
|
+
}
|
|
33
|
+
return !route.middleware.includes(name);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (!this.#filters.match) {
|
|
37
|
+
return allowRoute;
|
|
38
|
+
}
|
|
39
|
+
if (route.name.includes(this.#filters.match)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (route.pattern.includes(this.#filters.match)) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (route.handler.type === 'controller'
|
|
46
|
+
? route.handler.moduleNameOrPath.includes(this.#filters.match)
|
|
47
|
+
: route.handler.name.includes(this.#filters.match)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
#serializeMiddleware(middleware) {
|
|
53
|
+
return [...middleware.all()].reduce((result, one) => {
|
|
54
|
+
if (typeof one === 'function') {
|
|
55
|
+
result.push(one.name || 'closure');
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
if ('name' in one && one.name) {
|
|
59
|
+
result.push(one.name);
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}, []);
|
|
63
|
+
}
|
|
64
|
+
async #serializeHandler(handler) {
|
|
65
|
+
if ('reference' in handler) {
|
|
66
|
+
return {
|
|
67
|
+
type: 'controller',
|
|
68
|
+
...(await parseBindingReference(handler.reference)),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
type: 'closure',
|
|
73
|
+
name: handler.name || 'closure',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async #serializeRoute(route) {
|
|
77
|
+
let methods = route.methods;
|
|
78
|
+
if (!this.#options.displayHeadRoutes) {
|
|
79
|
+
methods = methods.filter((method) => method !== 'HEAD');
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
name: route.name || '',
|
|
83
|
+
pattern: route.pattern,
|
|
84
|
+
methods: methods,
|
|
85
|
+
handler: await this.#serializeHandler(route.handler),
|
|
86
|
+
middleware: this.#serializeMiddleware(route.middleware),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
#formatRouteMethod(method) {
|
|
90
|
+
return this.#colors.dim(method);
|
|
91
|
+
}
|
|
92
|
+
#formatRoutePattern(route) {
|
|
93
|
+
const pattern = this.#router
|
|
94
|
+
.parsePattern(route.pattern)
|
|
95
|
+
.map((token) => {
|
|
96
|
+
if (token.type === 1) {
|
|
97
|
+
return this.#colors.yellow(`:${token.val}`);
|
|
98
|
+
}
|
|
99
|
+
if (token.type === 3) {
|
|
100
|
+
return this.#colors.yellow(`:${token.val}?`);
|
|
101
|
+
}
|
|
102
|
+
if (token.type === 2) {
|
|
103
|
+
return this.#colors.red(token.val);
|
|
104
|
+
}
|
|
105
|
+
return token.val;
|
|
106
|
+
})
|
|
107
|
+
.join('/');
|
|
108
|
+
return `${pattern === '/' ? pattern : `/${pattern}`}${route.name ? ` ${this.#colors.dim(`(${route.name})`)}` : ''} `;
|
|
109
|
+
}
|
|
110
|
+
#formatControllerName(route) {
|
|
111
|
+
return route.handler.type === 'controller' ? ` ${route.handler.moduleNameOrPath}.` : '';
|
|
112
|
+
}
|
|
113
|
+
#formatAction(route) {
|
|
114
|
+
return route.handler.type === 'controller'
|
|
115
|
+
? `${this.#colors.cyan(route.handler.method)}`
|
|
116
|
+
: ` ${this.#colors.cyan(route.handler.name)}`;
|
|
117
|
+
}
|
|
118
|
+
#formatMiddleware(route, mode = 'normal') {
|
|
119
|
+
if (mode === 'compact' && route.middleware.length > 3) {
|
|
120
|
+
const firstMiddleware = route.middleware[0];
|
|
121
|
+
const secondMiddleware = route.middleware[1];
|
|
122
|
+
const diff = route.middleware.length - 2;
|
|
123
|
+
return this.#colors.dim(`${firstMiddleware}, ${secondMiddleware}, and ${diff} more`);
|
|
124
|
+
}
|
|
125
|
+
return this.#colors.dim(`${route.middleware.filter((one) => one).join(', ')}`);
|
|
126
|
+
}
|
|
127
|
+
#formatDomainHeadline(domain) {
|
|
128
|
+
if (domain !== 'root') {
|
|
129
|
+
return cliHelpers.justify([`${this.#colors.dim('..')} ${this.#colors.green(domain)} `], {
|
|
130
|
+
maxWidth: this.#options.maxPrettyPrintWidth || cliHelpers.TERMINAL_SIZE,
|
|
131
|
+
paddingChar: this.#colors.dim('.'),
|
|
132
|
+
})[0];
|
|
133
|
+
}
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
#justifyListTables(tables) {
|
|
137
|
+
return tables.map((table) => {
|
|
138
|
+
const methods = table.rows.map((columns) => columns[0]);
|
|
139
|
+
const largestMethodsLength = Math.max(...methods.map((method) => stringWidth(method)));
|
|
140
|
+
const formattedMethods = cliHelpers.justify(methods, {
|
|
141
|
+
maxWidth: largestMethodsLength,
|
|
142
|
+
});
|
|
143
|
+
const patterns = table.rows.map((columns) => columns[1]);
|
|
144
|
+
const largestPatternLength = Math.max(...patterns.map((pattern) => stringWidth(pattern)));
|
|
145
|
+
const formattedPatterns = cliHelpers.justify(patterns, {
|
|
146
|
+
maxWidth: largestPatternLength,
|
|
147
|
+
paddingChar: this.#colors.dim('.'),
|
|
148
|
+
});
|
|
149
|
+
const middleware = table.rows.map((columns) => columns[3]);
|
|
150
|
+
const largestMiddlewareLength = Math.max(...middleware.map((one) => stringWidth(one)));
|
|
151
|
+
const formattedMiddleware = cliHelpers.justify(middleware, {
|
|
152
|
+
maxWidth: largestMiddlewareLength,
|
|
153
|
+
align: 'right',
|
|
154
|
+
paddingChar: ' ',
|
|
155
|
+
});
|
|
156
|
+
const controllers = table.rows.map((columns) => columns[2]);
|
|
157
|
+
const largestControllerLength = (this.#options.maxPrettyPrintWidth || cliHelpers.TERMINAL_SIZE) -
|
|
158
|
+
(largestPatternLength + largestMethodsLength + largestMiddlewareLength);
|
|
159
|
+
const formattedControllers = cliHelpers.truncate(cliHelpers.justify(controllers, {
|
|
160
|
+
maxWidth: largestControllerLength,
|
|
161
|
+
align: 'right',
|
|
162
|
+
paddingChar: this.#colors.dim('.'),
|
|
163
|
+
}), {
|
|
164
|
+
maxWidth: largestControllerLength,
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
heading: table.heading,
|
|
168
|
+
rows: formattedMethods.reduce((result, method, index) => {
|
|
169
|
+
result.push(`${method}${formattedPatterns[index]}${formattedControllers[index]}${formattedMiddleware[index]}`);
|
|
170
|
+
return result;
|
|
171
|
+
}, []),
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
async formatAsJSON() {
|
|
176
|
+
const routes = this.#router.toJSON();
|
|
177
|
+
const domains = Object.keys(routes);
|
|
178
|
+
let routesJSON = [];
|
|
179
|
+
for (let domain of domains) {
|
|
180
|
+
const domainRoutes = await Promise.all(routes[domain].map((route) => this.#serializeRoute(route)));
|
|
181
|
+
routesJSON.push({
|
|
182
|
+
domain,
|
|
183
|
+
routes: domainRoutes.filter((route) => this.#isAllowedByFilters(route)),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return routesJSON;
|
|
187
|
+
}
|
|
188
|
+
async formatAsAnsiList() {
|
|
189
|
+
const routes = this.#router.toJSON();
|
|
190
|
+
const domains = Object.keys(routes);
|
|
191
|
+
const tables = [];
|
|
192
|
+
for (let domain of domains) {
|
|
193
|
+
const list = {
|
|
194
|
+
heading: this.#formatDomainHeadline(domain),
|
|
195
|
+
rows: [
|
|
196
|
+
[
|
|
197
|
+
this.#colors.dim('METHOD'),
|
|
198
|
+
` ${this.#colors.dim('ROUTE')} `,
|
|
199
|
+
` ${this.#colors.dim('HANDLER')}`,
|
|
200
|
+
` ${this.#colors.dim('MIDDLEWARE')}`,
|
|
201
|
+
],
|
|
202
|
+
],
|
|
203
|
+
};
|
|
204
|
+
for (let route of routes[domain]) {
|
|
205
|
+
const serializedRoute = await this.#serializeRoute(route);
|
|
206
|
+
if (this.#isAllowedByFilters(serializedRoute)) {
|
|
207
|
+
serializedRoute.methods.forEach((method) => {
|
|
208
|
+
list.rows.push([
|
|
209
|
+
this.#formatRouteMethod(method),
|
|
210
|
+
` ${this.#formatRoutePattern(serializedRoute)}`,
|
|
211
|
+
`${this.#formatControllerName(serializedRoute)}${this.#formatAction(serializedRoute)}`,
|
|
212
|
+
` ${this.#formatMiddleware(serializedRoute, 'compact')}`,
|
|
213
|
+
]);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
tables.push(list);
|
|
218
|
+
}
|
|
219
|
+
return this.#justifyListTables(tables);
|
|
220
|
+
}
|
|
221
|
+
async formatAsAnsiTable() {
|
|
222
|
+
const routes = this.#router.toJSON();
|
|
223
|
+
const domains = Object.keys(routes);
|
|
224
|
+
const tables = [];
|
|
225
|
+
for (let domain of domains) {
|
|
226
|
+
const list = {
|
|
227
|
+
heading: this.#formatDomainHeadline(domain),
|
|
228
|
+
table: this.#table()
|
|
229
|
+
.fullWidth()
|
|
230
|
+
.fluidColumnIndex(2)
|
|
231
|
+
.head([
|
|
232
|
+
this.#colors.dim('METHOD'),
|
|
233
|
+
this.#colors.dim('ROUTE'),
|
|
234
|
+
{ hAlign: 'right', content: this.#colors.dim('HANDLER') },
|
|
235
|
+
{ content: this.#colors.dim('MIDDLEWARE'), hAlign: 'right' },
|
|
236
|
+
]),
|
|
237
|
+
};
|
|
238
|
+
for (let route of routes[domain]) {
|
|
239
|
+
const serializedRoute = await this.#serializeRoute(route);
|
|
240
|
+
if (this.#isAllowedByFilters(serializedRoute)) {
|
|
241
|
+
serializedRoute.methods.forEach((method) => {
|
|
242
|
+
list.table.row([
|
|
243
|
+
this.#formatRouteMethod(method),
|
|
244
|
+
this.#formatRoutePattern(serializedRoute),
|
|
245
|
+
{
|
|
246
|
+
content: `${this.#formatControllerName(serializedRoute)}${this.#formatAction(serializedRoute)}`,
|
|
247
|
+
hAlign: 'right',
|
|
248
|
+
},
|
|
249
|
+
{ content: this.#formatMiddleware(serializedRoute), hAlign: 'right' },
|
|
250
|
+
]);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
tables.push(list);
|
|
255
|
+
}
|
|
256
|
+
return tables;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
export { default as parseImports } from 'parse-imports';
|
|
1
2
|
export { createId as cuid } from '@paralleldrive/cuid2';
|
|
2
3
|
export { safeEqual, compose, base64, fsImportAll, fsReadAll, slash } from '@poppinss/utils';
|
|
4
|
+
export { parseBindingReference } from './parse_binding_reference.js';
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
export { default as parseImports } from 'parse-imports';
|
|
1
2
|
export { createId as cuid } from '@paralleldrive/cuid2';
|
|
2
3
|
export { safeEqual, compose, base64, fsImportAll, fsReadAll, slash } from '@poppinss/utils';
|
|
4
|
+
export { parseBindingReference } from './parse_binding_reference.js';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import parseImports from 'parse-imports';
|
|
2
|
+
export async function parseBindingReference(binding) {
|
|
3
|
+
if (typeof binding === 'string') {
|
|
4
|
+
const tokens = binding.split('.');
|
|
5
|
+
if (tokens.length === 1) {
|
|
6
|
+
return { moduleNameOrPath: binding, method: 'handle' };
|
|
7
|
+
}
|
|
8
|
+
return { method: tokens.pop(), moduleNameOrPath: tokens.join('.') };
|
|
9
|
+
}
|
|
10
|
+
const [bindingReference, method] = binding;
|
|
11
|
+
const imports = [...(await parseImports(bindingReference.toString()))];
|
|
12
|
+
const importedModule = imports.find(($import) => $import.isDynamicImport && $import.moduleSpecifier.value);
|
|
13
|
+
if (importedModule) {
|
|
14
|
+
return {
|
|
15
|
+
moduleNameOrPath: importedModule.moduleSpecifier.value,
|
|
16
|
+
method: method || 'handle',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
moduleNameOrPath: bindingReference.name,
|
|
21
|
+
method: method || 'handle',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import fs from 'fs
|
|
1
|
+
import fs from 'node:fs';
|
|
2
2
|
export async function importAssembler(app) {
|
|
3
3
|
try {
|
|
4
4
|
return await app.import('@adonisjs/assembler');
|
|
@@ -15,14 +15,14 @@ export async function detectAssetsBundler(app) {
|
|
|
15
15
|
if (app.rcFile.assetsBundler) {
|
|
16
16
|
return app.rcFile.assetsBundler;
|
|
17
17
|
}
|
|
18
|
-
if (
|
|
18
|
+
if (fs.existsSync(app.makePath('vite.config.js'))) {
|
|
19
19
|
return {
|
|
20
20
|
name: 'vite',
|
|
21
21
|
devServerCommand: 'vite',
|
|
22
22
|
buildCommand: 'vite build',
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
if (
|
|
25
|
+
if (fs.existsSync(app.makePath('webpack.config.js'))) {
|
|
26
26
|
return {
|
|
27
27
|
name: 'encore',
|
|
28
28
|
devServerCommand: 'encore dev-server',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/core",
|
|
3
|
-
"version": "6.1.5-
|
|
3
|
+
"version": "6.1.5-2",
|
|
4
4
|
"description": "Core of AdonisJS",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -103,19 +103,17 @@
|
|
|
103
103
|
"author": "virk,adonisjs",
|
|
104
104
|
"license": "MIT",
|
|
105
105
|
"devDependencies": {
|
|
106
|
-
"@adonisjs/assembler": "^6.1.3-
|
|
106
|
+
"@adonisjs/assembler": "^6.1.3-3",
|
|
107
107
|
"@commitlint/cli": "^17.4.4",
|
|
108
108
|
"@commitlint/config-conventional": "^17.4.4",
|
|
109
109
|
"@japa/assert": "^1.4.1",
|
|
110
110
|
"@japa/expect-type": "^1.0.3",
|
|
111
111
|
"@japa/file-system": "^1.0.1",
|
|
112
|
-
"@japa/preset-adonis": "^1.2.0",
|
|
113
112
|
"@japa/run-failed-tests": "^1.1.1",
|
|
114
|
-
"@japa/runner": "^2.5.
|
|
113
|
+
"@japa/runner": "^2.5.1",
|
|
115
114
|
"@japa/spec-reporter": "^1.3.3",
|
|
116
|
-
"@swc/core": "^1.3.
|
|
117
|
-
"@types/
|
|
118
|
-
"@types/node": "^18.15.0",
|
|
115
|
+
"@swc/core": "^1.3.40",
|
|
116
|
+
"@types/node": "^18.15.3",
|
|
119
117
|
"@types/pretty-hrtime": "^1.0.1",
|
|
120
118
|
"@types/sinon": "^10.0.13",
|
|
121
119
|
"@types/supertest": "^2.0.12",
|
|
@@ -124,7 +122,7 @@
|
|
|
124
122
|
"copyfiles": "^2.4.1",
|
|
125
123
|
"cross-env": "^7.0.3",
|
|
126
124
|
"del-cli": "^5.0.0",
|
|
127
|
-
"eslint": "^8.
|
|
125
|
+
"eslint": "^8.36.0",
|
|
128
126
|
"eslint-config-prettier": "^8.7.0",
|
|
129
127
|
"eslint-plugin-adonis": "^3.0.3",
|
|
130
128
|
"eslint-plugin-prettier": "^4.2.1",
|
|
@@ -133,40 +131,40 @@
|
|
|
133
131
|
"husky": "^8.0.3",
|
|
134
132
|
"np": "^7.6.3",
|
|
135
133
|
"prettier": "^2.8.4",
|
|
136
|
-
"
|
|
137
|
-
"sinon": "^15.0.1",
|
|
134
|
+
"sinon": "^15.0.2",
|
|
138
135
|
"supertest": "^6.3.3",
|
|
139
136
|
"test-console": "^2.0.0",
|
|
140
137
|
"ts-node": "^10.9.1",
|
|
141
138
|
"typescript": "^4.9.5"
|
|
142
139
|
},
|
|
143
140
|
"dependencies": {
|
|
144
|
-
"@adonisjs/ace": "^12.3.1-
|
|
145
|
-
"@adonisjs/application": "^7.1.2-
|
|
146
|
-
"@adonisjs/bodyparser": "^9.3.2-
|
|
141
|
+
"@adonisjs/ace": "^12.3.1-3",
|
|
142
|
+
"@adonisjs/application": "^7.1.2-2",
|
|
143
|
+
"@adonisjs/bodyparser": "^9.3.2-2",
|
|
147
144
|
"@adonisjs/config": "^4.2.1-0",
|
|
148
145
|
"@adonisjs/encryption": "^5.1.2-0",
|
|
149
|
-
"@adonisjs/env": "^4.2.0-
|
|
150
|
-
"@adonisjs/events": "^8.4.9-
|
|
151
|
-
"@adonisjs/fold": "^9.9.3-
|
|
152
|
-
"@adonisjs/hash": "^8.3.1-
|
|
153
|
-
"@adonisjs/http-server": "^6.8.2-
|
|
146
|
+
"@adonisjs/env": "^4.2.0-1",
|
|
147
|
+
"@adonisjs/events": "^8.4.9-1",
|
|
148
|
+
"@adonisjs/fold": "^9.9.3-3",
|
|
149
|
+
"@adonisjs/hash": "^8.3.1-1",
|
|
150
|
+
"@adonisjs/http-server": "^6.8.2-4",
|
|
154
151
|
"@adonisjs/logger": "^5.4.2-0",
|
|
155
152
|
"@adonisjs/validator": "^13.0.2-0",
|
|
156
153
|
"@paralleldrive/cuid2": "^2.2.0",
|
|
157
|
-
"@poppinss/macroable": "^1.0.0-
|
|
158
|
-
"@poppinss/utils": "^6.5.0-
|
|
154
|
+
"@poppinss/macroable": "^1.0.0-3",
|
|
155
|
+
"@poppinss/utils": "^6.5.0-1",
|
|
159
156
|
"@sindresorhus/is": "^5.3.0",
|
|
160
157
|
"@types/he": "^1.2.0",
|
|
161
|
-
"execa": "^7.
|
|
162
|
-
"fs-extra": "^11.1.0",
|
|
158
|
+
"execa": "^7.1.1",
|
|
163
159
|
"he": "^1.2.0",
|
|
160
|
+
"parse-imports": "^1.1.0",
|
|
164
161
|
"pretty-hrtime": "^1.0.3",
|
|
162
|
+
"string-width": "^5.1.2",
|
|
165
163
|
"youch": "^3.2.3",
|
|
166
164
|
"youch-terminal": "^2.2.0"
|
|
167
165
|
},
|
|
168
166
|
"peerDependencies": {
|
|
169
|
-
"@adonisjs/assembler": "^6.1.3-
|
|
167
|
+
"@adonisjs/assembler": "^6.1.3-2",
|
|
170
168
|
"argon2": "^0.30.3",
|
|
171
169
|
"bcrypt": "^5.0.1"
|
|
172
170
|
},
|