Compare commits
27 Commits
Author | SHA1 | Date | |
---|---|---|---|
8ed151b941 | |||
d2294dd587 | |||
9fd1efd3e7 | |||
61a0bfc966 | |||
2a4526297c | |||
3f4ce9a9bd | |||
f4e9bb9497 | |||
5aede68c43 | |||
44d30f82a6 | |||
9b5241e684 | |||
5ee46b1ccc | |||
2e5f69c6a7 | |||
bf168f688c | |||
5e92004a9f | |||
db268d4fad | |||
0acb00c9c4 | |||
b2bf396bb6 | |||
0d2e0ca4f7 | |||
aa74482b29 | |||
ffe0f202f0 | |||
e1bbd5a844 | |||
83dcc897a8 | |||
db19c7480f | |||
c1a93102be | |||
01fd22c7d0 | |||
69592933aa | |||
10074b5888 |
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
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5jbGFzc2VzLnNtYXJ0aW50ZXJhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGludGVyYWN0LmNsYXNzZXMuc21hcnRpbnRlcmFjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBQUEsbURBQWtEO0FBQ2xELGlDQUFnQztBQUNoQyw2QkFBK0I7QUEyQi9COztHQUVHO0FBQ0g7SUFPRTs7T0FFRztJQUNILFlBQWEsZ0JBQW9DO1FBUmpEOztXQUVHO1FBQ0ssZ0JBQVcsR0FBRyxJQUFJLGVBQVMsRUFBbUIsQ0FBQTtRQU1wRCxFQUFFLENBQUMsQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFDLENBQUM7WUFDckIsSUFBSSxDQUFDLFlBQVksQ0FBQyxnQkFBZ0IsQ0FBQyxDQUFBO1FBQ3JDLENBQUM7SUFDSCxDQUFDO0lBQ0Q7OztPQUdHO0lBQ0gsV0FBVyxDQUFFLFVBQTJCO1FBQ3RDLElBQUksSUFBSSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQWlCLENBQUE7UUFDeEMsRUFBRSxDQUFDLENBQUMsSUFBSSxDQUFDLFVBQVUsRUFBRSxDQUFDLENBQUMsQ0FBQztZQUN0QixPQUFPLENBQUMsUUFBUSxDQUFDLE1BQU0sQ0FBQyxDQUFFO29CQUN4QixJQUFJLEVBQUUsVUFBVSxDQUFDLElBQUk7b0JBQ3JCLElBQUksRUFBRSxVQUFVLENBQUMsSUFBSTtvQkFDckIsT0FBTyxFQUFFLFVBQVUsQ0FBQyxPQUFPO29CQUMzQixPQUFPLEVBQUUsVUFBVSxDQUFDLE9BQU87b0JBQzNCLE9BQU8sRUFBRSxVQUFVLENBQUMsT0FBTztvQkFDM0IsUUFBUSxFQUFFLFVBQVUsQ0FBQyxRQUFRO2lCQUM5QixDQUFDLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxPQUF3QjtnQkFDaEMsNkRBQTZEO2dCQUM3RCxJQUFJLFdBQVcsR0FBUSxPQUFPLENBQUE7Z0JBQzlCLElBQUksU0FBUyxHQUFHLFVBQVUsQ0FBQyxJ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
|
|
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,35 +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,6 +1,32 @@
|
|||||||
{
|
{
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "code.foss.global",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartinteract",
|
||||||
|
"description": "A package for creating smart CLI interactions with customizable questions and answers.",
|
||||||
|
"npmPackagename": "@push.rocks/smartinteract",
|
||||||
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"CLI",
|
||||||
|
"interactive prompts",
|
||||||
|
"command line interface",
|
||||||
|
"user input handling",
|
||||||
|
"inquirer integration",
|
||||||
|
"CLI questions",
|
||||||
|
"CLI validations",
|
||||||
|
"CLI interactions",
|
||||||
|
"smart CLI",
|
||||||
|
"typescript"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": ["npmts"],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
|
},
|
||||||
|
"tsdoc": {
|
||||||
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
1291
package-lock.json
generated
1291
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
69
package.json
69
package.json
@ -1,40 +1,63 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartinteract",
|
"name": "@push.rocks/smartinteract",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "2.0.6",
|
"version": "2.0.15",
|
||||||
"description": "smart cli interaction",
|
"description": "A package for creating smart CLI interactions with customizable questions and answers.",
|
||||||
"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",
|
||||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartinteract.git"
|
"url": "https://code.foss.global/push.rocks/smartinteract.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"interaction",
|
"CLI",
|
||||||
"cli"
|
"interactive prompts",
|
||||||
|
"command line interface",
|
||||||
|
"user input handling",
|
||||||
|
"inquirer integration",
|
||||||
|
"CLI questions",
|
||||||
|
"CLI validations",
|
||||||
|
"CLI interactions",
|
||||||
|
"smart CLI",
|
||||||
|
"typescript"
|
||||||
],
|
],
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://gitlab.com/pushrocks/smartinteract/issues"
|
"url": "https://gitlab.com/pushrocks/smartinteract/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
|
"homepage": "https://code.foss.global/push.rocks/smartinteract",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.13",
|
"@push.rocks/lik": "^6.0.15",
|
||||||
"@pushrocks/smartparam": "^1.1.6",
|
"@push.rocks/smartobject": "^1.0.12",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@push.rocks/smartpromise": "^4.0.4",
|
||||||
"@types/inquirer": "^6.5.0",
|
"inquirer": "^11.1.0"
|
||||||
"inquirer": "^7.0.4"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@git.zone/tsbuild": "^2.1.84",
|
||||||
"@pushrocks/tapbundle": "^3.2.0",
|
"@git.zone/tsrun": "^1.2.49",
|
||||||
"tslint": "^6.0.0",
|
"@git.zone/tstest": "^1.0.90",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"@push.rocks/tapbundle": "^5.3.0"
|
||||||
}
|
},
|
||||||
}
|
"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"
|
||||||
|
}
|
6887
pnpm-lock.yaml
generated
Normal file
6887
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
157
readme.md
157
readme.md
@ -1,62 +1,127 @@
|
|||||||
# smartinteract
|
# @push.rocks/smartinteract
|
||||||
|
|
||||||
smart cli interaction
|
smart cli interaction
|
||||||
|
|
||||||
## Availabililty
|
## Install
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartinteract)
|
To install `@push.rocks/smartinteract`, use npm or yarn as follows:
|
||||||
[](https://GitLab.com/pushrocks/smartinteract)
|
|
||||||
[](https://github.com/pushrocks/smartinteract)
|
|
||||||
[](https://pushrocks.gitlab.io/smartinteract/)
|
|
||||||
|
|
||||||
## Status for master
|
```bash
|
||||||
|
npm install @push.rocks/smartinteract --save
|
||||||
|
# or using yarn
|
||||||
|
yarn add @push.rocks/smartinteract
|
||||||
|
```
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/smartinteract/commits/master)
|
This will add it to your project's `node_modules` folder and list it as a dependency in your project's `package.json` file.
|
||||||
[](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
|
## Usage
|
||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
The `@push.rocks/smartinteract` module is designed to facilitate smart command-line interactions by providing a flexible way to query input from users in a structured manner. It leverages TypeScript for enhanced development experience, offering strong types and IntelliSense in supported editors.
|
||||||
|
|
||||||
```javascript
|
### Getting Started
|
||||||
import { SmartInteract } from 'smartinteract'
|
|
||||||
|
|
||||||
let myInteract = new SmartInteract([{ // note: its an array. You can specify multiple questions
|
To begin, import `SmartInteract` from the module:
|
||||||
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
|
```typescript
|
||||||
myInteract.askQuestion{ // note: its an array. You can specify multiple questions
|
import { SmartInteract } from '@push.rocks/smartinteract';
|
||||||
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.
|
### Creating and Running Interactions
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
You can specify questions for user interaction as shown below:
|
||||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[](https://push.rocks)
|
```typescript
|
||||||
|
const smartInteract = new SmartInteract([
|
||||||
|
{
|
||||||
|
name: 'userName',
|
||||||
|
type: 'input',
|
||||||
|
message: 'What is your name?',
|
||||||
|
default: 'John Doe',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'userConfirmation',
|
||||||
|
type: 'confirm',
|
||||||
|
message: 'Do you agree with the terms?',
|
||||||
|
default: false,
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
`SmartInteract` supports various question types such as 'input', 'confirm', 'list', 'rawlist', 'checkbox', 'password', and 'editor'. This allows for a diverse range of user inputs from simple text inputs to selections from a list.
|
||||||
|
|
||||||
|
### Adding Additional Questions Dynamically
|
||||||
|
|
||||||
|
You can dynamically add more questions to the interaction:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
smartInteract.addQuestions([
|
||||||
|
{
|
||||||
|
name: 'userHobby',
|
||||||
|
type: 'input',
|
||||||
|
message: 'What is your favorite hobby?',
|
||||||
|
default: 'Programming',
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running the Interaction Queue
|
||||||
|
|
||||||
|
Execute the queued interaction and process the responses:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
smartInteract.runQueue()
|
||||||
|
.then(answerBucket => {
|
||||||
|
const userResponse = {
|
||||||
|
name: answerBucket.getAnswerFor('userName'),
|
||||||
|
agreed: answerBucket.getAnswerFor('userConfirmation'),
|
||||||
|
hobby: answerBucket.getAnswerFor('userHobby')
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(userResponse);
|
||||||
|
// Output: { name: 'John Doe', agreed: true/false, hobby: 'Programming'}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Direct Questioning
|
||||||
|
|
||||||
|
For immediate prompting without queuing, you can utilize the `askQuestion` method:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
smartInteract.askQuestion({
|
||||||
|
name: 'urgentQuery',
|
||||||
|
type: 'confirm',
|
||||||
|
message: 'Do you need to save changes?',
|
||||||
|
default: true,
|
||||||
|
})
|
||||||
|
.then(answerObject => {
|
||||||
|
console.log(answerObject);
|
||||||
|
// Output: { name: 'urgentQuery', value: true/false }
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Usage
|
||||||
|
|
||||||
|
You can customize validations, provide choice selections for 'list', 'rawlist', 'expand', and 'checkbox' types, and much more according to the [Inquirer.js](https://github.com/SBoudrias/Inquirer.js/) module which `@push.rocks/smartinteract` leverages internally.
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
`@push.rocks/smartinteract` offers an elegant and robust solution for CLI interactions in Node.js projects. Its integration of TypeScript enhances code quality and developer workflow. Whether for simple prompts or complex inquisitive flows, it provides the tools necessary for obtaining and managing user inputs efficiently.
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
32
test/test.ts
32
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 aValidAnswer',
|
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 () => {
|
||||||
const 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.15',
|
||||||
|
description: 'smart cli interaction'
|
||||||
|
}
|
@ -1,2 +1,2 @@
|
|||||||
export * from './smartinteract.classes.smartinteract';
|
export * from './smartinteract.classes.smartinteract.js';
|
||||||
export * from './smartinteract.classes.answerbucket';
|
export * from './smartinteract.classes.answerbucket.js';
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
import * as plugins from './smartinteract.plugins';
|
import * as plugins from './smartinteract.plugins.js';
|
||||||
import { IAnswerObject } from './smartinteract.classes.smartinteract';
|
import { type IAnswerObject } from './smartinteract.classes.smartinteract.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.findSync((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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 { AnswerBucket } from './smartinteract.classes.answerbucket';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 plugins.lik.Objectmap<IQuestionObject>();
|
private questionMap = new plugins.lik.ObjectMap<IQuestionObject>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* constructor of class SmartInteract
|
* constructor of class SmartInteract
|
||||||
@ -63,34 +78,34 @@ 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,
|
||||||
type: optionsArg.type,
|
type: optionsArg.type,
|
||||||
message: optionsArg.message,
|
message: optionsArg.message,
|
||||||
default: optionsArg.default,
|
default: optionsArg.default,
|
||||||
choices: optionsArg.choices,
|
choices: optionsArg.choices as any,
|
||||||
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.smartobject.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 +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 {
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@push.rocks/lik';
|
||||||
import * as smartparam from '@pushrocks/smartparam';
|
import * as smartobject from '@push.rocks/smartobject';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
export {
|
|
||||||
lik,
|
|
||||||
smartparam
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export { lik, smartobject, smartpromise };
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import * as inquirer from 'inquirer';
|
import * as inquirer from '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,7 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user