Skip to content

Commit b086d2d

Browse files
feat(cli): lb4 service install service-proxy if missing
1 parent d4f5b5c commit b086d2d

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

packages/cli/generators/service/index.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
6161
async checkPaths() {
6262
// check for datasources
6363
if (!fs.existsSync(this.artifactInfo.datasourcesDir)) {
64-
return this.exit(
65-
new Error(
66-
`${ERROR_NO_DATA_SOURCES_FOUND} ${
67-
this.artifactInfo.datasourcesDir
68-
}.${chalk.yellow(
69-
'Please visit https://loopback.io/doc/en/lb4/DataSource-generator.html for information on how datasources are discovered',
70-
)}`,
71-
),
64+
new Error(
65+
`${ERROR_NO_DATA_SOURCES_FOUND} ${
66+
this.artifactInfo.datasourcesDir
67+
}. ${chalk.yellow(
68+
'Please visit https://loopback.io/doc/en/lb4/DataSource-generator.html for information on how datasources are discovered',
69+
)}`,
7270
);
7371
}
7472
}
@@ -142,7 +140,7 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
142140
new Error(
143141
`${ERROR_NO_DATA_SOURCES_FOUND} ${
144142
this.artifactInfo.datasourcesDir
145-
}.${chalk.yellow(
143+
}. ${chalk.yellow(
146144
'Please visit https://loopback.io/doc/en/lb4/DataSource-generator.html for information on how datasources are discovered',
147145
)}`,
148146
),
@@ -223,10 +221,9 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
223221
path.join(this.artifactInfo.outDir, this.artifactInfo.outFile),
224222
);
225223

226-
if (debug.enabled) {
227-
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
228-
debug(`Copying artifact to: ${dest}`);
229-
}
224+
debug(`artifactInfo: ${inspect(this.artifactInfo)}`);
225+
debug(`Copying artifact to: ${dest}`);
226+
230227
this.fs.copyTpl(
231228
source,
232229
dest,
@@ -237,6 +234,19 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
237234
return;
238235
}
239236

237+
install() {
238+
if (this.shouldExit()) return false;
239+
debug('install npm dependencies');
240+
const pkgJson = this.packageJson || {};
241+
const deps = pkgJson.dependencies || {};
242+
const pkgs = [];
243+
244+
if (!deps['@loopback/service-proxy']) {
245+
pkgs.push('@loopback/service-proxy');
246+
}
247+
if (pkgs.length) this.npmInstall(pkgs, {save: true});
248+
}
249+
240250
async end() {
241251
await super.end();
242252
}

0 commit comments

Comments
 (0)