Comparing version 0.0.1 to 1.0.0
{ | ||
"author": "marak <marak.squires@gmail.com>", | ||
"name": "wizard", | ||
"version": "0.0.1", | ||
"main": "./lib/wizard", | ||
"version": "1.0.0", | ||
"description": "Wizard is a highly configurable library for building complex CLI based installation/setup wizards", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"start": "babel src -d lib -w", | ||
"build": "babel src -d lib", | ||
"build:demo": "babel example/src -d build", | ||
"precommit": "lint-staged", | ||
"prepare": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/AaronGillBraun/wizard.git" | ||
}, | ||
"keywords": [ | ||
"cli", | ||
"library", | ||
"wizard" | ||
], | ||
"author": "Aaron Gill-Braun <aarongillbraun@gmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/AaronGillBraun/wizard/issues" | ||
}, | ||
"homepage": "https://github.com/AaronGillBraun/wizard#readme", | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/plugin-proposal-class-properties": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"babel-eslint": "^9.0.0", | ||
"eslint": "^5.5.0", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^7.2.2", | ||
"prettier": "^1.14.2" | ||
}, | ||
"dependencies": { | ||
"prompt": "*" | ||
}, | ||
"devDependencies": {}, | ||
"optionalDependencies": {}, | ||
"engines": { | ||
"node": "*" | ||
"@babel/polyfill": "^7.0.0", | ||
"ansi-escapes": "^3.1.0", | ||
"chalk": "^2.4.1" | ||
} | ||
} |
205
README.md
@@ -1,13 +0,202 @@ | ||
# wizard | ||
<div align="center"> | ||
<img src="https://bit.ly/2CmaW7u" width="100" height="auto" /> | ||
<br> | ||
Wizard | ||
<br> | ||
<img src="https://media.giphy.com/media/cYeQv0qqTYvB7NvAvA/giphy.gif" /> | ||
<br> | ||
The fastest way to build CLI setup wizards. | ||
</div> | ||
<br> | ||
a configuration tool for node.js apps. | ||
## Installation | ||
# usage | ||
`npm install wizard` | ||
First, run cli app configuration install wizard: | ||
```javascript | ||
import Wizard from 'wizard'; | ||
node examples/helloworld/cli-installer.js | ||
Second, start your app | ||
import questions from './questions'; | ||
node examples/helloworld/server.js | ||
const main = async () => { | ||
const wizard = new Wizard(questions); | ||
const selections = await wizard.init(); | ||
console.log(selections); | ||
}; | ||
main(); | ||
``` | ||
## Api | ||
#### `Wizard(questions, [styles, components])` | ||
##### `Wizard` represents a new setup wizard. | ||
- **questions** (Object - see _Questions object_) containing the complete specification of your setup wizard. | ||
- **styles** (Object **optional** - see _Styles object_) containing style options for your wizard. | ||
- **components** (Object **optional** - see _Custom Components_) containing custom input components. | ||
#### `wizard.init() -> Promise<Object>` | ||
##### `init` initializes your setup wizard. | ||
- It returns the Promise of a `selection` object. | ||
--- | ||
### Questions Object | ||
The _Questions Object_ represents every step of your setup wizard. It is an infinitely nested object representing the flow of choices from the first question, to the last. | ||
Every `section` of the _Questions Object_ must have the following fields: | ||
- **question** (string) Your question | ||
- **id** (string) The variable name that the answer will be stored under. | ||
- **type** (string) The type of input asociated with this question (See _Input types_). | ||
Depending on the input type, you may be required to have: | ||
- **options** (Array of `option`) All options for a question (List & ListToggle inputs). | ||
- **option** - (Object) Represents one choice | ||
- **name** (string) Your choice. | ||
- **value** (string | bool) The value your variable is asigned if chosen. | ||
- **then** (string **optional**) Which question the user is directed to next. | ||
- **then** (string) The next question (not used with input type List & ListToggle). | ||
Example: | ||
``` | ||
question: 'My question' | ||
id: 'my-question', | ||
type: 'list', | ||
options: [ | ||
{ name: 'Answer 1', value: 'answer-1', then: 'question2' }, | ||
{ name: 'Answer 2', value: 'answer-2', then: 'question3' }, | ||
], | ||
then: { | ||
question2: { | ||
question: 'Question 2', | ||
id: 'question-2', | ||
type: 'text', | ||
}, | ||
question3: { | ||
question: 'Question 3', | ||
id: 'question-3', | ||
type: 'list', | ||
options: [ | ||
{ name: 'Answer 1, value: 'answer-1' }, | ||
{ name: 'Answer 2, value: 'answer-2' }, | ||
{ name: 'Answer 3, value: 'answer-3' }, | ||
{ name: 'Answer 4, value: 'answer-4' }, | ||
] | ||
} | ||
} | ||
``` | ||
### Styles Object | ||
The styles object is passed in on the creation of the wizard. There are defaults that will be overridden. | ||
``` | ||
{ | ||
caret : { | ||
icon: string - The character representing the caret | ||
color: function - The color of the caret | ||
paddingRight: int - Right padding for the caret | ||
paddingLeft: int - Left padding for the caret | ||
}, | ||
list: { | ||
wrapToTop: bool - Whether the caret wraps to top | ||
defaultColor: function - The color of non-selected items | ||
selectedColor: function - The color of currently selected item | ||
toggledColor: function - The color of toggled items | ||
preserveAnswer: bool - Whether the previous questions and answers are printed | ||
paddingLeft: int - Left padding for the whole list | ||
toggle: { | ||
icon: string - The character representing selected items | ||
color: function - The color of the selected item icon | ||
paddingRight: int - Right padding for the selected icon | ||
paddingLeft: int - Left padding for the selected icon | ||
} | ||
} | ||
} | ||
``` | ||
### Input Types | ||
Right now Wizard includes the following input types: | ||
#### `List` - A list of choices, select one with `Enter` | ||
- **Needs:** | ||
- options (Array of Options) | ||
- Use it by selecting `list` in your questions object: `type: 'list'` | ||
#### `ListToggle` - A list of choices, select multiple with `Space` | ||
- **Needs:** | ||
- options (Array of Options) | ||
- Use it by selecting `listToggle` in your questions object: `type: 'listToggle'` | ||
### Custom Components | ||
You can make your very own personalized inputs if you can't achieve what you wish through styling. A `Component` class is made available through: `import { Component } from 'wizard` that allows you to create and use your own inputs. | ||
Each Input must have an `init` method. | ||
- **init** A method that starts your input - This must be a promise! | ||
To create a basic component: | ||
``` | ||
import { Component } from 'wizard'; | ||
class MyComponent extends Component { | ||
init() { | ||
return new Promise(resolve => { | ||
this.write('Welcome to my component!'); | ||
this.newline(); | ||
process.stdin.on('data', key => { | ||
const value = this.handleInput(key); | ||
if (value !== null) { | ||
resolve(value); | ||
} | ||
}); | ||
}); | ||
} | ||
handleInput(key) { | ||
switch(key) { | ||
this.keys.KEY_SPACE: | ||
this.write(this.colors.red('Space pressed')); | ||
this.newline(); | ||
return 'some value'; | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
``` | ||
Now import it and use it: | ||
```javascript | ||
import Wizard from 'wizard'; | ||
import MyComponent from './MyComponent'; | ||
const question = { | ||
question: 'Press space: ', | ||
id: 'space', | ||
type: 'myComponent', | ||
}; | ||
const main = async () => { | ||
const wizard = new Wizard(questions, {}, { myComponent: MyComponent }); | ||
const selections = await wizard.init(); | ||
console.log(selections); | ||
}; | ||
``` | ||
For coloring, we make the `chalk` library useful by way of `this.color`. Check out the library here: https://github.com/chalk/chalk |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
54726
27
0
1266
1
1
203
1
3
11
2
+ Added@babel/polyfill@^7.0.0
+ Addedansi-escapes@^3.1.0
+ Addedchalk@^2.4.1
+ Added@babel/polyfill@7.12.1(transitive)
+ Addedansi-escapes@3.2.0(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedregenerator-runtime@0.13.11(transitive)
+ Addedsupports-color@5.5.0(transitive)
- Removedprompt@*
- Removed@colors/colors@1.5.0(transitive)
- Removedasync@2.6.43.2.3(transitive)
- Removedcolors@1.0.3(transitive)
- Removedcycle@1.0.3(transitive)
- Removedeyes@0.1.8(transitive)
- Removedisstream@0.1.2(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmute-stream@0.0.8(transitive)
- Removedprompt@1.3.0(transitive)
- Removedread@1.0.7(transitive)
- Removedrevalidator@0.1.8(transitive)
- Removedstack-trace@0.0.10(transitive)
- Removedwinston@2.4.7(transitive)