Skip to content

Commit

Permalink
fix(cli): install deps if necessary for datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed Jul 10, 2018
1 parent 77f15c7 commit 4c605b0
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions packages/cli/generators/datasource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,26 +223,6 @@ module.exports = class DataSourceGenerator extends ArtifactGenerator {
});
}

install() {
debug('install npm dependencies');
const pkgs = [];

// Connector package.
const connector = connectors[this.artifactInfo.connector];
if (connector && connector.package) {
pkgs.push(
connector.package.name +
`${connector.package.version ? '@' + connector.package.version : ''}`,
);

debug(`npmModule - ${pkgs[0]}`);
}

pkgs.push('@loopback/repository');

this.npmInstall(pkgs, {save: true});
}

/**
* Scaffold DataSource related files
* super.scaffold() doesn't provide a way to rename files -- don't call it
Expand Down Expand Up @@ -304,6 +284,35 @@ module.exports = class DataSourceGenerator extends ArtifactGenerator {
this.fs.copyTpl(classTemplatePath, tsPath, this.artifactInfo);
}

install() {
if (this.shouldExit()) return false;
debug('install npm dependencies');
const pkgJson = this.packageJson || {};
const deps = pkgJson.dependencies || {};
const pkgs = [];

// Connector package.
const connector = connectors[this.artifactInfo.connector];
if (connector && connector.package) {
if (!deps[connector.package.name]) {
pkgs.push(
connector.package.name +
`${
connector.package.version ? '@' + connector.package.version : ''
}`,
);
}

debug(`npmModule - ${pkgs[0]}`);
}

if (!deps['@loopback/repository']) {
pkgs.push('@loopback/repository');
}

if (pkgs.length) this.npmInstall(pkgs, {save: true});
}

async end() {
await super.end();
}
Expand Down

0 comments on commit 4c605b0

Please sign in to comment.