Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

common-questions

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

common-questions - npm Package Compare versions

Comparing version 0.2.4 to 0.3.0

lib/hints.js

171

index.js

@@ -10,3 +10,6 @@ /*!

var utils = require('./utils');
var questions = require('./lib/questions');
var listener = require('./lib/listener');
var utils = require('./lib/utils');
var hints = require('./lib/hints');

@@ -16,4 +19,6 @@ module.exports = function(config) {

return function(app, base) {
return function(app) {
if (!utils.isValid(app, 'common-questions')) return;
var opts = utils.extend({}, app.options, config);
app.cache.data = app.cache.data || {};

@@ -25,159 +30,29 @@ /**

app.use(utils.project());
app.use(utils.pkg());
app.use(utils.questions());
app.use(utils.pkg());
this.cache.data = this.cache.data || {};
if (typeof app.option === 'function') {
app.option(config);
} else {
utils.merge(this.options, config);
}
/**
* Author questions
* Questions
*
* Default prompt messages. These can be be overridden in your app
* by creating a new question with the same key. For example, the
* folling will override the `name` question:
*
* ```js
* app.question('name', 'custom message...');
* ```
*/
app.questions.disable('save')
.set('author.name', 'Author\'s name?', {
default: store(app, 'author.name')
})
.set('author.username', 'Author\'s GitHub username?', {
default: store(app, 'author.username')
})
.set('author.twitter', 'Author\'s twitter username?', {
default: store(app, 'author.twitter')
})
.set('author.email', 'Author\'s email address?', {
default: store(app, 'author.email')
})
.set('author.url', 'Author\'s URL?', {
default: store(app, 'author.url')
});
questions.all(app, opts);
/**
* Project questions
* Hints. Provides hints for the default prompts.
*/
app.questions.disable('save')
.set('project.name', 'Project name?', {
default: projectName(app)
})
.set('project.alias', 'Project alias?', {
default: projectAlias(app)
})
.set('project.description', 'Project description?', {
default: app.pkg.get('description')
})
.set('project.version', 'Project version?', {
default: app.pkg.get('version') || '0.1.0'
})
.set('project.owner', 'Project owner?', {
default: projectOwner(app)
});
app.questions.disable('save')
.set('name', 'Project name?', {
default: projectName(app)
})
.set('alias', 'Project alias?', {
default: projectAlias(app)
})
.set('description', 'Project description?', {
default: app.pkg.get('description')
})
.set('version', 'Project version?', {
default: app.pkg.get('version') || '0.1.0'
})
.set('owner', 'Project owner?', {
default: projectOwner(app)
});
listener(app, opts);
};
};
function store(app, prop) {
var expanded = app.pkg.expand();
utils.merge(app.cache.data, expanded);
var val = app.get(['cache.data', prop]);
if (typeof val !== 'undefined') {
return val;
}
if (app.store && typeof app.store.has === 'function' && app.store.has(prop)) {
return app.store.get(prop);
}
if (app.globals && typeof app.globals.has === 'function' && app.globals.has(prop)) {
return app.globals.get(prop);
}
}
function getAuthor(app) {
var author = app.cache.data.author;
if (!utils.isObject(author)) {
var expanded = app.pkg.expand();
var val = expanded.get('author');
if (utils.isObject(val)) {
author = val;
}
}
return author;
}
function projectName(app) {
return app.get('cache.data.name')
|| app.get('cache.data.project.name')
|| app.pkg.get('name')
|| app.project;
}
function projectAlias(app) {
if (typeof app.toAlias === 'function') {
return app.toAlias.call(app, projectName(app));
}
if (typeof app.options.toAlias === 'function') {
return app.options.toAlias.call(app, projectName(app));
}
var name = projectName(app);
if (typeof name === 'string') {
return name.slice(name.lastIndexOf('-') + 1);
}
}
function projectOwner(app) {
if (!userIsOwner(app)) {
return app.cache.data.owner;
}
var name = app.cache.data.name;
if (/^base-/.test(name)) {
return 'node-base';
}
if (/^assemble-/.test(name)) {
return 'assemble';
}
if (/^generate-/.test(name)) {
return 'generate';
}
if (/^(helper|handlebars-helper)-/.test(name)) {
return 'helpers';
}
if (/^updater?-/.test(name)) {
return 'update';
}
if (/^verb-/.test(name)) {
return 'verbose';
}
return app.get('cache.data.owner') || app.get('cache.data.author.username');
}
function userIsOwner(app) {
var username = app.get('cache.data.author.username');
if (typeof username === 'undefined') {
return true;
}
var config = utils.parse.sync({cwd: app.cwd});
if (!config || !config.user) {
config = utils.parse.sync('global');
}
if (!config || !config.user || typeof config.user.name !== 'string') {
return;
}
return username.indexOf(config.user.name) !== -1;
}
module.exports.disableHints = hints;
module.exports.questions = questions;
module.exports.listener = listener;
{
"name": "common-questions",
"description": "An object of questions commonly used by project generators or when initializing projects. Questions can be overridden, updated or extended.",
"version": "0.2.4",
"version": "0.3.0",
"homepage": "https://github.com/generate/common-questions",

@@ -14,3 +14,5 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"index.js",
"utils.js"
"lib",
"LICENSE",
"README.md"
],

@@ -28,12 +30,16 @@ "main": "index.js",

"base-questions": "^0.6.6",
"is-valid-app": "^0.1.1",
"isobject": "^2.1.0",
"camel-case": "^3.0.0",
"common-config": "^0.1.0",
"define-property": "^0.2.5",
"extend-shallow": "^2.0.1",
"is-valid-app": "^0.2.0",
"lazy-cache": "^2.0.1",
"mixin-deep": "^1.1.3",
"parse-git-config": "^0.4.2"
"omit-empty": "^0.4.1",
"set-getter": "^0.1.0"
},
"devDependencies": {
"base": "^0.11.0",
"ask-when": "^0.1.1",
"base": "^0.11.1",
"gulp-format-md": "^0.1.9",
"mocha": "^2.4.5"
"mocha": "^2.5.3"
},

@@ -56,13 +62,10 @@ "keywords": [

"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"reflinks": [
"base",
"inquirer",
"question-cache",
"question-store",
"verb",
"verb-readme-generator"
],
"related": {

@@ -77,11 +80,13 @@ "list": [

},
"toc": false,
"layout": "default",
"reflinks": [
"base",
"question-cache",
"question-store",
"verb",
"verb-generate-readme"
],
"lint": {
"reflinks": true
},
"tasks": [
"readme"
]
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc