Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
311232aeea | |||
4cd0844bc3 | |||
17c1a687c8 | |||
1d1264c2b3 | |||
b036e609ce | |||
c2ec0df907 | |||
167b4d29df | |||
02fec216db | |||
4e9d2f3e8c | |||
65d8a8b6f5 | |||
8e04bd6a62 | |||
687a5f7c4e |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
|||||||
|
|
||||||
# builds
|
# builds
|
||||||
dist/
|
dist/
|
||||||
dist_web/
|
dist_*/
|
||||||
dist_serve/
|
|
||||||
dist_ts_web/
|
|
||||||
|
|
||||||
# custom
|
# custom
|
@ -19,22 +19,35 @@ mirror:
|
|||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- npmci git mirror
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
snyk:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
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
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci command npm install --ignore-scripts
|
- 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:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -49,9 +62,7 @@ testStable:
|
|||||||
- npmci npm test
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- priv
|
|
||||||
|
|
||||||
testBuild:
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
@ -62,9 +73,7 @@ testBuild:
|
|||||||
- npmci command npm run build
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
@ -84,6 +93,8 @@ release:
|
|||||||
codequality:
|
codequality:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g tslint typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
|
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -15,7 +15,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"projectType": {
|
"projectType": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["website", "element", "service", "npm"]
|
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
||||||
|
11266
package-lock.json
generated
11266
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
42
package.json
42
package.json
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartcli",
|
"name": "@pushrocks/smartcli",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.8",
|
"version": "3.0.14",
|
||||||
"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",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -26,32 +26,36 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.19",
|
"@pushrocks/lik": "^4.0.20",
|
||||||
"@pushrocks/smartlog": "^2.0.21",
|
"@pushrocks/smartlog": "^2.0.39",
|
||||||
"@pushrocks/smartparam": "^1.1.6",
|
"@pushrocks/smartparam": "^1.1.6",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@types/yargs": "^15.0.4",
|
"@types/yargs": "^16.0.1",
|
||||||
"rxjs": "^6.5.4",
|
"rxjs": "^6.6.7",
|
||||||
"yargs": "^15.3.0"
|
"yargs": "^16.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.20",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.52",
|
||||||
"@pushrocks/tapbundle": "^3.2.0",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^13.9.0",
|
"@types/node": "^14.14.37",
|
||||||
"tslint": "^6.1.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
"ts_web/**/*",
|
"ts_web/**/*",
|
||||||
"dist/**/*",
|
"dist/**/*",
|
||||||
"dist_web/**/*",
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
"dist_ts_web/**/*",
|
"dist_ts_web/**/*",
|
||||||
"assets/**/*",
|
"assets/**/*",
|
||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"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)
|
@ -4,7 +4,7 @@ import { Subject } from 'rxjs';
|
|||||||
import * as plugins from './smartcli.plugins';
|
import * as plugins from './smartcli.plugins';
|
||||||
|
|
||||||
// import classes
|
// import classes
|
||||||
import { Objectmap } from '@pushrocks/lik';
|
import { ObjectMap } from '@pushrocks/lik';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
export interface ICommandPromiseObject {
|
export interface ICommandPromiseObject {
|
||||||
@ -17,6 +17,8 @@ export interface ITriggerObservableObject {
|
|||||||
subject: Subject<any>;
|
subject: Subject<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const logger = new plugins.smartlog.ConsoleLog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
@ -27,12 +29,12 @@ export class Smartcli {
|
|||||||
commands;
|
commands;
|
||||||
questions;
|
questions;
|
||||||
version: string;
|
version: string;
|
||||||
private onlyOnProcessEnvCliCall = false;
|
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>();
|
allTriggerObservablesMap = new ObjectMap<ITriggerObservableObject>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor of Smartcli
|
* The constructor of Smartcli
|
||||||
@ -46,8 +48,8 @@ export class Smartcli {
|
|||||||
/**
|
/**
|
||||||
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,7 +65,7 @@ export class Smartcli {
|
|||||||
* 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> {
|
addCommand(commandNameArg: string): Subject<any> {
|
||||||
let triggerSubject = this.addTrigger(commandNameArg);
|
const triggerSubject = this.addTrigger(commandNameArg);
|
||||||
this.parseStarted.promise.then(() => {
|
this.parseStarted.promise.then(() => {
|
||||||
if (this.argv._.indexOf(commandNameArg) === 0) {
|
if (this.argv._.indexOf(commandNameArg) === 0) {
|
||||||
this.trigger(commandNameArg);
|
this.trigger(commandNameArg);
|
||||||
@ -76,11 +78,11 @@ export class Smartcli {
|
|||||||
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
||||||
*/
|
*/
|
||||||
addTrigger(triggerNameArg: string) {
|
addTrigger(triggerNameArg: string) {
|
||||||
let triggerSubject = new Subject<any>();
|
const triggerSubject = new Subject<any>();
|
||||||
if (!this.getTriggerSubject(triggerNameArg)) {
|
if (!this.getTriggerSubject(triggerNameArg)) {
|
||||||
this.allTriggerObservablesMap.add({
|
this.allTriggerObservablesMap.add({
|
||||||
triggerName: triggerNameArg,
|
triggerName: triggerNameArg,
|
||||||
subject: triggerSubject
|
subject: triggerSubject,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`you can't add a trigger twice`);
|
throw new Error(`you can't add a trigger twice`);
|
||||||
@ -93,14 +95,14 @@ export class Smartcli {
|
|||||||
* @param commandNameArg - the name of the command to trigger
|
* @param commandNameArg - the name of the command to trigger
|
||||||
*/
|
*/
|
||||||
trigger(triggerName: string) {
|
trigger(triggerName: string) {
|
||||||
let triggerSubject = this.getTriggerSubject(triggerName);
|
const triggerSubject = this.getTriggerSubject(triggerName);
|
||||||
triggerSubject.next(this.argv);
|
triggerSubject.next(this.argv);
|
||||||
return triggerSubject;
|
return triggerSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTriggerSubject(triggerName: string) {
|
getTriggerSubject(triggerName: string) {
|
||||||
const triggerObservableObject = this.allTriggerObservablesMap.find(
|
const triggerObservableObject = this.allTriggerObservablesMap.find(
|
||||||
triggerObservableObjectArg => {
|
(triggerObservableObjectArg) => {
|
||||||
return triggerObservableObjectArg.triggerName === triggerName;
|
return triggerObservableObjectArg.triggerName === triggerName;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -115,8 +117,8 @@ 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 }) {
|
addHelp(optionsArg: { helpText: string }) {
|
||||||
this.addCommand('help').subscribe(argvArg => {
|
this.addCommand('help').subscribe((argvArg) => {
|
||||||
plugins.smartlog.defaultLogger.log('info', optionsArg.helpText);
|
logger.log('info', optionsArg.helpText);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,18 +139,14 @@ 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> {
|
standardTask(): Subject<any> {
|
||||||
let standardSubject = this.addTrigger('standardTask');
|
const standardSubject = this.addTrigger('standardTask');
|
||||||
this.parseStarted.promise.then(() => {
|
this.parseStarted.promise.then(() => {
|
||||||
if (this.argv._.length === 0 && !this.argv.v) {
|
if (
|
||||||
if (this.onlyOnProcessEnvCliCall) {
|
(this.argv._.length === 0 ||
|
||||||
if (process.env.CLI_CALL === 'true') {
|
(this.argv._.length === 1 && this.argv._[0].startsWith('test/'))) &&
|
||||||
this.trigger('standardTask');
|
!this.argv.v
|
||||||
} else {
|
) {
|
||||||
return;
|
this.trigger('standardTask');
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.trigger('standardTask');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return standardSubject;
|
return standardSubject;
|
||||||
@ -158,6 +156,12 @@ export class Smartcli {
|
|||||||
* start the process of evaluating commands
|
* start the process of evaluating commands
|
||||||
*/
|
*/
|
||||||
startParse(): void {
|
startParse(): void {
|
||||||
|
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;
|
||||||
|
}
|
||||||
this.argv = this.argv.argv;
|
this.argv = this.argv.argv;
|
||||||
this.parseStarted.resolve();
|
this.parseStarted.resolve();
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user