Compare commits
53 Commits
Author | SHA1 | Date | |
---|---|---|---|
5e2225669d | |||
a4a3343b1d | |||
e10e8cf90d | |||
19900d088e | |||
3e5793f842 | |||
4fd13e65c4 | |||
e5a8bbf4a3 | |||
f28589603b | |||
fed411a30f | |||
2328801f03 | |||
60883fed6d | |||
e9fc5b98f2 | |||
fef954c423 | |||
39408d9832 | |||
26d9b3e9cc | |||
5f027430bf | |||
d3385782ed | |||
7384b54e09 | |||
0eac72e15d | |||
b7957b0ab6 | |||
99a0a9ca81 | |||
bd66903419 | |||
740d8dac35 | |||
488e7410fe | |||
04deb8960c | |||
19f0a9563f | |||
db1e866fe1 | |||
f7c24a0bd2 | |||
fa59d2da40 | |||
311232aeea | |||
4cd0844bc3 | |||
17c1a687c8 | |||
1d1264c2b3 | |||
b036e609ce | |||
c2ec0df907 | |||
167b4d29df | |||
02fec216db | |||
4e9d2f3e8c | |||
65d8a8b6f5 | |||
8e04bd6a62 | |||
687a5f7c4e | |||
17983b1da9 | |||
5fcdf1ff8f | |||
ef7ee7fc73 | |||
c48e85897e | |||
9466b3e473 | |||
ab3127b8a6 | |||
1e62e27980 | |||
4b87004478 | |||
7750f1fbf5 | |||
c4e5ba6587 | |||
9d1f0f22ba | |||
1ce9e32116 |
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
|
18
.gitignore
vendored
18
.gitignore
vendored
@ -1,4 +1,20 @@
|
||||
node_modules/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
141
.gitlab-ci.yml
141
.gitlab-ci.yml
@ -1,141 +0,0 @@
|
||||
# gitzone standard
|
||||
image: 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
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# 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:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--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:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g npmpage
|
||||
- npmci command npmpage
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
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
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
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://)
|
1
dist/index.d.ts
vendored
1
dist/index.d.ts
vendored
@ -1 +0,0 @@
|
||||
export { Smartcli } from './smartcli.classes.smartcli';
|
5
dist/index.js
vendored
5
dist/index.js
vendored
@ -1,5 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var smartcli_classes_smartcli_1 = require("./smartcli.classes.smartcli");
|
||||
exports.Smartcli = smartcli_classes_smartcli_1.Smartcli;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHlFQUF1RDtBQUE5QywrQ0FBQSxRQUFRLENBQUEifQ==
|
72
dist/smartcli.classes.smartcli.d.ts
vendored
72
dist/smartcli.classes.smartcli.d.ts
vendored
@ -1,72 +0,0 @@
|
||||
import * as smartq from 'smartq';
|
||||
import { Subject } from 'rxjs';
|
||||
import * as plugins from './smartcli.plugins';
|
||||
export interface ICommandPromiseObject {
|
||||
commandName: string;
|
||||
promise: Promise<void>;
|
||||
}
|
||||
export interface ITriggerObservableObject {
|
||||
triggerName: string;
|
||||
subject: Subject<any>;
|
||||
}
|
||||
/**
|
||||
* class to create a new instance of Smartcli. Handles parsing of command line arguments.
|
||||
*/
|
||||
export declare class Smartcli {
|
||||
argv: any;
|
||||
questionsDone: any;
|
||||
parseStarted: smartq.Deferred<any>;
|
||||
commands: any;
|
||||
questions: any;
|
||||
version: string;
|
||||
private onlyOnProcessEnvCliCall;
|
||||
/**
|
||||
* map of all Trigger/Observable objects to keep track
|
||||
*/
|
||||
allTriggerObservablesMap: plugins.lik.Objectmap<ITriggerObservableObject>;
|
||||
/**
|
||||
* The constructor of Smartcli
|
||||
*/
|
||||
constructor();
|
||||
/**
|
||||
* halts any execution of commands if (process.env.CLI_CALL === false)
|
||||
*/
|
||||
onlyTriggerOnProcessEnvCliCall(): void;
|
||||
/**
|
||||
* adds an alias, meaning one equals the other in terms of command execution.
|
||||
*/
|
||||
addCommandAlias(keyArg: any, aliasArg: any): void;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
addCommand(commandNameArg: string): Subject<any>;
|
||||
/**
|
||||
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
||||
*/
|
||||
addTrigger(triggerNameArg: string): Subject<any>;
|
||||
/**
|
||||
* execute trigger by name
|
||||
* @param commandNameArg - the name of the command to trigger
|
||||
*/
|
||||
trigger(triggerName: string): Subject<any>;
|
||||
getTriggerSubject(triggerName: string): Subject<any>;
|
||||
/**
|
||||
* allows to specify help text to be printed above the rest of the help text
|
||||
*/
|
||||
addHelp(optionsArg: {
|
||||
helpText: string;
|
||||
}): void;
|
||||
/**
|
||||
* specify version to be printed for -v --version
|
||||
*/
|
||||
addVersion(versionArg: string): void;
|
||||
/**
|
||||
* adds a trigger that is called when no command is specified
|
||||
*/
|
||||
standardTask(): Subject<any>;
|
||||
/**
|
||||
* start the process of evaluating commands
|
||||
*/
|
||||
startParse(): void;
|
||||
}
|
139
dist/smartcli.classes.smartcli.js
vendored
139
dist/smartcli.classes.smartcli.js
vendored
@ -1,139 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const smartq = require("smartq");
|
||||
const rxjs_1 = require("rxjs");
|
||||
const plugins = require("./smartcli.plugins");
|
||||
// import classes
|
||||
const lik_1 = require("lik");
|
||||
/**
|
||||
* class to create a new instance of Smartcli. Handles parsing of command line arguments.
|
||||
*/
|
||||
class Smartcli {
|
||||
/**
|
||||
* The constructor of Smartcli
|
||||
*/
|
||||
constructor() {
|
||||
this.onlyOnProcessEnvCliCall = false;
|
||||
/**
|
||||
* map of all Trigger/Observable objects to keep track
|
||||
*/
|
||||
this.allTriggerObservablesMap = new lik_1.Objectmap();
|
||||
this.argv = plugins.yargs;
|
||||
this.questionsDone = smartq.defer();
|
||||
this.parseStarted = smartq.defer();
|
||||
}
|
||||
/**
|
||||
* halts any execution of commands if (process.env.CLI_CALL === false)
|
||||
*/
|
||||
onlyTriggerOnProcessEnvCliCall() {
|
||||
this.onlyOnProcessEnvCliCall = true;
|
||||
}
|
||||
/**
|
||||
* adds an alias, meaning one equals the other in terms of command execution.
|
||||
*/
|
||||
addCommandAlias(keyArg, aliasArg) {
|
||||
this.argv = this.argv.alias(keyArg, aliasArg);
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
addCommand(commandNameArg) {
|
||||
let triggerSubject = this.addTrigger(commandNameArg);
|
||||
this.parseStarted.promise.then(() => {
|
||||
if (this.argv._.indexOf(commandNameArg) === 0) {
|
||||
this.trigger(commandNameArg);
|
||||
}
|
||||
});
|
||||
return triggerSubject;
|
||||
}
|
||||
/**
|
||||
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
||||
*/
|
||||
addTrigger(triggerNameArg) {
|
||||
let triggerSubject = new rxjs_1.Subject();
|
||||
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
|
||||
* @param commandNameArg - the name of the command to trigger
|
||||
*/
|
||||
trigger(triggerName) {
|
||||
let triggerSubject = this.getTriggerSubject(triggerName);
|
||||
triggerSubject.next(this.argv);
|
||||
return triggerSubject;
|
||||
}
|
||||
getTriggerSubject(triggerName) {
|
||||
const triggerObservableObject = this.allTriggerObservablesMap.find(triggerObservableObjectArg => {
|
||||
return triggerObservableObjectArg.triggerName === triggerName;
|
||||
});
|
||||
if (triggerObservableObject) {
|
||||
return triggerObservableObject.subject;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* allows to specify help text to be printed above the rest of the help text
|
||||
*/
|
||||
addHelp(optionsArg) {
|
||||
this.addCommand('help').subscribe(argvArg => {
|
||||
plugins.beautylog.log(optionsArg.helpText);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* specify version to be printed for -v --version
|
||||
*/
|
||||
addVersion(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
|
||||
*/
|
||||
standardTask() {
|
||||
let standardSubject = this.addTrigger('standardTask');
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* start the process of evaluating commands
|
||||
*/
|
||||
startParse() {
|
||||
this.argv = this.argv.argv;
|
||||
this.parseStarted.resolve();
|
||||
return;
|
||||
}
|
||||
}
|
||||
exports.Smartcli = Smartcli;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxpQ0FBaUM7QUFDakMsK0JBQStCO0FBRS9CLDhDQUE4QztBQUU5QyxpQkFBaUI7QUFDakIsNkJBQWdDO0FBYWhDOztHQUVHO0FBQ0g7SUFjRTs7T0FFRztJQUNIO1FBVlEsNEJBQXVCLEdBQUcsS0FBSyxDQUFDO1FBRXhDOztXQUVHO1FBQ0gsNkJBQXdCLEdBQUcsSUFBSSxlQUFTLEVBQTRCLENBQUM7UUFNbkUsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsS0FBSyxDQUFDO1FBQzFCLElBQUksQ0FBQyxhQUFhLEdBQUcsTUFBTSxDQUFDLEtBQUssRUFBRSxDQUFDO1FBQ3BDLElBQ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IsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQztRQUMzQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxDQUFDO1FBQzVCLE9BQU87SUFDVCxDQUFDO0NBQ0Y7QUE5SUQsNEJBOElDIn0=
|
6
dist/smartcli.plugins.d.ts
vendored
6
dist/smartcli.plugins.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
import * as yargs from 'yargs';
|
||||
import * as beautylog from 'beautylog';
|
||||
import * as lik from 'lik';
|
||||
import * as path from 'path';
|
||||
import * as smartparam from 'smartparam';
|
||||
export { yargs, beautylog, lik, path, smartparam };
|
13
dist/smartcli.plugins.js
vendored
13
dist/smartcli.plugins.js
vendored
@ -1,13 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const yargs = require("yargs");
|
||||
exports.yargs = yargs;
|
||||
const beautylog = require("beautylog");
|
||||
exports.beautylog = beautylog;
|
||||
const lik = require("lik");
|
||||
exports.lik = lik;
|
||||
const path = require("path");
|
||||
exports.path = path;
|
||||
const smartparam = require("smartparam");
|
||||
exports.smartparam = smartparam;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwrQkFBK0I7QUFNdEIsc0JBQUs7QUFMZCx1Q0FBdUM7QUFLdkIsOEJBQVM7QUFKekIsMkJBQTJCO0FBSUEsa0JBQUc7QUFIOUIsNkJBQTZCO0FBR0csb0JBQUk7QUFGcEMseUNBQXlDO0FBRUgsZ0NBQVUifQ==
|
@ -23,45 +23,6 @@ nodejs wrapper for CLI related tasks
|
||||
|
||||
## 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.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
|
@ -1,9 +1,32 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"@gitzone/npmts",
|
||||
"ts-node"
|
||||
],
|
||||
"npmGlobalTools": [],
|
||||
"npmAccesslevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartcli",
|
||||
"description": "A library for easily creating observable CLI tasks with support for commands, arguments, and options.",
|
||||
"npmPackagename": "@push.rocks/smartcli",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"CLI",
|
||||
"command line",
|
||||
"observable",
|
||||
"tasks",
|
||||
"commands",
|
||||
"arguments",
|
||||
"options",
|
||||
"typescript",
|
||||
"node.js",
|
||||
"development tool"
|
||||
]
|
||||
}
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
1038
package-lock.json
generated
1038
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
72
package.json
72
package.json
@ -1,23 +1,31 @@
|
||||
{
|
||||
"name": "@pushrocks/smartcli",
|
||||
"name": "@push.rocks/smartcli",
|
||||
"private": false,
|
||||
"version": "3.0.2",
|
||||
"description": "nodejs wrapper for CLI related tasks",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"version": "4.0.11",
|
||||
"description": "A library for easily creating observable CLI tasks with support for commands, arguments, and options.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(tsrun test/test.ts)",
|
||||
"build": "(npmts)"
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gitlab.com/pushrocks/smartcli.git"
|
||||
},
|
||||
"keywords": [
|
||||
"cli",
|
||||
"promise",
|
||||
"task",
|
||||
"push.rocks"
|
||||
"CLI",
|
||||
"command line",
|
||||
"observable",
|
||||
"tasks",
|
||||
"commands",
|
||||
"arguments",
|
||||
"options",
|
||||
"typescript",
|
||||
"node.js",
|
||||
"development tool"
|
||||
],
|
||||
"author": "Lossless GmbH <office@lossless.com> (https://lossless.com)",
|
||||
"license": "MIT",
|
||||
@ -26,23 +34,33 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
||||
"dependencies": {
|
||||
"@types/yargs": "^11.0.0",
|
||||
"beautylog": "^6.1.10",
|
||||
"lik": "^2.0.5",
|
||||
"rxjs": "^6.2.1",
|
||||
"smartparam": "1.0.2",
|
||||
"smartq": "^1.1.8",
|
||||
"yargs": "^11.0.0"
|
||||
"@push.rocks/lik": "^6.0.15",
|
||||
"@push.rocks/smartlog": "^3.0.6",
|
||||
"@push.rocks/smartobject": "^1.0.12",
|
||||
"@push.rocks/smartpromise": "^4.0.3",
|
||||
"@push.rocks/smartrx": "^3.0.3",
|
||||
"yargs-parser": "21.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsrun": "^1.0.7",
|
||||
"@types/node": "^10.5.0",
|
||||
"cz-conventional-changelog": "^2.1.0",
|
||||
"tapbundle": "^2.0.2"
|
||||
"@git.zone/tsbuild": "^2.1.80",
|
||||
"@git.zone/tsrun": "^1.2.42",
|
||||
"@git.zone/tstest": "^1.0.90",
|
||||
"@push.rocks/tapbundle": "^5.0.23",
|
||||
"@types/node": "^20.12.12"
|
||||
},
|
||||
"config": {
|
||||
"commitizen": {
|
||||
"path": "./node_modules/cz-conventional-changelog"
|
||||
}
|
||||
}
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
6825
pnpm-lock.yaml
generated
Normal file
6825
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 @@
|
||||
No specific hints.
|
133
readme.md
Normal file
133
readme.md
Normal file
@ -0,0 +1,133 @@
|
||||
# @push.rocks/smartcli
|
||||
|
||||
easy observable cli tasks
|
||||
|
||||
## Install
|
||||
|
||||
To install `@push.rocks/smartcli`, use the following command in your terminal:
|
||||
|
||||
```sh
|
||||
npm install @push.rocks/smartcli --save
|
||||
```
|
||||
|
||||
This will add `@push.rocks/smartcli` as a dependency to your project's `package.json` file and download it into the `node_modules` folder.
|
||||
|
||||
## Usage
|
||||
|
||||
The `@push.rocks/smartcli` module is designed to simplify the creation of command-line interfaces (CLIs) by providing an easy-to-use API for managing CLI commands and options. It combines observables with the parsing power of [yargs-parser](https://www.npmjs.com/package/yargs-parser) to offer a dynamic and flexible way to handle various CLI tasks.
|
||||
|
||||
### Getting Started
|
||||
|
||||
First, ensure you have TypeScript and the necessary types for node installed in your project. If not, you can add them by running:
|
||||
|
||||
```sh
|
||||
npm install typescript @types/node --save-dev
|
||||
```
|
||||
|
||||
Then, import the `Smartcli` class from the `@push.rocks/smartcli` package.
|
||||
|
||||
```typescript
|
||||
import { Smartcli } from '@push.rocks/smartcli';
|
||||
```
|
||||
|
||||
### Creating an Instance
|
||||
|
||||
Create an instance of `Smartcli`. This instance will be used to define and manage your CLI commands.
|
||||
|
||||
```typescript
|
||||
const mySmartcli = new Smartcli();
|
||||
```
|
||||
|
||||
### Defining Commands
|
||||
|
||||
With `Smartcli`, you can define commands that your CLI tool can execute. Here's how you can add a new command:
|
||||
|
||||
```typescript
|
||||
mySmartcli.addCommand('install').subscribe((argv) => {
|
||||
console.log('Install command was called with arguments:', argv);
|
||||
});
|
||||
```
|
||||
|
||||
In this example, when the user types `install` after your CLI tool's name in the terminal, the provided function will execute, printing the parsed arguments to the console.
|
||||
|
||||
### Handling Options
|
||||
|
||||
Options can be accessed using the `getOption` method. If you have an option named `--config` or `-c`, you can access its value like this:
|
||||
|
||||
```typescript
|
||||
const configValue = mySmartcli.getOption('config');
|
||||
console.log('Config value:', configValue);
|
||||
```
|
||||
|
||||
### Default Task (Standard Command)
|
||||
|
||||
If you want to perform a task when no specific command is provided, you can use the `standardCommand` method:
|
||||
|
||||
```typescript
|
||||
mySmartcli.standardCommand().subscribe((argv) => {
|
||||
console.log('No specific command provided. Running default task with arguments:', argv);
|
||||
});
|
||||
```
|
||||
|
||||
### Version and Help
|
||||
|
||||
To add a version option that prints the version of your CLI tool, use `addVersion`:
|
||||
|
||||
```typescript
|
||||
mySmartcli.addVersion('1.0.0');
|
||||
```
|
||||
|
||||
For a help option that displays helpful information about your CLI commands and options, use `addHelp`:
|
||||
|
||||
```typescript
|
||||
mySmartcli.addHelp({
|
||||
helpText: 'Here are the commands you can use...'
|
||||
});
|
||||
```
|
||||
|
||||
### Parsing and Execution
|
||||
|
||||
After defining all your commands and options, call `startParse` to begin parsing the command line input and execute the corresponding actions:
|
||||
|
||||
```typescript
|
||||
mySmartcli.startParse();
|
||||
```
|
||||
|
||||
### Advanced Usage: Command Aliases
|
||||
|
||||
You can also define aliases for your commands, allowing users to use alternate names for them:
|
||||
|
||||
```typescript
|
||||
mySmartcli.addCommandAlias('install', 'i');
|
||||
```
|
||||
|
||||
With this setup, both `install` and `i` will trigger the same command action.
|
||||
|
||||
### Observables and Async Operations
|
||||
|
||||
Since commands in `smartcli` are handled using observables, you can easily integrate asynchronous operations within your command actions. This makes it perfect for CLI tasks that involve file operations, network requests, or any other async tasks.
|
||||
|
||||
### Conclusion
|
||||
|
||||
`@push.rocks/smartcli` offers a robust and intuitive way to build CLI tools with TypeScript, leveraging the reactive programming paradigm. By following the examples provided in this guide, you'll be able to create a feature-rich command-line application tailored to your specific needs.
|
||||
|
||||
Remember, this is just the start. The true power of `smartcli` lies in its flexibility and the vast ecosystem of RxJS. Dive into the RxJS documentation to explore more ways to handle data streams and asynchronous events in your CLI app.
|
||||
|
||||
## 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.
|
49
test/test.ts
49
test/test.ts
@ -1,43 +1,42 @@
|
||||
import { tap, expect } from 'tapbundle';
|
||||
import { Subject } from 'rxjs';
|
||||
import { tap, expect } from '@push.rocks/tapbundle';
|
||||
import * as smartrx from '@push.rocks/smartrx';
|
||||
|
||||
import smartcli = require('../ts/index');
|
||||
|
||||
let smartCliTestObject: smartcli.Smartcli;
|
||||
import * as smartcli from '../ts/index.js';
|
||||
|
||||
tap.test('should create a new Smartcli', async () => {
|
||||
smartCliTestObject = new smartcli.Smartcli();
|
||||
expect(smartCliTestObject).to.be.instanceof(smartcli.Smartcli);
|
||||
const smartCliTestObject = new smartcli.Smartcli();
|
||||
expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
|
||||
});
|
||||
|
||||
tap.test('should add an command', async () => {
|
||||
expect(smartCliTestObject.addCommand('awesome')).to.be.instanceOf(Subject);
|
||||
tap.test('should add an command', async (toolsArg) => {
|
||||
const done = toolsArg.defer();
|
||||
const smartCliTestObject = new smartcli.Smartcli();
|
||||
const awesomeCommandSubject = smartCliTestObject.addCommand('awesome');
|
||||
expect(awesomeCommandSubject).toBeInstanceOf(smartrx.rxjs.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 () => {
|
||||
expect(smartCliTestObject.standardTask()).to.be.instanceOf(Subject);
|
||||
const smartCliTestObject = new smartcli.Smartcli();
|
||||
expect(smartCliTestObject.standardCommand()).toBeInstanceOf(smartrx.rxjs.Subject);
|
||||
});
|
||||
|
||||
let hasExecuted: boolean = false;
|
||||
|
||||
tap.test('should accept a command', async () => {
|
||||
smartCliTestObject.addTrigger('triggerme').subscribe(() => {
|
||||
const smartCliTestObject = new smartcli.Smartcli();
|
||||
smartCliTestObject.addCommand('triggerme').subscribe(() => {
|
||||
hasExecuted = true;
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
smartCliTestObject.triggerCommand('triggerme', {});
|
||||
expect(hasExecuted).toBeTrue();
|
||||
});
|
||||
|
||||
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/smartcli',
|
||||
version: '4.0.11',
|
||||
description: 'A library for easily creating observable CLI tasks with support for commands, arguments, and options.'
|
||||
}
|
@ -1 +1 @@
|
||||
export { Smartcli } from './smartcli.classes.smartcli';
|
||||
export { Smartcli } from './smartcli.classes.smartcli.js';
|
||||
|
@ -1,107 +1,83 @@
|
||||
import * as smartq from 'smartq';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
import * as plugins from './smartcli.plugins';
|
||||
|
||||
// import classes
|
||||
import { Objectmap } from 'lik';
|
||||
import * as plugins from './smartcli.plugins.js';
|
||||
|
||||
// interfaces
|
||||
export interface ICommandPromiseObject {
|
||||
export interface ICommandObservableObject {
|
||||
commandName: string;
|
||||
promise: Promise<void>;
|
||||
subject: plugins.smartrx.rxjs.Subject<any>;
|
||||
}
|
||||
|
||||
export interface ITriggerObservableObject {
|
||||
triggerName: string;
|
||||
subject: Subject<any>;
|
||||
}
|
||||
const logger = new plugins.smartlog.ConsoleLog();
|
||||
|
||||
/**
|
||||
* class to create a new instance of Smartcli. Handles parsing of command line arguments.
|
||||
*/
|
||||
export class Smartcli {
|
||||
argv: any;
|
||||
questionsDone;
|
||||
parseStarted: smartq.Deferred<any>;
|
||||
commands;
|
||||
questions;
|
||||
version: string;
|
||||
private onlyOnProcessEnvCliCall = false;
|
||||
/**
|
||||
* this Deferred contains the parsed result in the end
|
||||
*/
|
||||
public parseCompleted = plugins.smartpromise.defer<any>();
|
||||
|
||||
public version: string;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
constructor() {
|
||||
this.argv = plugins.yargs;
|
||||
this.questionsDone = smartq.defer();
|
||||
this.parseStarted = smartq.defer();
|
||||
}
|
||||
|
||||
/**
|
||||
* halts any execution of commands if (process.env.CLI_CALL === false)
|
||||
*/
|
||||
onlyTriggerOnProcessEnvCliCall() {
|
||||
this.onlyOnProcessEnvCliCall = true;
|
||||
}
|
||||
constructor() {}
|
||||
|
||||
/**
|
||||
* adds an alias, meaning one equals the other in terms of command execution.
|
||||
*/
|
||||
addCommandAlias(keyArg, aliasArg): void {
|
||||
this.argv = this.argv.alias(keyArg, aliasArg);
|
||||
return;
|
||||
public addCommandAlias(originalArg: string, aliasArg: string): void {
|
||||
this.aliasObject[originalArg] = this.aliasObject[originalArg] || [];
|
||||
this.aliasObject[originalArg].push(aliasArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
addCommand(commandNameArg: string): Subject<any> {
|
||||
let triggerSubject = this.addTrigger(commandNameArg);
|
||||
this.parseStarted.promise.then(() => {
|
||||
if (this.argv._.indexOf(commandNameArg) === 0) {
|
||||
this.trigger(commandNameArg);
|
||||
}
|
||||
});
|
||||
return triggerSubject;
|
||||
}
|
||||
public addCommand(commandNameArg: string): plugins.smartrx.rxjs.Subject<any> {
|
||||
let commandSubject: plugins.smartrx.rxjs.Subject<any>;
|
||||
const existingCommandSubject = this.getCommandSubject(commandNameArg);
|
||||
commandSubject = existingCommandSubject || new plugins.smartrx.rxjs.Subject<any>();
|
||||
|
||||
/**
|
||||
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
||||
*/
|
||||
addTrigger(triggerNameArg: string) {
|
||||
let triggerSubject = new Subject<any>();
|
||||
if (!this.getTriggerSubject(triggerNameArg)) {
|
||||
this.allTriggerObservablesMap.add({
|
||||
triggerName: triggerNameArg,
|
||||
subject: triggerSubject
|
||||
});
|
||||
} else {
|
||||
throw new Error(`you can't add a trigger twice`);
|
||||
}
|
||||
return triggerSubject;
|
||||
this.commandObservableMap.add({
|
||||
commandName: commandNameArg,
|
||||
subject: commandSubject,
|
||||
});
|
||||
return commandSubject;
|
||||
}
|
||||
|
||||
/**
|
||||
* execute trigger by name
|
||||
* @param commandNameArg - the name of the command to trigger
|
||||
*/
|
||||
trigger(triggerName: string) {
|
||||
let triggerSubject = this.getTriggerSubject(triggerName);
|
||||
triggerSubject.next(this.argv);
|
||||
public triggerCommand(commandNameArg: string, argvObject: any) {
|
||||
const triggerSubject = this.getCommandSubject(commandNameArg);
|
||||
triggerSubject.next(argvObject);
|
||||
return triggerSubject;
|
||||
}
|
||||
|
||||
getTriggerSubject(triggerName: string) {
|
||||
const triggerObservableObject = this.allTriggerObservablesMap.find(
|
||||
triggerObservableObjectArg => {
|
||||
return triggerObservableObjectArg.triggerName === triggerName;
|
||||
/**
|
||||
* gets the command subject for the specified name.
|
||||
* call this before calling .parse()
|
||||
* @param commandNameArg
|
||||
* @returns
|
||||
*/
|
||||
public getCommandSubject(commandNameArg: string) {
|
||||
const triggerObservableObject = this.commandObservableMap.findSync(
|
||||
(triggerObservableObjectArg) => {
|
||||
return triggerObservableObjectArg.commandName === commandNameArg;
|
||||
}
|
||||
);
|
||||
if (triggerObservableObject) {
|
||||
@ -111,55 +87,88 @@ export class Smartcli {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getOption
|
||||
*/
|
||||
public getOption(optionNameArg: string) {
|
||||
const parsedYargs = plugins.yargsParser(process.argv);
|
||||
return parsedYargs[optionNameArg];
|
||||
}
|
||||
|
||||
/**
|
||||
* allows to specify help text to be printed above the rest of the help text
|
||||
*/
|
||||
addHelp(optionsArg: { helpText: string }) {
|
||||
this.addCommand('help').subscribe(argvArg => {
|
||||
plugins.beautylog.log(optionsArg.helpText);
|
||||
public addHelp(optionsArg: { helpText: string }) {
|
||||
this.addCommand('help').subscribe((argvArg) => {
|
||||
logger.log('info', optionsArg.helpText);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* specify version to be printed for -v --version
|
||||
*/
|
||||
addVersion(versionArg: string) {
|
||||
public addVersion(versionArg: string) {
|
||||
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
|
||||
*/
|
||||
standardTask(): Subject<any> {
|
||||
let standardSubject = this.addTrigger('standardTask');
|
||||
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');
|
||||
}
|
||||
}
|
||||
});
|
||||
public standardCommand(): plugins.smartrx.rxjs.Subject<any> {
|
||||
const standardSubject = this.addCommand('standardCommand');
|
||||
return standardSubject;
|
||||
}
|
||||
|
||||
/**
|
||||
* start the process of evaluating commands
|
||||
*/
|
||||
startParse(): void {
|
||||
this.argv = this.argv.argv;
|
||||
this.parseStarted.resolve();
|
||||
public startParse(): void {
|
||||
const parsedYArgs = plugins.yargsParser(process.argv);
|
||||
|
||||
// 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;
|
||||
}
|
||||
console.log(`Wanted command: ${wantedCommand}`);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,14 @@
|
||||
import * as yargs from 'yargs';
|
||||
import * as beautylog from 'beautylog';
|
||||
import * as lik from 'lik';
|
||||
// @pushrocks scope
|
||||
import * as smartlog from '@push.rocks/smartlog';
|
||||
import * as lik from '@push.rocks/lik';
|
||||
import * as path from 'path';
|
||||
import * as smartparam from 'smartparam';
|
||||
import * as smartparam from '@push.rocks/smartobject';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import * as smartrx from '@push.rocks/smartrx';
|
||||
|
||||
export { yargs, beautylog, lik, path, smartparam };
|
||||
export { smartlog, lik, path, smartparam, smartpromise, smartrx };
|
||||
|
||||
// thirdparty scope
|
||||
import yargsParser from 'yargs-parser';
|
||||
|
||||
export { yargsParser };
|
||||
|
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"
|
||||
]
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user