Compare commits
77 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 | |||
adfda70522 | |||
c701e3e04c | |||
7b1de5b31d | |||
7908fd8cfd | |||
21bd0c9279 | |||
9d1108e40d | |||
390e0cb491 | |||
032fd0c2fd | |||
440881c3d8 | |||
f208121e2c | |||
7c4ae84871 | |||
668f6c3e16 | |||
b1e08aad1f | |||
f1ab614cdf | |||
995c808512 | |||
28acb867a0 | |||
3148a50d43 | |||
41c99de4d8 | |||
a91f56dacf | |||
f60f17f91e | |||
d154cf0d0f | |||
a6e0fa65e0 | |||
c7e940f597 | |||
45d3ce8ffc | |||
ce121b8b7f | |||
ce65b8d7c9 | |||
9acdfca460 | |||
59bcd8dadf | |||
b6375fd8fa | |||
8183417c90 | |||
5e66d35125 | |||
3ff4c3ff2f | |||
6508b29bfc | |||
66fd7138ab | |||
f3ce1c1408 |
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 @gitzone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,3 +1,20 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_*/
|
||||||
|
|
||||||
|
# custom
|
@ -1,50 +0,0 @@
|
|||||||
image: hosttoday/ht-docker-node:npmts
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- page
|
|
||||||
|
|
||||||
testLEGACY:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test legacy
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
testLTS:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test lts
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testSTABLE:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci test stable
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
pages:
|
|
||||||
image: hosttoday/ht-docker-node:npmpage
|
|
||||||
stage: page
|
|
||||||
script:
|
|
||||||
- npmci test stable
|
|
||||||
- npmci command npmpage --host gitlab
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
README.md
26
README.md
@ -1,26 +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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHlFQUFzRDtBQUE3QywrQ0FBQSxRQUFRLENBQUEifQ==
|
|
67
dist/smartcli.classes.smartcli.d.ts
vendored
67
dist/smartcli.classes.smartcli.d.ts
vendored
@ -1,67 +0,0 @@
|
|||||||
import { Subject } from 'rxjs';
|
|
||||||
import { Objectmap } from 'lik';
|
|
||||||
export interface ICommandPromiseObject {
|
|
||||||
commandName: string;
|
|
||||||
promise: Promise<void>;
|
|
||||||
}
|
|
||||||
export interface ITriggerObservableObject {
|
|
||||||
triggerName: string;
|
|
||||||
subject: Subject<any>;
|
|
||||||
}
|
|
||||||
export declare class Smartcli {
|
|
||||||
argv: any;
|
|
||||||
questionsDone: any;
|
|
||||||
parseStarted: any;
|
|
||||||
commands: any;
|
|
||||||
questions: any;
|
|
||||||
version: string;
|
|
||||||
/**
|
|
||||||
* map of all Command/Promise objects to keep track
|
|
||||||
*/
|
|
||||||
allCommandPromisesMap: Objectmap<ICommandPromiseObject>;
|
|
||||||
/**
|
|
||||||
* map of all Trigger/Observable objects to keep track
|
|
||||||
*/
|
|
||||||
allTriggerObservablesMap: Objectmap<ITriggerObservableObject>;
|
|
||||||
constructor();
|
|
||||||
/**
|
|
||||||
* 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): Promise<any>;
|
|
||||||
/**
|
|
||||||
* gets a Promise for a command word
|
|
||||||
*/
|
|
||||||
getCommandPromiseByName(commandNameArg: string): Promise<void>;
|
|
||||||
/**
|
|
||||||
* 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>;
|
|
||||||
/**
|
|
||||||
* 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;
|
|
||||||
/**
|
|
||||||
* returns promise that is resolved when no commands are specified
|
|
||||||
*/
|
|
||||||
standardTask(): Promise<any>;
|
|
||||||
/**
|
|
||||||
* start the process of evaluating commands
|
|
||||||
*/
|
|
||||||
startParse(): void;
|
|
||||||
}
|
|
134
dist/smartcli.classes.smartcli.js
vendored
134
dist/smartcli.classes.smartcli.js
vendored
@ -1,134 +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 Smartcli {
|
|
||||||
constructor() {
|
|
||||||
/**
|
|
||||||
* map of all Command/Promise objects to keep track
|
|
||||||
*/
|
|
||||||
this.allCommandPromisesMap = new lik_1.Objectmap();
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 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 done = smartq.defer();
|
|
||||||
this.allCommandPromisesMap.add({
|
|
||||||
commandName: commandNameArg,
|
|
||||||
promise: done.promise
|
|
||||||
});
|
|
||||||
this.parseStarted.promise
|
|
||||||
.then(() => {
|
|
||||||
if (this.argv._.indexOf(commandNameArg) === 0) {
|
|
||||||
done.resolve(this.argv);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
done.reject(this.argv);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* gets a Promise for a command word
|
|
||||||
*/
|
|
||||||
getCommandPromiseByName(commandNameArg) {
|
|
||||||
return this.allCommandPromisesMap.find(commandDeferredObjectArg => {
|
|
||||||
return commandDeferredObjectArg.commandName === commandNameArg;
|
|
||||||
}).promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
|
||||||
*/
|
|
||||||
addTrigger(triggerNameArg) {
|
|
||||||
let triggerSubject = new rxjs_1.Subject();
|
|
||||||
this.allTriggerObservablesMap.add({
|
|
||||||
triggerName: triggerNameArg,
|
|
||||||
subject: triggerSubject
|
|
||||||
});
|
|
||||||
this.addCommand(triggerNameArg).then(() => {
|
|
||||||
triggerSubject.next(this.argv);
|
|
||||||
});
|
|
||||||
return triggerSubject;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* execute trigger by name
|
|
||||||
* @param commandNameArg - the name of the command to trigger
|
|
||||||
*/
|
|
||||||
trigger(triggerName) {
|
|
||||||
let triggerSubject = this.allTriggerObservablesMap.find(triggerObservableObjectArg => {
|
|
||||||
return triggerObservableObjectArg.triggerName === triggerName;
|
|
||||||
}).subject;
|
|
||||||
triggerSubject.next(this.argv);
|
|
||||||
return triggerSubject;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* allows to specify help text to be printed above the rest of the help text
|
|
||||||
*/
|
|
||||||
addHelp(optionsArg) {
|
|
||||||
this.addCommand('help').then(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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* returns promise that is resolved when no commands are specified
|
|
||||||
*/
|
|
||||||
standardTask() {
|
|
||||||
let done = smartq.defer();
|
|
||||||
this.allCommandPromisesMap.add({
|
|
||||||
commandName: 'standard',
|
|
||||||
promise: done.promise
|
|
||||||
});
|
|
||||||
this.parseStarted.promise
|
|
||||||
.then(() => {
|
|
||||||
if (this.argv._.length === 0 && !this.argv.v) {
|
|
||||||
done.resolve(this.argv);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
done.reject(this.argv);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* start the process of evaluating commands
|
|
||||||
*/
|
|
||||||
startParse() {
|
|
||||||
this.argv = this.argv.argv;
|
|
||||||
this.parseStarted.resolve();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Smartcli = Smartcli;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21h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QUksR0FBRyxNQUFNLENBQUMsS0FBSyxFQUFPLENBQUE7UUFDOUIsSUFBSSxDQUFDLHFCQUFxQixDQUFDLEdBQUcsQ0FBQztZQUM3QixXQUFXLEVBQUUsVUFBVTtZQUN2QixPQUFPLEVBQUUsSUFBSSxDQUFDLE9BQU87U0FDdEIsQ0FBQyxDQUFBO1FBQ0YsSUFBSSxDQUFDLFlBQVksQ0FBQyxPQUFPO2FBQ3RCLElBQUksQ0FBQztZQUNKLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLE1BQU0sS0FBSyxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUM7Z0JBQzdDLElBQUksQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQyxDQUFBO1lBQ3pCLENBQUM7WUFBQyxJQUFJLENBQUMsQ0FBQztnQkFDTixJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQTtZQUN4QixDQUFDO1FBQ0gsQ0FBQyxDQUFDLENBQUE7UUFDSixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUNyQixDQUFDO0lBRUQ7O09BRUc7SUFDSCxVQUFVO1FBQ1IsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQTtRQUMxQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQzNCLE1BQU0sQ0FBQTtJQUNSLENBQUM7Q0FFRjtBQS9JRCw0QkErSUMifQ==
|
|
7
dist/smartcli.plugins.d.ts
vendored
7
dist/smartcli.plugins.d.ts
vendored
@ -1,7 +0,0 @@
|
|||||||
import 'typings-global';
|
|
||||||
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 };
|
|
14
dist/smartcli.plugins.js
vendored
14
dist/smartcli.plugins.js
vendored
@ -1,14 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
require("typings-global");
|
|
||||||
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFFdkIsK0JBQThCO0FBTzVCLHNCQUFLO0FBTlAsdUNBQXNDO0FBT3BDLDhCQUFTO0FBTlgsMkJBQTBCO0FBT3hCLGtCQUFHO0FBTkwsNkJBQTRCO0FBTzFCLG9CQUFJO0FBTk4seUNBQXdDO0FBT3RDLGdDQUFVIn0=
|
|
@ -1,13 +1,16 @@
|
|||||||
# smartcli
|
# smartcli
|
||||||
|
|
||||||
nodejs wrapper for CLI related tasks
|
nodejs wrapper for CLI related tasks
|
||||||
|
|
||||||
## Availabililty
|
## Availabililty
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/smartcli)
|
[](https://www.npmjs.com/package/smartcli)
|
||||||
[](https://GitLab.com/pushrocks/smartcli)
|
[](https://GitLab.com/pushrocks/smartcli)
|
||||||
[](https://github.com/pushrocks/smartcli)
|
[](https://github.com/pushrocks/smartcli)
|
||||||
[](https://pushrocks.gitlab.io/smartcli/)
|
[](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)
|
||||||
[](https://GitLab.com/pushrocks/smartcli/commits/master)
|
[](https://GitLab.com/pushrocks/smartcli/commits/master)
|
||||||
[](https://www.npmjs.com/package/smartcli)
|
[](https://www.npmjs.com/package/smartcli)
|
||||||
@ -20,49 +23,9 @@ 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)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[](https://push.rocks)
|
[](https://push.rocks)
|
||||||
|
17
npmextra.json
Normal file
17
npmextra.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"npmci": {
|
||||||
|
"npmGlobalTools": [],
|
||||||
|
"npmAccesslevel": "public"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "push.rocks",
|
||||||
|
"gitrepo": "smartcli",
|
||||||
|
"description": "easy observable cli tasks",
|
||||||
|
"npmPackagename": "@push.rocks/smartcli",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"mode":"default"
|
|
||||||
}
|
|
58
package.json
58
package.json
@ -1,16 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "smartcli",
|
"name": "@push.rocks/smartcli",
|
||||||
"version": "2.0.2",
|
"private": false,
|
||||||
"description": "nodejs wrapper for CLI related tasks",
|
"version": "4.0.7",
|
||||||
"main": "dist/index.js",
|
"description": "easy observable cli tasks",
|
||||||
"typings": "dist/index.d.ts",
|
"main": "dist_ts/index.js",
|
||||||
|
"typings": "dist_ts/index.d.ts",
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)",
|
"test": "(tstest test/ --web)",
|
||||||
"testm": "(cd ts/compile && gulp) && (node test.js jazz jam --awesome)",
|
"build": "(tsbuild --web)",
|
||||||
"devTest": "(npm test) && (node test.js --test true)",
|
"buildDocs": "tsdoc"
|
||||||
"reinstall": "(rm -r node_modules && npm install)",
|
|
||||||
"release": "(git pull origin master && npm version patch && git push origin master && git checkout release && git merge master && git push origin release && git checkout master)",
|
|
||||||
"startdev": "(git checkout master && git pull origin master)"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -29,16 +28,33 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/yargs": "6.x.x",
|
"@push.rocks/lik": "^6.0.3",
|
||||||
"beautylog": "^6.1.10",
|
"@push.rocks/smartlog": "^3.0.1",
|
||||||
"lik": "^1.0.30",
|
"@push.rocks/smartparam": "^1.1.10",
|
||||||
"rxjs": "^5.3.0",
|
"@push.rocks/smartpromise": "^4.0.3",
|
||||||
"smartparam": "0.1.1",
|
"@push.rocks/smartrx": "^3.0.3",
|
||||||
"smartq": "^1.1.1",
|
"yargs-parser": "21.1.1"
|
||||||
"typings-global": "^1.0.14",
|
|
||||||
"yargs": "^7.1.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tapbundle": "^1.0.5"
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
}
|
"@gitzone/tsrun": "^1.2.42",
|
||||||
|
"@gitzone/tstest": "^1.0.74",
|
||||||
|
"@push.rocks/tapbundle": "^5.0.4",
|
||||||
|
"@types/node": "^20.4.1"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_*/**/*",
|
||||||
|
"dist_ts/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
],
|
||||||
|
"browserslist": [
|
||||||
|
"last 1 chrome versions"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
4771
pnpm-lock.yaml
generated
Normal file
4771
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
74
readme.md
Normal file
74
readme.md
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# @push.rocks/smartcli
|
||||||
|
easy observable cli tasks
|
||||||
|
|
||||||
|
## Availabililty and Links
|
||||||
|
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartcli)
|
||||||
|
* [gitlab.com (source)](https://gitlab.com/push.rocks/smartcli)
|
||||||
|
* [github.com (source mirror)](https://github.com/push.rocks/smartcli)
|
||||||
|
* [docs (typedoc)](https://push.rocks.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)
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
68
test/test.ts
68
test/test.ts
@ -1,44 +1,42 @@
|
|||||||
import { tap, expect } from 'tapbundle'
|
import { tap, expect } from '@push.rocks/tapbundle';
|
||||||
|
import * as smartrx from '@push.rocks/smartrx';
|
||||||
|
|
||||||
import smartcli = require('../dist/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();
|
||||||
return expect(smartCliTestObject).be.instanceof(smartcli.Smartcli)
|
expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
|
||||||
tap.test('should add an command', async () => {
|
|
||||||
smartCliTestObject.addCommand('awesome')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
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 () => {
|
tap.test('should start parsing a standardTask', async () => {
|
||||||
smartCliTestObject.standardTask()
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
.then(() => {
|
expect(smartCliTestObject.standardCommand()).toBeInstanceOf(smartrx.rxjs.Subject);
|
||||||
console.log('this is the standard Task!')
|
});
|
||||||
})
|
|
||||||
})
|
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')
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
.subscribe(() => {
|
smartCliTestObject.addCommand('triggerme').subscribe(() => {
|
||||||
hasExecuted = true
|
hasExecuted = true;
|
||||||
})
|
});
|
||||||
})
|
smartCliTestObject.triggerCommand('triggerme', {});
|
||||||
tap.test('should not have executed yet', async () => {
|
expect(hasExecuted).toBeTrue();
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
|
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.7',
|
||||||
|
description: 'easy observable cli tasks'
|
||||||
|
}
|
@ -1 +1 @@
|
|||||||
export { Smartcli } from './smartcli.classes.smartcli'
|
export { Smartcli } from './smartcli.classes.smartcli.js';
|
||||||
|
@ -1,163 +1,160 @@
|
|||||||
import * as smartq from 'smartq'
|
import * as plugins from './smartcli.plugins.js';
|
||||||
import { Subject } from 'rxjs'
|
|
||||||
|
|
||||||
import * as plugins from './smartcli.plugins'
|
|
||||||
|
|
||||||
// import classes
|
|
||||||
import { Objectmap } from '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.
|
||||||
|
*/
|
||||||
export class Smartcli {
|
export class Smartcli {
|
||||||
argv: any
|
|
||||||
questionsDone
|
|
||||||
parseStarted
|
|
||||||
commands
|
|
||||||
questions
|
|
||||||
version: string
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* map of all Command/Promise objects to keep track
|
* this Deferred contains the parsed result in the end
|
||||||
*/
|
*/
|
||||||
allCommandPromisesMap = new Objectmap<ICommandPromiseObject>()
|
public parseCompleted = plugins.smartpromise.defer<any>();
|
||||||
|
|
||||||
|
public version: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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>();
|
||||||
|
|
||||||
constructor() {
|
/**
|
||||||
this.argv = plugins.yargs
|
* maps alias
|
||||||
this.questionsDone = smartq.defer()
|
*/
|
||||||
this.parseStarted = smartq.defer()
|
public aliasObject: { [key: string]: string[] } = {};
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* The constructor of Smartcli
|
||||||
|
*/
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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): Promise<any> {
|
public addCommand(commandNameArg: string): plugins.smartrx.rxjs.Subject<any> {
|
||||||
let done = smartq.defer<any>()
|
let commandSubject: plugins.smartrx.rxjs.Subject<any>;
|
||||||
this.allCommandPromisesMap.add({
|
const existingCommandSubject = this.getCommandSubject(commandNameArg);
|
||||||
|
commandSubject = existingCommandSubject || new plugins.smartrx.rxjs.Subject<any>();
|
||||||
|
|
||||||
|
this.commandObservableMap.add({
|
||||||
commandName: commandNameArg,
|
commandName: commandNameArg,
|
||||||
promise: done.promise
|
subject: commandSubject,
|
||||||
})
|
});
|
||||||
this.parseStarted.promise
|
return commandSubject;
|
||||||
.then(() => {
|
|
||||||
if (this.argv._.indexOf(commandNameArg) === 0) {
|
|
||||||
done.resolve(this.argv)
|
|
||||||
} else {
|
|
||||||
done.reject(this.argv)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets a Promise for a command word
|
|
||||||
*/
|
|
||||||
getCommandPromiseByName(commandNameArg: string): Promise<void> {
|
|
||||||
return this.allCommandPromisesMap.find(commandDeferredObjectArg => {
|
|
||||||
return commandDeferredObjectArg.commandName === commandNameArg
|
|
||||||
}).promise
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
|
||||||
*/
|
|
||||||
addTrigger(triggerNameArg: string) {
|
|
||||||
let triggerSubject = new Subject<any>()
|
|
||||||
this.allTriggerObservablesMap.add({
|
|
||||||
triggerName: triggerNameArg,
|
|
||||||
subject: triggerSubject
|
|
||||||
})
|
|
||||||
this.addCommand(triggerNameArg).then(() => {
|
|
||||||
triggerSubject.next(this.argv)
|
|
||||||
})
|
|
||||||
return triggerSubject
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute trigger by name
|
* execute trigger by name
|
||||||
* @param commandNameArg - the name of the command to trigger
|
* @param commandNameArg - the name of the command to trigger
|
||||||
*/
|
*/
|
||||||
trigger(triggerName: string) {
|
public triggerCommand(commandNameArg: string, argvObject: any) {
|
||||||
let triggerSubject = this.allTriggerObservablesMap.find(triggerObservableObjectArg => {
|
const triggerSubject = this.getCommandSubject(commandNameArg);
|
||||||
return triggerObservableObjectArg.triggerName === triggerName
|
triggerSubject.next(argvObject);
|
||||||
}).subject
|
return triggerSubject;
|
||||||
triggerSubject.next(this.argv)
|
}
|
||||||
return triggerSubject
|
|
||||||
|
public getCommandSubject(commandNameArg: string) {
|
||||||
|
const triggerObservableObject = this.commandObservableMap.findSync(
|
||||||
|
(triggerObservableObjectArg) => {
|
||||||
|
return triggerObservableObjectArg.commandName === commandNameArg;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (triggerObservableObject) {
|
||||||
|
return triggerObservableObject.subject;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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: {
|
public addHelp(optionsArg: { helpText: string }) {
|
||||||
helpText: string
|
this.addCommand('help').subscribe((argvArg) => {
|
||||||
}) {
|
logger.log('info', optionsArg.helpText);
|
||||||
this.addCommand('help').then(argvArg => {
|
});
|
||||||
plugins.beautylog.log(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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns promise that is resolved when no commands are specified
|
* adds a trigger that is called when no command is specified
|
||||||
*/
|
*/
|
||||||
standardTask(): Promise<any> {
|
public standardCommand(): plugins.smartrx.rxjs.Subject<any> {
|
||||||
let done = smartq.defer<any>()
|
const standardSubject = this.addCommand('standardCommand');
|
||||||
this.allCommandPromisesMap.add({
|
return standardSubject;
|
||||||
commandName: 'standard',
|
|
||||||
promise: done.promise
|
|
||||||
})
|
|
||||||
this.parseStarted.promise
|
|
||||||
.then(() => {
|
|
||||||
if (this.argv._.length === 0 && !this.argv.v) {
|
|
||||||
done.resolve(this.argv)
|
|
||||||
} else {
|
|
||||||
done.reject(this.argv)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start the process of evaluating commands
|
* start the process of evaluating commands
|
||||||
*/
|
*/
|
||||||
startParse(): void {
|
public startParse(): void {
|
||||||
this.argv = this.argv.argv
|
const parsedYArgs = plugins.yargsParser(process.argv);
|
||||||
this.parseStarted.resolve()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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,15 +1,14 @@
|
|||||||
import 'typings-global'
|
// @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 '@push.rocks/smartparam';
|
||||||
|
import * as smartpromise from '@push.rocks/smartpromise';
|
||||||
|
import * as smartrx from '@push.rocks/smartrx';
|
||||||
|
|
||||||
import * as yargs from 'yargs'
|
export { smartlog, lik, path, smartparam, smartpromise, smartrx };
|
||||||
import * as beautylog from 'beautylog'
|
|
||||||
import * as lik from 'lik'
|
|
||||||
import * as path from 'path'
|
|
||||||
import * as smartparam from 'smartparam'
|
|
||||||
|
|
||||||
export {
|
// thirdparty scope
|
||||||
yargs,
|
import yargsParser from 'yargs-parser';
|
||||||
beautylog,
|
|
||||||
lik,
|
export { yargsParser };
|
||||||
path,
|
|
||||||
smartparam
|
|
||||||
}
|
|
||||||
|
10
tsconfig.json
Normal file
10
tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "tslint-config-standard"
|
|
||||||
}
|
|
Reference in New Issue
Block a user