Skip to content

Commit f035255

Browse files
committed
Merge branch 'develop', prepare 0.18.0
2 parents cff104a + c4a3782 commit f035255

File tree

3 files changed

+75
-9
lines changed

3 files changed

+75
-9
lines changed

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,13 @@ node_js: node
55
cache: yarn
66

77
after_success:
8-
- yarn coveralls
8+
- yarn coveralls
9+
10+
deploy:
11+
provider: npm
12+
13+
api_key:
14+
secure: E0jdvpJugRD1upHJI0S+g0xvDkGvGGJv0plyZaY/zHqKf5oNspok74Ew8cqkP4IRdB/G/57eXoiyCCOkQM/P44a2xt7TEiBvn4PBhxRD1Dfw+u5ukreQPAn4QCXvC9pRF2KuRSswnkZk+QYRiYUVcsv7S7C6p7xDyCw5Po0ywiHzUR75c56B657sCOG4w+wTFcawIjpb369DqPoefUK1C837YYfu0DJXX6NBrV1BN6kOUiSHITbUcwPFg5VfZLRMOZIqQzb3ud0IDfvy5KdcOiKOCes7bi179NMWG8evPr7l6NikA882xqdDjmxvUPY0x6H1tzXTKca8pzX2l5Pkh0qPXipkjgKAjrg4qrQmoH4lW3sr+6zan6Nk3RwwE7QdhuvXHuyNQ/YJHxGHr1uI5SV7AQyUCM0AtdkXnIJ97LoEm8zm/48YzeMQel53iw01quOubmRP3qv6PNJU8Nlbfy02caXhIftkEBxanXAQl8OSnYUaZYN2XmvAqlzMdyygBWhg/f7NbZLkjWY6JdzFzBnSAkghKt//CfsylYvQt7xNk7sjGvoUjuKx+hWfrCb7fnjIjWwalchyjHRRokUROx0QdRltUbZDGPL0JG3vYTlDV1/k0tkw9C3faq2ckoXccEHXItZrspAk1EYVL6FvlHPu6YqZtQupMIxszI4BvXQ=
15+
on:
16+
tags: true
17+
repo: exoframejs/exoframe

src/commands/deploy.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,28 @@ const ignores = ['.git', 'node_modules'];
1818

1919
const streamToResponse = ({tarStream, remoteUrl, options}) =>
2020
new Promise((resolve, reject) => {
21-
// pipe stream to remote
21+
// store error and result
22+
let error;
2223
let result = '';
24+
// pipe stream to remote
2325
const stream = tarStream.pipe(got.stream.post(remoteUrl, options));
24-
// log output if in verbose mode
26+
// store output
2527
stream.on('data', str => (result += str.toString()));
2628
// listen for read stream end
2729
stream.on('end', () => {
2830
const res = JSON.parse(result);
29-
// ignore errored out results
30-
if (res.status !== 'success') {
31+
// if stream had error - reject
32+
if (error) {
33+
// add response to allow access to body
34+
error.response = res;
35+
reject(error);
3136
return;
3237
}
33-
// resolve on end
38+
// otherwise resolve
3439
resolve(res);
3540
});
3641
// listen for stream errors
37-
stream.on('error', e => reject(e));
42+
stream.on('error', e => (error = e));
3843
});
3944

4045
exports.command = ['*', 'deploy'];
@@ -148,14 +153,21 @@ exports.handler = async (args = {}) => {
148153
opn(`http://${formattedServices[0].domain.split(',')[0].trim()}`);
149154
}
150155
} catch (e) {
151-
spinner.fail('Upload failed!');
156+
spinner.fail('Deployment failed!');
152157
// if authorization is expired/broken/etc
153158
if (e.statusCode === 401) {
154159
logout(userConfig);
155160
console.log(chalk.red('Error: authorization expired!'), 'Please, relogin and try again.');
156161
return;
157162
}
158163

159-
console.log(chalk.red('Error deploying project:'), e.toString());
164+
const reason = e.response.result ? e.response.result.error : e.toString();
165+
console.log(chalk.red('Error deploying project:'), reason);
166+
console.log('Build log:\n');
167+
e.response.result.log
168+
.filter(l => l !== undefined)
169+
.map(l => l.trim())
170+
.filter(l => l && l.length > 0)
171+
.forEach(line => console.log(line));
160172
}
161173
};

test/deploy.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,51 @@ module.exports = () => {
219219
});
220220
});
221221

222+
// test
223+
tap.test('Should display error log', t => {
224+
// spy on console
225+
const consoleSpy = sinon.spy(console, 'log');
226+
227+
// handle correct request
228+
const deployServer = nock('http://localhost:8080').post('/deploy').reply((uri, requestBody, cb) => {
229+
cb(null, [
230+
400,
231+
{
232+
status: 'error',
233+
result: {
234+
error: 'Build failed! See build log for details.',
235+
log: ['Error log', 'here'],
236+
image: 'test:latest',
237+
},
238+
},
239+
]);
240+
});
241+
242+
// execute
243+
deploy().then(() => {
244+
// make sure log in was successful
245+
// check that server was called
246+
t.ok(deployServer.isDone());
247+
// first check console output
248+
t.deepEqual(
249+
consoleSpy.args,
250+
[
251+
['Deploying current project to endpoint:', 'http://localhost:8080'],
252+
['Error deploying project:', 'Build failed! See build log for details.'],
253+
['Build log:\n'],
254+
['Error log'],
255+
['here'],
256+
],
257+
'Correct log output'
258+
);
259+
// restore console
260+
console.log.restore();
261+
// tear down nock
262+
deployServer.done();
263+
t.end();
264+
});
265+
});
266+
222267
// test
223268
tap.test('Should not deploy with broken config', t => {
224269
// spy on console

0 commit comments

Comments
 (0)