Comparing version 0.0.1 to 0.1.0
@@ -6,4 +6,5 @@ var NewForm = require('./'); | ||
{ key: "workspace", title: "Where do you keep your code?", default: process.cwd(), forOnce: true }, | ||
{ key: "name", title: "What's your new project name?", validate: { len: [1], name: "Project Name" } }, | ||
{ title: "Starter", desc: "user/repo (Github) or a full Git URL to clone.", default: "bud/react-starter" } | ||
{ key: "name", title: "What's your new project name?", expect: { len: [1], name: "Project Name" } }, | ||
{ title: "Starter", desc: "user/repo (Github) or a full Git URL to clone.", default: "bud/react-starter" }, | ||
{ title: "Github Repo?", default: "{github}/{name}" } | ||
]); | ||
@@ -10,0 +11,0 @@ |
72
index.js
@@ -1,71 +0,1 @@ | ||
var struct = require("new-struct"); | ||
var NewDoc = require("config-doc"); | ||
var QA = require("cli-qa"); | ||
var format = require("format-text"); | ||
var Form = struct({ | ||
ask: ask, | ||
questions: questions, | ||
isMissingQuestion: isMissingQuestion, | ||
formatQuestion: formatQuestion, | ||
rememberLastAnswer: rememberLastAnswer | ||
}); | ||
module.exports = NewForm; | ||
function NewForm (filename, options) { | ||
return Form({ | ||
content: NewDoc(filename), | ||
options: options | ||
}); | ||
} | ||
function ask (form, callback) { | ||
QA(form.questions(), function (answers) { | ||
var key; | ||
for (key in answers) { | ||
form.content.set(key, answers[key]); | ||
} | ||
callback(form.content.document); | ||
}); | ||
} | ||
function questions (form) { | ||
var result = form.options | ||
.map(QA.normalizeQuestion) | ||
.filter(form.isMissingQuestion); | ||
result.forEach(form.rememberLastAnswer); | ||
result.forEach(form.formatQuestion); | ||
return result; | ||
} | ||
function isMissingQuestion (form, question) { | ||
return !question.forOnce || form.content.get(question.key) === undefined; | ||
} | ||
function formatQuestion (form, question) { | ||
var desc = question.desc || question.description || ''; | ||
var defaultValue = ''; | ||
if (question.default) { | ||
defaultValue = format(' (Default: {0})', question.default); | ||
} | ||
if (desc) { | ||
desc = format(' {0} ', desc); | ||
} | ||
question.title = format("\n {bold}{white}{0}{reset}{1}{2}\n {reset}{bold}{white}> {reset}", question.title, desc, defaultValue); | ||
} | ||
function rememberLastAnswer (form, question) { | ||
var last = form.content.get(question.key); | ||
if (question.default || !last) return; | ||
question.default = last; | ||
} | ||
module.exports = require('./lib/form'); |
{ | ||
"name": "cli-form", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Build user-friendly command-line forms", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"cli-qa": "^1.0.0", | ||
"cli-qa": "^2.1.0", | ||
"config-doc": "^0.1.0", | ||
@@ -24,0 +24,0 @@ "format-text": "0.0.3", |
@@ -21,4 +21,5 @@ ## cli-form | ||
{ key: "workspace", title: "Where do you keep your code?", default: process.cwd(), forOnce: true }, | ||
{ key: "name", title: "What's your new project name?", validate: { len: [1] } }, | ||
{ title: "Starter", desc: "user/repo (Github) or a full Git URL to clone.", default: "bud/react-starter" } | ||
{ key: "name", title: "What's your new project name?", expect: { len: [1] } }, | ||
{ title: "Starter", desc: "user/repo (Github) or a full Git URL to clone.", default: "bud/react-starter" }, | ||
{ title: "Github Repo?", default: "{github}/{name}" } | ||
]) | ||
@@ -39,2 +40,5 @@ | ||
cli-form is a wrapper for [cli-qa](http://github.com/azer/cli-qa) module, formatted by default with a description option. [Reference](https://github.com/azer/cli-qa#reference) | ||
cli-form is a wrapper for [cli-qa](http://github.com/azer/cli-qa) module. In addition to what cli-qa's [Reference](https://github.com/azer/cli-qa#reference) lists; | ||
* desc | ||
* forOnce |
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
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
4462
7
104
43
+ Addedcli-qa@2.3.0(transitive)
+ Addedcomma-list@0.0.1(transitive)
+ Addedmix-objects@0.0.3(transitive)
- Removedcli-qa@1.0.0(transitive)
- Removedleft-pad@0.0.4(transitive)
Updatedcli-qa@^2.1.0