Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
f7c24a0bd2 | |||
fa59d2da40 | |||
311232aeea | |||
4cd0844bc3 | |||
17c1a687c8 | |||
1d1264c2b3 | |||
b036e609ce | |||
c2ec0df907 | |||
167b4d29df | |||
02fec216db | |||
4e9d2f3e8c | |||
65d8a8b6f5 | |||
8e04bd6a62 | |||
687a5f7c4e | |||
17983b1da9 | |||
5fcdf1ff8f | |||
ef7ee7fc73 | |||
c48e85897e | |||
9466b3e473 | |||
ab3127b8a6 | |||
1e62e27980 | |||
4b87004478 |
18
.gitignore
vendored
18
.gitignore
vendored
@ -1,4 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
.yarn/
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
115
.gitlab-ci.yml
115
.gitlab-ci.yml
@ -1,16 +1,16 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .npmci_cache/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- security
|
- security
|
||||||
- test
|
- test
|
||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
@ -19,56 +19,61 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g snyk
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- npmci command npm install --production --ignore-scripts
|
||||||
- npmci command snyk test
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
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
|
# 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:
|
testStable:
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install lts
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
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:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -78,6 +83,7 @@ release:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
@ -86,20 +92,16 @@ release:
|
|||||||
# ====================
|
# ====================
|
||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
image: docker:stable
|
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
services:
|
only:
|
||||||
- docker:stable-dind
|
- tags
|
||||||
script:
|
script:
|
||||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
- npmci command npm install -g tslint typescript
|
||||||
- docker run
|
- npmci npm prepare
|
||||||
--env SOURCE_CODE="$PWD"
|
- npmci npm install
|
||||||
--volume "$PWD":/code
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
--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:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- priv
|
- priv
|
||||||
|
|
||||||
@ -110,17 +112,20 @@ trigger:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g typedoc typescript
|
- npmci node install lts
|
||||||
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
only:
|
only:
|
||||||
@ -130,13 +135,3 @@ pages:
|
|||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
allow_failure: true
|
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
|
|
||||||
|
9
.snyk
9
.snyk
@ -1,9 +0,0 @@
|
|||||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
|
||||||
version: v1.12.0
|
|
||||||
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
|
||||||
ignore:
|
|
||||||
'npm:mem:20180117':
|
|
||||||
- yargs > os-locale > mem:
|
|
||||||
reason: None given
|
|
||||||
expires: '2018-09-29T22:12:38.004Z'
|
|
||||||
patch: {}
|
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
29
README.md
29
README.md
@ -1,29 +0,0 @@
|
|||||||
# smartcli
|
|
||||||
|
|
||||||
nodejs wrapper for CLI related tasks
|
|
||||||
|
|
||||||
## Availabililty
|
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartcli)
|
|
||||||
[](https://GitLab.com/pushrocks/smartcli)
|
|
||||||
[](https://github.com/pushrocks/smartcli)
|
|
||||||
[](https://pushrocks.gitlab.io/smartcli/)
|
|
||||||
|
|
||||||
## Status for master
|
|
||||||
|
|
||||||
[](https://GitLab.com/pushrocks/smartcli/commits/master)
|
|
||||||
[](https://GitLab.com/pushrocks/smartcli/commits/master)
|
|
||||||
[](https://www.npmjs.com/package/smartcli)
|
|
||||||
[](https://david-dm.org/pushrocks/smartcli)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartcli/master/dependencies/npm)
|
|
||||||
[](https://www.bithound.io/github/pushrocks/smartcli)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
|
||||||
[](http://standardjs.com/)
|
|
||||||
|
|
||||||
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://)
|
|
@ -23,45 +23,6 @@ nodejs wrapper for CLI related tasks
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
this plugin tries to establish some logic in which CLI tools work.
|
|
||||||
|
|
||||||
take the following commandline input:
|
|
||||||
|
|
||||||
```
|
|
||||||
mytool command argument1 argument2 --option1 -o2 option2Value
|
|
||||||
```
|
|
||||||
|
|
||||||
- `mytool` obviously is the tool (like git)
|
|
||||||
- `command` is the main thing the tool shall do (like commit)
|
|
||||||
- `argument1` and `argument2` are arguments
|
|
||||||
- `option1` is a longform option you can add (like --message for message)
|
|
||||||
- `optionValue` is the referenced option value (like a commit message)
|
|
||||||
|
|
||||||
When there is no command and no option specified the standardTask applied.
|
|
||||||
When there is a option specified but no command, standardTask applies,
|
|
||||||
except when of the options is -v, --version or --help.
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
import { Smartcli } from 'smartcli';
|
|
||||||
mySmartcli = new Smartcli();
|
|
||||||
mySmartcli.standardTask().then(argvArg => {
|
|
||||||
// do something if program is called without an command
|
|
||||||
});
|
|
||||||
|
|
||||||
mySmartcli.addCommand({ commandname: 'install' }).then(argvArg => {
|
|
||||||
// do something if program is called with command "install"
|
|
||||||
});
|
|
||||||
|
|
||||||
mySmartcli.addVersion('1.0.0'); // -v and --version options will display the specified version in the terminal
|
|
||||||
|
|
||||||
mySmartCli.addHelp({
|
|
||||||
// is triggered by help command and --help option
|
|
||||||
helpText: 'some help text to print' // the helpText to display
|
|
||||||
});
|
|
||||||
|
|
||||||
mySmartcli.startParse(); // starts the evaluation and fullfills or rejects promises.
|
|
||||||
```
|
|
||||||
|
|
||||||
For further information read the linked docs at the top of this README.
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [],
|
||||||
"@gitzone/npmts",
|
|
||||||
"ts-node"
|
|
||||||
],
|
|
||||||
"npmAccesslevel": "public"
|
"npmAccesslevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartcli",
|
||||||
|
"description": "easy observable cli tasks",
|
||||||
|
"npmPackagename": "@pushrocks/smartcli",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
15715
package-lock.json
generated
15715
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
55
package.json
55
package.json
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartcli",
|
"name": "@pushrocks/smartcli",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.4",
|
"version": "4.0.0",
|
||||||
"description": "nodejs wrapper for CLI related tasks",
|
"description": "easy observable cli tasks",
|
||||||
"main": "dist/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -26,19 +27,35 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.1",
|
"@pushrocks/lik": "^6.0.0",
|
||||||
"@pushrocks/smartlog": "^2.0.1",
|
"@pushrocks/smartlog": "^3.0.1",
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartparam": "^1.1.6",
|
||||||
"@types/yargs": "^11.1.1",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"rxjs": "^6.3.0",
|
"@pushrocks/smartrx": "^2.0.25",
|
||||||
"smartparam": "1.0.2",
|
"@types/yargs": "^17.0.10",
|
||||||
"yargs": "^12.0.1"
|
"@types/yargs-parser": "^21.0.0",
|
||||||
|
"yargs-parser": "^21.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.0.22",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsrun": "^1.1.12",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.0.5",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^10.9.4"
|
"@types/node": "^18.6.3"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
76
readme.md
Normal file
76
readme.md
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# @pushrocks/smartcli
|
||||||
|
easy observable cli tasks
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartcli)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartcli)
|
||||||
|
* [github.com (source mirror)](https://github.com/pushrocks/smartcli)
|
||||||
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartcli/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
|
||||||
|
Status Category | Status Badge
|
||||||
|
-- | --
|
||||||
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
|
npm | [](https://lossless.cloud)
|
||||||
|
Snyk | [](https://lossless.cloud)
|
||||||
|
TypeScript Support | [](https://lossless.cloud)
|
||||||
|
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||||
|
Code Style | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
|
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
this plugin tries to establish some logic in which CLI tools work.
|
||||||
|
|
||||||
|
take the following commandline input:
|
||||||
|
|
||||||
|
```
|
||||||
|
mytool command argument1 argument2 --option1 -o2 option2Value
|
||||||
|
```
|
||||||
|
|
||||||
|
- `mytool` obviously is the tool (like git)
|
||||||
|
- `command` is the main thing the tool shall do (like commit)
|
||||||
|
- `argument1` and `argument2` are arguments
|
||||||
|
- `option1` is a longform option you can add (like --message for message)
|
||||||
|
- `optionValue` is the referenced option value (like a commit message)
|
||||||
|
|
||||||
|
When there is no command and no option specified the standardTask applied.
|
||||||
|
When there is a option specified but no command, standardTask applies,
|
||||||
|
except when of the options is -v, --version or --help.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { Smartcli } from 'smartcli';
|
||||||
|
mySmartcli = new Smartcli();
|
||||||
|
mySmartcli.standardTask().then((argvArg) => {
|
||||||
|
// do something if program is called without an command
|
||||||
|
});
|
||||||
|
|
||||||
|
mySmartcli.addCommand({ commandname: 'install' }).then((argvArg) => {
|
||||||
|
// do something if program is called with command "install"
|
||||||
|
});
|
||||||
|
|
||||||
|
mySmartcli.addVersion('1.0.0'); // -v and --version options will display the specified version in the terminal
|
||||||
|
|
||||||
|
mySmartCli.addHelp({
|
||||||
|
// is triggered by help command and --help option
|
||||||
|
helpText: 'some help text to print', // the helpText to display
|
||||||
|
});
|
||||||
|
|
||||||
|
mySmartcli.startParse(); // starts the evaluation and fullfills or rejects promises.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
|
[](https://maintainedby.lossless.com)
|
18
test/test.ts
18
test/test.ts
@ -1,43 +1,43 @@
|
|||||||
import { tap, expect } from '@pushrocks/tapbundle';
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
import smartcli = require('../ts/index');
|
import * as smartcli from '../ts/index.js';
|
||||||
|
|
||||||
let smartCliTestObject: smartcli.Smartcli;
|
let smartCliTestObject: smartcli.Smartcli;
|
||||||
|
|
||||||
tap.test('should create a new Smartcli', async () => {
|
tap.test('should create a new Smartcli', async () => {
|
||||||
smartCliTestObject = new smartcli.Smartcli();
|
smartCliTestObject = new smartcli.Smartcli();
|
||||||
expect(smartCliTestObject).to.be.instanceof(smartcli.Smartcli);
|
expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should add an command', async () => {
|
tap.test('should add an command', async () => {
|
||||||
expect(smartCliTestObject.addCommand('awesome')).to.be.instanceOf(Subject);
|
expect(smartCliTestObject.addCommand('awesome')).toBeInstanceOf(Subject);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start parsing a standardTask', async () => {
|
tap.test('should start parsing a standardTask', async () => {
|
||||||
expect(smartCliTestObject.standardTask()).to.be.instanceOf(Subject);
|
expect(smartCliTestObject.standardCommand()).toBeInstanceOf(Subject);
|
||||||
});
|
});
|
||||||
|
|
||||||
let hasExecuted: boolean = false;
|
let hasExecuted: boolean = false;
|
||||||
|
|
||||||
tap.test('should accept a command', async () => {
|
tap.test('should accept a command', async () => {
|
||||||
smartCliTestObject.addTrigger('triggerme').subscribe(() => {
|
smartCliTestObject.addCommand('triggerme').subscribe(() => {
|
||||||
hasExecuted = true;
|
hasExecuted = true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should not have executed yet', async () => {
|
tap.test('should not have executed yet', async () => {
|
||||||
expect(hasExecuted).to.be.false;
|
expect(hasExecuted).toBeFalse();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should execute when triggered', async () => {
|
tap.test('should execute when triggered', async () => {
|
||||||
smartCliTestObject.trigger('triggerme');
|
smartCliTestObject.triggerCommand('triggerme', {});
|
||||||
expect(hasExecuted).be.true;
|
expect(hasExecuted).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start parsing the CLI input', async () => {
|
tap.test('should start parsing the CLI input', async () => {
|
||||||
smartCliTestObject.startParse();
|
smartCliTestObject.startParse();
|
||||||
expect(smartCliTestObject.parseStarted.promise).to.be.instanceOf(Promise);
|
expect(smartCliTestObject.parseCompleted.promise).toBeInstanceOf(Promise);
|
||||||
});
|
});
|
||||||
|
|
||||||
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: '@pushrocks/smartcli',
|
||||||
|
version: '4.0.0',
|
||||||
|
description: 'easy observable cli tasks'
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
export { Smartcli } from './smartcli.classes.smartcli';
|
export { Smartcli } from './smartcli.classes.smartcli.js';
|
||||||
|
@ -1,107 +1,86 @@
|
|||||||
import * as smartq from 'smartq';
|
import * as plugins from './smartcli.plugins.js';
|
||||||
import { Subject } from 'rxjs';
|
|
||||||
|
|
||||||
import * as plugins from './smartcli.plugins';
|
|
||||||
|
|
||||||
// import classes
|
|
||||||
import { Objectmap } from '@pushrocks/lik';
|
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
export interface ICommandPromiseObject {
|
export interface ICommandObservableObject {
|
||||||
commandName: string;
|
commandName: string;
|
||||||
promise: Promise<void>;
|
subject: plugins.smartrx.rxjs.Subject<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITriggerObservableObject {
|
const logger = new plugins.smartlog.ConsoleLog();
|
||||||
triggerName: string;
|
|
||||||
subject: Subject<any>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class to create a new instance of Smartcli. Handles parsing of command line arguments.
|
* class to create a new instance of Smartcli. Handles parsing of command line arguments.
|
||||||
*/
|
*/
|
||||||
export class Smartcli {
|
export class Smartcli {
|
||||||
argv: any;
|
/**
|
||||||
questionsDone;
|
* this Deferred contains the parsed result in the end
|
||||||
parseStarted: smartq.Deferred<any>;
|
*/
|
||||||
commands;
|
public parseCompleted = plugins.smartpromise.defer<any>();
|
||||||
questions;
|
|
||||||
version: string;
|
|
||||||
private onlyOnProcessEnvCliCall = false;
|
public version: string;
|
||||||
|
private checkForEnvCliCall = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* map of all Trigger/Observable objects to keep track
|
* map of all Trigger/Observable objects to keep track
|
||||||
*/
|
*/
|
||||||
allTriggerObservablesMap = new Objectmap<ITriggerObservableObject>();
|
private commandObservableMap = new plugins.lik.ObjectMap<ICommandObservableObject>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* maps alias
|
||||||
|
*/
|
||||||
|
public aliasObject: {[key: string]: string[]} = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor of Smartcli
|
* The constructor of Smartcli
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor() {}
|
||||||
this.argv = plugins.yargs;
|
|
||||||
this.questionsDone = smartq.defer();
|
|
||||||
this.parseStarted = smartq.defer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* halts any execution of commands if (process.env.CLI_CALL === false)
|
* halts any execution of commands if (process.env.CLI_CALL === false)
|
||||||
*/
|
*/
|
||||||
onlyTriggerOnProcessEnvCliCall() {
|
disableEnvCliCall() {
|
||||||
this.onlyOnProcessEnvCliCall = true;
|
this.checkForEnvCliCall = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adds an alias, meaning one equals the other in terms of command execution.
|
* adds an alias, meaning one equals the other in terms of command execution.
|
||||||
*/
|
*/
|
||||||
addCommandAlias(keyArg, aliasArg): void {
|
public addCommandAlias(originalArg, aliasArg): void {
|
||||||
this.argv = this.argv.alias(keyArg, aliasArg);
|
this.aliasObject[originalArg] = this.aliasObject[originalArg] || [];
|
||||||
return;
|
this.aliasObject[originalArg].push(aliasArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adds a Command by returning a Promise that reacts to the specific commandString given.
|
* adds a Command by returning a Promise that reacts to the specific commandString given.
|
||||||
* Note: in e.g. "npm install something" the "install" is considered the command.
|
* Note: in e.g. "npm install something" the "install" is considered the command.
|
||||||
*/
|
*/
|
||||||
addCommand(commandNameArg: string): Subject<any> {
|
public addCommand(commandNameArg: string): plugins.smartrx.rxjs.Subject<any> {
|
||||||
let triggerSubject = this.addTrigger(commandNameArg);
|
let commandSubject: plugins.smartrx.rxjs.Subject<any>;
|
||||||
this.parseStarted.promise.then(() => {
|
const existingCommandSubject = this.getCommandSubject(commandNameArg);
|
||||||
if (this.argv._.indexOf(commandNameArg) === 0) {
|
commandSubject = existingCommandSubject || new plugins.smartrx.rxjs.Subject<any>();
|
||||||
this.trigger(commandNameArg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return triggerSubject;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
this.commandObservableMap.add({
|
||||||
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
commandName: commandNameArg,
|
||||||
*/
|
subject: commandSubject,
|
||||||
addTrigger(triggerNameArg: string) {
|
})
|
||||||
let triggerSubject = new Subject<any>();
|
return commandSubject;
|
||||||
if (!this.getTriggerSubject(triggerNameArg)) {
|
|
||||||
this.allTriggerObservablesMap.add({
|
|
||||||
triggerName: triggerNameArg,
|
|
||||||
subject: triggerSubject
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
throw new Error(`you can't add a trigger twice`);
|
|
||||||
}
|
|
||||||
return triggerSubject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute trigger by name
|
* execute trigger by name
|
||||||
* @param commandNameArg - the name of the command to trigger
|
* @param commandNameArg - the name of the command to trigger
|
||||||
*/
|
*/
|
||||||
trigger(triggerName: string) {
|
public triggerCommand(commandNameArg: string, argvObject: any) {
|
||||||
let triggerSubject = this.getTriggerSubject(triggerName);
|
const triggerSubject = this.getCommandSubject(commandNameArg);
|
||||||
triggerSubject.next(this.argv);
|
triggerSubject.next(argvObject);
|
||||||
return triggerSubject;
|
return triggerSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTriggerSubject(triggerName: string) {
|
public getCommandSubject(commandNameArg: string) {
|
||||||
const triggerObservableObject = this.allTriggerObservablesMap.find(
|
const triggerObservableObject = this.commandObservableMap.findSync(
|
||||||
triggerObservableObjectArg => {
|
(triggerObservableObjectArg) => {
|
||||||
return triggerObservableObjectArg.triggerName === triggerName;
|
return triggerObservableObjectArg.commandName === commandNameArg;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (triggerObservableObject) {
|
if (triggerObservableObject) {
|
||||||
@ -114,20 +93,20 @@ export class Smartcli {
|
|||||||
/**
|
/**
|
||||||
* allows to specify help text to be printed above the rest of the help text
|
* allows to specify help text to be printed above the rest of the help text
|
||||||
*/
|
*/
|
||||||
addHelp(optionsArg: { helpText: string }) {
|
public addHelp(optionsArg: { helpText: string }) {
|
||||||
this.addCommand('help').subscribe(argvArg => {
|
this.addCommand('help').subscribe((argvArg) => {
|
||||||
plugins.smartlog.defaultLogger.info(optionsArg.helpText);
|
logger.log('info', optionsArg.helpText);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* specify version to be printed for -v --version
|
* specify version to be printed for -v --version
|
||||||
*/
|
*/
|
||||||
addVersion(versionArg: string) {
|
public addVersion(versionArg: string) {
|
||||||
this.version = versionArg;
|
this.version = versionArg;
|
||||||
this.addCommandAlias('v', 'version');
|
this.addCommandAlias('v', 'version');
|
||||||
this.parseStarted.promise.then(() => {
|
this.parseCompleted.promise.then(argv => {
|
||||||
if (this.argv.v) {
|
if (argv.v) {
|
||||||
console.log(this.version);
|
console.log(this.version);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -136,30 +115,61 @@ export class Smartcli {
|
|||||||
/**
|
/**
|
||||||
* adds a trigger that is called when no command is specified
|
* adds a trigger that is called when no command is specified
|
||||||
*/
|
*/
|
||||||
standardTask(): Subject<any> {
|
public standardCommand(): plugins.smartrx.rxjs.Subject<any> {
|
||||||
let standardSubject = this.addTrigger('standardTask');
|
const standardSubject = this.addCommand('standardCommand');
|
||||||
this.parseStarted.promise.then(() => {
|
|
||||||
if (this.argv._.length === 0 && !this.argv.v) {
|
|
||||||
if (this.onlyOnProcessEnvCliCall) {
|
|
||||||
if (process.env.CLI_CALL === 'true') {
|
|
||||||
this.trigger('standardTask');
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.trigger('standardTask');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return standardSubject;
|
return standardSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start the process of evaluating commands
|
* start the process of evaluating commands
|
||||||
*/
|
*/
|
||||||
startParse(): void {
|
public startParse(): void {
|
||||||
this.argv = this.argv.argv;
|
// if we check for cli env calls, we might want to abort here.
|
||||||
this.parseStarted.resolve();
|
if (!process.env.CLI_CALL && this.checkForEnvCliCall) {
|
||||||
|
console.log(
|
||||||
|
`note: @pushrocks/smartcli: You called .startParse() on a SmartCli instance. However process.env.CLI_CALL being absent prevented parsing.`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const parsedYArgs = plugins.yargsParser(process.argv);
|
||||||
|
|
||||||
|
// lets handle commands
|
||||||
|
let counter = 0;
|
||||||
|
let foundCommand = false;
|
||||||
|
parsedYArgs._.map((commandPartArg) => {
|
||||||
|
counter ++;
|
||||||
|
if (typeof commandPartArg === 'number') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (counter <= 2 && !foundCommand) {
|
||||||
|
const isPath = commandPartArg.startsWith('/');
|
||||||
|
foundCommand = !isPath;
|
||||||
|
return foundCommand;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
for (const command of this.commandObservableMap.getArray()) {
|
||||||
|
if (!parsedYArgs._[0]) {
|
||||||
|
const standardCommand = this.commandObservableMap.findSync(commandArg => {
|
||||||
|
return commandArg.commandName === "standardCommand";
|
||||||
|
});
|
||||||
|
if (standardCommand) {
|
||||||
|
standardCommand.subject.next(parsedYArgs);
|
||||||
|
} else {
|
||||||
|
console.log('no smartcli standard task was created or assigned.');
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (command.commandName === parsedYArgs._[0]) {
|
||||||
|
command.subject.next(parsedYArgs);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (this.aliasObject[parsedYArgs[0]]) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.parseCompleted.resolve(parsedYArgs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
import * as yargs from 'yargs';
|
// @pushrocks scope
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
import * as lik from '@pushrocks/lik';
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as smartparam from 'smartparam';
|
import * as smartparam from '@pushrocks/smartparam';
|
||||||
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
|
import * as smartrx from '@pushrocks/smartrx';
|
||||||
|
|
||||||
export { yargs, smartlog, lik, path, smartparam };
|
export { smartlog, lik, path, smartparam, smartpromise, smartrx };
|
||||||
|
|
||||||
|
// thirdparty scope
|
||||||
|
import yargsParser from 'yargs-parser';
|
||||||
|
|
||||||
|
export {
|
||||||
|
yargsParser
|
||||||
|
}
|
||||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "tslint-config-standard"
|
|
||||||
}
|
|
Reference in New Issue
Block a user