Skip to content

Commit

Permalink
feat(start): direct user to admin interface
Browse files Browse the repository at this point in the history
closes #665

- added a new message that shows the URL to the admin interface
- uses custom admin URL, if set in config
- shows a slightly different message when rendered after the `install` process
  • Loading branch information
aileen authored and acburdine committed May 10, 2018
1 parent 4715aae commit 2850af3
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 9 deletions.
16 changes: 15 additions & 1 deletion lib/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class StartCommand extends Command {

run(argv) {
const ProcessManager = require('../process-manager');
const url = require('url');
const chalk = require('chalk');

const instance = this.system.getInstance();
const runOptions = {quiet: argv.quiet};
Expand Down Expand Up @@ -59,7 +61,19 @@ class StartCommand extends Command {
});
}).then(() => {
if (!argv.quiet) {
this.ui.log(`You can access your blog at ${instance.config.get('url')}`, 'cyan');
const isInstall = process.argv[2] === 'install';
let adminUrl = instance.config.get('admin.url') || instance.config.get('url');

adminUrl = url.resolve(adminUrl, '/ghost/');

this.ui.log(`You can access your publication at ${chalk.cyan(instance.config.get('url'))}`, 'white');

if (isInstall) {
// Show a different message after a fresh install
this.ui.log(`Next, go to to your admin interface at ${chalk.cyan(adminUrl)} to complete the setup of your publication`, 'white');
} else {
this.ui.log(`Your admin interface is located at ${chalk.cyan(adminUrl)}`, 'white');
}

if (instance.config.get('mail.transport') === 'Direct') {
this.ui.log('\nGhost uses direct mail by default', 'green');
Expand Down
75 changes: 67 additions & 8 deletions test/unit/commands/start-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const proxyquire = require('proxyquire').noCallThru();

const modulePath = '../../../lib/commands/start';
const StartCommand = require(modulePath);
const sandbox = sinon.sandbox.create();

describe('Unit: Commands > Start', function () {
describe('run', function () {
Expand All @@ -13,7 +14,8 @@ describe('Unit: Commands > Start', function () {
beforeEach(function () {
myInstance = {
checkEnvironment: () => true,
running: () => Promise.resolve(false)
running: () => Promise.resolve(false),
config: {get: sandbox.stub()}
};

mySystem = {
Expand All @@ -22,6 +24,10 @@ describe('Unit: Commands > Start', function () {
};
});

afterEach(function () {
sandbox.restore();
});

it('gracefully notifies of already running instance', function () {
const runningStub = sinon.stub().resolves(true)
const logStub = sinon.stub();
Expand Down Expand Up @@ -184,7 +190,30 @@ describe('Unit: Commands > Start', function () {
});

it('is normally loud', function () {
myInstance.config = {get: () => ''};
myInstance.config.get.withArgs('url').returns('https://my-amazing.blog.com');
myInstance.process = {};
const ui = {
run: () => Promise.resolve(),
listr: () => Promise.resolve(),
log: sinon.stub()
};
const start = new StartCommand(ui, mySystem);
const runCommandStub = sinon.stub(start, 'runCommand').resolves();
return start.run({enable: false}).then(() => {
expect(runCommandStub.calledOnce).to.be.true;
expect(ui.log.calledTwice).to.be.true;
expect(ui.log.args[0][0]).to.match(/You can access your publication at/);
expect(ui.log.args[0][0]).to.include('https://my-amazing.blog.com');
expect(ui.log.args[1][0]).to.match(/Your admin interface is located at/);
expect(ui.log.args[1][0]).to.include('https://my-amazing.blog.com/ghost');
});
});

it('shows custom admin url', function () {
const oldArgv = process.argv;
process.argv = ['', '', 'start']
myInstance.config.get.withArgs('url').returns('https://my-amazing.blog.com');
myInstance.config.get.withArgs('admin.url').returns('https://admin.my-amazing.blog.com');
myInstance.process = {};
const ui = {
run: () => Promise.resolve(),
Expand All @@ -195,13 +224,43 @@ describe('Unit: Commands > Start', function () {
const runCommandStub = sinon.stub(start, 'runCommand').resolves();
return start.run({enable: false}).then(() => {
expect(runCommandStub.calledOnce).to.be.true;
expect(ui.log.calledOnce).to.be.true;
expect(ui.log.args[0][0]).to.match(/You can access your blog/);
expect(ui.log.calledTwice).to.be.true;
expect(ui.log.args[0][0]).to.match(/You can access your publication at/);
expect(ui.log.args[0][0]).to.include('https://my-amazing.blog.com');
expect(ui.log.args[1][0]).to.match(/Your admin interface is located at/);
expect(ui.log.args[1][0]).to.include('https://admin.my-amazing.blog.com/ghost');

process.argv = oldArgv;
});
});

it('shows different message after fresh install', function () {
const oldArgv = process.argv;
process.argv = ['', '', 'install']
myInstance.config.get.withArgs('url').returns('https://my-amazing.blog.com');
myInstance.process = {};
const ui = {
run: () => Promise.resolve(),
listr: () => Promise.resolve(),
log: sinon.stub()
};
const start = new StartCommand(ui, mySystem);
const runCommandStub = sinon.stub(start, 'runCommand').resolves();
return start.run({enable: false}).then(() => {
expect(runCommandStub.calledOnce).to.be.true;
expect(ui.log.calledTwice).to.be.true;
expect(ui.log.args[0][0]).to.match(/You can access your publication at/);
expect(ui.log.args[0][0]).to.include('https://my-amazing.blog.com');
expect(ui.log.args[1][0]).to.match(/Next, go to to your admin interface at /);
expect(ui.log.args[1][0]).to.include('https://my-amazing.blog.com/ghost');

process.argv = oldArgv;
});
});

it('warns of direct mail transport', function () {
myInstance.config = {get: () => 'Direct'};
myInstance.config.get.withArgs('url').returns('https://my-amazing.blog.com');
myInstance.config.get.withArgs('mail.transport').returns('Direct');
myInstance.process = {};
const ui = {
run: () => Promise.resolve(),
Expand All @@ -212,9 +271,9 @@ describe('Unit: Commands > Start', function () {
const runCommandStub = sinon.stub(start, 'runCommand').resolves();
return start.run({enable: false}).then(() => {
expect(runCommandStub.calledOnce).to.be.true;
expect(ui.log.calledThrice).to.be.true;
expect(ui.log.args[1][0]).to.match(/Ghost uses direct mail/);
expect(ui.log.args[2][0]).to.match(/alternative email method/);
expect(ui.log.callCount).to.equal(4);
expect(ui.log.args[2][0]).to.match(/Ghost uses direct mail/);
expect(ui.log.args[3][0]).to.match(/alternative email method/);
});
});
});
Expand Down

0 comments on commit 2850af3

Please sign in to comment.