fix(core): update

This commit is contained in:
Philipp Kunz 2020-08-31 19:23:51 +00:00
parent 83dcc897a8
commit e1bbd5a844
15 changed files with 10070 additions and 832 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -19,22 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -49,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -62,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -84,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

2
dist/index.d.ts vendored
View File

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

8
dist/index.js vendored
View File

@ -1,8 +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"));
__export(require("./smartinteract.classes.answerbucket"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDJEQUFzRDtBQUN0RCwwREFBcUQifQ==

View File

@ -1,57 +0,0 @@
import { AnswerBucket } from './smartinteract.classes.answerbucket';
/**
* the availeable question types
*/
export declare type questionType = 'input' | 'confirm' | 'list' | 'rawlist' | 'expand' | 'checkbox' | 'password' | 'editor';
/**
* a choice
*/
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;
}

View File

@ -1,107 +0,0 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = __importStar(require("./smartinteract.plugins"));
const smartpromise = __importStar(require("@pushrocks/smartpromise"));
const smartinteract_classes_answerbucket_1 = require("./smartinteract.classes.answerbucket");
/**
* 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 plugins.lik.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) {
const done = smartpromise.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
const answerValue = plugins.smartparam.smartGet(answers, optionsArg.name);
done.resolve({
name: optionsArg.name,
value: answerValue
});
})
.catch(err => {
console.log(err);
});
}
else {
const 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() {
const done = smartpromise.defer();
const answerBucket = new smartinteract_classes_answerbucket_1.AnswerBucket();
const handleQuestion = async () => {
if (!this.questionMap.isEmpty()) {
const oneQuestion = this.questionMap.getOneAndRemove();
const answer = await this.askQuestion(oneQuestion);
answerBucket.addAnswer(answer);
handleQuestion(); // recursion: as questions until empty
}
else {
done.resolve(answerBucket); // when empty, then resolve promise
}
};
handleQuestion();
return done.promise;
}
/**
* checks if the current env is valid for userinput
*/
isValidEnv() {
if (!process.env.CI) {
return true;
}
else {
return false;
}
}
}
exports.SmartInteract = SmartInteract;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5jbGFzc2VzLnNtYXJ0aW50ZXJhY3QuanMiLCJzb3VyY2VSb290IjoiIiwic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FDO2dCQUN2RCxNQUFNLE1BQU0sR0FBa0IsTUFBTSxJQUFJLENBQUMsV0FBVyxDQUFDLFdBQVcsQ0FBQyxDQUFDO2dCQUNsRSxZQUFZLENBQUMsU0FBUyxDQUFDLE1BQU0sQ0FBQyxDQUFDO2dCQUMvQixjQUFjLEVBQUUsQ0FBQyxDQUFDLHNDQUFzQzthQUN6RDtpQkFBTTtnQkFDTCxJQUFJLENBQUMsT0FBTyxDQUFDLFlBQVksQ0FBQyxDQUFDLENBQUMsbUNBQW1DO2FBQ2hFO1FBQ0gsQ0FBQyxDQUFDO1FBQ0YsY0FBYyxFQUFFLENBQUM7UUFDakIsT0FBTyxJQUFJLENBQUMsT0FBTyxDQUFDO0lBQ3RCLENBQUM7SUFFRDs7T0FFRztJQUNLLFVBQVU7UUFDaEIsSUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsRUFBRSxFQUFFO1lBQ25CLE9BQU8sSUFBSSxDQUFDO1NBQ2I7YUFBTTtZQUNMLE9BQU8sS0FBSyxDQUFDO1NBQ2Q7SUFDSCxDQUFDO0NBQ0Y7QUEzRkQsc0NBMkZDIn0=

View File

@ -1,5 +0,0 @@
import * as lik from '@pushrocks/lik';
import * as smartparam from '@pushrocks/smartparam';
export { lik, smartparam };
import * as inquirer from 'inquirer';
export { inquirer };

View File

@ -1,18 +0,0 @@
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// pushrocks scope
const lik = __importStar(require("@pushrocks/lik"));
exports.lik = lik;
const smartparam = __importStar(require("@pushrocks/smartparam"));
exports.smartparam = smartparam;
// third party scope
const inquirer = __importStar(require("inquirer"));
exports.inquirer = inquirer;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpbnRlcmFjdC5wbHVnaW5zLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRpbnRlcmFjdC5wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLGtCQUFrQjtBQUNsQixvREFBc0M7QUFHN0Isa0JBQUc7QUFGWixrRUFBb0Q7QUFFdEMsZ0NBQVU7QUFFeEIsb0JBQW9CO0FBQ3BCLG1EQUFxQztBQUU1Qiw0QkFBUSJ9

10575
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -3,11 +3,11 @@
"private": false,
"version": "2.0.9",
"description": "smart cli interaction",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild)"
"build": "(tsbuild --web)"
},
"repository": {
"type": "git",
@ -24,28 +24,32 @@
},
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
"dependencies": {
"@pushrocks/lik": "^3.0.17",
"@pushrocks/lik": "^4.0.17",
"@pushrocks/smartparam": "^1.1.6",
"@pushrocks/smartpromise": "^3.0.6",
"@types/inquirer": "^6.5.0",
"inquirer": "^7.0.4"
"@types/inquirer": "^7.3.1",
"inquirer": "^7.3.3"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.2.0",
"tslint": "^6.0.0",
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tstest": "^1.0.44",
"@pushrocks/tapbundle": "^3.2.9",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -8,13 +8,20 @@
* [docs (typedoc)](https://[object Object].gitlab.io/[object Object]/)
## Status for master
[![pipeline status](https://[object Object]/[object Object]/[object Object]/badges/master/pipeline.svg)](https://[object Object]/[object Object]/[object Object]/commits/master)
[![coverage report](https://[object Object]/[object Object]/[object Object]/badges/master/coverage.svg)](https://[object Object]/[object Object]/[object Object]/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/[object Object].svg)](https://www.npmjs.com/package/[object Object])
[![Known Vulnerabilities](https://snyk.io/test/npm/[object Object]/badge.svg)](https://snyk.io/test/npm/[object Object])
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://[object Object]/[object Object]/[object Object]/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://[object Object]/[object Object]/[object Object]/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/[object Object])](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/[object Object]/[object Object])](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/[object Object])](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/[object Object])](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/[object Object])](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage

View File

@ -9,30 +9,35 @@ tap.test('should create a valid new instance', async () => {
expect(testInteract).to.be.instanceOf(smartinteract.SmartInteract);
});
tap.test('should get a simple confirmation', async () => {
const response = await smartinteract.SmartInteract.getCliConfirmation('You feel awesome, right?', true);
expect(response).to.be.true;
});
tap.test('should add question to SmartInteract instance', async () => {
testInteract.addQuestions([
{
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',
},
]);
});

View File

@ -5,7 +5,7 @@ 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.find(answerArg => {
const answer = this.answerMap.find((answerArg) => {
return answerArg.name === nameArg;
});
return answer ? answer.value : null;

View File

@ -45,10 +45,23 @@ 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
@ -73,24 +86,24 @@ export class SmartInteract {
message: optionsArg.message,
default: optionsArg.default,
choices: optionsArg.choices,
validate: optionsArg.validate
}
validate: optionsArg.validate,
},
])
.then(answers => {
.then((answers) => {
// adjust to the fact that now dots define paths for inquirer
const 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 = {
name: optionsArg.name,
value: optionsArg.default
value: optionsArg.default,
};
done.resolve(answer);
}