Compare commits
42 Commits
Author | SHA1 | Date | |
---|---|---|---|
0d2e0ca4f7 | |||
aa74482b29 | |||
ffe0f202f0 | |||
e1bbd5a844 | |||
83dcc897a8 | |||
db19c7480f | |||
c1a93102be | |||
01fd22c7d0 | |||
69592933aa | |||
10074b5888 | |||
fe9564e37c | |||
fa5f2d0267 | |||
a4cd5175b3 | |||
97c3ccb329 | |||
cfdd54eff1 | |||
741365d325 | |||
b36e95af1a | |||
ac9ef4915e | |||
6ca2e427ff | |||
39f9bb11fe | |||
8925f29962 | |||
2e862d6840 | |||
516c0c21de | |||
5dd182d421 | |||
81a5ce026f | |||
2a45270902 | |||
8b6a15388e | |||
0a3b006139 | |||
1f4f9c0c44 | |||
9420815809 | |||
efada244c2 | |||
585f5a6310 | |||
34c4be2740 | |||
123bdac087 | |||
8d2ccf8b57 | |||
d986d6f9b6 | |||
653782859c | |||
199b99ae2d | |||
c5e55e8958 | |||
256c53b6f9 | |||
0dae90cc24 | |||
cc65584e9c |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,20 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
coverage/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
116
.gitlab-ci.yml
116
.gitlab-ci.yml
@ -1,59 +1,137 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npmpage --host gitlab
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
56
README.md
56
README.md
@ -1,56 +0,0 @@
|
||||
# smartinteract
|
||||
interact with terminal users
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smartinteract)
|
||||
[](https://gitlab.com/pushrocks/smartinteract)
|
||||
[](https://github.com/pushrocks/smartinteract)
|
||||
[](https://pushrocks.gitlab.io/smartinteract/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartinteract/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartinteract/commits/master)
|
||||
[](https://david-dm.org/pushrocks/smartinteract)
|
||||
[](https://www.bithound.io/github/pushrocks/smartinteract/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartinteract)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Usage
|
||||
We recommend the use of TypeScript for best in class intellesense
|
||||
|
||||
```javascript
|
||||
import { SmartInteract } from 'smartinteract'
|
||||
|
||||
let myInteract = new SmartInteract([{ // note: its an array. You can specify multiple questions
|
||||
name: 'question1',
|
||||
type: 'input',
|
||||
message: 'Who are you?',
|
||||
default: 'Somebody',
|
||||
validate: (inputString) => { return true } // implement your own validation
|
||||
}])
|
||||
SmartInteract.addQuestions([ ... ]) // add more questions
|
||||
SmartInteract.runQueue()
|
||||
.then(answerBucket => { // the bucket has all the answers of the completed queue
|
||||
let answerQuestion1 = answerBucket.getAnswerFor('question1')
|
||||
// do something with the answers
|
||||
})
|
||||
|
||||
// alternatively use .askQuestion() for more direct control
|
||||
SmartInteract.askQuestion{ // note: its an array. You can specify multiple questions
|
||||
name: 'question2',
|
||||
type: 'confirm',
|
||||
message: 'Do you speak English?',
|
||||
default: true,
|
||||
validate: (inputString) => { return true } // implement your own validation
|
||||
}().then(answerObject => {
|
||||
// answerObject looks like { name: 'question2', value: true }
|
||||
})
|
||||
```
|
||||
|
||||
### Environment
|
||||
In some environments like CI there is no user input to be expected.
|
||||
smartinteract will always directyl create an answer from the default value
|
||||
|
||||
[](https://push.rocks)
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
||||
export * from './smartinteract.classes.smartinteract';
|
6
dist/index.js
vendored
6
dist/index.js
vendored
@ -1,6 +0,0 @@
|
||||
"use strict";
|
||||
function __export(m) {
|
||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||
}
|
||||
__export(require("./smartinteract.classes.smartinteract"));
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsMkRBQXFEIn0=
|
71
dist/smartinteract.classes.smartinteract.d.ts
vendored
71
dist/smartinteract.classes.smartinteract.d.ts
vendored
@ -1,71 +0,0 @@
|
||||
/// <reference types="q" />
|
||||
import * as q from 'q';
|
||||
import { Objectmap } from 'lik';
|
||||
export declare type questionType = 'input' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor';
|
||||
export interface IChoiceObject {
|
||||
name: string;
|
||||
value: any;
|
||||
}
|
||||
export interface IQuestionObject {
|
||||
name: string;
|
||||
type: questionType;
|
||||
message: string;
|
||||
default: any;
|
||||
choices?: string[] | IChoiceObject[];
|
||||
validate?: IValidateFunction;
|
||||
}
|
||||
export interface IAnswerObject {
|
||||
name: string;
|
||||
value: any;
|
||||
}
|
||||
export interface IValidateFunction {
|
||||
(anyObject: any): boolean;
|
||||
}
|
||||
/**
|
||||
* class SmartInteract - allows to specify an user interaction during runtime
|
||||
*/
|
||||
export declare class SmartInteract {
|
||||
/**
|
||||
* holds the qestion queue, that is emptied once you call
|
||||
*/
|
||||
private questionMap;
|
||||
/**
|
||||
* constructor of class SmartInteract
|
||||
*/
|
||||
constructor(questionArrayArg?: IQuestionObject[]);
|
||||
/**
|
||||
* allows you to ask a single question and returns the answer in a promise
|
||||
* skips the queue
|
||||
*/
|
||||
askQuestion(optionsArg: IQuestionObject): q.Promise<IAnswerObject>;
|
||||
/**
|
||||
* add questions to queue
|
||||
*/
|
||||
addQuestions(questionArrayArg: IQuestionObject[]): void;
|
||||
/**
|
||||
* run the question queue
|
||||
*/
|
||||
runQueue(): q.Promise<AnswerBucket>;
|
||||
/**
|
||||
* checks if the current env is valid for userinput
|
||||
*/
|
||||
private isValidEnv();
|
||||
}
|
||||
/**
|
||||
* class AnswerBucket holds answers
|
||||
*/
|
||||
export declare class AnswerBucket {
|
||||
answerMap: Objectmap<IAnswerObject>;
|
||||
/**
|
||||
* add an answer to the bucket
|
||||
*/
|
||||
addAnswer(answerArg: IAnswerObject): void;
|
||||
/**
|
||||
* gets an answer for a specific name
|
||||
*/
|
||||
getAnswerFor(nameArg: string): any;
|
||||
/**
|
||||
* gets all answers as array
|
||||
*/
|
||||
getAllAnswers(): IAnswerObject[];
|
||||
}
|
121
dist/smartinteract.classes.smartinteract.js
vendored
121
dist/smartinteract.classes.smartinteract.js
vendored
@ -1,121 +0,0 @@
|
||||
"use strict";
|
||||
const plugins = require("./smartinteract.plugins");
|
||||
const q = require("q");
|
||||
const lik_1 = require("lik");
|
||||
/**
|
||||
* class SmartInteract - allows to specify an user interaction during runtime
|
||||
*/
|
||||
class SmartInteract {
|
||||
/**
|
||||
* constructor of class SmartInteract
|
||||
*/
|
||||
constructor(questionArrayArg) {
|
||||
/**
|
||||
* holds the qestion queue, that is emptied once you call
|
||||
*/
|
||||
this.questionMap = new lik_1.Objectmap();
|
||||
if (questionArrayArg) {
|
||||
this.addQuestions(questionArrayArg);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* allows you to ask a single question and returns the answer in a promise
|
||||
* skips the queue
|
||||
*/
|
||||
askQuestion(optionsArg) {
|
||||
let done = q.defer();
|
||||
if (this.isValidEnv()) {
|
||||
plugins.inquirer.prompt([{
|
||||
name: optionsArg.name,
|
||||
type: optionsArg.type,
|
||||
message: optionsArg.message,
|
||||
default: optionsArg.default,
|
||||
choices: optionsArg.choices,
|
||||
validate: optionsArg.validate
|
||||
}]).then((answers) => {
|
||||
done.resolve({
|
||||
name: optionsArg.name,
|
||||
value: answers[optionsArg.name]
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
let answer = {
|
||||
name: optionsArg.name,
|
||||
value: optionsArg.default
|
||||
};
|
||||
done.resolve(answer);
|
||||
}
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
* add questions to queue
|
||||
*/
|
||||
addQuestions(questionArrayArg) {
|
||||
this.questionMap.addArray(questionArrayArg);
|
||||
}
|
||||
/**
|
||||
* run the question queue
|
||||
*/
|
||||
runQueue() {
|
||||
let done = q.defer();
|
||||
let answerBucket = new AnswerBucket();
|
||||
let handleQuestion = () => {
|
||||
let oneQuestion = this.questionMap.getOneAndRemove();
|
||||
this.askQuestion(oneQuestion).then((answerArg) => {
|
||||
answerBucket.addAnswer(answerArg);
|
||||
if (!this.questionMap.isEmpty()) {
|
||||
handleQuestion(); // recursion: as questions until empty
|
||||
}
|
||||
else {
|
||||
done.resolve(answerBucket); // when empty, then resolve promise
|
||||
}
|
||||
});
|
||||
};
|
||||
handleQuestion();
|
||||
return done.promise;
|
||||
}
|
||||
/**
|
||||
* checks if the current env is valid for userinput
|
||||
*/
|
||||
isValidEnv() {
|
||||
if (!process.env.CI) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.SmartInteract = SmartInteract;
|
||||
/**
|
||||
* class AnswerBucket holds answers
|
||||
*/
|
||||
class AnswerBucket {
|
||||
constructor() {
|
||||
this.answerMap = new lik_1.Objectmap();
|
||||
}
|
||||
/**
|
||||
* add an answer to the bucket
|
||||
*/
|
||||
addAnswer(answerArg) {
|
||||
this.answerMap.add(answerArg);
|
||||
}
|
||||
/**
|
||||
* gets an answer for a specific name
|
||||
*/
|
||||
getAnswerFor(nameArg) {
|
||||
let answer = this.answerMap.find(answerArg => {
|
||||
return answerArg.name === nameArg;
|
||||
});
|
||||
return answer.value;
|
||||
}
|
||||
/**
|
||||
* gets all answers as array
|
||||
*/
|
||||
getAllAnswers() {
|
||||
return this.answerMap.getArray();
|
||||
}
|
||||
}
|
||||
exports.AnswerBucket = AnswerBucket;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5jbGFzc2VzLnNtYXJ0aW50ZXJhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGludGVyYWN0LmNsYXNzZXMuc21hcnRpbnRlcmFjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsbURBQWtEO0FBQ2xELHVCQUFzQjtBQUN0Qiw2QkFBK0I7QUEyQi9COztHQUVHO0FBQ0g7SUFPSTs7T0FFRztJQUNILFlBQVksZ0JBQW9DO1FBUmhEOztXQUVHO1FBQ0ss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
import 'typings-global';
|
||||
import * as inquirer from 'inquirer';
|
||||
export { inquirer };
|
5
dist/smartinteract.plugins.js
vendored
5
dist/smartinteract.plugins.js
vendored
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-global");
|
||||
const inquirer = require("inquirer");
|
||||
exports.inquirer = inquirer;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRpbnRlcmFjdC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSwwQkFBdUI7QUFDdkIscUNBQW9DO0FBR2hDLDRCQUFRIn0=
|
17
npmextra.json
Normal file
17
npmextra.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartinteract",
|
||||
"shortDescription": "smart cli interaction",
|
||||
"npmPackagename": "@pushrocks/smartinteract",
|
||||
"license": "MIT"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
}
|
||||
}
|
11243
package-lock.json
generated
Normal file
11243
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
package.json
49
package.json
@ -1,11 +1,13 @@
|
||||
{
|
||||
"name": "smartinteract",
|
||||
"version": "1.0.1",
|
||||
"name": "@pushrocks/smartinteract",
|
||||
"private": false,
|
||||
"version": "2.0.11",
|
||||
"description": "smart cli interaction",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -22,17 +24,32 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
|
||||
"dependencies": {
|
||||
"@types/inquirer": "0.0.31",
|
||||
"@types/node": "^6.0.48",
|
||||
"@types/q": "0.0.32",
|
||||
"@types/should": "^8.1.30",
|
||||
"inquirer": "^1.2.3",
|
||||
"lik": "^1.0.27",
|
||||
"q": "^1.4.1",
|
||||
"should": "^11.1.1",
|
||||
"typings-global": "^1.0.14"
|
||||
"@pushrocks/lik": "^4.0.17",
|
||||
"@pushrocks/smartparam": "^1.1.6",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@types/inquirer": "^7.3.1",
|
||||
"inquirer": "^7.3.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typings-test": "^1.0.3"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.25",
|
||||
"@gitzone/tstest": "^1.0.44",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
69
readme.md
Normal file
69
readme.md
Normal file
@ -0,0 +1,69 @@
|
||||
# @pushrocks/smartinteract
|
||||
smart cli interaction
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartinteract)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartinteract)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartinteract)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartinteract/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
```javascript
|
||||
import { SmartInteract } from 'smartinteract'
|
||||
|
||||
let myInteract = new SmartInteract([{ // note: its an array. You can specify multiple questions
|
||||
name: 'question1',
|
||||
type: 'input',
|
||||
message: 'Who are you?',
|
||||
default: 'Somebody',
|
||||
validate: (inputString) => { return true } // implement your own validation
|
||||
}])
|
||||
myInteract.addQuestions([ ... ]) // add more questions
|
||||
myInteract.runQueue()
|
||||
.then(answerBucket => { // the bucket has all the answers of the completed queue
|
||||
let answerQuestion1 = answerBucket.getAnswerFor('question1')
|
||||
// do something with the answers
|
||||
})
|
||||
|
||||
// alternatively use .askQuestion() for more direct control
|
||||
myInteract.askQuestion{ // note: its an array. You can specify multiple questions
|
||||
name: 'question2',
|
||||
type: 'confirm',
|
||||
message: 'Do you speak English?',
|
||||
default: true,
|
||||
validate: (inputString) => { return true } // implement your own validation
|
||||
}().then(answerObject => {
|
||||
// answerObject looks like { name: 'question2', value: true }
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
1
test/test.d.ts
vendored
1
test/test.d.ts
vendored
@ -1 +0,0 @@
|
||||
import 'typings-test';
|
37
test/test.js
37
test/test.js
@ -1,37 +0,0 @@
|
||||
"use strict";
|
||||
require("typings-test");
|
||||
const should = require("should");
|
||||
const smartinteract = require("../dist/index");
|
||||
describe('smartinteract', function () {
|
||||
let testInteract;
|
||||
it('should create a valid new instance', function () {
|
||||
testInteract = new smartinteract.SmartInteract();
|
||||
should(testInteract).be.instanceOf(smartinteract.SmartInteract);
|
||||
});
|
||||
it('should add question to SmartInteract instance', function () {
|
||||
testInteract.addQuestions([{
|
||||
name: 'testQuestion1',
|
||||
type: 'input',
|
||||
message: 'what is your favourite color? Answer is blue',
|
||||
default: 'blue'
|
||||
}]);
|
||||
testInteract.addQuestions([{
|
||||
name: 'testQuestion2',
|
||||
type: 'input',
|
||||
message: 'what is your second favourite color? Answer is red',
|
||||
default: 'red'
|
||||
}]);
|
||||
});
|
||||
it('should use default value when not in CI', function (done) {
|
||||
this.timeout(30000);
|
||||
testInteract.runQueue().then(answerBucket => {
|
||||
should(answerBucket.getAnswerFor('testQuestion1')).equal('blue');
|
||||
should(answerBucket.getAnswerFor('testQuestion2')).equal('red');
|
||||
done();
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
throw err;
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3Qud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ENBQUMsZUFBZSxDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsTUFBTSxDQUFDLENBQUE7WUFDaEUsTUFBTSxDQUFDLFlBQVksQ0FBQyxZQUFZLENBQUMsZUFBZSxDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsS0FBSyxDQUFDLENBQUE7WUFDL0QsSUFBSSxFQUFFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQyxLQUFLLENBQUMsR0FBRztZQUNSLE9BQU8sQ0FBQyxHQUFHLENBQUMsR0FBRyxDQUFDLENBQUE7WUFDaEIsTUFBTSxHQUFHLENBQUE7UUFDYixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
|
87
test/test.ts
87
test/test.ts
@ -1,37 +1,54 @@
|
||||
import 'typings-test'
|
||||
import * as should from 'should'
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartinteract from '../dist/index'
|
||||
import * as smartinteract from '../ts/index';
|
||||
|
||||
describe('smartinteract', function(){
|
||||
let testInteract: smartinteract.SmartInteract
|
||||
it('should create a valid new instance', function(){
|
||||
testInteract = new smartinteract.SmartInteract()
|
||||
should(testInteract).be.instanceOf(smartinteract.SmartInteract)
|
||||
})
|
||||
it('should add question to SmartInteract instance', function() {
|
||||
testInteract.addQuestions([{
|
||||
name: 'testQuestion1',
|
||||
type: 'input',
|
||||
message: 'what is your favourite color? Answer is blue',
|
||||
default: 'blue'
|
||||
}])
|
||||
testInteract.addQuestions([{
|
||||
name: 'testQuestion2',
|
||||
type: 'input',
|
||||
message: 'what is your second favourite color? Answer is red',
|
||||
default: 'red'
|
||||
}])
|
||||
})
|
||||
it('should use default value when not in CI', function(done){
|
||||
this.timeout(30000)
|
||||
testInteract.runQueue().then(answerBucket => {
|
||||
should(answerBucket.getAnswerFor('testQuestion1')).equal('blue')
|
||||
should(answerBucket.getAnswerFor('testQuestion2')).equal('red')
|
||||
done()
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
throw err
|
||||
})
|
||||
})
|
||||
})
|
||||
let testInteract: smartinteract.SmartInteract;
|
||||
|
||||
tap.test('should create a valid new instance', async () => {
|
||||
testInteract = new smartinteract.SmartInteract();
|
||||
expect(testInteract).to.be.instanceOf(smartinteract.SmartInteract);
|
||||
});
|
||||
|
||||
tap.test('should get a simple confirmation', async () => {
|
||||
const response = await smartinteract.SmartInteract.getCliConfirmation(
|
||||
'You feel awesome, right?',
|
||||
true
|
||||
);
|
||||
expect(response).to.be.true;
|
||||
});
|
||||
|
||||
tap.test('should add question to SmartInteract instance', async () => {
|
||||
testInteract.addQuestions([
|
||||
{
|
||||
name: 'testQuestion1',
|
||||
type: 'input',
|
||||
message: 'what is your favourite color? Answer is blue',
|
||||
default: 'blue',
|
||||
},
|
||||
]);
|
||||
testInteract.addQuestions([
|
||||
{
|
||||
name: 'testQuestion2',
|
||||
type: 'input',
|
||||
message: 'what is your second favourite color? Answer is red',
|
||||
default: 'red',
|
||||
},
|
||||
]);
|
||||
testInteract.addQuestions([
|
||||
{
|
||||
name: 'some.dotted.name',
|
||||
type: 'input',
|
||||
message: 'what is your second favourite color? Answer is aValidAnswer',
|
||||
default: 'aValidAnswer',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
tap.test('should use default value when not in CI', async () => {
|
||||
const answerBucket = await testInteract.runQueue();
|
||||
expect(answerBucket.getAnswerFor('testQuestion1')).to.equal('blue');
|
||||
expect(answerBucket.getAnswerFor('testQuestion2')).to.equal('red');
|
||||
expect(answerBucket.getAnswerFor('some.dotted.name')).to.equal('aValidAnswer');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1 +1,2 @@
|
||||
export * from './smartinteract.classes.smartinteract'
|
||||
export * from './smartinteract.classes.smartinteract';
|
||||
export * from './smartinteract.classes.answerbucket';
|
||||
|
33
ts/smartinteract.classes.answerbucket.ts
Normal file
33
ts/smartinteract.classes.answerbucket.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import * as plugins from './smartinteract.plugins';
|
||||
import { IAnswerObject } from './smartinteract.classes.smartinteract';
|
||||
|
||||
/**
|
||||
* class AnswerBucket holds answers
|
||||
*/
|
||||
export class AnswerBucket {
|
||||
private answerMap = new plugins.lik.ObjectMap<IAnswerObject>();
|
||||
|
||||
/**
|
||||
* add an answer to the bucket
|
||||
*/
|
||||
public addAnswer(answerArg: IAnswerObject) {
|
||||
this.answerMap.add(answerArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets an answer for a specific name
|
||||
*/
|
||||
public getAnswerFor(nameArg: string) {
|
||||
const answer = this.answerMap.find((answerArg) => {
|
||||
return answerArg.name === nameArg;
|
||||
});
|
||||
return answer ? answer.value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all answers as array
|
||||
*/
|
||||
public getAllAnswers() {
|
||||
return this.answerMap.getArray();
|
||||
}
|
||||
}
|
@ -1,148 +1,154 @@
|
||||
import * as plugins from './smartinteract.plugins'
|
||||
import * as q from 'q'
|
||||
import { Objectmap } from 'lik'
|
||||
import * as plugins from './smartinteract.plugins';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import { AnswerBucket } from './smartinteract.classes.answerbucket';
|
||||
|
||||
export type questionType = 'input' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor'
|
||||
/**
|
||||
* the availeable question types
|
||||
*/
|
||||
export type questionType =
|
||||
| 'input'
|
||||
| 'confirm'
|
||||
| 'list'
|
||||
| 'rawlist'
|
||||
| 'expand'
|
||||
| 'checkbox'
|
||||
| 'password'
|
||||
| 'editor';
|
||||
|
||||
/**
|
||||
* a choice
|
||||
*/
|
||||
export interface IChoiceObject {
|
||||
name: string
|
||||
value: any
|
||||
name: string;
|
||||
value: any;
|
||||
}
|
||||
|
||||
export interface IQuestionObject {
|
||||
name: string
|
||||
type: questionType
|
||||
message: string
|
||||
default: any
|
||||
choices?: string[] | IChoiceObject[]
|
||||
validate?: IValidateFunction
|
||||
name: string;
|
||||
type: questionType;
|
||||
message: string;
|
||||
default: any;
|
||||
choices?: string[] | IChoiceObject[];
|
||||
validate?: IValidateFunction;
|
||||
}
|
||||
|
||||
export interface IAnswerObject {
|
||||
name: string,
|
||||
value: any
|
||||
name: string;
|
||||
value: any;
|
||||
}
|
||||
|
||||
export interface IValidateFunction {
|
||||
(anyObject: any): boolean
|
||||
(anyObject: any): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* class SmartInteract - allows to specify an user interaction during runtime
|
||||
*/
|
||||
export class SmartInteract {
|
||||
// STATIC
|
||||
public static async getCliConfirmation(
|
||||
questionArg: string,
|
||||
defaultArg: boolean
|
||||
): Promise<boolean> {
|
||||
const smartinteractInstance = new SmartInteract();
|
||||
const response = await smartinteractInstance.askQuestion({
|
||||
default: defaultArg,
|
||||
message: questionArg,
|
||||
name: 'question',
|
||||
type: 'confirm',
|
||||
});
|
||||
return response.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* holds the qestion queue, that is emptied once you call
|
||||
*/
|
||||
private questionMap = new Objectmap<IQuestionObject>()
|
||||
// INSTANCE
|
||||
/**
|
||||
* holds the qestion queue, that is emptied once you call
|
||||
*/
|
||||
private questionMap = new plugins.lik.ObjectMap<IQuestionObject>();
|
||||
|
||||
/**
|
||||
* constructor of class SmartInteract
|
||||
*/
|
||||
constructor(questionArrayArg?: IQuestionObject[]) {
|
||||
if (questionArrayArg) {
|
||||
this.addQuestions(questionArrayArg)
|
||||
}
|
||||
/**
|
||||
* constructor of class SmartInteract
|
||||
*/
|
||||
constructor(questionArrayArg?: IQuestionObject[]) {
|
||||
if (questionArrayArg) {
|
||||
this.addQuestions(questionArrayArg);
|
||||
}
|
||||
/**
|
||||
* allows you to ask a single question and returns the answer in a promise
|
||||
* skips the queue
|
||||
*/
|
||||
askQuestion(optionsArg: IQuestionObject): q.Promise<IAnswerObject> {
|
||||
let done = q.defer<IAnswerObject>()
|
||||
if (this.isValidEnv()) {
|
||||
plugins.inquirer.prompt([{
|
||||
name: optionsArg.name,
|
||||
type: optionsArg.type,
|
||||
message: optionsArg.message,
|
||||
default: optionsArg.default,
|
||||
choices: optionsArg.choices,
|
||||
validate: optionsArg.validate
|
||||
}]).then((answers: IAnswerObject[]) => {
|
||||
done.resolve({
|
||||
name: optionsArg.name,
|
||||
value: answers[optionsArg.name]
|
||||
})
|
||||
})
|
||||
} else {
|
||||
let answer: IAnswerObject = {
|
||||
name: optionsArg.name,
|
||||
value: optionsArg.default
|
||||
}
|
||||
done.resolve(answer)
|
||||
}
|
||||
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* add questions to queue
|
||||
*/
|
||||
addQuestions(questionArrayArg: IQuestionObject[]) {
|
||||
this.questionMap.addArray(questionArrayArg)
|
||||
}
|
||||
|
||||
/**
|
||||
* run the question queue
|
||||
*/
|
||||
runQueue() {
|
||||
let done = q.defer<AnswerBucket>()
|
||||
let answerBucket = new AnswerBucket()
|
||||
let handleQuestion = () => {
|
||||
let oneQuestion = this.questionMap.getOneAndRemove()
|
||||
this.askQuestion(oneQuestion).then((answerArg: IAnswerObject) => {
|
||||
answerBucket.addAnswer(answerArg)
|
||||
if (!this.questionMap.isEmpty()) {
|
||||
handleQuestion() // recursion: as questions until empty
|
||||
} else {
|
||||
done.resolve(answerBucket) // when empty, then resolve promise
|
||||
}
|
||||
})
|
||||
}
|
||||
handleQuestion()
|
||||
return done.promise
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the current env is valid for userinput
|
||||
*/
|
||||
private isValidEnv(): boolean {
|
||||
if (!process.env.CI) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* class AnswerBucket holds answers
|
||||
*/
|
||||
export class AnswerBucket {
|
||||
answerMap = new Objectmap<IAnswerObject>()
|
||||
|
||||
/**
|
||||
* add an answer to the bucket
|
||||
*/
|
||||
addAnswer(answerArg: IAnswerObject) {
|
||||
this.answerMap.add(answerArg)
|
||||
}
|
||||
|
||||
/**
|
||||
* gets an answer for a specific name
|
||||
*/
|
||||
getAnswerFor(nameArg: string) {
|
||||
let answer = this.answerMap.find(answerArg => {
|
||||
return answerArg.name === nameArg
|
||||
}
|
||||
/**
|
||||
* allows you to ask a single question and returns the answer in a promise
|
||||
* skips the queue
|
||||
*/
|
||||
askQuestion(optionsArg: IQuestionObject): Promise<IAnswerObject> {
|
||||
const done = smartpromise.defer<IAnswerObject>();
|
||||
if (this.isValidEnv()) {
|
||||
plugins.inquirer
|
||||
.prompt([
|
||||
{
|
||||
name: optionsArg.name,
|
||||
type: optionsArg.type,
|
||||
message: optionsArg.message,
|
||||
default: optionsArg.default,
|
||||
choices: optionsArg.choices,
|
||||
validate: optionsArg.validate,
|
||||
},
|
||||
])
|
||||
.then((answers) => {
|
||||
// adjust to the fact that now dots define paths for inquirer
|
||||
const answerValue = plugins.smartparam.smartGet(answers, optionsArg.name);
|
||||
done.resolve({
|
||||
name: optionsArg.name,
|
||||
value: answerValue,
|
||||
});
|
||||
})
|
||||
return answer.value
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
} else {
|
||||
const answer: IAnswerObject = {
|
||||
name: optionsArg.name,
|
||||
value: optionsArg.default,
|
||||
};
|
||||
done.resolve(answer);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all answers as array
|
||||
*/
|
||||
getAllAnswers() {
|
||||
return this.answerMap.getArray()
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* add questions to queue
|
||||
*/
|
||||
addQuestions(questionArrayArg: IQuestionObject[]) {
|
||||
this.questionMap.addArray(questionArrayArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* run the question queue
|
||||
*/
|
||||
runQueue() {
|
||||
const done = smartpromise.defer<AnswerBucket>();
|
||||
const answerBucket = new AnswerBucket();
|
||||
const handleQuestion = async () => {
|
||||
if (!this.questionMap.isEmpty()) {
|
||||
const oneQuestion = this.questionMap.getOneAndRemove();
|
||||
const answer: IAnswerObject = await this.askQuestion(oneQuestion);
|
||||
answerBucket.addAnswer(answer);
|
||||
handleQuestion(); // recursion: as questions until empty
|
||||
} else {
|
||||
done.resolve(answerBucket); // when empty, then resolve promise
|
||||
}
|
||||
};
|
||||
handleQuestion();
|
||||
return done.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if the current env is valid for userinput
|
||||
*/
|
||||
private isValidEnv(): boolean {
|
||||
if (!process.env.CI) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
import 'typings-global'
|
||||
import * as inquirer from 'inquirer'
|
||||
// pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartparam from '@pushrocks/smartparam';
|
||||
|
||||
export {
|
||||
inquirer
|
||||
}
|
||||
export { lik, smartparam };
|
||||
|
||||
// third party scope
|
||||
import * as inquirer from 'inquirer';
|
||||
|
||||
export { inquirer };
|
||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
|
Reference in New Issue
Block a user