Skip to content

Commit

Permalink
feat: Update dashboard link to point new one
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 27, 2020
1 parent 74b7731 commit 973f14a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 28 deletions.
19 changes: 9 additions & 10 deletions lib/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';

const { urls } = require('@serverless/platform-sdk');
const dashboardUrl =
process.env.SERVERLESS_PLATFORM_STAGE === 'dev'
? 'https://app.serverless-dev.com/'
: 'https://app.serverless.com/';

module.exports.getDashboardUrl = (ctx) => {
let dashboardUrl = urls.frontendUrl;
if (ctx.sls.enterpriseEnabled) {
dashboardUrl += `tenants/${ctx.sls.service.org}/`;
dashboardUrl += `applications/${ctx.sls.service.app}/`;
dashboardUrl += `services/${ctx.sls.service.service}/`;
dashboardUrl += `stage/${ctx.provider.getStage()}/`;
dashboardUrl += `region/${ctx.provider.getRegion()}`;
}
return dashboardUrl;
if (!ctx.sls.enterpriseEnabled) return dashboardUrl;
const { service } = ctx.sls;
return `${dashboardUrl}${service.org}/apps/${service.app}/${
service.service
}/${ctx.provider.getStage()}/${ctx.provider.getRegion()}`;
};
5 changes: 3 additions & 2 deletions lib/deployment/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* - This uses the new deployment data model.
*/

const { getDashboardUrl } = require('../dashboard');
const parseDeploymentData = require('./parse');

module.exports = async function (ctx, archived = false) {
ctx.sls.cli.log('Publishing service to the Serverless Dashboard...');

const deployment = await parseDeploymentData(ctx, undefined, undefined, archived);

const result = await deployment.save();
await deployment.save();

ctx.sls.cli.log(
`Successfully published your service to the Serverless Dashboard: ${result.dashboardUrl}`
`Successfully published your service to the Serverless Dashboard: ${getDashboardUrl(ctx)}`
);
};
6 changes: 3 additions & 3 deletions lib/deployment/save.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const sinon = require('sinon');
const proxyquire = require('proxyquire');

const parseSave = sinon.stub().resolves({ dashboardUrl: 'https://dashboard.serverless.com/foo' });
const parseSave = sinon.stub().resolves({});
const parseDeploymentData = sinon.stub().resolves({ save: parseSave });
const saveDeployment = proxyquire('./save', {
'./parse': parseDeploymentData,
Expand All @@ -21,8 +21,8 @@ describe('saveDeployment', () => {
await saveDeployment(ctx);
expect(parseDeploymentData.args[0]).to.deep.equal([ctx, undefined, undefined, false]);
expect(parseSave.calledOnce).to.be.true;
expect(log.lastCall.args[0]).to.equal(
'Successfully published your service to the Serverless Dashboard: https://dashboard.serverless.com/foo'
expect(log.lastCall.args[0]).includes(
'Successfully published your service to the Serverless Dashboard'
);
});
});
5 changes: 3 additions & 2 deletions lib/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

const serializeError = require('./serializeError');
const { getDashboardUrl } = require('./dashboard');
const { parseDeploymentData } = require('./deployment');

module.exports = function (ctx) {
Expand All @@ -18,10 +19,10 @@ module.exports = function (ctx) {

const deployment = await parseDeploymentData(ctx, 'error', serializeError(error));

const result = await deployment.save();
await deployment.save();

ctx.sls.cli.log(
`Successfully published your service to the Serverless Dashboard: ${result.dashboardUrl}`
`Successfully published your service to the Serverless Dashboard: ${getDashboardUrl(ctx)}`
);
if (!ctx.state.deployment) {
ctx.state.deployment = {};
Expand Down
8 changes: 3 additions & 5 deletions lib/errorHandler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ describe('errorHandler', () => {
expect(parseDeploymentData.args[0][1]).to.equal('error');
expect(ctx.sls.cli.log.calledWith('Publishing service to the Serverless Dashboard...')).to.be
.true;
expect(
ctx.sls.cli.log.calledWith(
'Successfully published your service to the Serverless Dashboard: URL'
)
).to.be.true;
expect(ctx.sls.cli.log.lastCall.args[0]).includes(
'Successfully published your service to the Serverless Dashboard'
);
});
});
7 changes: 1 addition & 6 deletions lib/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const proxyquire = require('proxyquire');
const sinon = require('sinon');
const chalk = require('chalk');

const _ = require('lodash');

Expand Down Expand Up @@ -277,11 +276,7 @@ describe('plugin', () => {
expect(
// eslint-disable-next-line no-console
console.log.args[0][0]
).to.equal(
chalk.yellow(
'Run "serverless dashboard" to open the dashboard or visit https://dashboard/tenants/org/applications/app/services/service/stage/stage/region/region'
)
);
).to.include('Run "serverless dashboard" to open the dashboard or visit ');
});

it('sets app & org from CLI flags if not in interactive mode', async () => {
Expand Down

0 comments on commit 973f14a

Please sign in to comment.