Compare commits
40 Commits
Author | SHA1 | Date | |
---|---|---|---|
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 |
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,4 +1,22 @@
|
|||||||
node_modules/
|
.nogit/
|
||||||
|
|
||||||
|
# artifacts
|
||||||
coverage/
|
coverage/
|
||||||
public/
|
public/
|
||||||
|
pages/
|
||||||
|
|
||||||
|
# installs
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# caches
|
||||||
.yarn/
|
.yarn/
|
||||||
|
.cache/
|
||||||
|
.rpt2_cache
|
||||||
|
|
||||||
|
# builds
|
||||||
|
dist/
|
||||||
|
dist_web/
|
||||||
|
dist_serve/
|
||||||
|
dist_ts_web/
|
||||||
|
|
||||||
|
# custom
|
105
.gitlab-ci.yml
105
.gitlab-ci.yml
@ -1,71 +1,126 @@
|
|||||||
# gitzone standard
|
# gitzone ci_default
|
||||||
image: hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
paths:
|
paths:
|
||||||
- .yarn/
|
- .npmci_cache/
|
||||||
key: "$CI_BUILD_STAGE"
|
key: '$CI_BUILD_STAGE'
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- security
|
||||||
- release
|
- test
|
||||||
- trigger
|
- release
|
||||||
- pages
|
- metadata
|
||||||
|
|
||||||
testLEGACY:
|
# ====================
|
||||||
stage: test
|
# security stage
|
||||||
|
# ====================
|
||||||
|
mirror:
|
||||||
|
stage: security
|
||||||
script:
|
script:
|
||||||
- npmci test legacy
|
- npmci git mirror
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
allow_failure: true
|
- notpriv
|
||||||
|
|
||||||
testLTS:
|
snyk:
|
||||||
|
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||||
|
stage: security
|
||||||
|
script:
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci command npm install --ignore-scripts
|
||||||
|
- npmci command snyk test
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
|
|
||||||
|
testStable:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test lts
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci npm test
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
- priv
|
||||||
testSTABLE:
|
|
||||||
|
testBuild:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- npmci test stable
|
- npmci npm prepare
|
||||||
|
- npmci node install stable
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command npm run build
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
coverage: /\d+.?\d+?\%\s*coverage/
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
release:
|
release:
|
||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci publish
|
- npmci node install stable
|
||||||
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# metadata stage
|
||||||
|
# ====================
|
||||||
|
codequality:
|
||||||
|
stage: metadata
|
||||||
|
allow_failure: true
|
||||||
|
script:
|
||||||
|
- npmci command npm install -g tslint typescript
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||||
|
tags:
|
||||||
|
- lossless
|
||||||
|
- docker
|
||||||
|
- priv
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
stage: trigger
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci trigger
|
- npmci trigger
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
|
|
||||||
pages:
|
pages:
|
||||||
image: hosttoday/ht-docker-node:npmci
|
stage: metadata
|
||||||
stage: pages
|
|
||||||
script:
|
script:
|
||||||
- npmci command yarn global add npmpage
|
- npmci node install lts
|
||||||
- npmci command npmpage
|
- npmci command npm install -g @gitzone/tsdoc
|
||||||
|
- npmci npm prepare
|
||||||
|
- npmci npm install
|
||||||
|
- npmci command tsdoc
|
||||||
tags:
|
tags:
|
||||||
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
- notpriv
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
allow_failure: true
|
||||||
|
9
.snyk
Normal file
9
.snyk
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||||
|
version: v1.12.0
|
||||||
|
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
|
||||||
|
ignore:
|
||||||
|
'npm:mem:20180117':
|
||||||
|
- yargs > os-locale > mem:
|
||||||
|
reason: None given
|
||||||
|
expires: '2018-09-29T22:12:38.004Z'
|
||||||
|
patch: {}
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "current file",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"${relativeFile}"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "test.ts",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [
|
||||||
|
"test/test.ts"
|
||||||
|
],
|
||||||
|
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
|
"protocol": "inspector",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"json.schemas": [
|
||||||
|
{
|
||||||
|
"fileMatch": ["/npmextra.json"],
|
||||||
|
"schema": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"npmci": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for npmci"
|
||||||
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "settings for gitzone",
|
||||||
|
"properties": {
|
||||||
|
"projectType": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["website", "element", "service", "npm"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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==
|
|
68
dist/smartcli.classes.smartcli.d.ts
vendored
68
dist/smartcli.classes.smartcli.d.ts
vendored
@ -1,68 +0,0 @@
|
|||||||
import * as smartq from 'smartq';
|
|
||||||
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: smartq.Deferred<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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjbGkuY2xhc3Nlcy5zbWFydGNsaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y2xpLmNsYXNzZXMuc21hcnRjbGkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxpQ0FBZ0M7QUFDaEMsK0JBQThCO0FBRTlCLDhDQUE2QztBQUU3QyxpQkFBaUI7QUFDakIsNkJBQStCO0FBYS9CO0lBa0JFO1FBVkE7O1dBRUc7UUFDSCwwQkFBcUIsR0FBRyxJQUFJLGVBQVMsRUFBeUIsQ0FBQTtRQUU5RDs7V0FFRztRQUNILDZCQUF3QixHQUFHLElBQUksZUFBUyxFQUE0QixDQUFBO1FBR2xFLElBQUksQ0FBQyxJQUFJLEdBQUcsT0FBTyxDQUFDLEtBQUssQ0FBQTtRQUN6QixJQUFJLENBQUMsYUFBYSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQUUsQ0FBQTtRQUNuQyxJQUFJLENBQUMsWUFBWSxHQUFHLE1BQU0sQ0FBQyxLQUFLLEVBQUUsQ0FBQTtJQUNwQyxDQUFDO0lBRUQ7O09BRUc7SUFDSCxlQUFlLENBQUMsTUFBTSxFQUFFLFFBQVE7UUFDOUIsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxNQUFNLEVBQUUsUUFBUSxDQUFDLENBQUE7UUFDN0MsTUFBTSxDQUFBO0lBQ1IsQ0FBQztJQUVEOzs7T0FHRztJQUNILFVBQVUs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SxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsSUFBSSxDQUFDLElBQUksQ0FBQTtRQUMxQixJQUFJLENBQUMsWUFBWSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQzNCLE1BQU0sQ0FBQTtJQUNSLENBQUM7Q0FFRjtBQS9JRCw0QkErSUMifQ==
|
|
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)
|
||||||
@ -28,41 +31,40 @@ take the following commandline input:
|
|||||||
mytool command argument1 argument2 --option1 -o2 option2Value
|
mytool command argument1 argument2 --option1 -o2 option2Value
|
||||||
```
|
```
|
||||||
|
|
||||||
* `mytool` obviously is the tool (like git)
|
- `mytool` obviously is the tool (like git)
|
||||||
* `command` is the main thing the tool shall do (like commit)
|
- `command` is the main thing the tool shall do (like commit)
|
||||||
* `argument1` and `argument2` are arguments
|
- `argument1` and `argument2` are arguments
|
||||||
* `option1` is a longform option you can add (like --message for message)
|
- `option1` is a longform option you can add (like --message for message)
|
||||||
* `optionValue` is the referenced option value (like a commit 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 no command and no option specified the standardTask applied.
|
||||||
When there is a option specified but no command, standardTask applies,
|
When there is a option specified but no command, standardTask applies,
|
||||||
except when of the options is -v, --version or --help.
|
except when of the options is -v, --version or --help.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import {Smartcli} from "smartcli"
|
import { Smartcli } from 'smartcli';
|
||||||
mySmartcli = new Smartcli();
|
mySmartcli = new Smartcli();
|
||||||
mySmartcli.standardTask()
|
mySmartcli.standardTask().then(argvArg => {
|
||||||
.then(argvArg => {
|
// do something if program is called without an command
|
||||||
// do something if program is called without an command
|
});
|
||||||
});
|
|
||||||
|
|
||||||
mySmartcli.addCommand({commandname: 'install'})
|
mySmartcli.addCommand({ commandname: 'install' }).then(argvArg => {
|
||||||
.then(argvArg => {
|
// do something if program is called with command "install"
|
||||||
// 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.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
|
mySmartCli.addHelp({
|
||||||
|
// is triggered by help command and --help option
|
||||||
helpText: 'some help text to print' // the helpText to display
|
helpText: 'some help text to print' // the helpText to display
|
||||||
})
|
});
|
||||||
|
|
||||||
mySmartcli.startParse() // starts the evaluation and fullfills or rejects promises.
|
mySmartcli.startParse(); // starts the evaluation and fullfills or rejects promises.
|
||||||
```
|
```
|
||||||
|
|
||||||
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)
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
{
|
{
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"globalNpmTools": [
|
"npmGlobalTools": [],
|
||||||
"npmts"
|
"npmAccesslevel": "public"
|
||||||
]
|
},
|
||||||
|
"gitzone": {
|
||||||
|
"projectType": "npm",
|
||||||
|
"module": {
|
||||||
|
"githost": "gitlab.com",
|
||||||
|
"gitscope": "pushrocks",
|
||||||
|
"gitrepo": "smartcli",
|
||||||
|
"shortDescription": "easy observable cli tasks",
|
||||||
|
"npmPackagename": "@pushrocks/smartcli",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"mode":"default"
|
|
||||||
}
|
|
1825
package-lock.json
generated
Normal file
1825
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
package.json
49
package.json
@ -1,16 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "smartcli",
|
"name": "@pushrocks/smartcli",
|
||||||
"version": "2.0.5",
|
"private": false,
|
||||||
|
"version": "3.0.8",
|
||||||
"description": "nodejs wrapper for CLI related tasks",
|
"description": "nodejs wrapper for CLI related tasks",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(npmts)",
|
"test": "(tstest test/)",
|
||||||
"testm": "(cd ts/compile && gulp) && (node test.js jazz jam --awesome)",
|
"build": "(tsbuild)"
|
||||||
"devTest": "(npm test) && (node test.js --test true)",
|
|
||||||
"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 +26,32 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
"homepage": "https://gitlab.com/pushrocks/smartcli",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/yargs": "6.x.x",
|
"@pushrocks/lik": "^3.0.19",
|
||||||
"beautylog": "^6.1.10",
|
"@pushrocks/smartlog": "^2.0.21",
|
||||||
"lik": "^1.0.30",
|
"@pushrocks/smartparam": "^1.1.6",
|
||||||
"rxjs": "^5.3.0",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"smartparam": "0.1.1",
|
"@types/yargs": "^15.0.4",
|
||||||
"smartq": "^1.1.1",
|
"rxjs": "^6.5.4",
|
||||||
"typings-global": "^1.0.16",
|
"yargs": "^15.3.0"
|
||||||
"yargs": "^7.1.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tapbundle": "^1.0.5"
|
"@gitzone/tsbuild": "^2.1.20",
|
||||||
}
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
|
"@gitzone/tstest": "^1.0.28",
|
||||||
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
|
"@types/node": "^13.9.0",
|
||||||
|
"tslint": "^6.1.0",
|
||||||
|
"tslint-config-prettier": "^1.18.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"ts/**/*",
|
||||||
|
"ts_web/**/*",
|
||||||
|
"dist/**/*",
|
||||||
|
"dist_web/**/*",
|
||||||
|
"dist_ts_web/**/*",
|
||||||
|
"assets/**/*",
|
||||||
|
"cli.js",
|
||||||
|
"npmextra.json",
|
||||||
|
"readme.md"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
55
test/test.ts
55
test/test.ts
@ -1,44 +1,43 @@
|
|||||||
import { tap, expect } from 'tapbundle'
|
import { tap, expect } from '@pushrocks/tapbundle';
|
||||||
import { Subject } from 'rxjs'
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
import smartcli = require('../dist/index')
|
import smartcli = require('../ts/index');
|
||||||
|
|
||||||
let smartCliTestObject: smartcli.Smartcli
|
let smartCliTestObject: smartcli.Smartcli;
|
||||||
|
|
||||||
tap.test('should create a new Smartcli', async () => {
|
tap.test('should create a new Smartcli', async () => {
|
||||||
smartCliTestObject = new smartcli.Smartcli()
|
smartCliTestObject = new smartcli.Smartcli();
|
||||||
return expect(smartCliTestObject).be.instanceof(smartcli.Smartcli)
|
expect(smartCliTestObject).to.be.instanceof(smartcli.Smartcli);
|
||||||
}).catch(tap.threw)
|
});
|
||||||
|
|
||||||
tap.test('should add an command', async () => {
|
tap.test('should add an command', async () => {
|
||||||
return expect(smartCliTestObject.addCommand('awesome')).to.not.throw
|
expect(smartCliTestObject.addCommand('awesome')).to.be.instanceOf(Subject);
|
||||||
}).catch(tap.threw)
|
});
|
||||||
|
|
||||||
|
|
||||||
tap.test('should start parsing a standardTask', async () => {
|
tap.test('should start parsing a standardTask', async () => {
|
||||||
return expect(smartCliTestObject.standardTask()).to.be.instanceOf(Promise)
|
expect(smartCliTestObject.standardTask()).to.be.instanceOf(Subject);
|
||||||
}).catch(tap.threw)
|
});
|
||||||
|
|
||||||
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')
|
smartCliTestObject.addTrigger('triggerme').subscribe(() => {
|
||||||
.subscribe(() => {
|
hasExecuted = true;
|
||||||
hasExecuted = true
|
});
|
||||||
})
|
});
|
||||||
return expect(smartCliTestObject.addTrigger('triggerme')).to.be.instanceof(Subject)
|
|
||||||
}).catch(tap.threw)
|
|
||||||
|
|
||||||
tap.test('should not have executed yet', async () => {
|
tap.test('should not have executed yet', async () => {
|
||||||
return expect(hasExecuted).to.be.false
|
expect(hasExecuted).to.be.false;
|
||||||
}).catch(tap.threw)
|
});
|
||||||
|
|
||||||
tap.test('should execute when triggered', async () => {
|
tap.test('should execute when triggered', async () => {
|
||||||
smartCliTestObject.trigger('triggerme')
|
smartCliTestObject.trigger('triggerme');
|
||||||
return expect(hasExecuted).be.true
|
expect(hasExecuted).be.true;
|
||||||
}).catch(tap.threw)
|
});
|
||||||
|
|
||||||
/*tap.test('should start parsing the CLI input', async () => {
|
tap.test('should start parsing the CLI input', async () => {
|
||||||
smartCliTestObject.startParse()
|
smartCliTestObject.startParse();
|
||||||
return await expect(smartCliTestObject.parseStarted.promise).to.eventually.be.fulfilled
|
expect(smartCliTestObject.parseStarted.promise).to.be.instanceOf(Promise);
|
||||||
}).catch(tap.threw)*/
|
});
|
||||||
|
|
||||||
|
tap.start();
|
||||||
|
@ -1 +1 @@
|
|||||||
export { Smartcli } from './smartcli.classes.smartcli'
|
export { Smartcli } from './smartcli.classes.smartcli';
|
||||||
|
@ -1,97 +1,91 @@
|
|||||||
import * as smartq from 'smartq'
|
import * as smartpromise from '@pushrocks/smartpromise';
|
||||||
import { Subject } from 'rxjs'
|
import { Subject } from 'rxjs';
|
||||||
|
|
||||||
import * as plugins from './smartcli.plugins'
|
import * as plugins from './smartcli.plugins';
|
||||||
|
|
||||||
// import classes
|
// import classes
|
||||||
import { Objectmap } from 'lik'
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
export interface ICommandPromiseObject {
|
export interface ICommandPromiseObject {
|
||||||
commandName: string,
|
commandName: string;
|
||||||
promise: Promise<void>
|
promise: Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ITriggerObservableObject {
|
export interface ITriggerObservableObject {
|
||||||
triggerName: string
|
triggerName: string;
|
||||||
subject: Subject<any>
|
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
|
argv: any;
|
||||||
questionsDone
|
questionsDone;
|
||||||
parseStarted: smartq.Deferred<any>
|
parseStarted: smartpromise.Deferred<any>;
|
||||||
commands
|
commands;
|
||||||
questions
|
questions;
|
||||||
version: string
|
version: string;
|
||||||
|
private onlyOnProcessEnvCliCall = false;
|
||||||
/**
|
|
||||||
* map of all Command/Promise objects to keep track
|
|
||||||
*/
|
|
||||||
allCommandPromisesMap = new Objectmap<ICommandPromiseObject>()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* map of all Trigger/Observable objects to keep track
|
* map of all Trigger/Observable objects to keep track
|
||||||
*/
|
*/
|
||||||
allTriggerObservablesMap = new Objectmap<ITriggerObservableObject>()
|
allTriggerObservablesMap = new Objectmap<ITriggerObservableObject>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor of Smartcli
|
||||||
|
*/
|
||||||
constructor() {
|
constructor() {
|
||||||
this.argv = plugins.yargs
|
this.argv = plugins.yargs;
|
||||||
this.questionsDone = smartq.defer()
|
this.questionsDone = smartpromise.defer();
|
||||||
this.parseStarted = smartq.defer()
|
this.parseStarted = smartpromise.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.
|
* adds an alias, meaning one equals the other in terms of command execution.
|
||||||
*/
|
*/
|
||||||
addCommandAlias(keyArg, aliasArg): void {
|
addCommandAlias(keyArg, aliasArg): void {
|
||||||
this.argv = this.argv.alias(keyArg, aliasArg)
|
this.argv = this.argv.alias(keyArg, aliasArg);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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> {
|
addCommand(commandNameArg: string): Subject<any> {
|
||||||
let done = smartq.defer<any>()
|
let triggerSubject = this.addTrigger(commandNameArg);
|
||||||
this.allCommandPromisesMap.add({
|
this.parseStarted.promise.then(() => {
|
||||||
commandName: commandNameArg,
|
if (this.argv._.indexOf(commandNameArg) === 0) {
|
||||||
promise: done.promise
|
this.trigger(commandNameArg);
|
||||||
})
|
}
|
||||||
this.parseStarted.promise
|
});
|
||||||
.then(() => {
|
return triggerSubject;
|
||||||
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
|
* adds a Trigger. Like addCommand(), but returns an subscribable observable
|
||||||
*/
|
|
||||||
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) {
|
addTrigger(triggerNameArg: string) {
|
||||||
let triggerSubject = new Subject<any>()
|
let triggerSubject = new Subject<any>();
|
||||||
this.allTriggerObservablesMap.add({
|
if (!this.getTriggerSubject(triggerNameArg)) {
|
||||||
triggerName: triggerNameArg,
|
this.allTriggerObservablesMap.add({
|
||||||
subject: triggerSubject
|
triggerName: triggerNameArg,
|
||||||
})
|
subject: triggerSubject
|
||||||
this.addCommand(triggerNameArg).then(() => {
|
});
|
||||||
triggerSubject.next(this.argv)
|
} else {
|
||||||
})
|
throw new Error(`you can't add a trigger twice`);
|
||||||
return triggerSubject
|
}
|
||||||
|
return triggerSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -99,65 +93,73 @@ export class Smartcli {
|
|||||||
* @param commandNameArg - the name of the command to trigger
|
* @param commandNameArg - the name of the command to trigger
|
||||||
*/
|
*/
|
||||||
trigger(triggerName: string) {
|
trigger(triggerName: string) {
|
||||||
let triggerSubject = this.allTriggerObservablesMap.find(triggerObservableObjectArg => {
|
let triggerSubject = this.getTriggerSubject(triggerName);
|
||||||
return triggerObservableObjectArg.triggerName === triggerName
|
triggerSubject.next(this.argv);
|
||||||
}).subject
|
return triggerSubject;
|
||||||
triggerSubject.next(this.argv)
|
}
|
||||||
return triggerSubject
|
|
||||||
|
getTriggerSubject(triggerName: string) {
|
||||||
|
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
|
* allows to specify help text to be printed above the rest of the help text
|
||||||
*/
|
*/
|
||||||
addHelp(optionsArg: {
|
addHelp(optionsArg: { helpText: string }) {
|
||||||
helpText: string
|
this.addCommand('help').subscribe(argvArg => {
|
||||||
}) {
|
plugins.smartlog.defaultLogger.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) {
|
addVersion(versionArg: string) {
|
||||||
this.version = versionArg
|
this.version = versionArg;
|
||||||
this.addCommandAlias('v', 'version')
|
this.addCommandAlias('v', 'version');
|
||||||
this.parseStarted.promise
|
this.parseStarted.promise.then(() => {
|
||||||
.then(() => {
|
if (this.argv.v) {
|
||||||
if (this.argv.v) {
|
console.log(this.version);
|
||||||
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> {
|
standardTask(): Subject<any> {
|
||||||
let done = smartq.defer<any>()
|
let standardSubject = this.addTrigger('standardTask');
|
||||||
this.allCommandPromisesMap.add({
|
this.parseStarted.promise.then(() => {
|
||||||
commandName: 'standard',
|
if (this.argv._.length === 0 && !this.argv.v) {
|
||||||
promise: done.promise
|
if (this.onlyOnProcessEnvCliCall) {
|
||||||
})
|
if (process.env.CLI_CALL === 'true') {
|
||||||
this.parseStarted.promise
|
this.trigger('standardTask');
|
||||||
.then(() => {
|
} else {
|
||||||
if (this.argv._.length === 0 && !this.argv.v) {
|
return;
|
||||||
done.resolve(this.argv)
|
}
|
||||||
} else {
|
} else {
|
||||||
done.reject(this.argv)
|
this.trigger('standardTask');
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
return done.promise
|
});
|
||||||
|
return standardSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start the process of evaluating commands
|
* start the process of evaluating commands
|
||||||
*/
|
*/
|
||||||
startParse(): void {
|
startParse(): void {
|
||||||
this.argv = this.argv.argv
|
this.argv = this.argv.argv;
|
||||||
this.parseStarted.resolve()
|
this.parseStarted.resolve();
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,7 @@
|
|||||||
import 'typings-global'
|
import * as yargs from 'yargs';
|
||||||
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
|
import * as lik from '@pushrocks/lik';
|
||||||
|
import * as path from 'path';
|
||||||
|
import * as smartparam from '@pushrocks/smartparam';
|
||||||
|
|
||||||
import * as yargs from 'yargs'
|
export { yargs, smartlog, lik, path, smartparam };
|
||||||
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
|
|
||||||
}
|
|
||||||
|
16
tslint.json
16
tslint.json
@ -1,3 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "tslint-config-standard"
|
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||||
|
"rules": {
|
||||||
|
"semicolon": [true, "always"],
|
||||||
|
"no-console": false,
|
||||||
|
"ordered-imports": false,
|
||||||
|
"object-literal-sort-keys": false,
|
||||||
|
"member-ordering": {
|
||||||
|
"options":{
|
||||||
|
"order": [
|
||||||
|
"static-method"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultSeverity": "warning"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user