Skip to content

Commit

Permalink
Style inquirer
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jul 8, 2019
1 parent 4cccb85 commit 96f76a2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/plugins/interactiveCli/initializeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { join } = require('path');
const chalk = require('chalk');
const inquirer = require('inquirer');
const inquirer = require('./inquirer');
const createFromTemplate = require('../../utils/createFromTemplate');
const {
getConfigFilePath,
Expand Down
36 changes: 36 additions & 0 deletions lib/plugins/interactiveCli/inquirer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Customize inquirer style

'use strict';

const { dirname } = require('path');
const requireUncached = require('ncjsm/require-uncached');
const resolve = require('ncjsm/resolve/sync');
const chalk = require('chalk');

const inquirersChalkPath = resolve(dirname(require.resolve('inquirer')), 'chalk');

module.exports = requireUncached(inquirersChalkPath, () => {
// Ensure distinct chalk instance for inquirer and hack it with altered styles
Object.defineProperties(require(inquirersChalkPath), {
cyan: {
get() {
return chalk.bold;
},
},
bold: {
get() {
return chalk.bold.yellow;
},
},
});

// 'Serverless:' prefix
const BasePrompt = require('inquirer/lib/prompts/base');
const originalGetQuestion = BasePrompt.prototype.getQuestion;
BasePrompt.prototype.getQuestion = function() {
this.opt.prefix = 'Serverless:';
return originalGetQuestion.call(this);
};

return require('inquirer');
});
2 changes: 1 addition & 1 deletion lib/plugins/interactiveCli/setupAws.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const BbPromise = require('bluebird');
const chalk = require('chalk');
const inquirer = require('inquirer');
const inquirer = require('./inquirer');
const awsCredentials = require('../aws/utils/credentials');
const { confirm } = require('./utils');

Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/interactiveCli/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const inquirer = require('inquirer');
const inquirer = require('./inquirer');

module.exports = {
confirm: message =>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"mkdirp": "^0.5.1",
"moment": "^2.24.0",
"nanomatch": "^1.2.13",
"ncjsm": "^2.3.0",
"node-fetch": "^1.7.3",
"object-hash": "^1.3.1",
"promise-queue": "^2.2.5",
Expand Down

0 comments on commit 96f76a2

Please sign in to comment.