Skip to content

Commit

Permalink
Refactor output
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickreimer committed Oct 24, 2019
1 parent a7f5645 commit 273cfbc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bin/statickit
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('../src/index.js');
require('../src/cli.js');
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
},
"license": "MIT",
"author": "Derrick Reimer",
"main": "index.js",
"bin": {
"statickit": "bin/statickit"
},
Expand Down
File renamed without changes.
30 changes: 19 additions & 11 deletions src/cmds/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ const setErrorExit = () => {
process.exitCode = 1;
};

exports.command = ['deploy', '$0'];
const formatLine = str => {
return `${chalk.gray('>')} ${str}`;
};

const formatError = msg => {
return formatLine(chalk.red(msg));
};

exports.command = 'deploy';

exports.describe = 'Performs a deployment';

Expand Down Expand Up @@ -40,7 +48,7 @@ exports.handler = async args => {
const spinner = ora(chalk.gray('Deploying...'));

if (!rawConfig) {
console.error(chalk.bold.red('Configuration not provided'));
console.error(formatError('Configuration not provided'));
setErrorExit();
return;
}
Expand All @@ -50,15 +58,15 @@ exports.handler = async args => {
try {
config = JSON.parse(rawConfig);
} catch (err) {
console.error(chalk.bold.red('Configuration could not be parsed'));
console.error(formatError('Configuration could not be parsed'));
setErrorExit();
return;
}

const key = deploy.getDeployKey(args);

if (!key) {
console.error(chalk.bold.red('Deploy key not found'));
console.error(formatError('Deploy key not found'));
setErrorExit();
return;
}
Expand All @@ -77,34 +85,34 @@ exports.handler = async args => {

switch (response.status) {
case 200:
console.log(`--> ${chalk.green('Deployment succeeded')}`);
console.log(`${chalk.gray('id: ' + response.data.id)}`);
console.log(formatLine(chalk.green('Deployment succeeded')));
console.log(formatLine(chalk.gray('id: ' + response.data.id)));
return;

case 401:
console.error(`--> ${chalk.red('Deploy key is not valid')}`);
console.error(formatError('Deploy key is not valid'));
setErrorExit();
return;

case 422:
console.error(
`--> ${chalk.red('Deployment failed due to configuration errors')}`
formatError('Deployment failed due to configuration errors')
);
console.log('');
console.table(response.data.errors);
console.log('');
console.log(`${chalk.gray('id: ' + response.data.id)}`);
console.log(formatLine(chalk.gray('id: ' + response.data.id)));
setErrorExit();
return;

default:
console.error(`--> ${chalk.red('Deployment failed')}`);
console.error(formatError('Deployment failed'));
setErrorExit();
return;
}
} catch (error) {
spinner.stop();
console.error(`--> ${chalk.red('Deployment failed unexpectedly')}`);
console.error(formatError('Deployment failed unexpectedly'));
setErrorExit();
throw error;
}
Expand Down
9 changes: 3 additions & 6 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const parser = require('yargs');

module.exports = parser
.scriptName('statickit')
.usage('$0 <command> [options]')
.command(require('./cmds/deploy'))
module.exports = require('yargs')
.commandDir('cmds')
.demandCommand()
.help();

0 comments on commit 273cfbc

Please sign in to comment.