Compare commits
No commits in common. "master" and "v2.0.7" have entirely different histories.
@ -1,66 +0,0 @@
|
||||
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
|
@ -1,124 +0,0 @@
|
||||
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,20 +1,4 @@
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
node_modules/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
||||
coverage/
|
||||
|
142
.gitlab-ci.yml
Normal file
142
.gitlab-ci.yml
Normal file
@ -0,0 +1,142 @@
|
||||
# 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
11
.vscode/launch.json
vendored
@ -1,11 +0,0 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
26
.vscode/settings.json
vendored
@ -1,26 +0,0 @@
|
||||
{
|
||||
"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
Normal file
1
dist/index.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export * from './smartinteract.classes.smartinteract';
|
7
dist/index.js
vendored
Normal file
7
dist/index.js
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
"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
Normal file
69
dist/smartinteract.classes.smartinteract.d.ts
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
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
Normal file
137
dist/smartinteract.classes.smartinteract.js
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
"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;
|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BM0ZELHNDQTJGQztBQUVEOztHQUVHO0FBQ0g7SUFBQTtRQUNFLGNBQVMsR0FBRyxJQUFJLGVBQVMsRUFBaUIsQ0FBQTtJQXlCNUMsQ0FBQztJQXZCQzs7T0FFRztJQUNILFNBQVMsQ0FBRSxTQUF3QjtRQUNqQyxJQUFJLENBQUMsU0FBUyxDQUFDLEdBQUcsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUMvQixDQUFDO0lBRUQ7O09BRUc7SUFDSCxZQUFZLENBQUUsT0FBZTtRQUMzQixJQUFJLE1BQU0sR0FBRyxJQUFJLENBQUMsU0FBUyxDQUFDLElBQUksQ0FBQyxTQUFTO1lBQ3hDLE1BQU0sQ0FBQyxTQUFTLENBQUMsSUFBSSxLQUFLLE9BQU8sQ0FBQTtRQUNuQyxDQUFDLENBQUMsQ0FBQTtRQUNGLE1BQU0sQ0FBQyxNQUFNLENBQUMsS0FBSyxDQUFBO0lBQ3JCLENBQUM7SUFFRDs7T0FFRztJQUNILGFBQWE7UUFDWCxNQUFNLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxRQUFRLEVBQUUsQ0FBQTtJQUNsQyxDQUFDO0NBQ0Y7QUExQkQsb0NBMEJDIn0=
|
3
dist/smartinteract.plugins.d.ts
vendored
Normal file
3
dist/smartinteract.plugins.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import 'typings-global';
|
||||
import * as inquirer from 'inquirer';
|
||||
export { inquirer };
|
6
dist/smartinteract.plugins.js
vendored
Normal file
6
dist/smartinteract.plugins.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
const inquirer = require("inquirer");
|
||||
exports.inquirer = inquirer;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRpbnRlcmFjdC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsMEJBQXVCO0FBQ3ZCLHFDQUFvQztBQUdsQyw0QkFBUSJ9
|
35
docs/index.md
Normal file
35
docs/index.md
Normal file
@ -0,0 +1,35 @@
|
||||
# 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,32 +1,6 @@
|
||||
{
|
||||
"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": {
|
||||
"npmGlobalTools": [],
|
||||
"npmGlobalTools": ["npmts"],
|
||||
"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
Normal file
1291
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
69
package.json
69
package.json
@ -1,63 +1,40 @@
|
||||
{
|
||||
"name": "@push.rocks/smartinteract",
|
||||
"name": "@pushrocks/smartinteract",
|
||||
"private": false,
|
||||
"version": "2.0.15",
|
||||
"description": "A package for creating smart CLI interactions with customizable questions and answers.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"version": "2.0.7",
|
||||
"description": "smart cli interaction",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
"test": "tsrun test/test.ts",
|
||||
"testLocal": "(npmts --notest && ts-node --compilerOptions '{\"target\":\"es6\"}' test/test.ts)",
|
||||
"build": "(npmts --notest)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartinteract.git"
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartinteract.git"
|
||||
},
|
||||
"keywords": [
|
||||
"CLI",
|
||||
"interactive prompts",
|
||||
"command line interface",
|
||||
"user input handling",
|
||||
"inquirer integration",
|
||||
"CLI questions",
|
||||
"CLI validations",
|
||||
"CLI interactions",
|
||||
"smart CLI",
|
||||
"typescript"
|
||||
"interaction",
|
||||
"cli"
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartinteract/issues"
|
||||
},
|
||||
"homepage": "https://code.foss.global/push.rocks/smartinteract",
|
||||
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
|
||||
"dependencies": {
|
||||
"@push.rocks/lik": "^6.0.15",
|
||||
"@push.rocks/smartobject": "^1.0.12",
|
||||
"@push.rocks/smartpromise": "^4.0.4",
|
||||
"inquirer": "^11.1.0"
|
||||
"@pushrocks/lik": "^3.0.13",
|
||||
"@pushrocks/smartparam": "^1.1.6",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@types/inquirer": "^6.5.0",
|
||||
"inquirer": "^7.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@git.zone/tsbuild": "^2.1.84",
|
||||
"@git.zone/tsrun": "^1.2.49",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@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"
|
||||
}
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@pushrocks/tapbundle": "^3.2.0",
|
||||
"tslint": "^6.0.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
}
|
||||
}
|
||||
|
6887
pnpm-lock.yaml
generated
6887
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
|
153
readme.md
153
readme.md
@ -1,127 +1,62 @@
|
||||
# @push.rocks/smartinteract
|
||||
# smartinteract
|
||||
|
||||
smart cli interaction
|
||||
|
||||
## Install
|
||||
## Availabililty
|
||||
|
||||
To install `@push.rocks/smartinteract`, use npm or yarn as follows:
|
||||
[](https://www.npmjs.com/package/smartinteract)
|
||||
[](https://GitLab.com/pushrocks/smartinteract)
|
||||
[](https://github.com/pushrocks/smartinteract)
|
||||
[](https://pushrocks.gitlab.io/smartinteract/)
|
||||
|
||||
```bash
|
||||
npm install @push.rocks/smartinteract --save
|
||||
# or using yarn
|
||||
yarn add @push.rocks/smartinteract
|
||||
```
|
||||
## Status for 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://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
|
||||
|
||||
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.
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
### Getting Started
|
||||
```javascript
|
||||
import { SmartInteract } from 'smartinteract'
|
||||
|
||||
To begin, import `SmartInteract` from the module:
|
||||
|
||||
```typescript
|
||||
import { SmartInteract } from '@push.rocks/smartinteract';
|
||||
```
|
||||
|
||||
### Creating and Running Interactions
|
||||
|
||||
You can specify questions for user interaction as shown below:
|
||||
|
||||
```typescript
|
||||
const smartInteract = new SmartInteract([
|
||||
{
|
||||
name: 'userName',
|
||||
let myInteract = new SmartInteract([{ // note: its an array. You can specify multiple questions
|
||||
name: 'question1',
|
||||
type: 'input',
|
||||
message: 'What is your name?',
|
||||
default: 'John Doe',
|
||||
},
|
||||
{
|
||||
name: 'userConfirmation',
|
||||
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 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,
|
||||
message: 'Do you speak English?',
|
||||
default: true,
|
||||
validate: (inputString) => { return true } // implement your own validation
|
||||
}().then(answerObject => {
|
||||
// answerObject looks like { name: 'question2', value: true }
|
||||
})
|
||||
.then(answerObject => {
|
||||
console.log(answerObject);
|
||||
// Output: { name: 'urgentQuery', value: true/false }
|
||||
});
|
||||
```
|
||||
|
||||
### Advanced Usage
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
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.
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
### 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.
|
||||
[](https://push.rocks)
|
||||
|
32
test/test.ts
32
test/test.ts
@ -1,20 +1,12 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
|
||||
import * as smartinteract from '../ts/index.js';
|
||||
import * as smartinteract from '../ts/index';
|
||||
|
||||
let testInteract: smartinteract.SmartInteract;
|
||||
|
||||
tap.test('should create a valid new instance', async () => {
|
||||
testInteract = new 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();
|
||||
expect(testInteract).to.be.instanceOf(smartinteract.SmartInteract);
|
||||
});
|
||||
|
||||
tap.test('should add question to SmartInteract instance', async () => {
|
||||
@ -23,32 +15,32 @@ tap.test('should add question to SmartInteract instance', async () => {
|
||||
name: 'testQuestion1',
|
||||
type: 'input',
|
||||
message: 'what is your favourite color? Answer is blue',
|
||||
default: 'blue',
|
||||
},
|
||||
default: 'blue'
|
||||
}
|
||||
]);
|
||||
testInteract.addQuestions([
|
||||
{
|
||||
name: 'testQuestion2',
|
||||
type: 'input',
|
||||
message: 'what is your second favourite color? Answer is red',
|
||||
default: 'red',
|
||||
},
|
||||
default: 'red'
|
||||
}
|
||||
]);
|
||||
testInteract.addQuestions([
|
||||
{
|
||||
name: 'some.dotted.name',
|
||||
type: 'input',
|
||||
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 () => {
|
||||
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');
|
||||
expect(answerBucket.getAnswerFor('testQuestion1')).to.equal('blue');
|
||||
expect(answerBucket.getAnswerFor('testQuestion2')).to.equal('red');
|
||||
expect(answerBucket.getAnswerFor('some.dotted.name')).to.equal('aValidAnswer');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -1,8 +0,0 @@
|
||||
/**
|
||||
* 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.js';
|
||||
export * from './smartinteract.classes.answerbucket.js';
|
||||
export * from './smartinteract.classes.smartinteract';
|
||||
export * from './smartinteract.classes.answerbucket';
|
@ -1,11 +1,11 @@
|
||||
import * as plugins from './smartinteract.plugins.js';
|
||||
import { type IAnswerObject } from './smartinteract.classes.smartinteract.js';
|
||||
import * as plugins from './smartinteract.plugins';
|
||||
import { IAnswerObject } from './smartinteract.classes.smartinteract';
|
||||
|
||||
/**
|
||||
* class AnswerBucket holds answers
|
||||
*/
|
||||
export class AnswerBucket {
|
||||
private answerMap = new plugins.lik.ObjectMap<IAnswerObject>();
|
||||
private answerMap = new plugins.lik.Objectmap<IAnswerObject>();
|
||||
|
||||
/**
|
||||
* add an answer to the bucket
|
||||
@ -18,7 +18,7 @@ export class AnswerBucket {
|
||||
* gets an answer for a specific name
|
||||
*/
|
||||
public getAnswerFor(nameArg: string) {
|
||||
const answer = this.answerMap.findSync((answerArg) => {
|
||||
const answer = this.answerMap.find(answerArg => {
|
||||
return answerArg.name === nameArg;
|
||||
});
|
||||
return answer ? answer.value : null;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as plugins from './smartinteract.plugins.js';
|
||||
import { AnswerBucket } from './smartinteract.classes.answerbucket.js';
|
||||
import * as plugins from './smartinteract.plugins';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import { AnswerBucket } from './smartinteract.classes.answerbucket';
|
||||
|
||||
/**
|
||||
* the availeable question types
|
||||
@ -15,7 +16,7 @@ export type questionType =
|
||||
| 'editor';
|
||||
|
||||
/**
|
||||
* a choice
|
||||
* a choice
|
||||
*/
|
||||
export interface IChoiceObject {
|
||||
name: string;
|
||||
@ -44,26 +45,10 @@ export interface IValidateFunction {
|
||||
* class SmartInteract - allows to specify an user interaction during runtime
|
||||
*/
|
||||
export class SmartInteract {
|
||||
// STATIC
|
||||
public static async getCliConfirmation(
|
||||
questionArg: string,
|
||||
defaultArg: boolean
|
||||
): Promise<boolean> {
|
||||
const smartinteractInstance = new SmartInteract();
|
||||
const response = await smartinteractInstance.askQuestion({
|
||||
default: defaultArg,
|
||||
message: questionArg,
|
||||
name: 'question',
|
||||
type: 'confirm',
|
||||
});
|
||||
return response.value;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
/**
|
||||
* 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
|
||||
@ -78,34 +63,34 @@ export class SmartInteract {
|
||||
* skips the queue
|
||||
*/
|
||||
askQuestion(optionsArg: IQuestionObject): Promise<IAnswerObject> {
|
||||
const done = plugins.smartpromise.defer<IAnswerObject>();
|
||||
let done = smartpromise.defer<IAnswerObject>();
|
||||
if (this.isValidEnv()) {
|
||||
plugins.inquirer.default
|
||||
plugins.inquirer
|
||||
.prompt([
|
||||
{
|
||||
name: optionsArg.name,
|
||||
type: optionsArg.type,
|
||||
message: optionsArg.message,
|
||||
default: optionsArg.default,
|
||||
choices: optionsArg.choices as any,
|
||||
validate: optionsArg.validate,
|
||||
},
|
||||
choices: optionsArg.choices,
|
||||
validate: optionsArg.validate
|
||||
}
|
||||
])
|
||||
.then((answers) => {
|
||||
// adjust to the fact that now dots define paths for inquirer
|
||||
const answerValue = plugins.smartobject.smartGet(answers, optionsArg.name);
|
||||
let answerValue = plugins.smartparam.smartGet(answers, optionsArg.name);
|
||||
done.resolve({
|
||||
name: optionsArg.name,
|
||||
value: answerValue,
|
||||
value: answerValue
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
} else {
|
||||
const answer: IAnswerObject = {
|
||||
let answer: IAnswerObject = {
|
||||
name: optionsArg.name,
|
||||
value: optionsArg.default,
|
||||
value: optionsArg.default
|
||||
};
|
||||
done.resolve(answer);
|
||||
}
|
||||
@ -124,12 +109,12 @@ export class SmartInteract {
|
||||
* run the question queue
|
||||
*/
|
||||
runQueue() {
|
||||
const done = plugins.smartpromise.defer<AnswerBucket>();
|
||||
const answerBucket = new AnswerBucket();
|
||||
const handleQuestion = async () => {
|
||||
let done = smartpromise.defer<AnswerBucket>();
|
||||
let answerBucket = new AnswerBucket();
|
||||
let handleQuestion = async () => {
|
||||
if (!this.questionMap.isEmpty()) {
|
||||
const oneQuestion = this.questionMap.getOneAndRemove();
|
||||
const answer: IAnswerObject = await this.askQuestion(oneQuestion);
|
||||
let oneQuestion = this.questionMap.getOneAndRemove();
|
||||
let answer: IAnswerObject = await this.askQuestion(oneQuestion);
|
||||
answerBucket.addAnswer(answer);
|
||||
handleQuestion(); // recursion: as questions until empty
|
||||
} else {
|
||||
|
@ -1,9 +1,12 @@
|
||||
// pushrocks scope
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartobject from '@push.rocks/smartobject';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartparam from '@pushrocks/smartparam';
|
||||
|
||||
export {
|
||||
lik,
|
||||
smartparam
|
||||
}
|
||||
|
||||
export { lik, smartobject, smartpromise };
|
||||
|
||||
// third party scope
|
||||
import * as inquirer from 'inquirer';
|
||||
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
7
tslint.json
Normal file
7
tslint.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user