Skip to content

Commit

Permalink
refactor(CLI): Modern logs for install command
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Oct 1, 2021
1 parent 7d31410 commit bd4d215
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
32 changes: 18 additions & 14 deletions lib/plugins/install.js
Expand Up @@ -4,6 +4,7 @@ const BbPromise = require('bluebird');

const cliCommandsSchema = require('../cli/commands-schema');
const download = require('../utils/downloadTemplateFromRepo');
const { legacy, log, progress, style } = require('@serverless/utils/log');

class Install {
constructor(serverless, options) {
Expand All @@ -22,20 +23,23 @@ class Install {
}

async install() {
return download
.downloadTemplateFromRepo(this.options.url, this.options.name)
.then((serviceName) => {
const message = [
`Successfully installed "${serviceName}" `,
`${
this.options.name && this.options.name !== serviceName
? `as "${this.options.name}"`
: ''
}`,
].join('');

this.serverless.cli.log(message);
});
const commandRunStartTime = Date.now();
progress.get('main').notice(`Downloading service from provided url: ${this.options.url}`);
const serviceName = await download.downloadTemplateFromRepo(
this.options.url,
this.options.name
);
const message = [
`Successfully installed "${serviceName}" `,
`${
this.options.name && this.options.name !== serviceName ? `as "${this.options.name}"` : ''
}`,
].join('');

legacy.log(message);
log.notice.success(
`${message} ${style.aside(`(${Math.floor((Date.now() - commandRunStartTime) / 1000)}s)`)}`
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/utils/downloadTemplateFromRepo.js
Expand Up @@ -13,7 +13,7 @@ const renameService = require('./renameService').renameService;
const ServerlessError = require('../serverless-error');
const copyDirContentsSync = require('./fs/copyDirContentsSync');
const dirExistsSync = require('./fs/dirExistsSync');
const log = require('./log/serverlessLog');
const { legacy } = require('@serverless/utils/log');

/**
* Returns directory path
Expand Down Expand Up @@ -291,7 +291,7 @@ async function downloadTemplateFromRepo(inputUrl, templateName, downloadPath, op
}

if (!options.silent) {
log(`Downloading and installing "${serviceName}"...`);
legacy.log(`Downloading and installing "${serviceName}"...`);
}

if (isPlainGitURL(inputUrl)) {
Expand Down
12 changes: 0 additions & 12 deletions test/unit/lib/plugins/install.test.js
Expand Up @@ -16,7 +16,6 @@ describe('Install', () => {
let install;
let serverless;
let cwd;
let logSpy;

let serviceDir;

Expand All @@ -33,7 +32,6 @@ describe('Install', () => {
install = new Install(serverless);
return serverless.init().then(() => {
install.serverless.cli = new serverless.classes.CLI();
logSpy = sinon.spy(install.serverless.cli, 'log');
});
});

Expand Down Expand Up @@ -112,12 +110,7 @@ describe('Install', () => {
downloadStub.resolves('remote-service');

return install.install().then(() => {
const installationMessage = logSpy.args.filter((arg) =>
arg[0].includes('installed "remote-service"')
);

expect(downloadStub).to.have.been.calledOnce;
expect(installationMessage[0]).to.have.lengthOf(1);
});
});

Expand All @@ -127,12 +120,7 @@ describe('Install', () => {
downloadStub.resolves('remote-service');

return install.install().then(() => {
const installationMessage = logSpy.args.filter((arg) =>
arg[0].includes('installed "remote-service" as "remote"')
);

expect(downloadStub).to.have.been.calledOnce;
expect(installationMessage[0]).to.have.lengthOf(1);
});
});
});
Expand Down

0 comments on commit bd4d215

Please sign in to comment.