Skip to content

Commit d74b237

Browse files
bajtosraymondfeng
authored andcommitted
fixup! update CLI templates
Signed-off-by: Miroslav Bajtoš <[email protected]>
1 parent 83b2695 commit d74b237

File tree

11 files changed

+59
-69
lines changed

11 files changed

+59
-69
lines changed

packages/cli/generators/app/templates/index.js.ejs

Lines changed: 0 additions & 27 deletions
This file was deleted.

packages/cli/generators/app/templates/src/application.ts.ejs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
import path from 'path';
2222
import {MySequence} from './sequence';
2323

24+
export {ApplicationConfig};
25+
2426
<% if (project.appClassWithMixins) { -%>
2527
export class <%= project.applicationName %> extends BootMixin(
2628
<%= project.appClassWithMixins %>,

packages/cli/generators/app/templates/src/index.ts.ejs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import {<%= project.applicationName %>} from './application';
2-
import {ApplicationConfig} from '@loopback/core';
1+
import {ApplicationConfig, <%= project.applicationName %>} from './application';
32

4-
export {<%= project.applicationName %>};
3+
export * from './application';
54

65
export async function main(options: ApplicationConfig = {}) {
76
const app = new <%= project.applicationName %>(options);
@@ -14,3 +13,27 @@ export async function main(options: ApplicationConfig = {}) {
1413

1514
return app;
1615
}
16+
17+
if (require.main === module) {
18+
// Run the application
19+
const config = {
20+
rest: {
21+
port: +(process.env.PORT ?? 3000),
22+
host: process.env.HOST,
23+
// The `gracePeriodForClose` provides a graceful close for http/https
24+
// servers with keep-alive clients. The default value is `Infinity`
25+
// (don't force-close). If you want to immediately destroy all sockets
26+
// upon stop, set its value to `0`.
27+
// See https://www.npmjs.com/package/stoppable
28+
gracePeriodForClose: 5000, // 5 seconds
29+
openApiSpec: {
30+
// useful when used with OpenAPI-to-GraphQL to locate your application
31+
setServersFromRequest: true,
32+
},
33+
},
34+
};
35+
main(config).catch(err => {
36+
console.error('Cannot start the application.', err);
37+
process.exit(1);
38+
});
39+
}

packages/cli/generators/extension/templates/index.d.ts.ejs

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/cli/generators/extension/templates/index.js.ejs

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/cli/generators/project/templates/index.ts.ejs

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/cli/generators/project/templates/package.json.ejs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"loopback-<%= project.projectType -%>",
77
"loopback"
88
],
9-
"main": "index.js",
9+
"main": "dist/index.js",
10+
"types": "dist/index.d.ts",
1011
"engines": {
1112
"node": ">=10"
1213
},
@@ -65,8 +66,6 @@
6566
"license": "",
6667
"files": [
6768
"README.md",
68-
"index.js",
69-
"index.d.ts",
7069
"dist",
7170
"src",
7271
"!*/__tests__"

packages/cli/generators/project/templates/package.plain.json.ejs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"loopback-<%= project.projectType -%>",
77
"loopback"
88
],
9-
"main": "index.js",
9+
"main": "dist/index.js",
10+
"main": "types/index.d.ts",
1011
"engines": {
1112
"node": ">=10"
1213
},
@@ -65,8 +66,6 @@
6566
"license": "",
6667
"files": [
6768
"README.md",
68-
"index.js",
69-
"index.d.ts",
7069
"dist",
7170
"src",
7271
"!*/__tests__"

packages/cli/snapshots/integration/generators/app.integration.snapshots.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {ServiceMixin} from '@loopback/service-proxy';
2020
import path from 'path';
2121
import {MySequence} from './sequence';
2222
23+
export {ApplicationConfig};
24+
2325
export class MyAppApplication extends BootMixin(
2426
ServiceMixin(RepositoryMixin(RestApplication)),
2527
) {
@@ -55,15 +57,27 @@ export class MyAppApplication extends BootMixin(
5557

5658

5759
exports[`app-generator specific files generates all the proper files 2`] = `
58-
const application = require('./dist');
60+
import {ApplicationConfig, MyAppApplication} from './application';
61+
62+
export * from './application';
5963
60-
module.exports = application;
64+
export async function main(options: ApplicationConfig = {}) {
65+
const app = new MyAppApplication(options);
66+
await app.boot();
67+
await app.start();
68+
69+
const url = app.restServer.url;
70+
console.log(\`Server is running at \${url}\`);
71+
console.log(\`Try \${url}/ping\`);
72+
73+
return app;
74+
}
6175
6276
if (require.main === module) {
6377
// Run the application
6478
const config = {
6579
rest: {
66-
port: +(process.env.PORT || 3000),
80+
port: +(process.env.PORT ?? 3000),
6781
host: process.env.HOST,
6882
// The \`gracePeriodForClose\` provides a graceful close for http/https
6983
// servers with keep-alive clients. The default value is \`Infinity\`
@@ -77,7 +91,7 @@ if (require.main === module) {
7791
},
7892
},
7993
};
80-
application.main(config).catch(err => {
94+
main(config).catch(err => {
8195
console.error('Cannot start the application.', err);
8296
process.exit(1);
8397
});
@@ -87,27 +101,6 @@ if (require.main === module) {
87101

88102

89103
exports[`app-generator specific files generates all the proper files 3`] = `
90-
import {MyAppApplication} from './application';
91-
import {ApplicationConfig} from '@loopback/core';
92-
93-
export {MyAppApplication};
94-
95-
export async function main(options: ApplicationConfig = {}) {
96-
const app = new MyAppApplication(options);
97-
await app.boot();
98-
await app.start();
99-
100-
const url = app.restServer.url;
101-
console.log(\`Server is running at \${url}\`);
102-
console.log(\`Try \${url}/ping\`);
103-
104-
return app;
105-
}
106-
107-
`;
108-
109-
110-
exports[`app-generator specific files generates all the proper files 4`] = `
111104
import {Request, RestBindings, get, ResponseObject} from '@loopback/rest';
112105
import {inject} from '@loopback/context';
113106
@@ -164,7 +157,7 @@ export class PingController {
164157
`;
165158

166159

167-
exports[`app-generator specific files generates all the proper files 5`] = `
160+
exports[`app-generator specific files generates all the proper files 4`] = `
168161
import {Client, expect} from '@loopback/testlab';
169162
import {MyAppApplication} from '../..';
170163
import {setupApplication} from './test-helper';
@@ -190,7 +183,7 @@ describe('PingController', () => {
190183
`;
191184

192185

193-
exports[`app-generator specific files generates all the proper files 6`] = `
186+
exports[`app-generator specific files generates all the proper files 5`] = `
194187
import {Client} from '@loopback/testlab';
195188
import {MyAppApplication} from '../..';
196189
import {setupApplication} from './test-helper';
@@ -226,7 +219,7 @@ describe('HomePage', () => {
226219
`;
227220

228221

229-
exports[`app-generator specific files generates all the proper files 7`] = `
222+
exports[`app-generator specific files generates all the proper files 6`] = `
230223
import {MyAppApplication} from '../..';
231224
import {
232225
createRestAppClient,
@@ -349,6 +342,8 @@ import {
349342
import path from 'path';
350343
import {MySequence} from './sequence';
351344
345+
export {ApplicationConfig};
346+
352347
export class MyAppApplication extends BootMixin(
353348
ServiceMixin(RepositoryMixin(RestApplication)),
354349
) {
@@ -403,6 +398,8 @@ import {ServiceMixin} from '@loopback/service-proxy';
403398
import path from 'path';
404399
import {MySequence} from './sequence';
405400
401+
export {ApplicationConfig};
402+
406403
export class MyApp extends BootMixin(
407404
ServiceMixin(RepositoryMixin(RestApplication)),
408405
) {
@@ -450,6 +447,8 @@ import {ServiceMixin} from '@loopback/service-proxy';
450447
import path from 'path';
451448
import {MySequence} from './sequence';
452449
450+
export {ApplicationConfig};
451+
453452
export class MyApp extends BootMixin(
454453
ServiceMixin(RepositoryMixin(RestApplication)),
455454
) {

packages/cli/test/integration/generators/app.integration.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ describe('app-generator specific files', () => {
4242
assertFilesToMatchSnapshot(
4343
{},
4444
'src/application.ts',
45-
'index.js',
4645
'src/index.ts',
4746
'src/controllers/ping.controller.ts',
4847
'src/__tests__/acceptance/ping.controller.acceptance.ts',

packages/cli/test/integration/lib/project-generator.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ module.exports = function (projGenerator, props, projectType) {
365365
['.eslintrc.js', "extends: '@loopback/eslint-config'"],
366366
['tsconfig.json', '"compilerOptions"'],
367367
['tsconfig.json', '"resolveJsonModule": true'],
368-
['index.js', "require('./dist')"],
369368
]);
370369
});
371370
});

0 commit comments

Comments
 (0)