Compare commits
47 Commits
Author | SHA1 | Date | |
---|---|---|---|
f4e9bb9497 | |||
5aede68c43 | |||
44d30f82a6 | |||
9b5241e684 | |||
5ee46b1ccc | |||
2e5f69c6a7 | |||
bf168f688c | |||
5e92004a9f | |||
db268d4fad | |||
0acb00c9c4 | |||
b2bf396bb6 | |||
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 |
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 @git.zone/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
|
@ -1,59 +0,0 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- trigger
|
|
||||||
- pages
|
|
||||||
|
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test legacy
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test lts
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test stable
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: trigger
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmpage
|
|
||||||
stage: pages
|
|
||||||
script:
|
|
||||||
- npmci command npmpage --host gitlab
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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
|
|
||||||
}])
|
|
||||||
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 }
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
### 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5jbGFzc2VzLnNtYXJ0aW50ZXJhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGludGVyYWN0LmNsYXNzZXMuc21hcnRpbnRlcmFjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsbURBQWtEO0FBQ2xELHVCQUFzQjtBQUN0Qiw2QkFBK0I7QUEyQi9COztHQUVHO0FB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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 };
|
|
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=
|
|
@ -1,7 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"gitzone": {
|
||||||
"globalNpmTool": [
|
"projectType": "npm",
|
||||||
"npmts"
|
"module": {
|
||||||
]
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartinteract",
|
||||||
|
"description": "smart cli interaction",
|
||||||
|
"npmPackagename": "@push.rocks/smartinteract",
|
||||||
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"npmci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmAccessLevel": "public"
|
||||||
|
}
|
||||||
}
|
}
|
50
package.json
50
package.json
@ -1,11 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "smartinteract",
|
"name": "@push.rocks/smartinteract",
|
||||||
"version": "1.0.4",
|
"private": false,
|
||||||
|
"version": "2.0.15",
|
||||||
"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": "(npmts)"
|
"test": "(tstest test/)",
|
||||||
|
"build": "(tsbuild --web)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -22,17 +25,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
|
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/inquirer": "0.0.31",
|
"@push.rocks/lik": "^6.0.14",
|
||||||
"@types/node": "^6.0.48",
|
"@push.rocks/smartobject": "^1.0.12",
|
||||||
"@types/q": "0.0.32",
|
"@push.rocks/smartpromise": "^4.0.2",
|
||||||
"inquirer": "^1.2.3",
|
"@types/inquirer": "^9.0.7",
|
||||||
"lik": "^1.0.27",
|
"inquirer": "^9.2.17"
|
||||||
"q": "^1.4.1",
|
|
||||||
"typings-global": "^1.0.14"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/should": "^8.1.30",
|
"@git.zone/tsbuild": "^2.1.66",
|
||||||
"should": "^11.1.1",
|
"@git.zone/tsrun": "^1.2.44",
|
||||||
"typings-test": "^1.0.3"
|
"@git.zone/tstest": "^1.0.77",
|
||||||
}
|
"@push.rocks/tapbundle": "^5.0.22"
|
||||||
|
},
|
||||||
|
"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"
|
||||||
}
|
}
|
||||||
|
4945
pnpm-lock.yaml
generated
Normal file
4945
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)
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsK0NBQThDO0FBRTlDLFFBQVEsQ0FBQyxlQUFlLEVBQUU7SUFDdEIsSUFBSSxZQUF5QyxDQUFBO0lBQzdDLEVBQUUsQ0FBQyxvQ0FBb0MsRUFBRTtRQUNyQyxZQUFZLEdBQUcsSUFBSSxhQUFhLENBQUMsYUFBYSxFQUFFLENBQUE7UUFDaEQsTUFBTSxDQUFDLFlBQVksQ0FBQyxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsYUFBYSxDQUFDLGFBQWEsQ0FBQyxDQUFBO0lBQ25FLENBQUMsQ0FBQyxDQUFBO0lBQ0YsRUFBRSxDQUFDLCtDQUErQyxFQUFFO1FBQ2hELFlBQVksQ0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,54 @@
|
|||||||
import 'typings-test'
|
import { expect, tap } from '@push.rocks/tapbundle';
|
||||||
import * as should from 'should'
|
|
||||||
|
|
||||||
import * as smartinteract from '../dist/index'
|
import * as smartinteract from '../ts/index.js';
|
||||||
|
|
||||||
describe('smartinteract', function(){
|
let testInteract: smartinteract.SmartInteract;
|
||||||
let testInteract: smartinteract.SmartInteract
|
|
||||||
it('should create a valid new instance', function(){
|
tap.test('should create a valid new instance', async () => {
|
||||||
testInteract = new smartinteract.SmartInteract()
|
testInteract = new smartinteract.SmartInteract();
|
||||||
should(testInteract).be.instanceOf(smartinteract.SmartInteract)
|
expect(testInteract).toBeInstanceOf(smartinteract.SmartInteract);
|
||||||
})
|
});
|
||||||
it('should add question to SmartInteract instance', function() {
|
|
||||||
testInteract.addQuestions([{
|
tap.test('should get a simple confirmation', async () => {
|
||||||
name: 'testQuestion1',
|
const response = await smartinteract.SmartInteract.getCliConfirmation(
|
||||||
type: 'input',
|
'You feel awesome, right?',
|
||||||
message: 'what is your favourite color? Answer is blue',
|
true
|
||||||
default: 'blue'
|
);
|
||||||
}])
|
expect(response).toBeTrue();
|
||||||
testInteract.addQuestions([{
|
});
|
||||||
name: 'testQuestion2',
|
|
||||||
type: 'input',
|
tap.test('should add question to SmartInteract instance', async () => {
|
||||||
message: 'what is your second favourite color? Answer is red',
|
testInteract.addQuestions([
|
||||||
default: 'red'
|
{
|
||||||
}])
|
name: 'testQuestion1',
|
||||||
})
|
type: 'input',
|
||||||
it('should use default value when not in CI', function(done){
|
message: 'what is your favourite color? Answer is blue',
|
||||||
this.timeout(30000)
|
default: 'blue',
|
||||||
testInteract.runQueue().then(answerBucket => {
|
},
|
||||||
should(answerBucket.getAnswerFor('testQuestion1')).equal('blue')
|
]);
|
||||||
should(answerBucket.getAnswerFor('testQuestion2')).equal('red')
|
testInteract.addQuestions([
|
||||||
done()
|
{
|
||||||
}).catch(err => {
|
name: 'testQuestion2',
|
||||||
console.log(err)
|
type: 'input',
|
||||||
throw err
|
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')).toEqual('blue');
|
||||||
|
expect(answerBucket.getAnswerFor('testQuestion2')).toEqual('red');
|
||||||
|
expect(answerBucket.getAnswerFor('some.dotted.name')).toEqual('aValidAnswer');
|
||||||
|
});
|
||||||
|
|
||||||
|
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.15',
|
||||||
|
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,148 +1,153 @@
|
|||||||
import * as plugins from './smartinteract.plugins'
|
import * as plugins from './smartinteract.plugins.js';
|
||||||
import * as q from 'q'
|
import { AnswerBucket } from './smartinteract.classes.answerbucket.js';
|
||||||
import { Objectmap } from 'lik'
|
|
||||||
|
|
||||||
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 {
|
export interface IChoiceObject {
|
||||||
name: string
|
name: string;
|
||||||
value: any
|
value: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IQuestionObject {
|
export interface IQuestionObject {
|
||||||
name: string
|
name: string;
|
||||||
type: questionType
|
type: questionType;
|
||||||
message: string
|
message: string;
|
||||||
default: any
|
default: any;
|
||||||
choices?: string[] | IChoiceObject[]
|
choices?: string[] | IChoiceObject[];
|
||||||
validate?: IValidateFunction
|
validate?: IValidateFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IAnswerObject {
|
export interface IAnswerObject {
|
||||||
name: string,
|
name: string;
|
||||||
value: any
|
value: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IValidateFunction {
|
export interface IValidateFunction {
|
||||||
(anyObject: any): boolean
|
(anyObject: any): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
constructor(questionArrayArg?: IQuestionObject[]) {
|
constructor(questionArrayArg?: IQuestionObject[]) {
|
||||||
if (questionArrayArg) {
|
if (questionArrayArg) {
|
||||||
this.addQuestions(questionArrayArg)
|
this.addQuestions(questionArrayArg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
}
|
||||||
* allows you to ask a single question and returns the answer in a promise
|
/**
|
||||||
* skips the queue
|
* 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>()
|
askQuestion(optionsArg: IQuestionObject): Promise<IAnswerObject> {
|
||||||
if (this.isValidEnv()) {
|
const done = plugins.smartpromise.defer<IAnswerObject>();
|
||||||
plugins.inquirer.prompt([{
|
if (this.isValidEnv()) {
|
||||||
name: optionsArg.name,
|
plugins.inquirer.default
|
||||||
type: optionsArg.type,
|
.prompt([
|
||||||
message: optionsArg.message,
|
{
|
||||||
default: optionsArg.default,
|
name: optionsArg.name,
|
||||||
choices: optionsArg.choices,
|
type: optionsArg.type,
|
||||||
validate: optionsArg.validate
|
message: optionsArg.message,
|
||||||
}]).then((answers: IAnswerObject[]) => {
|
default: optionsArg.default,
|
||||||
done.resolve({
|
choices: optionsArg.choices,
|
||||||
name: optionsArg.name,
|
validate: optionsArg.validate,
|
||||||
value: answers[optionsArg.name]
|
},
|
||||||
})
|
])
|
||||||
})
|
.then((answers) => {
|
||||||
} else {
|
// adjust to the fact that now dots define paths for inquirer
|
||||||
let answer: IAnswerObject = {
|
const answerValue = plugins.smartobject.smartGet(answers, optionsArg.name);
|
||||||
name: optionsArg.name,
|
done.resolve({
|
||||||
value: optionsArg.default
|
name: optionsArg.name,
|
||||||
}
|
value: answerValue,
|
||||||
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
|
|
||||||
})
|
})
|
||||||
return answer.value
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const answer: IAnswerObject = {
|
||||||
|
name: optionsArg.name,
|
||||||
|
value: optionsArg.default,
|
||||||
|
};
|
||||||
|
done.resolve(answer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return done.promise;
|
||||||
* gets all answers as array
|
}
|
||||||
*/
|
|
||||||
getAllAnswers() {
|
/**
|
||||||
return this.answerMap.getArray()
|
* add questions to queue
|
||||||
|
*/
|
||||||
|
addQuestions(questionArrayArg: IQuestionObject[]) {
|
||||||
|
this.questionMap.addArray(questionArrayArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* run the question queue
|
||||||
|
*/
|
||||||
|
runQueue() {
|
||||||
|
const done = plugins.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,11 @@
|
|||||||
import 'typings-global'
|
// pushrocks scope
|
||||||
import * as inquirer from 'inquirer'
|
import * as lik from '@push.rocks/lik';
|
||||||
|
import * as smartobject from '@push.rocks/smartobject';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
|
||||||
export {
|
export { lik, smartobject, smartpromise };
|
||||||
inquirer
|
|
||||||
}
|
// third party scope
|
||||||
|
import * as inquirer from 'inquirer';
|
||||||
|
|
||||||
|
export { inquirer };
|
||||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"dist_*/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "tslint-config-standard"
|
|
||||||
}
|
|
Reference in New Issue
Block a user