Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
5f027430bf | |||
d3385782ed | |||
7384b54e09 | |||
0eac72e15d | |||
b7957b0ab6 | |||
99a0a9ca81 | |||
bd66903419 | |||
740d8dac35 | |||
488e7410fe | |||
04deb8960c | |||
19f0a9563f | |||
db1e866fe1 |
@ -12,20 +12,12 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
@ -36,6 +28,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
@ -96,10 +89,9 @@ codequality:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -119,11 +111,10 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
1381
package-lock.json
generated
1381
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartcli",
|
"name": "@pushrocks/smartcli",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "4.0.0",
|
"version": "4.0.6",
|
||||||
"description": "easy observable cli tasks",
|
"description": "easy observable cli tasks",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
"typings": "dist_ts/index.d.ts",
|
"typings": "dist_ts/index.d.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -32,9 +33,7 @@
|
|||||||
"@pushrocks/smartparam": "^1.1.6",
|
"@pushrocks/smartparam": "^1.1.6",
|
||||||
"@pushrocks/smartpromise": "^3.1.3",
|
"@pushrocks/smartpromise": "^3.1.3",
|
||||||
"@pushrocks/smartrx": "^2.0.25",
|
"@pushrocks/smartrx": "^2.0.25",
|
||||||
"@types/yargs": "^17.0.10",
|
"yargs-parser": "21.0.1"
|
||||||
"@types/yargs-parser": "^21.0.0",
|
|
||||||
"yargs-parser": "^21.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.25",
|
||||||
|
33
test/test.ts
33
test/test.ts
@ -3,41 +3,40 @@ import { Subject } from 'rxjs';
|
|||||||
|
|
||||||
import * as smartcli from '../ts/index.js';
|
import * as smartcli from '../ts/index.js';
|
||||||
|
|
||||||
let smartCliTestObject: smartcli.Smartcli;
|
|
||||||
|
|
||||||
tap.test('should create a new Smartcli', async () => {
|
tap.test('should create a new Smartcli', async () => {
|
||||||
smartCliTestObject = new smartcli.Smartcli();
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
|
expect(smartCliTestObject).toBeInstanceOf(smartcli.Smartcli);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should add an command', async () => {
|
tap.test('should add an command', async (toolsArg) => {
|
||||||
expect(smartCliTestObject.addCommand('awesome')).toBeInstanceOf(Subject);
|
const done = toolsArg.defer();
|
||||||
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
|
const awesomeCommandSubject = smartCliTestObject.addCommand('awesome')
|
||||||
|
expect(awesomeCommandSubject).toBeInstanceOf(Subject);
|
||||||
|
awesomeCommandSubject.subscribe(() => {
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
console.log(process.argv);
|
||||||
|
process.argv.splice(2, 0, 'awesome');
|
||||||
|
console.log(process.argv);
|
||||||
|
smartCliTestObject.startParse();
|
||||||
|
await done.promise;
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start parsing a standardTask', async () => {
|
tap.test('should start parsing a standardTask', async () => {
|
||||||
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
expect(smartCliTestObject.standardCommand()).toBeInstanceOf(Subject);
|
expect(smartCliTestObject.standardCommand()).toBeInstanceOf(Subject);
|
||||||
});
|
});
|
||||||
|
|
||||||
let hasExecuted: boolean = false;
|
let hasExecuted: boolean = false;
|
||||||
|
|
||||||
tap.test('should accept a command', async () => {
|
tap.test('should accept a command', async () => {
|
||||||
|
const smartCliTestObject = new smartcli.Smartcli();
|
||||||
smartCliTestObject.addCommand('triggerme').subscribe(() => {
|
smartCliTestObject.addCommand('triggerme').subscribe(() => {
|
||||||
hasExecuted = true;
|
hasExecuted = true;
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should not have executed yet', async () => {
|
|
||||||
expect(hasExecuted).toBeFalse();
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.test('should execute when triggered', async () => {
|
|
||||||
smartCliTestObject.triggerCommand('triggerme', {});
|
smartCliTestObject.triggerCommand('triggerme', {});
|
||||||
expect(hasExecuted).toBeTrue();
|
expect(hasExecuted).toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start parsing the CLI input', async () => {
|
|
||||||
smartCliTestObject.startParse();
|
|
||||||
expect(smartCliTestObject.parseCompleted.promise).toBeInstanceOf(Promise);
|
|
||||||
});
|
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartcli',
|
name: '@pushrocks/smartcli',
|
||||||
version: '4.0.0',
|
version: '4.0.6',
|
||||||
description: 'easy observable cli tasks'
|
description: 'easy observable cli tasks'
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,7 @@ export class Smartcli {
|
|||||||
*/
|
*/
|
||||||
public parseCompleted = plugins.smartpromise.defer<any>();
|
public parseCompleted = plugins.smartpromise.defer<any>();
|
||||||
|
|
||||||
|
|
||||||
public version: string;
|
public version: string;
|
||||||
private checkForEnvCliCall = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* map of all Trigger/Observable objects to keep track
|
* map of all Trigger/Observable objects to keep track
|
||||||
@ -29,24 +27,17 @@ export class Smartcli {
|
|||||||
/**
|
/**
|
||||||
* maps alias
|
* maps alias
|
||||||
*/
|
*/
|
||||||
public aliasObject: {[key: string]: string[]} = {};
|
public aliasObject: { [key: string]: string[] } = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor of Smartcli
|
* The constructor of Smartcli
|
||||||
*/
|
*/
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
/**
|
|
||||||
* halts any execution of commands if (process.env.CLI_CALL === false)
|
|
||||||
*/
|
|
||||||
disableEnvCliCall() {
|
|
||||||
this.checkForEnvCliCall = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* adds an alias, meaning one equals the other in terms of command execution.
|
* adds an alias, meaning one equals the other in terms of command execution.
|
||||||
*/
|
*/
|
||||||
public addCommandAlias(originalArg, aliasArg): void {
|
public addCommandAlias(originalArg: string, aliasArg: string): void {
|
||||||
this.aliasObject[originalArg] = this.aliasObject[originalArg] || [];
|
this.aliasObject[originalArg] = this.aliasObject[originalArg] || [];
|
||||||
this.aliasObject[originalArg].push(aliasArg);
|
this.aliasObject[originalArg].push(aliasArg);
|
||||||
}
|
}
|
||||||
@ -58,12 +49,12 @@ export class Smartcli {
|
|||||||
public addCommand(commandNameArg: string): plugins.smartrx.rxjs.Subject<any> {
|
public addCommand(commandNameArg: string): plugins.smartrx.rxjs.Subject<any> {
|
||||||
let commandSubject: plugins.smartrx.rxjs.Subject<any>;
|
let commandSubject: plugins.smartrx.rxjs.Subject<any>;
|
||||||
const existingCommandSubject = this.getCommandSubject(commandNameArg);
|
const existingCommandSubject = this.getCommandSubject(commandNameArg);
|
||||||
commandSubject = existingCommandSubject || new plugins.smartrx.rxjs.Subject<any>();
|
commandSubject = existingCommandSubject || new plugins.smartrx.rxjs.Subject<any>();
|
||||||
|
|
||||||
this.commandObservableMap.add({
|
this.commandObservableMap.add({
|
||||||
commandName: commandNameArg,
|
commandName: commandNameArg,
|
||||||
subject: commandSubject,
|
subject: commandSubject,
|
||||||
})
|
});
|
||||||
return commandSubject;
|
return commandSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,12 +95,6 @@ export class Smartcli {
|
|||||||
*/
|
*/
|
||||||
public addVersion(versionArg: string) {
|
public addVersion(versionArg: string) {
|
||||||
this.version = versionArg;
|
this.version = versionArg;
|
||||||
this.addCommandAlias('v', 'version');
|
|
||||||
this.parseCompleted.promise.then(argv => {
|
|
||||||
if (argv.v) {
|
|
||||||
console.log(this.version);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,20 +109,13 @@ export class Smartcli {
|
|||||||
* start the process of evaluating commands
|
* start the process of evaluating commands
|
||||||
*/
|
*/
|
||||||
public startParse(): void {
|
public startParse(): void {
|
||||||
// if we check for cli env calls, we might want to abort here.
|
|
||||||
if (!process.env.CLI_CALL && this.checkForEnvCliCall) {
|
|
||||||
console.log(
|
|
||||||
`note: @pushrocks/smartcli: You called .startParse() on a SmartCli instance. However process.env.CLI_CALL being absent prevented parsing.`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const parsedYArgs = plugins.yargsParser(process.argv);
|
const parsedYArgs = plugins.yargsParser(process.argv);
|
||||||
|
|
||||||
// lets handle commands
|
// lets handle commands
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
let foundCommand = false;
|
let foundCommand = false;
|
||||||
parsedYArgs._.map((commandPartArg) => {
|
parsedYArgs._ = parsedYArgs._.filter((commandPartArg) => {
|
||||||
counter ++;
|
counter++;
|
||||||
if (typeof commandPartArg === 'number') {
|
if (typeof commandPartArg === 'number') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -148,17 +126,25 @@ export class Smartcli {
|
|||||||
} else {
|
} else {
|
||||||
return true;
|
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()) {
|
for (const command of this.commandObservableMap.getArray()) {
|
||||||
if (!parsedYArgs._[0]) {
|
if (!wantedCommand) {
|
||||||
const standardCommand = this.commandObservableMap.findSync(commandArg => {
|
const standardCommand = this.commandObservableMap.findSync((commandArg) => {
|
||||||
return commandArg.commandName === "standardCommand";
|
return commandArg.commandName === 'standardCommand';
|
||||||
});
|
});
|
||||||
if (standardCommand) {
|
if (standardCommand) {
|
||||||
standardCommand.subject.next(parsedYArgs);
|
standardCommand.subject.next(parsedYArgs);
|
||||||
} else {
|
} else {
|
||||||
console.log('no smartcli standard task was created or assigned.');
|
console.log('no smartcli standard task was created or assigned.');
|
||||||
};
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (command.commandName === parsedYArgs._[0]) {
|
if (command.commandName === parsedYArgs._[0]) {
|
||||||
@ -166,7 +152,6 @@ export class Smartcli {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this.aliasObject[parsedYArgs[0]]) {
|
if (this.aliasObject[parsedYArgs[0]]) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.parseCompleted.resolve(parsedYArgs);
|
this.parseCompleted.resolve(parsedYArgs);
|
||||||
|
@ -11,6 +11,4 @@ export { smartlog, lik, path, smartparam, smartpromise, smartrx };
|
|||||||
// thirdparty scope
|
// thirdparty scope
|
||||||
import yargsParser from 'yargs-parser';
|
import yargsParser from 'yargs-parser';
|
||||||
|
|
||||||
export {
|
export { yargsParser };
|
||||||
yargsParser
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user