UNPKG

1.15 kBPlain TextView Raw
1// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
2// Node module: @loopback/boot
3// This file is licensed under the MIT License.
4// License text available at https://opensource.org/licenses/MIT
5
6import {Application, CoreBindings, inject} from '@loopback/core';
7import debugModule from 'debug';
8import path from 'path';
9import {BootBindings} from '../keys';
10import {Booter} from '../types';
11
12const debug = debugModule('loopback:boot:booter:application-metadata');
13
14/**
15 *
16 * Configure the application with metadata from `package.json`
17 *
18 * @param app - Application instance
19 * @param projectRoot - Root of User Project
20 */
21export class ApplicationMetadataBooter implements Booter {
22 constructor(
23 @inject(CoreBindings.APPLICATION_INSTANCE) public app: Application,
24 @inject(BootBindings.PROJECT_ROOT) private projectRoot: string,
25 ) {}
26
27 async configure() {
28 try {
29 // `this.projectRoot` points to `<project>/dist`
30 const pkg = require(path.resolve(this.projectRoot, '../package.json'));
31 this.app.setMetadata(pkg);
32 } catch (err) {
33 debug('package.json not found', err);
34 }
35 }
36}