Skip to content

Commit ff42cb2

Browse files
committed
Allow specifying endpoint as a deploy command flag
Closes #255
1 parent 2846b23 commit ff42cb2

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

src/commands/deploy.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ exports.builder = {
9696
description: 'Verbose mode; will output more information',
9797
count: true,
9898
},
99+
endpoint: {
100+
alias: 'e',
101+
description: 'Exoframe server endpoint to use (will override config value)',
102+
},
99103
};
100104
exports.handler = async (args = {}) => {
101105
const deployToken = args.token;
@@ -108,16 +112,14 @@ exports.handler = async (args = {}) => {
108112

109113
const folder = args._ ? args._.filter(arg => arg !== 'deploy').shift() : undefined;
110114
const update = args.update;
115+
const endpoint = args.endpoint || userConfig.endpoint;
111116

112-
console.log(
113-
chalk.bold(`${update ? 'Updating' : 'Deploying'} ${folder || 'current project'} to endpoint:`),
114-
userConfig.endpoint
115-
);
117+
console.log(chalk.bold(`${update ? 'Updating' : 'Deploying'} ${folder || 'current project'} to endpoint:`), endpoint);
116118

117119
// create config vars
118120
const workdir = folder ? path.join(process.cwd(), folder) : process.cwd();
119121
const folderName = path.basename(workdir);
120-
const remoteUrl = `${userConfig.endpoint}/${update ? 'update' : 'deploy'}`;
122+
const remoteUrl = `${endpoint}/${update ? 'update' : 'deploy'}`;
121123

122124
// make sure workdir exists
123125
if (!fs.existsSync(workdir)) {

test/__snapshots__/deploy.test.js.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ Array [
4747
]
4848
`;
4949

50+
exports[`Should deploy with endpoint flag 1`] = `
51+
Array [
52+
Array [
53+
"Deploying test/fixtures/test_html_project to endpoint:",
54+
"http://localhost:3000",
55+
],
56+
Array [
57+
"Your project is now deployed as:
58+
",
59+
],
60+
Array [
61+
" ID   URL   Hostname   Type 
62+
test   localhost   test   Container ",
63+
],
64+
]
65+
`;
66+
5067
exports[`Should deploy without auth but with token 1`] = `
5168
Array [
5269
Array [

test/deploy.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,38 @@ test('Should deploy', done => {
9292
});
9393
});
9494

95+
// test
96+
test('Should deploy with endpoint flag', done => {
97+
// spy on console
98+
const consoleSpy = sinon.spy(console, 'log');
99+
100+
// handle correct request
101+
const deployServer = nock('http://localhost:3000')
102+
.post('/deploy')
103+
.reply((uri, requestBody) => {
104+
const excgf = fs.readFileSync(path.join(testFolder, 'exoframe.json'));
105+
const index = fs.readFileSync(path.join(testFolder, 'index.html'));
106+
expect(requestBody).toContain(excgf);
107+
expect(requestBody).toContain(index);
108+
109+
return replyWithStream([{message: 'Deployment success!', deployments, level: 'info'}]);
110+
});
111+
112+
// execute login
113+
deploy({_: [folderPath], endpoint: 'http://localhost:3000'}).then(() => {
114+
// make sure log in was successful
115+
// check that server was called
116+
expect(deployServer.isDone()).toBeTruthy();
117+
// first check console output
118+
expect(consoleSpy.args).toMatchSnapshot();
119+
// restore console
120+
console.log.restore();
121+
// tear down nock
122+
deployServer.done();
123+
done();
124+
});
125+
});
126+
95127
// test
96128
test('Should deploy without path', done => {
97129
// spy on console

0 commit comments

Comments
 (0)