Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e5f69c6a7 | |||
bf168f688c | |||
5e92004a9f | |||
db268d4fad | |||
0acb00c9c4 | |||
b2bf396bb6 | |||
0d2e0ca4f7 | |||
aa74482b29 | |||
ffe0f202f0 | |||
e1bbd5a844 | |||
83dcc897a8 | |||
db19c7480f | |||
c1a93102be | |||
01fd22c7d0 | |||
69592933aa | |||
10074b5888 | |||
fe9564e37c | |||
fa5f2d0267 | |||
a4cd5175b3 | |||
97c3ccb329 | |||
cfdd54eff1 | |||
741365d325 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @gitzone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
20
.gitignore
vendored
20
.gitignore
vendored
@ -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
|
142
.gitlab-ci.yml
142
.gitlab-ci.yml
@ -1,142 +0,0 @@
|
|||||||
# gitzone standard
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: "$CI_BUILD_STAGE"
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
snyk:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g snyk
|
|
||||||
- npmci command npm install --ignore-scripts
|
|
||||||
- npmci command snyk test
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# 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:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
|
||||||
services:
|
|
||||||
- docker:stable-dind
|
|
||||||
script:
|
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
|
||||||
- docker run
|
|
||||||
--env SOURCE_CODE="$PWD"
|
|
||||||
--volume "$PWD":/code
|
|
||||||
--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:
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typedoc typescript
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- 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
|
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"command": "npm test",
|
||||||
|
"name": "Run npm test",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "node-terminal"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
33
README.md
33
README.md
@ -1,33 +0,0 @@
|
|||||||
# smartinteract
|
|
||||||
|
|
||||||
smart cli interaction
|
|
||||||
|
|
||||||
## 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://www.npmjs.com/package/smartinteract)
|
|
||||||
[](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
|
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
|
||||||
|
|
||||||
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.html)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
|||||||
export * from './smartinteract.classes.smartinteract';
|
|
7
dist/index.js
vendored
7
dist/index.js
vendored
@ -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
|
|
69
dist/smartinteract.classes.smartinteract.d.ts
vendored
69
dist/smartinteract.classes.smartinteract.d.ts
vendored
@ -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[];
|
|
||||||
}
|
|
137
dist/smartinteract.classes.smartinteract.js
vendored
137
dist/smartinteract.classes.smartinteract.js
vendored
@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5jbGFzc2VzLnNtYXJ0aW50ZXJhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGludGVyYWN0L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JQUFJLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUMvQixDQUFDO0lBRUQ7O09BRUc7SUFDSCxZQUFZLENBQUUsT0FBZTtRQUMzQixJQUFJLE1BQU0sR0FBRyxJQUFJLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxTQUFTO1lBQ3hDLE1BQU0sQ0FBQyxTQUFTLENBQUMsSUFBSSxLQUFLLE9BQU8sQ0FBQTtRQUNuQyxDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNILGFBQWE7UUFDWCxNQUFNLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxRQUFRLEVBQUUsQ0FBQTtJQUNsQyxDQUFDO0NBQ0Y7QUExQkQsb0NBMEJDIn0=
|
|
3
dist/smartinteract.plugins.d.ts
vendored
3
dist/smartinteract.plugins.d.ts
vendored
@ -1,3 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
import * as inquirer from 'inquirer';
|
|
||||||
export { inquirer };
|
|
6
dist/smartinteract.plugins.js
vendored
6
dist/smartinteract.plugins.js
vendored
@ -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
|
|
@ -1,62 +0,0 @@
|
|||||||
# smartinteract
|
|
||||||
|
|
||||||
smart cli interaction
|
|
||||||
|
|
||||||
## 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://www.npmjs.com/package/smartinteract)
|
|
||||||
[](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
|
|
||||||
|
|
||||||
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 }
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
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.html)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
|
@ -1,6 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"gitzone": {
|
||||||
"npmGlobalTools": ["npmts"]
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartinteract",
|
||||||
|
"description": "smart cli interaction",
|
||||||
|
"npmPackagename": "@push.rocks/smartinteract",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"npmAccessLevel": "public"
|
"npmci": {
|
||||||
}
|
"npmGlobalTools": [],
|
||||||
|
"npmAccessLevel": "public"
|
||||||
|
}
|
||||||
|
}
|
1285
package-lock.json
generated
1285
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
47
package.json
47
package.json
@ -1,14 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartinteract",
|
"name": "@push.rocks/smartinteract",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "2.0.3",
|
"version": "2.0.13",
|
||||||
"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)"
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -25,13 +25,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
|
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.1",
|
"@push.rocks/lik": "^6.0.2",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@push.rocks/smartobject": "^1.0.12",
|
||||||
"@types/inquirer": "0.0.42",
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
"inquirer": "^6.0.0"
|
"@types/inquirer": "^9.0.3",
|
||||||
|
"inquirer": "^9.2.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsrun": "^1.1.9",
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
"@pushrocks/tapbundle": "^3.0.1"
|
"@gitzone/tsrun": "^1.2.44",
|
||||||
}
|
"@gitzone/tstest": "^1.0.74",
|
||||||
|
"@push.rocks/tapbundle": "^5.0.12"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
],
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
4982
pnpm-lock.yaml
generated
Normal file
4982
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
66
readme.md
Normal file
66
readme.md
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# @push.rocks/smartinteract
|
||||||
|
smart cli interaction
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartinteract)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartinteract)
|
||||||
|
* [github.com (source mirror)](https://github.com/push.rocks/smartinteract)
|
||||||
|
* [docs (typedoc)](https://push.rocks.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)
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
36
test/test.ts
36
test/test.ts
@ -1,12 +1,20 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
|
|
||||||
import * as smartinteract from '../ts/index';
|
import * as smartinteract from '../ts/index.js';
|
||||||
|
|
||||||
let testInteract: smartinteract.SmartInteract;
|
let testInteract: smartinteract.SmartInteract;
|
||||||
|
|
||||||
tap.test('should create a valid new instance', async () => {
|
tap.test('should create a valid new instance', async () => {
|
||||||
testInteract = new smartinteract.SmartInteract();
|
testInteract = new smartinteract.SmartInteract();
|
||||||
expect(testInteract).to.be.instanceOf(smartinteract.SmartInteract);
|
expect(testInteract).toBeInstanceOf(smartinteract.SmartInteract);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should get a simple confirmation', async () => {
|
||||||
|
const response = await smartinteract.SmartInteract.getCliConfirmation(
|
||||||
|
'You feel awesome, right?',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
expect(response).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should add question to SmartInteract instance', async () => {
|
tap.test('should add question to SmartInteract instance', async () => {
|
||||||
@ -15,32 +23,32 @@ tap.test('should add question to SmartInteract instance', async () => {
|
|||||||
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 red',
|
message: 'what is your second favourite color? Answer is aValidAnswer',
|
||||||
default: 'aValidAnswer'
|
default: 'aValidAnswer',
|
||||||
}
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should use default value when not in CI', async () => {
|
tap.test('should use default value when not in CI', async () => {
|
||||||
let answerBucket = await testInteract.runQueue();
|
const answerBucket = await testInteract.runQueue();
|
||||||
expect(answerBucket.getAnswerFor('testQuestion1')).to.equal('blue');
|
expect(answerBucket.getAnswerFor('testQuestion1')).toEqual('blue');
|
||||||
expect(answerBucket.getAnswerFor('testQuestion2')).to.equal('red');
|
expect(answerBucket.getAnswerFor('testQuestion2')).toEqual('red');
|
||||||
expect(answerBucket.getAnswerFor('some.dotted.name')).to.equal('aValidAnswer');
|
expect(answerBucket.getAnswerFor('some.dotted.name')).toEqual('aValidAnswer');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@push.rocks/smartinteract',
|
||||||
|
version: '2.0.13',
|
||||||
|
description: 'smart cli interaction'
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
export * from './smartinteract.classes.smartinteract';
|
export * from './smartinteract.classes.smartinteract.js';
|
||||||
|
export * from './smartinteract.classes.answerbucket.js';
|
||||||
|
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.js';
|
||||||
|
import { type IAnswerObject } from './smartinteract.classes.smartinteract.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.findSync((answerArg) => {
|
||||||
|
return answerArg.name === nameArg;
|
||||||
|
});
|
||||||
|
return answer ? answer.value : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets all answers as array
|
||||||
|
*/
|
||||||
|
public getAllAnswers() {
|
||||||
|
return this.answerMap.getArray();
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
import * as plugins from './smartinteract.plugins';
|
import * as plugins from './smartinteract.plugins.js';
|
||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
import { AnswerBucket } from './smartinteract.classes.answerbucket.js';
|
||||||
import { Objectmap } from '@pushrocks/lik';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the availeable question types
|
* the availeable question types
|
||||||
@ -16,7 +15,7 @@ export type questionType =
|
|||||||
| 'editor';
|
| 'editor';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a choice
|
* a choice
|
||||||
*/
|
*/
|
||||||
export interface IChoiceObject {
|
export interface IChoiceObject {
|
||||||
name: string;
|
name: string;
|
||||||
@ -45,10 +44,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 Objectmap<IQuestionObject>();
|
private questionMap = new plugins.lik.ObjectMap<IQuestionObject>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor of class SmartInteract
|
* constructor of class SmartInteract
|
||||||
@ -63,9 +78,9 @@ 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 = plugins.smartpromise.defer<IAnswerObject>();
|
||||||
if (this.isValidEnv()) {
|
if (this.isValidEnv()) {
|
||||||
plugins.inquirer
|
plugins.inquirer.default
|
||||||
.prompt([
|
.prompt([
|
||||||
{
|
{
|
||||||
name: optionsArg.name,
|
name: optionsArg.name,
|
||||||
@ -73,28 +88,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: IAnswerObject[]) => {
|
.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: any = answers;
|
const answerValue = plugins.smartobject.smartGet(answers, optionsArg.name);
|
||||||
let nameArray = optionsArg.name.split('.');
|
|
||||||
for (let name of nameArray) {
|
|
||||||
answerValue = answerValue[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);
|
||||||
}
|
}
|
||||||
@ -113,12 +124,12 @@ export class SmartInteract {
|
|||||||
* run the question queue
|
* run the question queue
|
||||||
*/
|
*/
|
||||||
runQueue() {
|
runQueue() {
|
||||||
let done = smartpromise.defer<AnswerBucket>();
|
const done = plugins.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 {
|
||||||
@ -140,34 +151,3 @@ export class SmartInteract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
});
|
|
||||||
return answer.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets all answers as array
|
|
||||||
*/
|
|
||||||
getAllAnswers() {
|
|
||||||
return this.answerMap.getArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
// pushrocks scope
|
||||||
|
import * as lik from '@push.rocks/lik';
|
||||||
|
import * as smartobject from '@push.rocks/smartobject';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
|
||||||
|
export { lik, smartobject, smartpromise };
|
||||||
|
|
||||||
|
// third party scope
|
||||||
import * as inquirer from 'inquirer';
|
import * as inquirer from 'inquirer';
|
||||||
|
|
||||||
export { inquirer };
|
export { inquirer };
|
||||||
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Reference in New Issue
Block a user