Skip to content

Commit

Permalink
Flesh out 'auth required' error message
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickreimer committed Nov 13, 2019
1 parent fce8d7a commit f55c1f4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/cmds/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const deploy = require('@statickit/deploy');
const ora = require('ora');
const version = require('../../package.json').version;
const utils = require('../utils');
const messages = require('../messages');

exports.command = 'deploy';
exports.describe = 'Deploys statickit.json';
Expand Down Expand Up @@ -56,7 +57,7 @@ exports.handler = async args => {
const key = deploy.getDeployKey(args);

if (!key) {
utils.logError('Deploy key not found');
messages.logAuthRequired();
process.exitCode = 1;
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cmds/secrets_cmds/add.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const deploy = require('@statickit/deploy');
const axios = require('axios');
const utils = require('../../utils');
const messages = require('../../messages');
const version = require('../../../package.json').version;

const humanizeField = name => {
Expand Down Expand Up @@ -37,7 +38,7 @@ exports.handler = async args => {
utils.preamble();

if (!deployKey) {
utils.logError('Deploy key not found');
messages.logAuthRequired();
process.exitCode = 1;
return;
}
Expand Down
37 changes: 37 additions & 0 deletions src/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const chalk = require('chalk');
const utils = require('./utils');
const { stripIndent } = require('common-tags');

// prettier-ignore
const authRequired = stripIndent`
Your deploy key can be found under "Settings" in the UI.
There are couple ways to use your key:
- Use the ${utils.colorVariable('-k')} flag, or
- Set the ${utils.colorVariable('STATICKIT_DEPLOY_KEY')} env variable
${chalk.yellow.bold('-- Examples -----------------------------------------------')}
The inline method looks like this:
${chalk.gray('$')} statickit deploy ${chalk.cyan('-k')} c4cf8a3b6cc15b9ea0817e4fa00cb036
For convenience, you can add it to a ${utils.colorVariable('.env')} file.
That way, you don't have to copy/paste it every time
you run a command:
${chalk.gray('$')} echo "${chalk.gray('STATICKIT_DEPLOY_KEY=c4cf8a3b6cc...')}" >> .env
${chalk.gray('$')} statickit deploy
Just be sure to add ${utils.colorVariable('.env')} to your ${utils.colorVariable('.gitignore')} file,
so your deploy key does not end up in version control.
`;

const logAuthRequired = () => {
utils.logError('Deploy key is required');
console.error('');
console.error(authRequired);
console.error('');
};

module.exports = { authRequired, logAuthRequired };
6 changes: 5 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const withCaret = str => {
return `${chalk.gray('>')} ${str}`;
};

const withX = str => {
return `${chalk.red.bold('✕')} ${str}`;
};

/**
* Logs a green success message to stdout.
*
Expand Down Expand Up @@ -39,7 +43,7 @@ const logMeta = msg => {
* @param {string} msg
*/
const logError = msg => {
return console.error(withCaret(chalk.red(msg)));
return console.error(withX(chalk.red.bold(msg)));
};

/**
Expand Down

0 comments on commit f55c1f4

Please sign in to comment.