@adonisjs/assembler 5.9.5 → 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/LICENSE.md +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/src/bundler.d.ts +10 -0
- package/build/src/bundler.js +133 -0
- package/build/src/dev_server.d.ts +13 -0
- package/build/src/dev_server.js +189 -0
- package/build/src/run.d.ts +3 -0
- package/build/src/run.js +19 -0
- package/build/src/types.d.ts +26 -0
- package/build/src/watch.d.ts +8 -0
- package/build/src/watch.js +18 -0
- package/package.json +77 -99
- package/build/ace-manifest.json +0 -521
- package/build/commands/Build.d.ts +0 -37
- package/build/commands/Build.js +0 -138
- package/build/commands/Invoke.d.ts +0 -34
- package/build/commands/Invoke.js +0 -234
- package/build/commands/Make/Base.d.ts +0 -30
- package/build/commands/Make/Base.js +0 -75
- package/build/commands/Make/Command.d.ts +0 -35
- package/build/commands/Make/Command.js +0 -82
- package/build/commands/Make/Controller.d.ts +0 -37
- package/build/commands/Make/Controller.js +0 -89
- package/build/commands/Make/Exception.d.ts +0 -32
- package/build/commands/Make/Exception.js +0 -75
- package/build/commands/Make/Listener.d.ts +0 -30
- package/build/commands/Make/Listener.js +0 -70
- package/build/commands/Make/Middleware.d.ts +0 -31
- package/build/commands/Make/Middleware.js +0 -87
- package/build/commands/Make/PreloadFile.d.ts +0 -38
- package/build/commands/Make/PreloadFile.js +0 -157
- package/build/commands/Make/Provider.d.ts +0 -31
- package/build/commands/Make/Provider.js +0 -114
- package/build/commands/Make/Suite.d.ts +0 -41
- package/build/commands/Make/Suite.js +0 -120
- package/build/commands/Make/Test.d.ts +0 -35
- package/build/commands/Make/Test.js +0 -96
- package/build/commands/Make/Validator.d.ts +0 -31
- package/build/commands/Make/Validator.js +0 -71
- package/build/commands/Make/View.d.ts +0 -30
- package/build/commands/Make/View.js +0 -70
- package/build/commands/Serve.d.ts +0 -33
- package/build/commands/Serve.js +0 -112
- package/build/commands/Test.d.ts +0 -57
- package/build/commands/Test.js +0 -159
- package/build/commands/TypeCheck.d.ts +0 -16
- package/build/commands/TypeCheck.js +0 -85
- package/build/config/paths.d.ts +0 -7
- package/build/config/paths.js +0 -18
- package/build/register.js +0 -15
- package/build/src/AssetsBundler/index.d.ts +0 -76
- package/build/src/AssetsBundler/index.js +0 -216
- package/build/src/Compiler/index.d.ts +0 -62
- package/build/src/Compiler/index.js +0 -287
- package/build/src/Contracts/index.d.ts +0 -8
- package/build/src/Contracts/index.js +0 -10
- package/build/src/DevServer/index.d.ts +0 -70
- package/build/src/DevServer/index.js +0 -306
- package/build/src/EnvParser/index.d.ts +0 -21
- package/build/src/EnvParser/index.js +0 -48
- package/build/src/HttpServer/index.d.ts +0 -34
- package/build/src/HttpServer/index.js +0 -87
- package/build/src/Manifest/index.d.ts +0 -32
- package/build/src/Manifest/index.js +0 -88
- package/build/src/RcFile/index.d.ts +0 -72
- package/build/src/RcFile/index.js +0 -174
- package/build/src/Test/index.d.ts +0 -75
- package/build/src/Test/index.js +0 -346
- package/build/src/Test/process.d.ts +0 -22
- package/build/src/Test/process.js +0 -68
- package/build/src/Ts/index.d.ts +0 -24
- package/build/src/Ts/index.js +0 -55
- package/build/src/requireHook/index.d.ts +0 -5
- package/build/src/requireHook/index.js +0 -28
- package/build/src/requireHook/ioc-transformer.d.ts +0 -6
- package/build/src/requireHook/ioc-transformer.js +0 -21
- package/build/templates/command.txt +0 -33
- package/build/templates/controller.txt +0 -3
- package/build/templates/event-listener.txt +0 -3
- package/build/templates/exception.txt +0 -15
- package/build/templates/middleware.txt +0 -8
- package/build/templates/preload-file.txt +0 -9
- package/build/templates/provider.txt +0 -40
- package/build/templates/resource-controller.txt +0 -17
- package/build/templates/self-handle-exception.txt +0 -32
- package/build/templates/test-entrypoint.txt +0 -45
- package/build/templates/test.txt +0 -5
- package/build/templates/tests/bootstrap.txt +0 -69
- package/build/templates/tests/functional/hello_world_api.spec.txt +0 -8
- package/build/templates/tests/functional/hello_world_slim.spec.txt +0 -8
- package/build/templates/tests/functional/hello_world_web.spec.txt +0 -8
- package/build/templates/tests-contract.txt +0 -18
- package/build/templates/validator.txt +0 -40
- package/build/templates/view.txt +0 -0
- package/build/templates/webpack.config.txt +0 -214
- /package/build/{register.d.ts → src/types.js} +0 -0
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/assembler
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.Compiler = void 0;
|
|
15
|
-
const slash_1 = __importDefault(require("slash"));
|
|
16
|
-
const cpy_1 = __importDefault(require("cpy"));
|
|
17
|
-
const path_1 = require("path");
|
|
18
|
-
const fs_extra_1 = require("fs-extra");
|
|
19
|
-
const ioc_transformer_1 = require("@adonisjs/ioc-transformer");
|
|
20
|
-
const cliui_1 = require("@poppinss/cliui");
|
|
21
|
-
const Ts_1 = require("../Ts");
|
|
22
|
-
const RcFile_1 = require("../RcFile");
|
|
23
|
-
const Manifest_1 = require("../Manifest");
|
|
24
|
-
const paths_1 = require("../../config/paths");
|
|
25
|
-
const AssetsBundler_1 = require("../AssetsBundler");
|
|
26
|
-
/**
|
|
27
|
-
* Exposes the API to build the AdonisJs project for development or
|
|
28
|
-
* production. The production build has it's own set of node_modules
|
|
29
|
-
*/
|
|
30
|
-
class Compiler {
|
|
31
|
-
constructor(appRoot, encoreArgs, buildAssets, logger = cliui_1.logger, tsconfig) {
|
|
32
|
-
this.appRoot = appRoot;
|
|
33
|
-
this.encoreArgs = encoreArgs;
|
|
34
|
-
this.buildAssets = buildAssets;
|
|
35
|
-
this.logger = logger;
|
|
36
|
-
/**
|
|
37
|
-
* Reference to rc File
|
|
38
|
-
*/
|
|
39
|
-
this.rcFile = new RcFile_1.RcFile(this.appRoot);
|
|
40
|
-
this.ts = new Ts_1.Ts(this.appRoot, this.logger, tsconfig);
|
|
41
|
-
this.ts.tsCompiler.use(() => {
|
|
42
|
-
return (0, ioc_transformer_1.iocTransformer)(this.ts.tsCompiler.ts, this.rcFile.application.rcFile);
|
|
43
|
-
}, 'after');
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Returns relative unix path from the project root. Used for
|
|
47
|
-
* display only
|
|
48
|
-
*/
|
|
49
|
-
getRelativeUnixPath(absPath) {
|
|
50
|
-
return (0, slash_1.default)((0, path_1.relative)(this.appRoot, absPath));
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Cleans up the build directory
|
|
54
|
-
*/
|
|
55
|
-
async cleanupBuildDirectory(outDir) {
|
|
56
|
-
this.getRelativeUnixPath(outDir);
|
|
57
|
-
this.logger.info(`cleaning up ${this.logger.colors
|
|
58
|
-
.dim()
|
|
59
|
-
.yellow(`"./${this.getRelativeUnixPath(outDir)}"`)} directory`);
|
|
60
|
-
await (0, fs_extra_1.remove)(outDir);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Copies .adonisrc.json file to the destination
|
|
64
|
-
*/
|
|
65
|
-
async copyAdonisRcFile(outDir) {
|
|
66
|
-
this.logger.info(`copy { ${this.logger.colors
|
|
67
|
-
.dim()
|
|
68
|
-
.yellow(`${paths_1.RCFILE_NAME} => ${this.getRelativeUnixPath(outDir)}`)} }`);
|
|
69
|
-
await (0, fs_extra_1.outputJSON)((0, path_1.join)(outDir, paths_1.RCFILE_NAME), Object.assign({}, this.rcFile.getDiskContents(), {
|
|
70
|
-
typescript: false,
|
|
71
|
-
lastCompiledAt: new Date().toISOString(),
|
|
72
|
-
}), { spaces: 2 });
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Copy all meta files to the build directory
|
|
76
|
-
*/
|
|
77
|
-
async copyMetaFiles(outDir, extraFiles) {
|
|
78
|
-
const metaFiles = this.rcFile.getMetaFilesGlob().concat(extraFiles || []);
|
|
79
|
-
this.logger.info(`copy { ${this.logger.colors
|
|
80
|
-
.dim()
|
|
81
|
-
.yellow(`${metaFiles.join(',')} => ${this.getRelativeUnixPath(outDir)}`)} }`);
|
|
82
|
-
await this.copyFiles(metaFiles, outDir);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Copy files to destination directory
|
|
86
|
-
*/
|
|
87
|
-
async copyFiles(files, outDir) {
|
|
88
|
-
try {
|
|
89
|
-
await (0, cpy_1.default)(files, outDir, { cwd: this.appRoot, parents: true });
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
if (!error.message.includes("the file doesn't exist")) {
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Build typescript source files
|
|
99
|
-
*/
|
|
100
|
-
buildTypescriptSource(config) {
|
|
101
|
-
this.logger.info('compiling typescript source files');
|
|
102
|
-
const builder = this.ts.tsCompiler.builder(config);
|
|
103
|
-
const { skipped, diagnostics } = builder.build();
|
|
104
|
-
if (skipped) {
|
|
105
|
-
this.logger.warning('typescript emit skipped');
|
|
106
|
-
}
|
|
107
|
-
if (diagnostics.length) {
|
|
108
|
-
this.logger.error('typescript compiler errors');
|
|
109
|
-
this.ts.renderDiagnostics(diagnostics, builder.host);
|
|
110
|
-
}
|
|
111
|
-
return {
|
|
112
|
-
skipped,
|
|
113
|
-
hasErrors: diagnostics.length > 0,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Log the message that ts build and failed
|
|
118
|
-
*/
|
|
119
|
-
logTsBuildFailed() {
|
|
120
|
-
this.logger.logError('');
|
|
121
|
-
this.logger.logError(this.logger.colors.bgRed(`Cannot complete the build process as there are typescript errors. Use "--ignore-ts-errors" flag to ignore Typescript errors`));
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Typecheck the project without emit
|
|
125
|
-
*/
|
|
126
|
-
async typeCheck() {
|
|
127
|
-
const config = this.ts.parseConfig();
|
|
128
|
-
if (!config) {
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
this.logger.info('type checking typescript source files');
|
|
132
|
-
config.options.noEmit = true;
|
|
133
|
-
const builder = this.ts.tsCompiler.builder(config);
|
|
134
|
-
const { diagnostics } = builder.build();
|
|
135
|
-
if (diagnostics.length) {
|
|
136
|
-
this.logger.error('typescript compiler errors');
|
|
137
|
-
this.ts.renderDiagnostics(diagnostics, builder.host);
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
this.logger.success('built successfully');
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Compile project. See [[Compiler.compileForProduction]] for
|
|
145
|
-
* production build
|
|
146
|
-
*/
|
|
147
|
-
async compile(stopOnError = true, extraFiles) {
|
|
148
|
-
const config = this.ts.parseConfig();
|
|
149
|
-
if (!config) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Bundle frontend assets when encore is installed
|
|
154
|
-
*/
|
|
155
|
-
const encore = await new AssetsBundler_1.AssetsBundler(this.appRoot, this.encoreArgs, this.buildAssets, this.logger).build();
|
|
156
|
-
/**
|
|
157
|
-
* Skipped, coz of frontend errors
|
|
158
|
-
*/
|
|
159
|
-
if (encore.hasErrors) {
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Always cleanup the out directory
|
|
164
|
-
*/
|
|
165
|
-
await this.cleanupBuildDirectory(config.options.outDir);
|
|
166
|
-
/**
|
|
167
|
-
* Build typescript source
|
|
168
|
-
*/
|
|
169
|
-
const ts = this.buildTypescriptSource(config);
|
|
170
|
-
/**
|
|
171
|
-
* Do not continue when output was skipped
|
|
172
|
-
*/
|
|
173
|
-
if (ts.skipped) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Do not continue when has errors and "stopOnError" is true
|
|
178
|
-
*/
|
|
179
|
-
if (stopOnError && ts.hasErrors) {
|
|
180
|
-
this.logTsBuildFailed();
|
|
181
|
-
await this.cleanupBuildDirectory(config.options.outDir);
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Begin by copying meta files
|
|
186
|
-
*/
|
|
187
|
-
await this.copyMetaFiles(config.options.outDir, extraFiles);
|
|
188
|
-
/**
|
|
189
|
-
* Copy `.adonisrc.json` file
|
|
190
|
-
*/
|
|
191
|
-
await this.copyAdonisRcFile(config.options.outDir);
|
|
192
|
-
/**
|
|
193
|
-
* Manifest instance to generate ace manifest file
|
|
194
|
-
*/
|
|
195
|
-
const manifest = new Manifest_1.Manifest(config.options.outDir, this.logger);
|
|
196
|
-
const created = await manifest.generate();
|
|
197
|
-
/**
|
|
198
|
-
* Do not continue when unable to generate the manifest file as commands
|
|
199
|
-
* won't be available
|
|
200
|
-
*/
|
|
201
|
-
if (!created) {
|
|
202
|
-
await this.cleanupBuildDirectory(config.options.outDir);
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
this.logger.success('built successfully');
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Compile project. See [[Compiler.compile]] for development build
|
|
210
|
-
*/
|
|
211
|
-
async compileForProduction(stopOnError = true, client) {
|
|
212
|
-
const config = this.ts.parseConfig();
|
|
213
|
-
if (!config) {
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Bundle frontend assets when encore is installed
|
|
218
|
-
*/
|
|
219
|
-
const encore = await new AssetsBundler_1.AssetsBundler(this.appRoot, this.encoreArgs, this.buildAssets, this.logger).buildForProduction();
|
|
220
|
-
/**
|
|
221
|
-
* Skipped, coz of frontend errors
|
|
222
|
-
*/
|
|
223
|
-
if (encore.hasErrors) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
const pkgFiles = client === 'npm' ? ['package.json', 'package-lock.json'] : ['package.json', 'yarn.lock'];
|
|
227
|
-
/**
|
|
228
|
-
* Always cleanup the out directory
|
|
229
|
-
*/
|
|
230
|
-
await this.cleanupBuildDirectory(config.options.outDir);
|
|
231
|
-
/**
|
|
232
|
-
* Build typescript source
|
|
233
|
-
*/
|
|
234
|
-
const { skipped, hasErrors } = this.buildTypescriptSource(config);
|
|
235
|
-
/**
|
|
236
|
-
* Do not continue when output was skipped
|
|
237
|
-
*/
|
|
238
|
-
if (skipped) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Do not continue when has errors and "stopOnError" is true and cleanup
|
|
243
|
-
* the build directory
|
|
244
|
-
*/
|
|
245
|
-
if (stopOnError && hasErrors) {
|
|
246
|
-
this.logTsBuildFailed();
|
|
247
|
-
await this.cleanupBuildDirectory(config.options.outDir);
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Begin by copying meta files
|
|
252
|
-
*/
|
|
253
|
-
await this.copyMetaFiles(config.options.outDir, pkgFiles);
|
|
254
|
-
/**
|
|
255
|
-
* Copy `.adonisrc.json` file
|
|
256
|
-
*/
|
|
257
|
-
await this.copyAdonisRcFile(config.options.outDir);
|
|
258
|
-
/**
|
|
259
|
-
* Generate commands manifest
|
|
260
|
-
*/
|
|
261
|
-
const manifest = new Manifest_1.Manifest(config.options.outDir, this.logger);
|
|
262
|
-
const created = await manifest.generate();
|
|
263
|
-
/**
|
|
264
|
-
* Do not continue when unable to generate the manifest file as commands
|
|
265
|
-
* won't be available
|
|
266
|
-
*/
|
|
267
|
-
if (!created) {
|
|
268
|
-
await this.cleanupBuildDirectory(config.options.outDir);
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Print usage instructions
|
|
273
|
-
*/
|
|
274
|
-
const installCommand = client === 'npm' ? 'npm ci --production' : 'yarn install --production';
|
|
275
|
-
const relativeBuildPath = this.getRelativeUnixPath(config.options.outDir);
|
|
276
|
-
this.logger.success('built successfully');
|
|
277
|
-
this.logger.log('');
|
|
278
|
-
(0, cliui_1.instructions)()
|
|
279
|
-
.heading('Run the following commands to start the server in production')
|
|
280
|
-
.add(this.logger.colors.cyan(`cd ${relativeBuildPath}`))
|
|
281
|
-
.add(this.logger.colors.cyan(installCommand))
|
|
282
|
-
.add(this.logger.colors.cyan('node server.js'))
|
|
283
|
-
.render();
|
|
284
|
-
return true;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
exports.Compiler = Compiler;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/assembler
|
|
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 });
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { logger as uiLogger } from '@poppinss/cliui';
|
|
2
|
-
/**
|
|
3
|
-
* Exposes the API to watch project for compilition changes.
|
|
4
|
-
*/
|
|
5
|
-
export declare class DevServer {
|
|
6
|
-
private appRoot;
|
|
7
|
-
private nodeArgs;
|
|
8
|
-
private encoreArgs;
|
|
9
|
-
private buildAssets;
|
|
10
|
-
private logger;
|
|
11
|
-
private httpServer;
|
|
12
|
-
/**
|
|
13
|
-
* HTTP server port
|
|
14
|
-
*/
|
|
15
|
-
private serverPort?;
|
|
16
|
-
/**
|
|
17
|
-
* HTTP server host
|
|
18
|
-
*/
|
|
19
|
-
private serverHost?;
|
|
20
|
-
/**
|
|
21
|
-
* Encore dev server host
|
|
22
|
-
*/
|
|
23
|
-
private encoreDevServerResponse;
|
|
24
|
-
/**
|
|
25
|
-
* A boolean to know if we are watching for filesystem
|
|
26
|
-
*/
|
|
27
|
-
private watchingFileSystem;
|
|
28
|
-
/**
|
|
29
|
-
* Watcher state
|
|
30
|
-
*/
|
|
31
|
-
private watcherState;
|
|
32
|
-
/**
|
|
33
|
-
* Reference to the typescript compiler
|
|
34
|
-
*/
|
|
35
|
-
private ts;
|
|
36
|
-
/**
|
|
37
|
-
* Reference to the RCFile
|
|
38
|
-
*/
|
|
39
|
-
private rcFile;
|
|
40
|
-
/**
|
|
41
|
-
* Manifest instance to generate ace manifest file
|
|
42
|
-
*/
|
|
43
|
-
private manifest;
|
|
44
|
-
/**
|
|
45
|
-
* Require-ts watch helpers
|
|
46
|
-
*/
|
|
47
|
-
private watchHelpers;
|
|
48
|
-
constructor(appRoot: string, nodeArgs: string[], encoreArgs: string[], buildAssets: boolean, logger?: typeof uiLogger);
|
|
49
|
-
/**
|
|
50
|
-
* Kill current process
|
|
51
|
-
*/
|
|
52
|
-
private kill;
|
|
53
|
-
/**
|
|
54
|
-
* Create the http server
|
|
55
|
-
*/
|
|
56
|
-
private createHttpServer;
|
|
57
|
-
/**
|
|
58
|
-
* Renders box to notify about the server state
|
|
59
|
-
*/
|
|
60
|
-
private renderServerIsReady;
|
|
61
|
-
/**
|
|
62
|
-
* Start the dev server. Use [[watch]] to also watch for file
|
|
63
|
-
* changes
|
|
64
|
-
*/
|
|
65
|
-
start(): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Build and watch for file changes
|
|
68
|
-
*/
|
|
69
|
-
watch(poll?: boolean): Promise<void>;
|
|
70
|
-
}
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/assembler
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.DevServer = void 0;
|
|
15
|
-
const get_port_1 = __importDefault(require("get-port"));
|
|
16
|
-
const require_ts_1 = require("@adonisjs/require-ts");
|
|
17
|
-
const cliui_1 = require("@poppinss/cliui");
|
|
18
|
-
const Ts_1 = require("../Ts");
|
|
19
|
-
const RcFile_1 = require("../RcFile");
|
|
20
|
-
const Manifest_1 = require("../Manifest");
|
|
21
|
-
const EnvParser_1 = require("../EnvParser");
|
|
22
|
-
const HttpServer_1 = require("../HttpServer");
|
|
23
|
-
const paths_1 = require("../../config/paths");
|
|
24
|
-
const AssetsBundler_1 = require("../AssetsBundler");
|
|
25
|
-
/**
|
|
26
|
-
* Exposes the API to watch project for compilition changes.
|
|
27
|
-
*/
|
|
28
|
-
class DevServer {
|
|
29
|
-
constructor(appRoot, nodeArgs = [], encoreArgs, buildAssets, logger = cliui_1.logger) {
|
|
30
|
-
this.appRoot = appRoot;
|
|
31
|
-
this.nodeArgs = nodeArgs;
|
|
32
|
-
this.encoreArgs = encoreArgs;
|
|
33
|
-
this.buildAssets = buildAssets;
|
|
34
|
-
this.logger = logger;
|
|
35
|
-
/**
|
|
36
|
-
* A boolean to know if we are watching for filesystem
|
|
37
|
-
*/
|
|
38
|
-
this.watchingFileSystem = false;
|
|
39
|
-
/**
|
|
40
|
-
* Watcher state
|
|
41
|
-
*/
|
|
42
|
-
this.watcherState = 'pending';
|
|
43
|
-
/**
|
|
44
|
-
* Reference to the typescript compiler
|
|
45
|
-
*/
|
|
46
|
-
this.ts = new Ts_1.Ts(this.appRoot, this.logger);
|
|
47
|
-
/**
|
|
48
|
-
* Reference to the RCFile
|
|
49
|
-
*/
|
|
50
|
-
this.rcFile = new RcFile_1.RcFile(this.appRoot);
|
|
51
|
-
/**
|
|
52
|
-
* Manifest instance to generate ace manifest file
|
|
53
|
-
*/
|
|
54
|
-
this.manifest = new Manifest_1.Manifest(this.appRoot, this.logger);
|
|
55
|
-
/**
|
|
56
|
-
* Require-ts watch helpers
|
|
57
|
-
*/
|
|
58
|
-
this.watchHelpers = (0, require_ts_1.getWatcherHelpers)(this.appRoot);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Kill current process
|
|
62
|
-
*/
|
|
63
|
-
kill() {
|
|
64
|
-
this.logger.info('shutting down');
|
|
65
|
-
process.exit();
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Create the http server
|
|
69
|
-
*/
|
|
70
|
-
async createHttpServer() {
|
|
71
|
-
if (this.httpServer) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const envParser = new EnvParser_1.EnvParser();
|
|
75
|
-
await envParser.parse(this.appRoot);
|
|
76
|
-
const envOptions = envParser.asEnvObject(['PORT', 'TZ', 'HOST']);
|
|
77
|
-
const HOST = process.env.HOST || envOptions.HOST || '0.0.0.0';
|
|
78
|
-
let PORT = process.env.PORT || envOptions.PORT || '3333';
|
|
79
|
-
/**
|
|
80
|
-
* Obtains a random port by giving preference to the one defined inside
|
|
81
|
-
* the `.env` file. This eases the process of running the application
|
|
82
|
-
* without manually changing ports inside the `.env` file when
|
|
83
|
-
* original port is in use.
|
|
84
|
-
*/
|
|
85
|
-
if (!isNaN(Number(PORT))) {
|
|
86
|
-
PORT = String(await (0, get_port_1.default)({
|
|
87
|
-
port: [Number(PORT)],
|
|
88
|
-
host: HOST,
|
|
89
|
-
}));
|
|
90
|
-
}
|
|
91
|
-
this.httpServer = new HttpServer_1.HttpServer(paths_1.SERVER_ENTRY_FILE, this.appRoot, this.nodeArgs, this.logger, {
|
|
92
|
-
PORT,
|
|
93
|
-
HOST,
|
|
94
|
-
TZ: envOptions.TZ,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Renders box to notify about the server state
|
|
99
|
-
*/
|
|
100
|
-
renderServerIsReady() {
|
|
101
|
-
if (!this.serverHost || !this.serverPort) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (this.watchingFileSystem && this.watcherState === 'pending') {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const stickerInstance = (0, cliui_1.sticker)();
|
|
108
|
-
stickerInstance
|
|
109
|
-
.add(`Server address: ${this.logger.colors.cyan(`http://${this.serverHost === '0.0.0.0' ? '127.0.0.1' : this.serverHost}:${this.serverPort}`)}`)
|
|
110
|
-
.add(`Watching filesystem for changes: ${this.logger.colors.cyan(this.watchingFileSystem ? 'YES' : 'NO')}`);
|
|
111
|
-
/**
|
|
112
|
-
* Running the encore dev server
|
|
113
|
-
*/
|
|
114
|
-
if (this.encoreDevServerResponse.state === 'running') {
|
|
115
|
-
stickerInstance.add(`Encore server address: ${this.logger.colors.cyan(`http://${this.encoreDevServerResponse.host}:${this.encoreDevServerResponse.port}`)}`);
|
|
116
|
-
}
|
|
117
|
-
stickerInstance.render();
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Start the dev server. Use [[watch]] to also watch for file
|
|
121
|
-
* changes
|
|
122
|
-
*/
|
|
123
|
-
async start() {
|
|
124
|
-
/**
|
|
125
|
-
* Log getting ready
|
|
126
|
-
*/
|
|
127
|
-
this.logger.info('building project...');
|
|
128
|
-
/**
|
|
129
|
-
* Start the HTTP server right away
|
|
130
|
-
*/
|
|
131
|
-
await this.createHttpServer();
|
|
132
|
-
this.httpServer.start();
|
|
133
|
-
/**
|
|
134
|
-
* Notify that the http server has died
|
|
135
|
-
*/
|
|
136
|
-
this.httpServer.on('exit', ({ code }) => {
|
|
137
|
-
this.logger.warning(`Underlying HTTP server died with "${code} code"`);
|
|
138
|
-
});
|
|
139
|
-
/**
|
|
140
|
-
* Notify that the http server is running
|
|
141
|
-
*/
|
|
142
|
-
this.httpServer.on('ready', ({ port, host }) => {
|
|
143
|
-
this.serverPort = port;
|
|
144
|
-
this.serverHost = host;
|
|
145
|
-
this.renderServerIsReady();
|
|
146
|
-
});
|
|
147
|
-
const encore = new AssetsBundler_1.AssetsBundler(this.appRoot, this.encoreArgs, this.buildAssets, this.logger);
|
|
148
|
-
encore.on('exit', ({ code }) => {
|
|
149
|
-
this.logger.warning(`Underlying encore dev server died with "${code} code"`);
|
|
150
|
-
});
|
|
151
|
-
this.encoreDevServerResponse = await encore.startDevServer();
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Build and watch for file changes
|
|
155
|
-
*/
|
|
156
|
-
async watch(poll = false) {
|
|
157
|
-
this.watchingFileSystem = true;
|
|
158
|
-
/**
|
|
159
|
-
* Clear require-ts cache
|
|
160
|
-
*/
|
|
161
|
-
this.watchHelpers.clear();
|
|
162
|
-
/**
|
|
163
|
-
* Start HTTP server
|
|
164
|
-
*/
|
|
165
|
-
await this.start();
|
|
166
|
-
/**
|
|
167
|
-
* Parse config to find the files excluded inside
|
|
168
|
-
* tsconfig file
|
|
169
|
-
*/
|
|
170
|
-
const config = this.ts.parseConfig();
|
|
171
|
-
if (!config) {
|
|
172
|
-
this.logger.warning('Cannot start watcher because of errors in the config file');
|
|
173
|
-
this.watcherState = 'error';
|
|
174
|
-
this.renderServerIsReady();
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Stick file watcher
|
|
179
|
-
*/
|
|
180
|
-
const watcher = this.ts.tsCompiler.watcher(config, 'raw');
|
|
181
|
-
/**
|
|
182
|
-
* Watcher is ready after first compile
|
|
183
|
-
*/
|
|
184
|
-
watcher.on('watcher:ready', () => {
|
|
185
|
-
this.logger.info('watching file system for changes');
|
|
186
|
-
this.watcherState = 'ready';
|
|
187
|
-
this.renderServerIsReady();
|
|
188
|
-
});
|
|
189
|
-
/**
|
|
190
|
-
* Source file removed
|
|
191
|
-
*/
|
|
192
|
-
watcher.on('source:unlink', async ({ absPath, relativePath }) => {
|
|
193
|
-
this.watchHelpers.clear(absPath);
|
|
194
|
-
this.logger.action('delete').succeeded(relativePath);
|
|
195
|
-
/**
|
|
196
|
-
* Generate manifest when filePath is a commands path
|
|
197
|
-
*/
|
|
198
|
-
if (this.rcFile.isCommandsPath(relativePath)) {
|
|
199
|
-
this.manifest.generate();
|
|
200
|
-
}
|
|
201
|
-
this.httpServer.restart();
|
|
202
|
-
});
|
|
203
|
-
/**
|
|
204
|
-
* Source file added
|
|
205
|
-
*/
|
|
206
|
-
watcher.on('source:add', async ({ absPath, relativePath }) => {
|
|
207
|
-
this.watchHelpers.clear(absPath);
|
|
208
|
-
this.logger.action('add').succeeded(relativePath);
|
|
209
|
-
/**
|
|
210
|
-
* Generate manifest when filePath if file is in commands path
|
|
211
|
-
*/
|
|
212
|
-
if (this.rcFile.isCommandsPath(relativePath)) {
|
|
213
|
-
this.manifest.generate();
|
|
214
|
-
}
|
|
215
|
-
this.httpServer.restart();
|
|
216
|
-
});
|
|
217
|
-
/**
|
|
218
|
-
* Source file changed
|
|
219
|
-
*/
|
|
220
|
-
watcher.on('source:change', async ({ absPath, relativePath }) => {
|
|
221
|
-
this.watchHelpers.clear(absPath);
|
|
222
|
-
this.logger.action('update').succeeded(relativePath);
|
|
223
|
-
/**
|
|
224
|
-
* Generate manifest when filePath is a commands path
|
|
225
|
-
*/
|
|
226
|
-
if (this.rcFile.isCommandsPath(relativePath)) {
|
|
227
|
-
this.manifest.generate();
|
|
228
|
-
}
|
|
229
|
-
this.httpServer.restart();
|
|
230
|
-
});
|
|
231
|
-
/**
|
|
232
|
-
* New file added
|
|
233
|
-
*/
|
|
234
|
-
watcher.on('add', async ({ relativePath }) => {
|
|
235
|
-
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
236
|
-
this.logger.action('create').succeeded(relativePath);
|
|
237
|
-
this.httpServer.restart();
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const metaData = this.rcFile.getMetaData(relativePath);
|
|
241
|
-
if (!metaData.metaFile) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
this.logger.action('create').succeeded(relativePath);
|
|
245
|
-
if (metaData.reload) {
|
|
246
|
-
this.httpServer.restart();
|
|
247
|
-
}
|
|
248
|
-
});
|
|
249
|
-
/**
|
|
250
|
-
* File changed
|
|
251
|
-
*/
|
|
252
|
-
watcher.on('change', async ({ relativePath }) => {
|
|
253
|
-
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
254
|
-
this.logger.action('update').succeeded(relativePath);
|
|
255
|
-
this.httpServer.restart();
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
const metaData = this.rcFile.getMetaData(relativePath);
|
|
259
|
-
if (!metaData.metaFile) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
this.logger.action('update').succeeded(relativePath);
|
|
263
|
-
if (metaData.reload || metaData.rcFile) {
|
|
264
|
-
this.httpServer.restart();
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
/**
|
|
268
|
-
* File removed
|
|
269
|
-
*/
|
|
270
|
-
watcher.on('unlink', async ({ relativePath }) => {
|
|
271
|
-
if (paths_1.ENV_FILES.includes(relativePath)) {
|
|
272
|
-
this.logger.action('delete').succeeded(relativePath);
|
|
273
|
-
this.httpServer.restart();
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
const metaData = this.rcFile.getMetaData(relativePath);
|
|
277
|
-
if (!metaData.metaFile) {
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
if (metaData.rcFile) {
|
|
281
|
-
this.logger.info('cannot continue after deletion of .adonisrc.json file');
|
|
282
|
-
watcher.chokidar.close();
|
|
283
|
-
this.kill();
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
this.logger.action('delete').succeeded(relativePath);
|
|
287
|
-
if (metaData.reload) {
|
|
288
|
-
this.httpServer.restart();
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
/**
|
|
292
|
-
* Start the watcher
|
|
293
|
-
*/
|
|
294
|
-
watcher.watch(['.'], {
|
|
295
|
-
usePolling: poll,
|
|
296
|
-
});
|
|
297
|
-
/**
|
|
298
|
-
* Kill when watcher recieves an error
|
|
299
|
-
*/
|
|
300
|
-
watcher.chokidar.on('error', (error) => {
|
|
301
|
-
this.logger.fatal(error);
|
|
302
|
-
this.kill();
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
exports.DevServer = DevServer;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parses the env file inside the project root.
|
|
3
|
-
*/
|
|
4
|
-
export declare class EnvParser {
|
|
5
|
-
private envContents;
|
|
6
|
-
constructor();
|
|
7
|
-
/**
|
|
8
|
-
* Parse .env file contents
|
|
9
|
-
*/
|
|
10
|
-
parse(rootDir: string): Promise<void>;
|
|
11
|
-
/**
|
|
12
|
-
* Returns value for a key inside the `.env` file
|
|
13
|
-
*/
|
|
14
|
-
get(key: string): string | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* Returns an env object for the keys that has defined values
|
|
17
|
-
*/
|
|
18
|
-
asEnvObject(keys: string[]): {
|
|
19
|
-
[key: string]: string;
|
|
20
|
-
};
|
|
21
|
-
}
|