@adonisjs/core 5.8.9 → 6.0.0-0
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/README.md +6 -15
- package/build/commands/commands.json +1 -0
- package/build/commands/eject.d.ts +8 -0
- package/build/commands/eject.js +34 -0
- package/build/commands/{GenerateKey.d.ts → generate_key.d.ts} +3 -4
- package/build/commands/generate_key.js +47 -0
- package/build/commands/main.js +36 -0
- package/build/commands/make/_base.d.ts +6 -0
- package/build/commands/make/_base.js +19 -0
- package/build/commands/make/command.d.ts +8 -0
- package/build/commands/make/command.js +25 -0
- package/build/commands/make/controller.d.ts +12 -0
- package/build/commands/make/controller.js +57 -0
- package/build/commands/make/event.d.ts +8 -0
- package/build/commands/make/event.js +25 -0
- package/build/commands/make/listener.d.ts +10 -0
- package/build/commands/make/listener.js +48 -0
- package/build/commands/make/middleware.d.ts +8 -0
- package/build/commands/make/middleware.js +25 -0
- package/build/commands/make/provider.d.ts +8 -0
- package/build/commands/make/provider.js +25 -0
- package/build/index.d.ts +140 -0
- package/build/index.js +21 -0
- package/build/legacy/validator.d.ts +1 -0
- package/build/legacy/validator.js +1 -0
- package/build/modules/ace/commands.d.ts +26 -0
- package/build/modules/ace/commands.js +63 -0
- package/build/modules/ace/create_kernel.d.ts +3 -0
- package/build/modules/ace/create_kernel.js +33 -0
- package/build/modules/ace/kernel.d.ts +7 -0
- package/build/modules/ace/kernel.js +14 -0
- package/build/modules/ace/main.d.ts +3 -0
- package/build/modules/ace/main.js +3 -0
- package/build/modules/app.d.ts +1 -0
- package/build/modules/app.js +1 -0
- package/build/modules/bodyparser/bodyparser_middleware.d.ts +2 -0
- package/build/modules/bodyparser/bodyparser_middleware.js +2 -0
- package/build/modules/bodyparser/main.d.ts +1 -0
- package/build/modules/bodyparser/main.js +1 -0
- package/build/modules/config.d.ts +1 -0
- package/build/modules/config.js +1 -0
- package/build/modules/container.d.ts +1 -0
- package/build/modules/container.js +1 -0
- package/build/modules/encryption.d.ts +1 -0
- package/build/modules/encryption.js +1 -0
- package/build/modules/env.d.ts +1 -0
- package/build/modules/env.js +1 -0
- package/build/modules/events.d.ts +1 -0
- package/build/modules/events.js +1 -0
- package/build/modules/hash/define_config.d.ts +15 -0
- package/build/modules/hash/define_config.js +19 -0
- package/build/modules/hash/drivers_collection.d.ts +9 -0
- package/build/modules/hash/drivers_collection.js +22 -0
- package/build/modules/hash/main.d.ts +2 -0
- package/build/modules/hash/main.js +2 -0
- package/build/modules/http.d.ts +1 -0
- package/build/modules/http.js +1 -0
- package/build/modules/logger.d.ts +1 -0
- package/build/modules/logger.js +1 -0
- package/build/providers/app_provider.d.ts +16 -0
- package/build/providers/app_provider.js +74 -0
- package/build/providers/hash_provider.d.ts +9 -0
- package/build/providers/hash_provider.js +29 -0
- package/build/providers/http_provider.d.ts +9 -0
- package/build/providers/http_provider.js +36 -0
- package/build/services/ace.d.ts +3 -0
- package/build/services/ace.js +6 -0
- package/build/services/app.d.ts +4 -12
- package/build/services/app.js +5 -12
- package/build/services/config.d.ts +3 -3
- package/build/services/config.js +6 -12
- package/build/services/emitter.d.ts +3 -0
- package/build/services/emitter.js +7 -0
- package/build/services/encryption.d.ts +3 -3
- package/build/services/encryption.js +7 -12
- package/build/services/hash.d.ts +3 -3
- package/build/services/hash.js +7 -12
- package/build/services/logger.d.ts +3 -0
- package/build/services/logger.js +7 -0
- package/build/services/router.d.ts +3 -0
- package/build/services/router.js +7 -0
- package/build/services/server.d.ts +3 -0
- package/build/services/server.js +7 -0
- package/build/services/test_utils.d.ts +3 -0
- package/build/services/test_utils.js +6 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/debug.js +2 -0
- package/build/src/helpers/is.d.ts +2 -0
- package/build/src/helpers/is.js +2 -0
- package/build/src/helpers/main.d.ts +2 -0
- package/build/src/helpers/main.js +2 -0
- package/build/src/helpers/string.d.ts +17 -0
- package/build/src/helpers/string.js +26 -0
- package/build/src/helpers/string_builder.d.ts +23 -0
- package/build/src/helpers/string_builder.js +86 -0
- package/build/src/helpers/types.d.ts +24 -0
- package/build/src/helpers/types.js +29 -0
- package/build/src/ignitor/ace.d.ts +8 -0
- package/build/src/ignitor/ace.js +31 -0
- package/build/src/ignitor/http.d.ts +10 -0
- package/build/src/ignitor/http.js +62 -0
- package/build/src/ignitor/main.d.ts +17 -0
- package/build/src/ignitor/main.js +45 -0
- package/build/src/ignitor/test.d.ts +8 -0
- package/build/src/ignitor/test.js +18 -0
- package/build/src/test_utils/http.d.ts +10 -0
- package/build/src/test_utils/http.js +42 -0
- package/build/src/test_utils/main.d.ts +19 -0
- package/build/src/test_utils/main.js +33 -0
- package/build/src/types.d.ts +63 -0
- package/build/src/types.js +1 -0
- package/build/stubs/index.d.ts +1 -0
- package/build/stubs/index.js +2 -0
- package/build/stubs/make/command/main.stub +19 -0
- package/build/stubs/make/controller/api.stub +33 -0
- package/build/stubs/make/controller/main.stub +9 -0
- package/build/stubs/make/controller/resource.stub +43 -0
- package/build/stubs/make/event/main.stub +15 -0
- package/build/stubs/make/listener/for_event.stub +13 -0
- package/build/stubs/make/listener/main.stub +7 -0
- package/build/stubs/make/middleware/main.stub +22 -0
- package/build/stubs/make/provider/main.stub +35 -0
- package/build/types/ace.d.ts +5 -0
- package/build/types/ace.js +1 -0
- package/build/types/app.d.ts +1 -0
- package/build/types/app.js +1 -0
- package/build/types/bodyparser.d.ts +1 -0
- package/build/types/bodyparser.js +1 -0
- package/build/types/container.d.ts +1 -0
- package/build/types/container.js +1 -0
- package/build/types/encryption.d.ts +1 -0
- package/build/types/encryption.js +1 -0
- package/build/types/events.d.ts +1 -0
- package/build/types/events.js +1 -0
- package/build/types/hash.d.ts +1 -0
- package/build/types/hash.js +1 -0
- package/build/types/http.d.ts +1 -0
- package/build/types/http.js +1 -0
- package/build/types/logger.d.ts +1 -0
- package/build/types/logger.js +1 -0
- package/package.json +226 -245
- package/build/adonis-typings/ace.d.ts +0 -5
- package/build/adonis-typings/ace.js +0 -8
- package/build/adonis-typings/assets-manager.d.ts +0 -88
- package/build/adonis-typings/assets-manager.js +0 -8
- package/build/adonis-typings/container.d.ts +0 -14
- package/build/adonis-typings/container.js +0 -8
- package/build/adonis-typings/cors.d.ts +0 -15
- package/build/adonis-typings/cors.js +0 -8
- package/build/adonis-typings/exception-handler.d.ts +0 -31
- package/build/adonis-typings/exception-handler.js +0 -8
- package/build/adonis-typings/health-check.d.ts +0 -40
- package/build/adonis-typings/health-check.js +0 -8
- package/build/adonis-typings/index.d.ts +0 -17
- package/build/adonis-typings/index.js +0 -25
- package/build/adonis-typings/static.d.ts +0 -15
- package/build/adonis-typings/static.js +0 -8
- package/build/adonis-typings/test-utils.d.ts +0 -24
- package/build/adonis-typings/test-utils.js +0 -8
- package/build/adonis-typings/tests.d.ts +0 -13
- package/build/adonis-typings/tests.js +0 -11
- package/build/commands/DumpRc.d.ts +0 -13
- package/build/commands/DumpRc.js +0 -33
- package/build/commands/GenerateKey.js +0 -25
- package/build/commands/ListRoutes/Renderers/Base.d.ts +0 -31
- package/build/commands/ListRoutes/Renderers/Base.js +0 -70
- package/build/commands/ListRoutes/Renderers/PrettyRenderer.d.ts +0 -51
- package/build/commands/ListRoutes/Renderers/PrettyRenderer.js +0 -135
- package/build/commands/ListRoutes/Renderers/TableRenderer.d.ts +0 -36
- package/build/commands/ListRoutes/Renderers/TableRenderer.js +0 -137
- package/build/commands/ListRoutes/index.d.ts +0 -75
- package/build/commands/ListRoutes/index.js +0 -166
- package/build/commands/index.d.ts +0 -2
- package/build/commands/index.js +0 -15
- package/build/config.d.ts +0 -2
- package/build/config.js +0 -15
- package/build/instructions.js +0 -81
- package/build/providers/AppProvider.d.ts +0 -68
- package/build/providers/AppProvider.js +0 -201
- package/build/services/base.d.ts +0 -3
- package/build/services/base.js +0 -23
- package/build/services/bodyparser.d.ts +0 -2
- package/build/services/bodyparser.js +0 -12
- package/build/services/drive.d.ts +0 -3
- package/build/services/drive.js +0 -12
- package/build/services/event.d.ts +0 -3
- package/build/services/event.js +0 -12
- package/build/services/healthChecks.d.ts +0 -3
- package/build/services/healthChecks.js +0 -12
- package/build/services/httpContext.d.ts +0 -3
- package/build/services/httpContext.js +0 -12
- package/build/services/route.d.ts +0 -3
- package/build/services/route.js +0 -12
- package/build/services/validator.d.ts +0 -3
- package/build/services/validator.js +0 -12
- package/build/src/AssetsManager/Drivers/Encore.d.ts +0 -78
- package/build/src/AssetsManager/Drivers/Encore.js +0 -148
- package/build/src/AssetsManager/Drivers/Fake.d.ts +0 -37
- package/build/src/AssetsManager/Drivers/Fake.js +0 -60
- package/build/src/AssetsManager/index.d.ts +0 -83
- package/build/src/AssetsManager/index.js +0 -171
- package/build/src/Bindings/Repl.d.ts +0 -8
- package/build/src/Bindings/Repl.js +0 -90
- package/build/src/Bindings/Tests.d.ts +0 -7
- package/build/src/Bindings/Tests.js +0 -66
- package/build/src/HealthCheck/Checkers/AppKey.d.ts +0 -6
- package/build/src/HealthCheck/Checkers/AppKey.js +0 -60
- package/build/src/HealthCheck/Checkers/Env.d.ts +0 -6
- package/build/src/HealthCheck/Checkers/Env.js +0 -42
- package/build/src/HealthCheck/index.d.ts +0 -48
- package/build/src/HealthCheck/index.js +0 -99
- package/build/src/Hooks/Cors/index.d.ts +0 -70
- package/build/src/Hooks/Cors/index.js +0 -314
- package/build/src/Hooks/Static/index.d.ts +0 -18
- package/build/src/Hooks/Static/index.js +0 -66
- package/build/src/HttpExceptionHandler/index.d.ts +0 -82
- package/build/src/HttpExceptionHandler/index.js +0 -213
- package/build/src/Ignitor/Ace/App/index.d.ts +0 -60
- package/build/src/Ignitor/Ace/App/index.js +0 -236
- package/build/src/Ignitor/Ace/Exceptions/index.d.ts +0 -4
- package/build/src/Ignitor/Ace/Exceptions/index.js +0 -19
- package/build/src/Ignitor/Ace/GenerateManifest/index.d.ts +0 -28
- package/build/src/Ignitor/Ace/GenerateManifest/index.js +0 -75
- package/build/src/Ignitor/Ace/index.d.ts +0 -11
- package/build/src/Ignitor/Ace/index.js +0 -36
- package/build/src/Ignitor/HttpServer/index.d.ts +0 -56
- package/build/src/Ignitor/HttpServer/index.js +0 -127
- package/build/src/Ignitor/Kernel/index.d.ts +0 -56
- package/build/src/Ignitor/Kernel/index.js +0 -123
- package/build/src/Ignitor/SignalsListener/index.d.ts +0 -23
- package/build/src/Ignitor/SignalsListener/index.js +0 -66
- package/build/src/Ignitor/index.d.ts +0 -32
- package/build/src/Ignitor/index.js +0 -58
- package/build/src/TestUtils/HttpServer/index.d.ts +0 -27
- package/build/src/TestUtils/HttpServer/index.js +0 -56
- package/build/src/TestUtils/index.d.ts +0 -24
- package/build/src/TestUtils/index.js +0 -43
- package/build/src/utils/index.d.ts +0 -18
- package/build/src/utils/index.js +0 -82
- package/build/standalone.d.ts +0 -9
- package/build/standalone.js +0 -52
- package/build/templates/config/app.txt +0 -303
- package/build/templates/config/bodyparser.txt +0 -211
- package/build/templates/config/cors.txt +0 -134
- package/build/templates/config/drive.txt +0 -149
- package/build/templates/config/hash.txt +0 -96
- package/build/templates/config/static.txt +0 -89
- package/build/templates/contracts/drive.txt +0 -13
- package/build/templates/contracts/env.txt +0 -24
- package/build/templates/contracts/events.txt +0 -31
- package/build/templates/contracts/hash.txt +0 -13
- package/build/templates/env.txt +0 -31
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.HttpExceptionHandler = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Http exception handler serves as the base exception handler
|
|
14
|
-
* to handle all exceptions occured during the HTTP request
|
|
15
|
-
* lifecycle and makes appropriate response for them.
|
|
16
|
-
*/
|
|
17
|
-
class HttpExceptionHandler {
|
|
18
|
-
constructor(logger) {
|
|
19
|
-
this.logger = logger;
|
|
20
|
-
/**
|
|
21
|
-
* An array of error codes that must not be reported
|
|
22
|
-
*/
|
|
23
|
-
this.ignoreCodes = [];
|
|
24
|
-
/**
|
|
25
|
-
* An array of http statuses that must not be reported. The first
|
|
26
|
-
* level of filteration is on the basis of statuses and then
|
|
27
|
-
* the error codes.
|
|
28
|
-
*/
|
|
29
|
-
this.ignoreStatuses = [400, 422, 401];
|
|
30
|
-
/**
|
|
31
|
-
* An array of internal error codes to ignore
|
|
32
|
-
* from the reporting list
|
|
33
|
-
*/
|
|
34
|
-
this.internalIgnoreCodes = ['E_ROUTE_NOT_FOUND'];
|
|
35
|
-
/**
|
|
36
|
-
* Map of status pages to render, instead of making the
|
|
37
|
-
* regular response
|
|
38
|
-
*/
|
|
39
|
-
this.statusPages = {};
|
|
40
|
-
/**
|
|
41
|
-
* A flag to disable status pages during development
|
|
42
|
-
*/
|
|
43
|
-
this.disableStatusPagesInDevelopment = true;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* A custom context to send to the logger when reporting
|
|
47
|
-
* errors.
|
|
48
|
-
*/
|
|
49
|
-
context(ctx) {
|
|
50
|
-
const requestId = ctx.request.id();
|
|
51
|
-
return requestId
|
|
52
|
-
? {
|
|
53
|
-
'x-request-id': requestId,
|
|
54
|
-
}
|
|
55
|
-
: {};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns a boolean telling if a given error is supposed
|
|
59
|
-
* to be logged or not
|
|
60
|
-
*/
|
|
61
|
-
shouldReport(error) {
|
|
62
|
-
/**
|
|
63
|
-
* Do not report the error when it's status is mentioned inside
|
|
64
|
-
* the `ignoreStatuses` array.
|
|
65
|
-
*/
|
|
66
|
-
if (error.status && this.ignoreStatuses.indexOf(error.status) > -1) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Don't report when error has a code and it's in the ignore list.
|
|
71
|
-
*/
|
|
72
|
-
if (error.code && this.ignoreCodes.concat(this.internalIgnoreCodes).indexOf(error.code) > -1) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Makes the JSON response, based upon the environment in
|
|
79
|
-
* which the app is runing
|
|
80
|
-
*/
|
|
81
|
-
async makeJSONResponse(error, ctx) {
|
|
82
|
-
if (process.env.NODE_ENV === 'development') {
|
|
83
|
-
ctx.response.status(error.status).send({
|
|
84
|
-
message: error.message,
|
|
85
|
-
stack: error.stack,
|
|
86
|
-
code: error.code,
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
ctx.response.status(error.status).send({ message: error.message });
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Makes the JSON API response, based upon the environment in
|
|
94
|
-
* which the app is runing
|
|
95
|
-
*/
|
|
96
|
-
async makeJSONAPIResponse(error, ctx) {
|
|
97
|
-
ctx.response.status(error.status).send({
|
|
98
|
-
errors: [
|
|
99
|
-
{
|
|
100
|
-
title: error.message,
|
|
101
|
-
...(process.env.NODE_ENV === 'development' ? { detail: error.stack } : {}),
|
|
102
|
-
code: error.code,
|
|
103
|
-
status: error.status,
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Makes the HTML response, based upon the environment in
|
|
110
|
-
* which the app is runing
|
|
111
|
-
*/
|
|
112
|
-
async makeHtmlResponse(error, ctx) {
|
|
113
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
114
|
-
(!this.expandedStatusPages[error.status] || this.disableStatusPagesInDevelopment)) {
|
|
115
|
-
const Youch = require('youch');
|
|
116
|
-
const html = await new Youch(error, ctx.request.request).toHTML();
|
|
117
|
-
ctx.response.status(error.status).send(html);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Render status pages
|
|
122
|
-
*/
|
|
123
|
-
if (ctx['view'] && this.expandedStatusPages[error.status]) {
|
|
124
|
-
const html = await ctx['view'].render(this.expandedStatusPages[error.status], { error });
|
|
125
|
-
ctx.response.status(error.status).send(html);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
ctx.response.status(error.status).send(`<h1> ${error.message} </h1>`);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Report a given error
|
|
132
|
-
*/
|
|
133
|
-
report(error, ctx) {
|
|
134
|
-
error.status = error.status || 500;
|
|
135
|
-
if (!this.shouldReport(error)) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (typeof error.report === 'function') {
|
|
139
|
-
error.report(error, ctx);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* - Using `error` for `500 and above`
|
|
144
|
-
* - `warn` for `400 and above`
|
|
145
|
-
* - `info` for rest. This should not happen, but technically it's possible for someone
|
|
146
|
-
* to raise with 200
|
|
147
|
-
*/
|
|
148
|
-
if (!error.status || error.status >= 500) {
|
|
149
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
150
|
-
ctx.logger.error({ err: error, ...this.context(ctx) }, error.message);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else if (error.status >= 400) {
|
|
154
|
-
ctx.logger.warn(this.context(ctx), error.message);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
ctx.logger.info(this.context(ctx), error.message);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Handle exception and make response
|
|
162
|
-
*/
|
|
163
|
-
async handle(error, ctx) {
|
|
164
|
-
error.status = error.status || 500;
|
|
165
|
-
if (typeof error.handle === 'function') {
|
|
166
|
-
return error.handle(error, ctx);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Send stack in the response when in test environment and
|
|
170
|
-
* there is a fatal error.
|
|
171
|
-
*/
|
|
172
|
-
if (error.status >= 500 && error.stack && process.env.NODE_ENV === 'test') {
|
|
173
|
-
return ctx.response.status(error.status).send(error.stack);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Attempt to find the best error reporter for validation
|
|
177
|
-
*/
|
|
178
|
-
switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {
|
|
179
|
-
case 'html':
|
|
180
|
-
case null:
|
|
181
|
-
return this.makeHtmlResponse(error, ctx);
|
|
182
|
-
case 'json':
|
|
183
|
-
return this.makeJSONResponse(error, ctx);
|
|
184
|
-
case 'application/vnd.api+json':
|
|
185
|
-
return this.makeJSONAPIResponse(error, ctx);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.HttpExceptionHandler = HttpExceptionHandler;
|
|
190
|
-
/**
|
|
191
|
-
* Single getter to pull status pages after expanding the range expression
|
|
192
|
-
*/
|
|
193
|
-
Object.defineProperty(HttpExceptionHandler.prototype, 'expandedStatusPages', {
|
|
194
|
-
get() {
|
|
195
|
-
const value = Object.keys(this.statusPages).reduce((result, codeRange) => {
|
|
196
|
-
const parts = codeRange.split('.');
|
|
197
|
-
const min = Number(parts[0]);
|
|
198
|
-
const max = Number(parts[parts.length - 1]);
|
|
199
|
-
if (isNaN(min) || isNaN(max)) {
|
|
200
|
-
return result;
|
|
201
|
-
}
|
|
202
|
-
if (min === max) {
|
|
203
|
-
result[codeRange] = this.statusPages[codeRange];
|
|
204
|
-
}
|
|
205
|
-
Array.apply(null, new Array(max - min + 1)).forEach((_, step) => {
|
|
206
|
-
result[min + step] = this.statusPages[codeRange];
|
|
207
|
-
});
|
|
208
|
-
return result;
|
|
209
|
-
}, {});
|
|
210
|
-
Object.defineProperty(this, 'expandedStatusPages', { value });
|
|
211
|
-
return value;
|
|
212
|
-
},
|
|
213
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Exposes the API to execute app commands registered under
|
|
3
|
-
* the manifest file.
|
|
4
|
-
*/
|
|
5
|
-
export declare class App {
|
|
6
|
-
private appRoot;
|
|
7
|
-
private commandName;
|
|
8
|
-
/**
|
|
9
|
-
* Returns a boolean if mentioned command is an assembler
|
|
10
|
-
* command
|
|
11
|
-
*/
|
|
12
|
-
private get isAssemblerCommand();
|
|
13
|
-
/**
|
|
14
|
-
* Reference to the app kernel
|
|
15
|
-
*/
|
|
16
|
-
private kernel;
|
|
17
|
-
/**
|
|
18
|
-
* Reference to the ace kernel
|
|
19
|
-
*/
|
|
20
|
-
private ace;
|
|
21
|
-
/**
|
|
22
|
-
* Source root always points to the compiled source
|
|
23
|
-
* code.
|
|
24
|
-
*/
|
|
25
|
-
constructor(appRoot: string);
|
|
26
|
-
/**
|
|
27
|
-
* Print commands help
|
|
28
|
-
*/
|
|
29
|
-
private printHelp;
|
|
30
|
-
/**
|
|
31
|
-
* Print framework version
|
|
32
|
-
*/
|
|
33
|
-
private printVersion;
|
|
34
|
-
/**
|
|
35
|
-
* Invoked before command source will be read from the
|
|
36
|
-
* disk
|
|
37
|
-
*/
|
|
38
|
-
private onFind;
|
|
39
|
-
/**
|
|
40
|
-
* Invoked before command is about to run.
|
|
41
|
-
*/
|
|
42
|
-
private onRun;
|
|
43
|
-
/**
|
|
44
|
-
* Hooks into ace lifecycle events to conditionally
|
|
45
|
-
* load the app.
|
|
46
|
-
*/
|
|
47
|
-
private registerAceHooks;
|
|
48
|
-
/**
|
|
49
|
-
* Adding flags
|
|
50
|
-
*/
|
|
51
|
-
private registerAceFlags;
|
|
52
|
-
/**
|
|
53
|
-
* Load commands using manifest loader
|
|
54
|
-
*/
|
|
55
|
-
loadCommands(): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Handle application command
|
|
58
|
-
*/
|
|
59
|
-
handle(argv: string[]): Promise<void>;
|
|
60
|
-
}
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.App = void 0;
|
|
12
|
-
const ace_1 = require("@adonisjs/ace");
|
|
13
|
-
const cliui_1 = require("@poppinss/cliui");
|
|
14
|
-
const helpers_1 = require("@poppinss/utils/build/helpers");
|
|
15
|
-
const Kernel_1 = require("../../Kernel");
|
|
16
|
-
const utils_1 = require("../../../utils");
|
|
17
|
-
const GenerateManifest_1 = require("../GenerateManifest");
|
|
18
|
-
/**
|
|
19
|
-
* A local list of assembler commands. We need this, so that when assembler
|
|
20
|
-
* is not installed (probably in production) and someone is trying to
|
|
21
|
-
* build the project by running `serve` or `build`, we should give
|
|
22
|
-
* them a better descriptive error.
|
|
23
|
-
*
|
|
24
|
-
* Also, do note that at times this list will be stale, but we get it back
|
|
25
|
-
* in sync over time.
|
|
26
|
-
*/
|
|
27
|
-
const ASSEMBLER_COMMANDS = [
|
|
28
|
-
'build',
|
|
29
|
-
'serve',
|
|
30
|
-
'invoke',
|
|
31
|
-
'make:command',
|
|
32
|
-
'make:controller',
|
|
33
|
-
'make:exception',
|
|
34
|
-
'make:listener',
|
|
35
|
-
'make:middleware',
|
|
36
|
-
'make:prldfile',
|
|
37
|
-
'make:provider',
|
|
38
|
-
'make:validator',
|
|
39
|
-
'make:view',
|
|
40
|
-
];
|
|
41
|
-
/**
|
|
42
|
-
* Exposes the API to execute app commands registered under
|
|
43
|
-
* the manifest file.
|
|
44
|
-
*/
|
|
45
|
-
class App {
|
|
46
|
-
/**
|
|
47
|
-
* Source root always points to the compiled source
|
|
48
|
-
* code.
|
|
49
|
-
*/
|
|
50
|
-
constructor(appRoot) {
|
|
51
|
-
this.appRoot = appRoot;
|
|
52
|
-
/**
|
|
53
|
-
* Reference to the app kernel
|
|
54
|
-
*/
|
|
55
|
-
this.kernel = new Kernel_1.AppKernel(this.appRoot, 'console');
|
|
56
|
-
/**
|
|
57
|
-
* Reference to the ace kernel
|
|
58
|
-
*/
|
|
59
|
-
this.ace = new ace_1.Kernel(this.kernel.application);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Returns a boolean if mentioned command is an assembler
|
|
63
|
-
* command
|
|
64
|
-
*/
|
|
65
|
-
get isAssemblerCommand() {
|
|
66
|
-
return ASSEMBLER_COMMANDS.includes(this.commandName);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Print commands help
|
|
70
|
-
*/
|
|
71
|
-
printHelp(value, command) {
|
|
72
|
-
if (!value) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
this.ace.printHelp(command, [GenerateManifest_1.GenerateManifest.getManifestJSON()]);
|
|
76
|
-
process.exit(0);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Print framework version
|
|
80
|
-
*/
|
|
81
|
-
printVersion(value) {
|
|
82
|
-
if (!value) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const appVersion = this.kernel.application.version;
|
|
86
|
-
const adonisVersion = this.kernel.application.adonisVersion;
|
|
87
|
-
let assemblerVersion = 'Not Installed';
|
|
88
|
-
try {
|
|
89
|
-
assemblerVersion = require((0, helpers_1.resolveFrom)(this.appRoot, '@adonisjs/assembler/package.json')).version;
|
|
90
|
-
}
|
|
91
|
-
catch (error) { }
|
|
92
|
-
(0, cliui_1.sticker)()
|
|
93
|
-
.heading('node ace --version')
|
|
94
|
-
.add(`App version: ${cliui_1.logger.colors.cyan(appVersion ? appVersion.version : 'NA')}`)
|
|
95
|
-
.add(`Framework version: ${cliui_1.logger.colors.cyan(adonisVersion ? adonisVersion.version : 'NA')}`)
|
|
96
|
-
.add(`Assembler version: ${cliui_1.logger.colors.cyan(assemblerVersion)}`)
|
|
97
|
-
.render();
|
|
98
|
-
process.exit(0);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Invoked before command source will be read from the
|
|
102
|
-
* disk
|
|
103
|
-
*/
|
|
104
|
-
async onFind(command) {
|
|
105
|
-
if (!command) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Register ts hook when
|
|
110
|
-
*
|
|
111
|
-
* - Haven't registered it already
|
|
112
|
-
* - Is a typescript project
|
|
113
|
-
* - Is not an assembler command
|
|
114
|
-
*/
|
|
115
|
-
if (!this.isAssemblerCommand) {
|
|
116
|
-
this.kernel.registerTsCompilerHook();
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Only main command can load the application or switch
|
|
120
|
-
* the environment.
|
|
121
|
-
*
|
|
122
|
-
* If a sub-command needs application, then the main command
|
|
123
|
-
* should set "loadApp" to true as well.
|
|
124
|
-
*/
|
|
125
|
-
if (command.commandName === this.commandName || command.aliases.includes(this.commandName)) {
|
|
126
|
-
/**
|
|
127
|
-
* Switch environment before wiring the app
|
|
128
|
-
*/
|
|
129
|
-
if (command.settings.environment) {
|
|
130
|
-
this.kernel.application.switchEnvironment(command.settings.environment);
|
|
131
|
-
}
|
|
132
|
-
if (command.settings.loadApp) {
|
|
133
|
-
/**
|
|
134
|
-
* Set ace instance within the container, so that the underlying
|
|
135
|
-
* commands or the app can access it from the container
|
|
136
|
-
*/
|
|
137
|
-
this.kernel.application.container.singleton('Adonis/Core/Ace', () => this.ace);
|
|
138
|
-
await this.kernel.boot();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Invoked before command is about to run.
|
|
144
|
-
*/
|
|
145
|
-
async onRun() {
|
|
146
|
-
if (this.kernel.hasBooted) {
|
|
147
|
-
await this.kernel.start();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Hooks into ace lifecycle events to conditionally
|
|
152
|
-
* load the app.
|
|
153
|
-
*/
|
|
154
|
-
registerAceHooks() {
|
|
155
|
-
this.ace.before('find', async (command) => this.onFind(command));
|
|
156
|
-
this.ace.before('run', async () => this.onRun());
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Adding flags
|
|
160
|
-
*/
|
|
161
|
-
registerAceFlags() {
|
|
162
|
-
/**
|
|
163
|
-
* Showing help including core commands
|
|
164
|
-
*/
|
|
165
|
-
this.ace.flag('help', async (value, _, command) => this.printHelp(value, command), {
|
|
166
|
-
alias: 'h',
|
|
167
|
-
});
|
|
168
|
-
/**
|
|
169
|
-
* Showing app and AdonisJs version
|
|
170
|
-
*/
|
|
171
|
-
this.ace.flag('version', async (value) => this.printVersion(value), { alias: 'v' });
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Load commands using manifest loader
|
|
175
|
-
*/
|
|
176
|
-
async loadCommands() {
|
|
177
|
-
await (0, utils_1.loadAceCommands)(this.kernel.application, this.ace);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Handle application command
|
|
181
|
-
*/
|
|
182
|
-
async handle(argv) {
|
|
183
|
-
try {
|
|
184
|
-
/**
|
|
185
|
-
* Manifest files to load
|
|
186
|
-
*/
|
|
187
|
-
await this.loadCommands();
|
|
188
|
-
/**
|
|
189
|
-
* Define ace hooks to wire the application (if required)
|
|
190
|
-
*/
|
|
191
|
-
this.registerAceHooks();
|
|
192
|
-
/**
|
|
193
|
-
* Define global flags
|
|
194
|
-
*/
|
|
195
|
-
this.registerAceFlags();
|
|
196
|
-
/**
|
|
197
|
-
* Print help when no arguments have been passed
|
|
198
|
-
*/
|
|
199
|
-
if (!argv.length) {
|
|
200
|
-
this.printHelp(true);
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Hold reference to the command name. We will use this to decide whether
|
|
205
|
-
* or not to exit the process forcefully after the command has been
|
|
206
|
-
* executed
|
|
207
|
-
*/
|
|
208
|
-
this.commandName = argv[0];
|
|
209
|
-
/**
|
|
210
|
-
* Listen for the exit signal on ace kernel
|
|
211
|
-
*/
|
|
212
|
-
this.ace.onExit(async () => {
|
|
213
|
-
if (this.kernel.hasBooted) {
|
|
214
|
-
await this.kernel.close();
|
|
215
|
-
}
|
|
216
|
-
if (!this.ace.error) {
|
|
217
|
-
process.exit(this.ace.exitCode);
|
|
218
|
-
}
|
|
219
|
-
return this.kernel
|
|
220
|
-
.handleError(this.ace.error)
|
|
221
|
-
.finally(() => process.exit(this.ace.exitCode));
|
|
222
|
-
});
|
|
223
|
-
/**
|
|
224
|
-
* Handle command
|
|
225
|
-
*/
|
|
226
|
-
await this.ace.handle(argv);
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
if (!error) {
|
|
230
|
-
process.exit(1);
|
|
231
|
-
}
|
|
232
|
-
this.kernel.handleError(error).finally(() => process.exit(1));
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
exports.App = App;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.AceRuntimeException = void 0;
|
|
12
|
-
const cliui_1 = require("@poppinss/cliui");
|
|
13
|
-
const utils_1 = require("@poppinss/utils");
|
|
14
|
-
class AceRuntimeException extends utils_1.Exception {
|
|
15
|
-
handle(error) {
|
|
16
|
-
cliui_1.logger.error(error.message);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.AceRuntimeException = AceRuntimeException;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Exposes the API to generate the manifest file
|
|
3
|
-
*/
|
|
4
|
-
export declare class GenerateManifest {
|
|
5
|
-
private appRoot;
|
|
6
|
-
private kernel;
|
|
7
|
-
/**
|
|
8
|
-
* Source root always points to the compiled source
|
|
9
|
-
* code.
|
|
10
|
-
*/
|
|
11
|
-
constructor(appRoot: string);
|
|
12
|
-
/**
|
|
13
|
-
* Returns manifest object for showing help
|
|
14
|
-
*/
|
|
15
|
-
static getManifestJSON(): {
|
|
16
|
-
commandName: string;
|
|
17
|
-
description: string;
|
|
18
|
-
args: never[];
|
|
19
|
-
flags: never[];
|
|
20
|
-
settings: {};
|
|
21
|
-
aliases: never[];
|
|
22
|
-
commandPath: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Generates the manifest file for commands
|
|
26
|
-
*/
|
|
27
|
-
handle(): Promise<void>;
|
|
28
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.GenerateManifest = void 0;
|
|
12
|
-
const cliui_1 = require("@poppinss/cliui");
|
|
13
|
-
const ace_1 = require("@adonisjs/ace");
|
|
14
|
-
const Kernel_1 = require("../../Kernel");
|
|
15
|
-
const Exceptions_1 = require("../Exceptions");
|
|
16
|
-
/**
|
|
17
|
-
* Exposes the API to generate the manifest file
|
|
18
|
-
*/
|
|
19
|
-
class GenerateManifest {
|
|
20
|
-
/**
|
|
21
|
-
* Source root always points to the compiled source
|
|
22
|
-
* code.
|
|
23
|
-
*/
|
|
24
|
-
constructor(appRoot) {
|
|
25
|
-
this.appRoot = appRoot;
|
|
26
|
-
this.kernel = new Kernel_1.AppKernel(this.appRoot, 'console');
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Returns manifest object for showing help
|
|
30
|
-
*/
|
|
31
|
-
static getManifestJSON() {
|
|
32
|
-
return {
|
|
33
|
-
commandName: 'generate:manifest',
|
|
34
|
-
description: 'Generate ace commands manifest file. Manifest file speeds up commands lookup',
|
|
35
|
-
args: [],
|
|
36
|
-
flags: [],
|
|
37
|
-
settings: {},
|
|
38
|
-
aliases: [],
|
|
39
|
-
commandPath: '',
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Generates the manifest file for commands
|
|
44
|
-
*/
|
|
45
|
-
async handle() {
|
|
46
|
-
try {
|
|
47
|
-
this.kernel.registerTsCompilerHook();
|
|
48
|
-
const commands = this.kernel.application.rcFile.commands;
|
|
49
|
-
/**
|
|
50
|
-
* Generating manifest requires us to import the command files to read their
|
|
51
|
-
* meta data defined as class static properties. However, at this stage
|
|
52
|
-
* the application is not booted and hence top level IoC container
|
|
53
|
-
* imports will break
|
|
54
|
-
*/
|
|
55
|
-
this.kernel.application.container.trap((namespace) => {
|
|
56
|
-
if (namespace === 'Adonis/Core/Application') {
|
|
57
|
-
return this.kernel.application;
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
__esModule: new Proxy({ namespace }, {
|
|
61
|
-
get(target) {
|
|
62
|
-
throw new Exceptions_1.AceRuntimeException(`Top level import for module "${target.namespace}" is not allowed in commands. Learn more https://docs.adonisjs.com/guides/ace-commandline#top-level-imports-are-not-allowed`);
|
|
63
|
-
},
|
|
64
|
-
}),
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
await new ace_1.ManifestGenerator(this.appRoot, commands).generate();
|
|
68
|
-
cliui_1.logger.action('create').succeeded('ace-manifest.json file');
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
await this.kernel.handleError(error).finally(() => process.exit(1));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.GenerateManifest = GenerateManifest;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.Ace = void 0;
|
|
12
|
-
const App_1 = require("./App");
|
|
13
|
-
const GenerateManifest_1 = require("./GenerateManifest");
|
|
14
|
-
/**
|
|
15
|
-
* Exposes the API to execute ace commands.
|
|
16
|
-
*/
|
|
17
|
-
class Ace {
|
|
18
|
-
constructor(appRoot) {
|
|
19
|
-
this.appRoot = appRoot;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Handles the ace command
|
|
23
|
-
*/
|
|
24
|
-
async handle(argv) {
|
|
25
|
-
process.env.ADONIS_ACE_CWD = this.appRoot;
|
|
26
|
-
if (argv[0] === 'generate:manifest' && !argv.includes('--help')) {
|
|
27
|
-
await new GenerateManifest_1.GenerateManifest(this.appRoot).handle();
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Proxy over to application commands
|
|
32
|
-
*/
|
|
33
|
-
await new App_1.App(this.appRoot).handle(argv);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.Ace = Ace;
|