common-questions
Advanced tools
Comparing version 0.2.4 to 0.3.0
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" | ||
] | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10741
7
279
11
4
1
+ Addedcamel-case@^3.0.0
+ Addedcommon-config@^0.1.0
+ Addeddefine-property@^0.2.5
+ Addedextend-shallow@^2.0.1
+ Addedomit-empty@^0.4.1
+ Addedset-getter@^0.1.0
+ Addedarr-diff@2.0.0(transitive)
+ Addedasync-done@0.4.01.3.2(transitive)
+ Addedasync-settle@0.2.1(transitive)
+ Addedbach@0.5.0(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addedcamel-case@3.0.0(transitive)
+ Addedcamelcase@3.0.0(transitive)
+ Addedco@4.6.0(transitive)
+ Addedcommon-config@0.1.1(transitive)
+ Addedcomposer@0.13.0(transitive)
+ Addedend-of-stream@0.1.51.4.4(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-generator@1.0.3(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@4.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-valid-app@0.2.1(transitive)
+ Addedis-valid-instance@0.2.0(transitive)
+ Addedlodash.assign@4.2.0(transitive)
+ Addedlodash.filter@4.6.0(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
+ Addedlodash.foreach@4.5.0(transitive)
+ Addedlodash.initial@4.1.1(transitive)
+ Addedlodash.last@3.0.0(transitive)
+ Addedlodash.map@4.6.0(transitive)
+ Addedlower-case@1.1.4(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addednanoseconds@0.1.0(transitive)
+ Addednext-tick@0.2.2(transitive)
+ Addedno-case@2.3.2(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addednow-and-later@0.0.6(transitive)
+ Addedonce@1.3.3(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedset-value@3.0.3(transitive)
+ Addedstream-exhaust@1.0.2(transitive)
+ Addedtableize-object@0.1.0(transitive)
+ Addedtext-table@0.2.0(transitive)
+ Addedupper-case@1.1.3(transitive)
+ Addedyargs-parser@2.4.1(transitive)
- Removedisobject@^2.1.0
- Removedmixin-deep@^1.1.3
- Removedparse-git-config@^0.4.2
- Removedis-valid-app@0.1.2(transitive)
- Removedparse-git-config@0.4.3(transitive)
Updatedis-valid-app@^0.2.0