Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
8ed151b941 | |||
d2294dd587 | |||
9fd1efd3e7 | |||
61a0bfc966 | |||
2a4526297c | |||
3f4ce9a9bd | |||
f4e9bb9497 | |||
5aede68c43 | |||
44d30f82a6 | |||
9b5241e684 | |||
5ee46b1ccc | |||
2e5f69c6a7 | |||
bf168f688c | |||
5e92004a9f | |||
db268d4fad | |||
0acb00c9c4 | |||
b2bf396bb6 |
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
|
137
.gitlab-ci.yml
137
.gitlab-ci.yml
@ -1,137 +0,0 @@
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/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
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
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 npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -2,16 +2,31 @@
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartinteract",
|
||||
"shortDescription": "smart cli interaction",
|
||||
"npmPackagename": "@pushrocks/smartinteract",
|
||||
"license": "MIT"
|
||||
"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": [],
|
||||
"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"
|
||||
}
|
||||
}
|
11243
package-lock.json
generated
11243
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,41 +1,48 @@
|
||||
{
|
||||
"name": "@pushrocks/smartinteract",
|
||||
"name": "@push.rocks/smartinteract",
|
||||
"private": false,
|
||||
"version": "2.0.11",
|
||||
"description": "smart cli interaction",
|
||||
"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",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild --web)"
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@gitlab.com/pushrocks/smartinteract.git"
|
||||
"url": "https://code.foss.global/push.rocks/smartinteract.git"
|
||||
},
|
||||
"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",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartinteract/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartinteract#README",
|
||||
"homepage": "https://code.foss.global/push.rocks/smartinteract",
|
||||
"dependencies": {
|
||||
"@pushrocks/lik": "^4.0.17",
|
||||
"@pushrocks/smartparam": "^1.1.6",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@types/inquirer": "^7.3.1",
|
||||
"inquirer": "^7.3.3"
|
||||
"@push.rocks/lik": "^6.0.15",
|
||||
"@push.rocks/smartobject": "^1.0.12",
|
||||
"@push.rocks/smartpromise": "^4.0.4",
|
||||
"inquirer": "^11.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@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"
|
||||
"@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/**/*",
|
||||
@ -51,5 +58,6 @@
|
||||
],
|
||||
"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 @@
|
||||
|
162
readme.md
162
readme.md
@ -1,69 +1,127 @@
|
||||
# @pushrocks/smartinteract
|
||||
# @push.rocks/smartinteract
|
||||
|
||||
smart cli interaction
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartinteract)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartinteract)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartinteract)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartinteract/)
|
||||
## Install
|
||||
|
||||
## Status for master
|
||||
To install `@push.rocks/smartinteract`, use npm or yarn as follows:
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
```bash
|
||||
npm install @push.rocks/smartinteract --save
|
||||
# or using yarn
|
||||
yarn add @push.rocks/smartinteract
|
||||
```
|
||||
|
||||
This will add it to your project's `node_modules` folder and list it as a dependency in your project's `package.json` file.
|
||||
|
||||
## 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
|
||||
import { SmartInteract } from 'smartinteract'
|
||||
### Getting Started
|
||||
|
||||
let myInteract = new SmartInteract([{ // note: its an array. You can specify multiple questions
|
||||
name: 'question1',
|
||||
type: 'input',
|
||||
message: 'Who are you?',
|
||||
default: 'Somebody',
|
||||
validate: (inputString) => { return true } // implement your own validation
|
||||
}])
|
||||
myInteract.addQuestions([ ... ]) // add more questions
|
||||
myInteract.runQueue()
|
||||
.then(answerBucket => { // the bucket has all the answers of the completed queue
|
||||
let answerQuestion1 = answerBucket.getAnswerFor('question1')
|
||||
// do something with the answers
|
||||
})
|
||||
To begin, import `SmartInteract` from the module:
|
||||
|
||||
// alternatively use .askQuestion() for more direct control
|
||||
myInteract.askQuestion{ // note: its an array. You can specify multiple questions
|
||||
name: 'question2',
|
||||
type: 'confirm',
|
||||
message: 'Do you speak English?',
|
||||
default: true,
|
||||
validate: (inputString) => { return true } // implement your own validation
|
||||
}().then(answerObject => {
|
||||
// answerObject looks like { name: 'question2', value: true }
|
||||
})
|
||||
```typescript
|
||||
import { SmartInteract } from '@push.rocks/smartinteract';
|
||||
```
|
||||
|
||||
### Creating and Running Interactions
|
||||
|
||||
## Contribution
|
||||
You can specify questions for user interaction as shown below:
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
```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,
|
||||
}
|
||||
]);
|
||||
```
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
`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.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
### Adding Additional Questions Dynamically
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
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.
|
||||
|
14
test/test.ts
14
test/test.ts
@ -1,12 +1,12 @@
|
||||
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;
|
||||
|
||||
tap.test('should create a valid new instance', async () => {
|
||||
testInteract = new smartinteract.SmartInteract();
|
||||
expect(testInteract).to.be.instanceOf(smartinteract.SmartInteract);
|
||||
expect(testInteract).toBeInstanceOf(smartinteract.SmartInteract);
|
||||
});
|
||||
|
||||
tap.test('should get a simple confirmation', async () => {
|
||||
@ -14,7 +14,7 @@ tap.test('should get a simple confirmation', async () => {
|
||||
'You feel awesome, right?',
|
||||
true
|
||||
);
|
||||
expect(response).to.be.true;
|
||||
expect(response).toBeTrue();
|
||||
});
|
||||
|
||||
tap.test('should add question to SmartInteract instance', async () => {
|
||||
@ -46,9 +46,9 @@ tap.test('should add question to SmartInteract instance', async () => {
|
||||
|
||||
tap.test('should use default value when not in CI', async () => {
|
||||
const answerBucket = await testInteract.runQueue();
|
||||
expect(answerBucket.getAnswerFor('testQuestion1')).to.equal('blue');
|
||||
expect(answerBucket.getAnswerFor('testQuestion2')).to.equal('red');
|
||||
expect(answerBucket.getAnswerFor('some.dotted.name')).to.equal('aValidAnswer');
|
||||
expect(answerBucket.getAnswerFor('testQuestion1')).toEqual('blue');
|
||||
expect(answerBucket.getAnswerFor('testQuestion2')).toEqual('red');
|
||||
expect(answerBucket.getAnswerFor('some.dotted.name')).toEqual('aValidAnswer');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartinteract',
|
||||
version: '2.0.15',
|
||||
description: 'smart cli interaction'
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
export * from './smartinteract.classes.smartinteract';
|
||||
export * from './smartinteract.classes.answerbucket';
|
||||
export * from './smartinteract.classes.smartinteract.js';
|
||||
export * from './smartinteract.classes.answerbucket.js';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as plugins from './smartinteract.plugins';
|
||||
import { IAnswerObject } from './smartinteract.classes.smartinteract';
|
||||
import * as plugins from './smartinteract.plugins.js';
|
||||
import { type IAnswerObject } from './smartinteract.classes.smartinteract.js';
|
||||
|
||||
/**
|
||||
* class AnswerBucket holds answers
|
||||
@ -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.findSync((answerArg) => {
|
||||
return answerArg.name === nameArg;
|
||||
});
|
||||
return answer ? answer.value : null;
|
||||
|
@ -1,6 +1,5 @@
|
||||
import * as plugins from './smartinteract.plugins';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import { AnswerBucket } from './smartinteract.classes.answerbucket';
|
||||
import * as plugins from './smartinteract.plugins.js';
|
||||
import { AnswerBucket } from './smartinteract.classes.answerbucket.js';
|
||||
|
||||
/**
|
||||
* the availeable question types
|
||||
@ -79,22 +78,22 @@ export class SmartInteract {
|
||||
* skips the queue
|
||||
*/
|
||||
askQuestion(optionsArg: IQuestionObject): Promise<IAnswerObject> {
|
||||
const done = smartpromise.defer<IAnswerObject>();
|
||||
const done = plugins.smartpromise.defer<IAnswerObject>();
|
||||
if (this.isValidEnv()) {
|
||||
plugins.inquirer
|
||||
plugins.inquirer.default
|
||||
.prompt([
|
||||
{
|
||||
name: optionsArg.name,
|
||||
type: optionsArg.type,
|
||||
message: optionsArg.message,
|
||||
default: optionsArg.default,
|
||||
choices: optionsArg.choices,
|
||||
choices: optionsArg.choices as any,
|
||||
validate: optionsArg.validate,
|
||||
},
|
||||
])
|
||||
.then((answers) => {
|
||||
// adjust to the fact that now dots define paths for inquirer
|
||||
const answerValue = plugins.smartparam.smartGet(answers, optionsArg.name);
|
||||
const answerValue = plugins.smartobject.smartGet(answers, optionsArg.name);
|
||||
done.resolve({
|
||||
name: optionsArg.name,
|
||||
value: answerValue,
|
||||
@ -125,7 +124,7 @@ export class SmartInteract {
|
||||
* run the question queue
|
||||
*/
|
||||
runQueue() {
|
||||
const done = smartpromise.defer<AnswerBucket>();
|
||||
const done = plugins.smartpromise.defer<AnswerBucket>();
|
||||
const answerBucket = new AnswerBucket();
|
||||
const handleQuestion = async () => {
|
||||
if (!this.questionMap.isEmpty()) {
|
||||
|
@ -1,8 +1,9 @@
|
||||
// pushrocks scope
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartparam from '@pushrocks/smartparam';
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as smartobject from '@push.rocks/smartobject';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
export { lik, smartparam };
|
||||
export { lik, smartobject, smartpromise };
|
||||
|
||||
// third party scope
|
||||
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"
|
||||
]
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user