Skip to content

Commit

Permalink
Add rdme open command to open the current logged in project
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Harrington committed Oct 1, 2018
1 parent 8b81dac commit c00f52d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
// eslint-disable-next-line global-require
cli: require('../package.json').name,
host: 'https://dash.readme.io',
hub: 'https://{project}.readme.io'
};
3 changes: 2 additions & 1 deletion config/localhost.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"host": "http://dash.readme.local:3000"
"host": "http://dash.readme.local:3000",
"hub": "http://{project}.readme.local:3000"
}
20 changes: 20 additions & 0 deletions lib/open.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const config = require('config');
const open = require('opn');

exports.desc = 'Open your current ReadMe project in the browser';
exports.category = 'utilities';
exports.weight = 1;

const configStore = require('../lib/configstore');

exports.run = function ({ opts }) {
const project = configStore.get('project');

if (!project) {
return Promise.reject(new Error(`Please login using ${config.cli} login`));
}

return (opts.mockOpen || open)(config.hub.replace('{project}', project), {
wait: false,
}).then(() => null);
}
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"isemail": "^3.1.3",
"minimist": "^1.2.0",
"oas": "^0.8.8",
"opn": "^5.4.0",
"read": "^1.0.7",
"request": "^2.88.0",
"request-promise-native": "^1.0.5"
Expand Down
12 changes: 5 additions & 7 deletions test/login.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const nock = require('nock');
const config = require('config');
const assert = require('assert');
const Configstore = require('configstore');

const pkg = require('../package');

const login = require('../cli').bind(null, 'login');
const configStore = require('../lib/configstore');

describe('login command', () => {
beforeAll(() => nock.disableNetConnect());
Expand Down Expand Up @@ -35,10 +33,10 @@ describe('login command', () => {

return login([], { email, password, project }).then(() => {
mock.done();
const conf = new Configstore(pkg.name);
assert.equal(conf.get('apiKey'), apiKey);
assert.equal(conf.get('email'), email);
assert.equal(conf.get('project'), project);
assert.equal(configStore.get('apiKey'), apiKey);
assert.equal(configStore.get('email'), email);
assert.equal(configStore.get('project'), project);
configStore.clear();
});
});

Expand Down
29 changes: 29 additions & 0 deletions test/open.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const assert = require('assert');
const config = require('config');

const configStore = require('../lib/configstore');

const open = require('../cli').bind(null, 'open');

describe('open command', () => {
it('should error if no project provided', (done) => {
configStore.delete('project');

open([], {}).catch(err => {
assert.equal(err.message, `Please login using ${config.cli} login`);
return done();
})
});

it('should open the project', (done) => {
configStore.set('project', 'subdomain');

function mockOpen(url) {
assert.equal(url, 'https://subdomain.readme.io');
done();
return Promise.resolve();
}

open([], { mockOpen });
});
});

0 comments on commit c00f52d

Please sign in to comment.