Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
5f027430bf | |||
d3385782ed | |||
7384b54e09 | |||
0eac72e15d | |||
b7957b0ab6 | |||
99a0a9ca81 | |||
bd66903419 | |||
740d8dac35 | |||
488e7410fe | |||
04deb8960c | |||
19f0a9563f | |||
db1e866fe1 | |||
f7c24a0bd2 | |||
fa59d2da40 | |||
311232aeea | |||
4cd0844bc3 | |||
17c1a687c8 | |||
1d1264c2b3 | |||
b036e609ce | |||
c2ec0df907 |
@ -12,30 +12,35 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
auditProductionDependencies:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci git mirror
|
- 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:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
audit:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
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 npm config set registry https://registry.npmjs.org
|
- npmci command npm config set registry https://registry.npmjs.org
|
||||||
- npmci command npm audit --audit-level=high
|
- npmci command npm audit --audit-level=high --only=dev
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
|
||||||
- docker
|
- docker
|
||||||
- notpriv
|
allow_failure: true
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# test stage
|
# test stage
|
||||||
@ -50,9 +55,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
|
||||||
@ -63,9 +66,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
|
||||||
@ -85,11 +86,12 @@ 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 typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -109,11 +111,10 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
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: {}
|
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${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"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
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"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartcli",
|
"gitrepo": "smartcli",
|
||||||
"shortDescription": "easy observable cli tasks",
|
"description": "easy observable cli tasks",
|
||||||
"npmPackagename": "@pushrocks/smartcli",
|
"npmPackagename": "@pushrocks/smartcli",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
13781
package-lock.json
generated
13781
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@ -1,13 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartcli",
|
"name": "@pushrocks/smartcli",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "3.0.11",
|
"version": "4.0.6",
|
||||||
"description": "easy observable cli tasks",
|
"description": "easy observable cli tasks",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/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)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -26,22 +28,19 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/lik": "^3.0.19",
|
"@pushrocks/lik": "^6.0.0",
|
||||||
"@pushrocks/smartlog": "^2.0.21",
|
"@pushrocks/smartlog": "^3.0.1",
|
||||||
"@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",
|
"@pushrocks/smartrx": "^2.0.25",
|
||||||
"rxjs": "^6.5.5",
|
"yargs-parser": "21.0.1"
|
||||||
"yargs": "^15.3.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.22",
|
"@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.1",
|
"@pushrocks/tapbundle": "^5.0.4",
|
||||||
"@types/node": "^13.11.1",
|
"@types/node": "^18.6.3"
|
||||||
"tslint": "^6.1.1",
|
|
||||||
"tslint-config-prettier": "^1.18.0"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
@ -54,5 +53,8 @@
|
|||||||
"cli.js",
|
"cli.js",
|
||||||
"npmextra.json",
|
"npmextra.json",
|
||||||
"readme.md"
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
27
readme.md
27
readme.md
@ -8,13 +8,20 @@ easy observable cli tasks
|
|||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartcli/)
|
* [docs (typedoc)](https://pushrocks.gitlab.io/smartcli/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
[](https://gitlab.com/pushrocks/smartcli/commits/master)
|
|
||||||
[](https://gitlab.com/pushrocks/smartcli/commits/master)
|
Status Category | Status Badge
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartcli)
|
-- | --
|
||||||
[](https://snyk.io/test/npm/@pushrocks/smartcli)
|
GitLab Pipelines | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
npm | [](https://lossless.cloud)
|
||||||
[](https://prettier.io/)
|
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
|
## Usage
|
||||||
|
|
||||||
@ -39,11 +46,11 @@ except when of the options is -v, --version or --help.
|
|||||||
```javascript
|
```javascript
|
||||||
import { Smartcli } from 'smartcli';
|
import { Smartcli } from 'smartcli';
|
||||||
mySmartcli = new Smartcli();
|
mySmartcli = new Smartcli();
|
||||||
mySmartcli.standardTask().then(argvArg => {
|
mySmartcli.standardTask().then((argvArg) => {
|
||||||
// do something if program is called without an command
|
// do something if program is called without an command
|
||||||
});
|
});
|
||||||
|
|
||||||
mySmartcli.addCommand({ commandname: 'install' }).then(argvArg => {
|
mySmartcli.addCommand({ commandname: 'install' }).then((argvArg) => {
|
||||||
// do something if program is called with command "install"
|
// do something if program is called with command "install"
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -51,7 +58,7 @@ mySmartcli.addVersion('1.0.0'); // -v and --version options will display the spe
|
|||||||
|
|
||||||
mySmartCli.addHelp({
|
mySmartCli.addHelp({
|
||||||
// is triggered by help command and --help option
|
// is triggered by help command and --help option
|
||||||
helpText: 'some help text to print' // the helpText to display
|
helpText: 'some help text to print', // the helpText to display
|
||||||
});
|
});
|
||||||
|
|
||||||
mySmartcli.startParse(); // starts the evaluation and fullfills or rejects promises.
|
mySmartcli.startParse(); // starts the evaluation and fullfills or rejects promises.
|
||||||
|
45
test/test.ts
45
test/test.ts
@ -1,43 +1,42 @@
|
|||||||
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;
|
|
||||||
|
|
||||||
tap.test('should create a new Smartcli', async () => {
|
tap.test('should create a new Smartcli', async () => {
|
||||||
smartCliTestObject = new smartcli.Smartcli();
|
const 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 (toolsArg) => {
|
||||||
expect(smartCliTestObject.addCommand('awesome')).to.be.instanceOf(Subject);
|
const done = toolsArg.defer();
|
||||||
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
|
const awesomeCommandSubject = smartCliTestObject.addCommand('awesome')
|
||||||
|
expect(awesomeCommandSubject).toBeInstanceOf(Subject);
|
||||||
|
awesomeCommandSubject.subscribe(() => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
console.log(process.argv);
|
||||||
|
process.argv.splice(2, 0, 'awesome');
|
||||||
|
console.log(process.argv);
|
||||||
|
smartCliTestObject.startParse();
|
||||||
|
await done.promise;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start parsing a standardTask', async () => {
|
tap.test('should start parsing a standardTask', async () => {
|
||||||
expect(smartCliTestObject.standardTask()).to.be.instanceOf(Subject);
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
|
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(() => {
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
|
smartCliTestObject.addCommand('triggerme').subscribe(() => {
|
||||||
hasExecuted = true;
|
hasExecuted = true;
|
||||||
});
|
});
|
||||||
});
|
smartCliTestObject.triggerCommand('triggerme', {});
|
||||||
|
expect(hasExecuted).toBeTrue();
|
||||||
tap.test('should not have executed yet', async () => {
|
|
||||||
expect(hasExecuted).to.be.false;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should execute when triggered', async () => {
|
|
||||||
smartCliTestObject.trigger('triggerme');
|
|
||||||
expect(hasExecuted).be.true;
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should start parsing the CLI input', async () => {
|
|
||||||
smartCliTestObject.startParse();
|
|
||||||
expect(smartCliTestObject.parseStarted.promise).to.be.instanceOf(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.6',
|
||||||
|
description: 'easy observable cli tasks'
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
export { Smartcli } from './smartcli.classes.smartcli';
|
export { Smartcli } from './smartcli.classes.smartcli.js';
|
||||||
|
@ -1,107 +1,77 @@
|
|||||||
import * as smartpromise from '@pushrocks/smartpromise';
|
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: smartpromise.Deferred<any>;
|
*/
|
||||||
commands;
|
public parseCompleted = plugins.smartpromise.defer<any>();
|
||||||
questions;
|
|
||||||
version: string;
|
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 = smartpromise.defer();
|
|
||||||
this.parseStarted = smartpromise.defer();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* halts any execution of commands if (process.env.CLI_CALL === false)
|
|
||||||
*/
|
|
||||||
disableEnvCliCall() {
|
|
||||||
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: string, aliasArg: string): 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> {
|
||||||
const 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) {
|
});
|
||||||
const 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) {
|
||||||
const 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,52 +84,77 @@ 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.log('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.parseStarted.promise.then(() => {
|
|
||||||
if (this.argv.v) {
|
|
||||||
console.log(this.version);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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> {
|
||||||
const standardSubject = this.addTrigger('standardTask');
|
const standardSubject = this.addCommand('standardCommand');
|
||||||
this.parseStarted.promise.then(() => {
|
|
||||||
if (
|
|
||||||
(this.argv._.length === 0 ||
|
|
||||||
(this.argv._.length === 1 && this.argv._[0].startsWith('test/'))) &&
|
|
||||||
!this.argv.v
|
|
||||||
) {
|
|
||||||
this.trigger('standardTask');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return standardSubject;
|
return standardSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start the process of evaluating commands
|
* start the process of evaluating commands
|
||||||
*/
|
*/
|
||||||
startParse(): void {
|
public startParse(): void {
|
||||||
if (!process.env.CLI_CALL && this.checkForEnvCliCall) {
|
const parsedYArgs = plugins.yargsParser(process.argv);
|
||||||
console.log(`note: @pushrocks/smartcli: You called .startParse() on a SmartCli instance. However process.env.CLI_CALL being absent prevented parsing.`);
|
|
||||||
|
// lets handle commands
|
||||||
|
let counter = 0;
|
||||||
|
let foundCommand = false;
|
||||||
|
parsedYArgs._ = parsedYArgs._.filter((commandPartArg) => {
|
||||||
|
counter++;
|
||||||
|
if (typeof commandPartArg === 'number') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (counter <= 2 && !foundCommand) {
|
||||||
|
const isPath = commandPartArg.startsWith('/');
|
||||||
|
foundCommand = !isPath;
|
||||||
|
return foundCommand;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const wantedCommand = parsedYArgs._[0];
|
||||||
|
|
||||||
|
// lets handle some standards
|
||||||
|
if (!wantedCommand && (parsedYArgs.v || parsedYArgs.version)) {
|
||||||
|
console.log(this.version || 'unknown version');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.argv = this.argv.argv;
|
console.log(`Wanted command: ${wantedCommand}`);
|
||||||
this.parseStarted.resolve();
|
for (const command of this.commandObservableMap.getArray()) {
|
||||||
|
if (!wantedCommand) {
|
||||||
|
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,14 @@
|
|||||||
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 '@pushrocks/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
|
||||||
|
}
|
||||||
|
}
|
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