Skip to content

Commit 31aa5ea

Browse files
committed
feat(example-greeter-extension): add npm start script to run the example app
1 parent 633821f commit 31aa5ea

File tree

6 files changed

+52
-12
lines changed

6 files changed

+52
-12
lines changed

examples/greeter-extension/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,16 @@ app.bind('greeters.ChineseGreeter.options').to({nameFirst: false});
354354
- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md)
355355
- [Join the team](https://github.com/strongloop/loopback-next/issues/110)
356356

357+
## Try out
358+
359+
Run `npm start` from the root folder to run the sample application. You should
360+
see the following message:
361+
362+
```
363+
English: Hello, Raymond
364+
Chinese: Raymond,你好
365+
```
366+
357367
## Tests
358368

359369
Run `npm test` from the root folder.

examples/greeter-extension/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
// License text available at https://opensource.org/licenses/MIT
55

66
module.exports = require('./dist');
7+
8+
if (require.main === module) {
9+
const app = new module.exports.GreetingApplication();
10+
app.main();
11+
}

examples/greeter-extension/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
2323
"posttest": "npm run lint",
2424
"test:dev": "lb-mocha --allow-console-logs dist/__tests__/**/*.js && npm run posttest",
25+
"prestart": "npm run build",
26+
"start": "node .",
2527
"verify": "npm pack && tar xf *example-greeter-extension*.tgz && tree package && npm run clean"
2628
},
2729
"repository": {

examples/greeter-extension/src/__tests__/greeter-extension.acceptance.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
import {Application, bind, createBindingFromClass} from '@loopback/core';
6+
import {bind, createBindingFromClass} from '@loopback/core';
77
import {expect} from '@loopback/testlab';
88
import chalk from 'chalk';
9-
import {
10-
asGreeter,
11-
Greeter,
12-
GreeterComponent,
13-
GreetingService,
14-
GREETING_SERVICE,
15-
} from '..';
9+
import {asGreeter, Greeter, GreetingService, GREETING_SERVICE} from '..';
10+
import {GreetingApplication} from '../application';
1611

1712
describe('greeter-extension-pont', () => {
18-
let app: Application;
13+
let app: GreetingApplication;
1914
let greetingService: GreetingService;
2015

2116
beforeEach(givenAppWithGreeterComponent);
@@ -71,11 +66,10 @@ describe('greeter-extension-pont', () => {
7166
});
7267

7368
function givenAppWithGreeterComponent() {
74-
app = new Application();
75-
app.component(GreeterComponent);
69+
app = new GreetingApplication();
7670
}
7771

7872
async function findGreetingService() {
79-
greetingService = await app.get(GREETING_SERVICE);
73+
greetingService = await app.getGreetingService();
8074
}
8175
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright IBM Corp. 2019. All Rights Reserved.
2+
// Node module: @loopback/example-greeter-extension
3+
// This file is licensed under the MIT License.
4+
// License text available at https://opensource.org/licenses/MIT
5+
6+
/* istanbul ignore file */
7+
import {Application} from '@loopback/core';
8+
import {GreeterComponent} from './component';
9+
import {GREETING_SERVICE} from './keys';
10+
11+
export class GreetingApplication extends Application {
12+
constructor() {
13+
super();
14+
this.component(GreeterComponent);
15+
}
16+
17+
async main() {
18+
const greetingService = await this.getGreetingService();
19+
let msg = await greetingService.greet('en', 'Raymond');
20+
console.log('English:', msg);
21+
msg = await greetingService.greet('zh', 'Raymond');
22+
console.log('Chinese:', msg);
23+
}
24+
25+
async getGreetingService() {
26+
return await this.get(GREETING_SERVICE);
27+
}
28+
}

examples/greeter-extension/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6+
export * from './application';
67
export * from './component';
78
export * from './greeting-service';
89
export * from './keys';

0 commit comments

Comments
 (0)