10 Commits

Author SHA1 Message Date
0d2e0ca4f7 2.0.11 2020-08-31 19:25:26 +00:00
aa74482b29 fix(core): update 2020-08-31 19:25:25 +00:00
ffe0f202f0 2.0.10 2020-08-31 19:23:52 +00:00
e1bbd5a844 fix(core): update 2020-08-31 19:23:51 +00:00
83dcc897a8 2.0.9 2020-02-07 16:45:49 +00:00
db19c7480f fix(core): update 2020-02-07 16:45:48 +00:00
c1a93102be 2.0.8 2020-02-07 16:36:36 +00:00
01fd22c7d0 fix(core): update 2020-02-07 16:36:35 +00:00
69592933aa 2.0.7 2020-02-02 18:05:50 +00:00
10074b5888 fix(core): update 2020-02-02 18:05:50 +00:00
21 changed files with 10753 additions and 930 deletions

20
.gitignore vendored
View File

@ -1,4 +1,20 @@
node_modules/ .nogit/
# artifacts
coverage/
public/ public/
pages/ pages/
coverage/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,16 +1,16 @@
# gitzone standard # gitzone ci_default
image: hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .npmci_cache/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: '$CI_BUILD_STAGE'
stages: stages:
- security - security
- test - test
- release - release
- metadata - metadata
# ==================== # ====================
# security stage # security stage
@ -18,109 +18,114 @@ stages:
mirror: mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
snyk: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci command npm install -g snyk - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --production --ignore-scripts
- npmci command snyk test - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags: tags:
- docker - docker
- notpriv
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
# ==================== # ====================
# test stage # test stage
# ==================== # ====================
testLEGACY:
stage: test
script:
- npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
allow_failure: true
testLTS: testStable:
stage: test stage: test
script: script:
- npmci node install lts - npmci npm prepare
- npmci npm install - npmci node install stable
- npmci npm test - npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
testBuild:
testSTABLE:
stage: test stage: test
script: script:
- npmci node install stable - npmci npm prepare
- npmci npm install - npmci node install stable
- npmci npm test - npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install stable - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
# ==================== # ====================
# metadata stage # metadata stage
# ==================== # ====================
codequality: codequality:
stage: metadata stage: metadata
image: docker:stable
allow_failure: true allow_failure: true
services: only:
- docker:stable-dind - tags
script: script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - npmci command npm install -g tslint typescript
- docker run - npmci npm prepare
--env SOURCE_CODE="$PWD" - npmci npm install
--volume "$PWD":/code - npmci command "tslint -c tslint.json ./ts/**/*.ts"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags: tags:
- docker - lossless
- priv - docker
- priv
trigger: trigger:
stage: metadata stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - lossless
- notpriv - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata stage: metadata
script: script:
- npmci command npm install -g typedoc typescript - npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/ - npmci command tsdoc
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
only: only:
@ -128,15 +133,5 @@ pages:
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true allow_failure: true

29
.vscode/launch.json vendored Normal file
View 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
View 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"]
}
}
}
}
}
}
]
}

1
dist/index.d.ts vendored
View File

@ -1 +0,0 @@
export * from './smartinteract.classes.smartinteract';

7
dist/index.js vendored
View File

@ -1,7 +0,0 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./smartinteract.classes.smartinteract"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDJEQUFxRCJ9

View File

@ -1,69 +0,0 @@
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): Promise<IAnswerObject>;
/**
* add questions to queue
*/
addQuestions(questionArrayArg: IQuestionObject[]): void;
/**
* run the question queue
*/
runQueue(): 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[];
}

View File

@ -1,137 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./smartinteract.plugins");
const smartq = require("smartq");
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 = smartq.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) => {
// adjust to the fact that now dots define paths for inquirer
let answerValue = answers;
let nameArray = optionsArg.name.split('.');
for (let name of nameArray) {
answerValue = answerValue[name];
}
done.resolve({
name: optionsArg.name,
value: answerValue
});
}).catch(err => {
console.log(err);
});
}
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 = smartq.defer();
let answerBucket = new AnswerBucket();
let handleQuestion = () => __awaiter(this, void 0, void 0, function* () {
if (!this.questionMap.isEmpty()) {
let oneQuestion = this.questionMap.getOneAndRemove();
let answer = yield 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
*/
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5jbGFzc2VzLnNtYXJ0aW50ZXJhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGludGVyYWN0LmNsYXNzZXMuc21hcnRpbnRlcmFjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsbURBQWtEO0FBQ2xELGlDQUFnQztBQUNoQyw2QkFBK0I7QUEyQi9COztHQUVHO0FBQ0g7SUFPRTs7T0FFRztJQUNILFlBQWEsZ0JBQW9DO1FBUmpEOztXQUVHO1FBQ0ssZ0JBQVcsR0FBRyxJQUFJLGVBQVMsRUFBbUIsQ0FBQTtRQU1wRCxFQUFFLENBQUMsQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUM7WUFDckIsSUFBSSxDQUFDLFlBQVksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFBO1FBQ3JDLENBQUM7SUFDSCxDQUFDO0lBQ0Q7OztPQUdHO0lBQ0gsV0FBVyxDQUFFLFVBQTJCO1FBQ3RDLElBQUksSUFBSSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQWlCLENBQUE7UUFDeEMsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxDQUFDLENBQUMsQ0FB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QUMsT0FBTyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNLLFVBQVU7UUFDaEIsRUFBRSxDQUFDLENBQUMsQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUM7WUFDcEIsTUFBTSxDQUFDLElBQUksQ0FBQTtRQUNiLENBQUM7UUFBQyxJQUFJLENBQUMsQ0FBQztZQUNOLE1BQU0sQ0FBQyxLQUFLLENBQUE7UUFDZCxDQUFDO0lBQ0gsQ0FBQztDQUNGO0FBM0ZELHNDQTJGQztBQUVEOztHQUVHO0FBQ0g7SUFBQTtRQUNFLGNBQVMsR0FBRyxJQUFJLGVBQVMsRUFBaUIsQ0FBQTtJQXlCNUMsQ0FBQztJQXZCQzs7T0FFRztJQUNILFNBQVMsQ0FBRSxTQUF3QjtRQUNqQyxJQUFJLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUMvQixDQUFDO0lBRUQ7O09BRUc7SUFDSCxZQUFZLENBQUUsT0FBZTtRQUMzQixJQUFJLE1BQU0sR0FBRyxJQUFJLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxTQUFTO1lBQ3hDLE1BQU0sQ0FBQyxTQUFTLENBQUMsSUFBSSxLQUFLLE9BQU8sQ0FBQTtRQUNuQyxDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNILGFBQWE7UUFDWCxNQUFNLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxRQUFRLEVBQUUsQ0FBQTtJQUNsQyxDQUFDO0NBQ0Y7QUExQkQsb0NBMEJDIn0=

View File

@ -1,3 +0,0 @@
import 'typings-global';
import * as inquirer from 'inquirer';
export { inquirer };

View File

@ -1,6 +0,0 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("typings-global");
const inquirer = require("inquirer");
exports.inquirer = inquirer;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRpbnRlcmFjdC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsMEJBQXVCO0FBQ3ZCLHFDQUFvQztBQUdsQyw0QkFBUSJ9

View File

@ -1,35 +0,0 @@
# smartinteract
smart cli interaction
## Availabililty
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartinteract)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartinteract)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartinteract)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartinteract/)
## Status for master
[![build status](https://GitLab.com/pushrocks/smartinteract/badges/master/build.svg)](https://GitLab.com/pushrocks/smartinteract/commits/master)
[![coverage report](https://GitLab.com/pushrocks/smartinteract/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartinteract/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/smartinteract.svg)](https://www.npmjs.com/package/smartinteract)
[![Dependency Status](https://david-dm.org/pushrocks/smartinteract.svg)](https://david-dm.org/pushrocks/smartinteract)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartinteract/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartinteract/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartinteract/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartinteract)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
Use TypeScript for best in class instellisense.
For further information read the linked docs at the top of this README.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks)

View File

@ -1,6 +1,17 @@
{ {
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartinteract",
"shortDescription": "smart cli interaction",
"npmPackagename": "@pushrocks/smartinteract",
"license": "MIT"
}
},
"npmci": { "npmci": {
"npmGlobalTools": ["npmts"], "npmGlobalTools": [],
"npmAccessLevel": "public" "npmAccessLevel": "public"
} }
} }

10996
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,13 @@
{ {
"name": "@pushrocks/smartinteract", "name": "@pushrocks/smartinteract",
"private": false, "private": false,
"version": "2.0.6", "version": "2.0.11",
"description": "smart cli interaction", "description": "smart cli interaction",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "tsrun test/test.ts", "test": "(tstest test/)",
"testLocal": "(npmts --notest && ts-node --compilerOptions '{\"target\":\"es6\"}' test/test.ts)", "build": "(tsbuild --web)"
"build": "(npmts --notest)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -25,16 +24,32 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartinteract#README", "homepage": "https://gitlab.com/pushrocks/smartinteract#README",
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.13", "@pushrocks/lik": "^4.0.17",
"@pushrocks/smartparam": "^1.1.6", "@pushrocks/smartparam": "^1.1.6",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.0.6",
"@types/inquirer": "^6.5.0", "@types/inquirer": "^7.3.1",
"inquirer": "^7.0.4" "inquirer": "^7.3.3"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsbuild": "^2.1.25",
"@pushrocks/tapbundle": "^3.2.0", "@gitzone/tstest": "^1.0.44",
"tslint": "^6.0.0", "@pushrocks/tapbundle": "^3.2.9",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0" "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"
]
} }

View File

@ -1,25 +1,27 @@
# smartinteract # @pushrocks/smartinteract
smart cli interaction smart cli interaction
## Availabililty ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartinteract)
[![npm](https://pushrocks.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartinteract) * [gitlab.com (source)](https://gitlab.com/pushrocks/smartinteract)
[![git](https://pushrocks.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartinteract) * [github.com (source mirror)](https://github.com/pushrocks/smartinteract)
[![git](https://pushrocks.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartinteract) * [docs (typedoc)](https://pushrocks.gitlab.io/smartinteract/)
[![docs](https://pushrocks.gitlab.io/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartinteract/)
## Status for master ## Status for master
[![build status](https://GitLab.com/pushrocks/smartinteract/badges/master/build.svg)](https://GitLab.com/pushrocks/smartinteract/commits/master) Status Category | Status Badge
[![coverage report](https://GitLab.com/pushrocks/smartinteract/badges/master/coverage.svg)](https://GitLab.com/pushrocks/smartinteract/commits/master) -- | --
[![npm downloads per month](https://img.shields.io/npm/dm/smartinteract.svg)](https://www.npmjs.com/package/smartinteract) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartinteract/badges/master/pipeline.svg)](https://lossless.cloud)
[![Dependency Status](https://david-dm.org/pushrocks/smartinteract.svg)](https://david-dm.org/pushrocks/smartinteract) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartinteract/badges/master/coverage.svg)](https://lossless.cloud)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartinteract/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartinteract/master/dependencies/npm) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartinteract)](https://lossless.cloud)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartinteract/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartinteract) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartinteract)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/) node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartinteract)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartinteract)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartinteract)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
@ -54,9 +56,14 @@ myInteract.askQuestion{ // note: its an array. You can specify multiple question
}) })
``` ```
## 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. For further information read the linked docs at the top of this readme.
> MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://push.rocks) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -9,30 +9,38 @@ tap.test('should create a valid new instance', async () => {
expect(testInteract).to.be.instanceOf(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 () => { tap.test('should add question to SmartInteract instance', async () => {
testInteract.addQuestions([ testInteract.addQuestions([
{ {
name: 'testQuestion1', name: 'testQuestion1',
type: 'input', type: 'input',
message: 'what is your favourite color? Answer is blue', message: 'what is your favourite color? Answer is blue',
default: 'blue' default: 'blue',
} },
]); ]);
testInteract.addQuestions([ testInteract.addQuestions([
{ {
name: 'testQuestion2', name: 'testQuestion2',
type: 'input', type: 'input',
message: 'what is your second favourite color? Answer is red', message: 'what is your second favourite color? Answer is red',
default: 'red' default: 'red',
} },
]); ]);
testInteract.addQuestions([ testInteract.addQuestions([
{ {
name: 'some.dotted.name', name: 'some.dotted.name',
type: 'input', type: 'input',
message: 'what is your second favourite color? Answer is aValidAnswer', message: 'what is your second favourite color? Answer is aValidAnswer',
default: 'aValidAnswer' default: 'aValidAnswer',
} },
]); ]);
}); });

View File

@ -1,2 +1,2 @@
export * from './smartinteract.classes.smartinteract'; export * from './smartinteract.classes.smartinteract';
export * from './smartinteract.classes.answerbucket'; export * from './smartinteract.classes.answerbucket';

View File

@ -5,20 +5,20 @@ import { IAnswerObject } from './smartinteract.classes.smartinteract';
* class AnswerBucket holds answers * class AnswerBucket holds answers
*/ */
export class AnswerBucket { export class AnswerBucket {
answerMap = new plugins.lik.Objectmap<IAnswerObject>(); private answerMap = new plugins.lik.ObjectMap<IAnswerObject>();
/** /**
* add an answer to the bucket * add an answer to the bucket
*/ */
addAnswer(answerArg: IAnswerObject) { public addAnswer(answerArg: IAnswerObject) {
this.answerMap.add(answerArg); this.answerMap.add(answerArg);
} }
/** /**
* gets an answer for a specific name * gets an answer for a specific name
*/ */
getAnswerFor(nameArg: string) { public getAnswerFor(nameArg: string) {
let answer = this.answerMap.find(answerArg => { const answer = this.answerMap.find((answerArg) => {
return answerArg.name === nameArg; return answerArg.name === nameArg;
}); });
return answer ? answer.value : null; return answer ? answer.value : null;
@ -27,7 +27,7 @@ export class AnswerBucket {
/** /**
* gets all answers as array * gets all answers as array
*/ */
getAllAnswers() { public getAllAnswers() {
return this.answerMap.getArray(); return this.answerMap.getArray();
} }
} }

View File

@ -16,7 +16,7 @@ export type questionType =
| 'editor'; | 'editor';
/** /**
* a choice * a choice
*/ */
export interface IChoiceObject { export interface IChoiceObject {
name: string; name: string;
@ -45,10 +45,26 @@ export interface IValidateFunction {
* class SmartInteract - allows to specify an user interaction during runtime * class SmartInteract - allows to specify an user interaction during runtime
*/ */
export class SmartInteract { 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;
}
// INSTANCE
/** /**
* holds the qestion queue, that is emptied once you call * holds the qestion queue, that is emptied once you call
*/ */
private questionMap = new plugins.lik.Objectmap<IQuestionObject>(); private questionMap = new plugins.lik.ObjectMap<IQuestionObject>();
/** /**
* constructor of class SmartInteract * constructor of class SmartInteract
@ -63,7 +79,7 @@ export class SmartInteract {
* skips the queue * skips the queue
*/ */
askQuestion(optionsArg: IQuestionObject): Promise<IAnswerObject> { askQuestion(optionsArg: IQuestionObject): Promise<IAnswerObject> {
let done = smartpromise.defer<IAnswerObject>(); const done = smartpromise.defer<IAnswerObject>();
if (this.isValidEnv()) { if (this.isValidEnv()) {
plugins.inquirer plugins.inquirer
.prompt([ .prompt([
@ -73,24 +89,24 @@ export class SmartInteract {
message: optionsArg.message, message: optionsArg.message,
default: optionsArg.default, default: optionsArg.default,
choices: optionsArg.choices, choices: optionsArg.choices,
validate: optionsArg.validate validate: optionsArg.validate,
} },
]) ])
.then((answers) => { .then((answers) => {
// adjust to the fact that now dots define paths for inquirer // adjust to the fact that now dots define paths for inquirer
let answerValue = plugins.smartparam.smartGet(answers, optionsArg.name); const answerValue = plugins.smartparam.smartGet(answers, optionsArg.name);
done.resolve({ done.resolve({
name: optionsArg.name, name: optionsArg.name,
value: answerValue value: answerValue,
}); });
}) })
.catch(err => { .catch((err) => {
console.log(err); console.log(err);
}); });
} else { } else {
let answer: IAnswerObject = { const answer: IAnswerObject = {
name: optionsArg.name, name: optionsArg.name,
value: optionsArg.default value: optionsArg.default,
}; };
done.resolve(answer); done.resolve(answer);
} }
@ -109,12 +125,12 @@ export class SmartInteract {
* run the question queue * run the question queue
*/ */
runQueue() { runQueue() {
let done = smartpromise.defer<AnswerBucket>(); const done = smartpromise.defer<AnswerBucket>();
let answerBucket = new AnswerBucket(); const answerBucket = new AnswerBucket();
let handleQuestion = async () => { const handleQuestion = async () => {
if (!this.questionMap.isEmpty()) { if (!this.questionMap.isEmpty()) {
let oneQuestion = this.questionMap.getOneAndRemove(); const oneQuestion = this.questionMap.getOneAndRemove();
let answer: IAnswerObject = await this.askQuestion(oneQuestion); const answer: IAnswerObject = await this.askQuestion(oneQuestion);
answerBucket.addAnswer(answer); answerBucket.addAnswer(answer);
handleQuestion(); // recursion: as questions until empty handleQuestion(); // recursion: as questions until empty
} else { } else {

View File

@ -2,11 +2,7 @@
import * as lik from '@pushrocks/lik'; import * as lik from '@pushrocks/lik';
import * as smartparam from '@pushrocks/smartparam'; import * as smartparam from '@pushrocks/smartparam';
export { export { lik, smartparam };
lik,
smartparam
}
// third party scope // third party scope
import * as inquirer from 'inquirer'; import * as inquirer from 'inquirer';

View File

@ -1,7 +1,17 @@
{ {
"extends": ["tslint:latest", "tslint-config-prettier"], "extends": ["tslint:latest", "tslint-config-prettier"],
"rules": { "rules": {
"semicolon": [true, "always"] "semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
} }
} },
"defaultSeverity": "warning"
}