Skip to content

Commit ea91802

Browse files
committed
chore: fix spinner and logs collection
1 parent 6bfbd43 commit ea91802

12 files changed

+59
-35
lines changed

bin/deploy-delete.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env node
2+
import ora from 'ora';
3+
4+
export default async function(cli) {
5+
const spinner = ora().start();
26

3-
export default async function(cli, spinner) {
47
spinner.text = `Deleting deployment ${cli.application}`;
58

69
const { token, username } = await cli.getCredentials();

bin/deploy-deploy.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import fs from 'fs';
44
import path from 'path';
5+
import ora from 'ora';
6+
7+
export default async function(cli) {
8+
const spinner = ora().start();
59

6-
export default async function(cli, spinner) {
710
spinner.text = 'Creating application bundle';
811

912
await cli.createBundle(process.cwd());

bin/deploy-list.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
import moment from 'moment';
33
import Url from 'url';
44
import Table from 'turtler';
5+
import ora from 'ora';
6+
7+
export default async function(cli) {
8+
const spinner = ora().start();
59

6-
export default async function(cli, spinner) {
710
spinner.text = 'Getting deployment list';
811

912
const { token, username } = await cli.getCredentials();

bin/deploy-login.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env node
22
import inquirer from 'inquirer';
3+
import ora from 'ora';
34

4-
export default async function(cli, spinner) {
5-
spinner.stop();
5+
export default async function(cli) {
6+
const spinner = ora().start();
67

78
const { username, password } = await inquirer.prompt([
89
{
@@ -34,5 +35,5 @@ export default async function(cli, spinner) {
3435
const credentials = await cli.login({ username, password});
3536
await cli.cacheCredentials(credentials);
3637

37-
console.log(`Successfully logged in as ${credentials.username}`); // eslint-disable-line
38+
spinner.succeed(`Logged in as ${credentials.username}`); // eslint-disable-line
3839
};

bin/deploy-logout.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/usr/bin/env node
22

3-
export default async function(cli, spinner) {
3+
import ora from 'ora';
4+
5+
export default async function(cli) {
6+
const spinner = ora().start();
7+
48
const { token, username } = await cli.getCredentials();
59

610
spinner.text = `Logging out of current session for ${username}`;
711

812
await cli.logout({ token, username });
913
await cli.cacheCredentials({ username: '', token: '' });
1014

11-
spinner.succeed(`Logged out of session for ${username} successfully`);
15+
spinner.succeed(`Logged out as ${username}`);
1216
};

bin/deploy-logs.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#!/usr/bin/env node
22

3-
export default async function(cli, spinner) {
4-
spinner.text = `Getting logs for ${cli.application}`;
3+
import ora from 'ora';
4+
5+
export default async function(cli) {
6+
const spinner = ora().start();
7+
8+
spinner.text = `Getting logs for application: "${cli.application}"`;
59

610
const { token, username } = await cli.getCredentials();
711
const { logs } = await cli.getLogs({ token, username, name: cli.application });
812

9-
spinner.stop();
10-
1113
if(logs) {
12-
console.log('' + // eslint-disable-line
13-
`==========
14-
${logs.join('').trim()}
15-
==========`);
14+
spinner.info(`
15+
==========
16+
${logs.join('').trim()}
17+
==========
18+
`);
1619
} else {
17-
console.log('No logs available 🙈'); // eslint-disable-line
20+
spinner.info('No logs available 🙈'); // eslint-disable-line
1821
}
1922
};

bin/deploy-open.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import Url from 'url';
44
import opn from 'opn';
5+
import ora from 'ora';
6+
7+
export default async function(cli) {
8+
const spinner = ora().start();
59

6-
export default async function(cli, spinner) {
710
spinner.text = 'Opening up url to deployment instance';
811

912
const { token, username } = await cli.getCredentials();

bin/deploy-register.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env node
22

33
import inquirer from 'inquirer';
4+
import ora from 'ora';
45

5-
export default async function(cli, spinner) {
6-
spinner.stop();
6+
export default async function(cli) {
7+
const spinner = ora().start();
78

89
const { username, password } = await inquirer.prompt([
910
{
@@ -36,5 +37,5 @@ export default async function(cli, spinner) {
3637
const credentials = await cli.register({ username, password });
3738
await cli.cacheCredentials(credentials);
3839

39-
console.log(`registered as ${credentials.username}`); // eslint-disable-line
40+
spinner.succeed(`registered as ${credentials.username}`); // eslint-disable-line
4041
};

bin/deploy-server.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env node
22

3-
export default async function(cli, spinner) {
3+
import ora from 'ora';
4+
5+
export default async function(cli) {
6+
const spinner = ora().start();
7+
48
const { default: importCommand } = await import('../index.js');
59

610
importCommand(cli, spinner);

bin/deploy-whoami.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/env node
22

3-
export default async function(cli, spinner) {
3+
import ora from 'ora';
4+
5+
export default async function(cli) {
6+
const spinner = ora().start();
7+
48
spinner.text = 'Figuring out who you are';
59

610
const { token, username } = await cli.getCredentials();
711
const { user } = await cli.getUserDetails({ token, username });
812

9-
spinner.stop();
10-
11-
console.log(`currently logged in as ${user.username}`); // eslint-disable-line
13+
spinner.info(`currently logged in as ${user.username}`); // eslint-disable-line
1214
};

bin/deploy.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ let program = woof(`
9292

9393
(async function() {
9494
const cli = new CLI(program);
95-
const spinner = ora('').start();
9695

9796
let found = false;
9897
let commands = ['deploy','list','register','whoami','login','logout','open','logs','delete','server'];
@@ -104,12 +103,10 @@ let program = woof(`
104103
found = true;
105104

106105
const { default: commandImported } = await import(`./deploy-${command}.js`);
107-
commandImported(cli, spinner);
106+
commandImported(cli);
108107
} catch(ex) {
109-
spinner.stop();
110108
if(ex === 'credentials not found') return console.log('Please login for this action'); // eslint-disable-line
111-
console.log(ex.stack);
112-
console.log(`something happened when running ${command} \n ${ex}`); // eslint-disable-line
109+
console.log(`something happened when running ${command} \n ${ex.stack}`); // eslint-disable-line
113110
}
114111
}
115112
}
@@ -120,13 +117,11 @@ let program = woof(`
120117
try {
121118
found = true;
122119
const { default: commandImported } = await import(`./deploy-deploy.js`);
123-
commandImported(cli, spinner);
120+
commandImported(cli);
124121
} catch(ex) {
125-
spinner.stop();
126-
console.log(`something happened when running deploy \n ${ex}`); // eslint-disable-line
122+
console.log(`something happened when running deploy \n ${ex.stack}`); // eslint-disable-line
127123
}
128124
}
129125

130-
spinner.stop();
131126
updateNotifier({pkg}).notify();
132127
}());

lib/models/deployment.js

+2
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ class Deployment {
408408

409409
setTimeout(function() {
410410
cStream.destroy();
411+
412+
return resolve(logs);
411413
}, 2000);
412414
} catch(ex) {
413415
return reject(ex);

0 commit comments

Comments
 (0)