Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
067f1a9c17 | |||
e7cf3bcb5e | |||
18cfa3e16a | |||
ea921766dc | |||
7e6d632afb | |||
25c61d7d7d |
@ -8,10 +8,10 @@
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartshell",
|
||||
"description": "shell actions designed as promises",
|
||||
"npmPackagename": "@pushrocks/smartshell",
|
||||
"npmPackagename": "@push.rocks/smartshell",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
|
24
package.json
24
package.json
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@pushrocks/smartshell",
|
||||
"name": "@push.rocks/smartshell",
|
||||
"private": false,
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.4",
|
||||
"description": "shell actions designed as promises",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
@ -26,19 +26,19 @@
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartshell#README",
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.66",
|
||||
"@gitzone/tsrun": "^1.2.42",
|
||||
"@gitzone/tstest": "^1.0.74",
|
||||
"@pushrocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.3.1"
|
||||
"@git.zone/tsbuild": "^2.1.66",
|
||||
"@git.zone/tsrun": "^1.2.44",
|
||||
"@git.zone/tstest": "^1.0.77",
|
||||
"@push.rocks/tapbundle": "^5.0.8",
|
||||
"@types/node": "^20.11.28"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartdelay": "^3.0.1",
|
||||
"@pushrocks/smartexit": "^1.0.20",
|
||||
"@pushrocks/smartpromise": "^4.0.2",
|
||||
"@types/which": "^3.0.0",
|
||||
"@push.rocks/smartdelay": "^3.0.1",
|
||||
"@push.rocks/smartexit": "^1.0.20",
|
||||
"@push.rocks/smartpromise": "^4.0.2",
|
||||
"@types/which": "^3.0.3",
|
||||
"tree-kill": "^1.2.2",
|
||||
"which": "^3.0.1"
|
||||
"which": "^4.0.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
2519
pnpm-lock.yaml
generated
2519
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
12
readme.md
12
readme.md
@ -1,8 +1,8 @@
|
||||
# @pushrocks/smartshell
|
||||
# @push.rocks/smartshell
|
||||
shell actions designed as promises
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartshell)
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartshell)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartshell)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartshell)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartshell/)
|
||||
@ -13,14 +13,14 @@ Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](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)
|
||||
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
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
|
||||
import * as smartshell from '../ts/index.js';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
|
||||
let testSmartshell: smartshell.Smartshell;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartshell',
|
||||
version: '3.0.1',
|
||||
name: '@push.rocks/smartshell',
|
||||
version: '3.0.4',
|
||||
description: 'shell actions designed as promises'
|
||||
}
|
||||
|
@ -30,44 +30,45 @@ export class Smartshell {
|
||||
* executes a given command async
|
||||
*/
|
||||
private async _exec(options: {
|
||||
commandString: string,
|
||||
silent?: boolean,
|
||||
strict?: boolean,
|
||||
streaming?: boolean,
|
||||
interactive?: boolean
|
||||
commandString: string;
|
||||
silent?: boolean;
|
||||
strict?: boolean;
|
||||
streaming?: boolean;
|
||||
interactive?: boolean;
|
||||
}): Promise<IExecResult | IExecResultStreaming | void> {
|
||||
|
||||
if (options.interactive) {
|
||||
if (process.env.CI) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const done = plugins.smartpromise.defer();
|
||||
const shell = cp.spawn('sh', [], { stdio: ['pipe', 'inherit', 'inherit'] });
|
||||
this.smartexit.addProcess(shell);
|
||||
|
||||
shell.on('close', (code) => {
|
||||
console.log(`interactive shell terminated with code ${code}`);
|
||||
this.smartexit.removeProcess(shell);
|
||||
done.resolve();
|
||||
|
||||
// Notice that stdio is set to 'inherit'
|
||||
const shell = cp.spawn(options.commandString, {
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
detached: true
|
||||
});
|
||||
|
||||
let commandString = options.commandString;
|
||||
|
||||
shell.stdin.write(commandString + '\n exit \n');
|
||||
|
||||
|
||||
this.smartexit.addProcess(shell);
|
||||
|
||||
shell.on('close', (code) => {
|
||||
console.log(`interactive shell terminated with code ${code}`);
|
||||
this.smartexit.removeProcess(shell);
|
||||
done.resolve();
|
||||
});
|
||||
|
||||
await done.promise;
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
||||
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
||||
|
||||
let commandToExecute = options.commandString;
|
||||
commandToExecute = this.shellEnv.createEnvExecString(options.commandString);
|
||||
|
||||
|
||||
const spawnlogInstance = new ShellLog();
|
||||
const execChildProcess = cp.spawn(commandToExecute, [], {
|
||||
shell: true,
|
||||
@ -143,19 +144,30 @@ export class Smartshell {
|
||||
return (await this._exec({ commandString, silent: true, strict: true })) as IExecResult;
|
||||
}
|
||||
|
||||
public async execStreaming(commandString: string, silent: boolean = false): Promise<IExecResultStreaming> {
|
||||
public async execStreaming(
|
||||
commandString: string,
|
||||
silent: boolean = false
|
||||
): Promise<IExecResultStreaming> {
|
||||
return (await this._exec({ commandString, silent, streaming: true })) as IExecResultStreaming;
|
||||
}
|
||||
|
||||
public async execStreamingSilent(commandString: string): Promise<IExecResultStreaming> {
|
||||
return (await this._exec({ commandString, silent: true, streaming: true })) as IExecResultStreaming;
|
||||
return (await this._exec({
|
||||
commandString,
|
||||
silent: true,
|
||||
streaming: true,
|
||||
})) as IExecResultStreaming;
|
||||
}
|
||||
|
||||
public async execInteractive(commandString: string) {
|
||||
await this._exec({ commandString, interactive: true });
|
||||
}
|
||||
|
||||
public async execAndWaitForLine(commandString: string, regexArg: RegExp, silentArg: boolean = false) {
|
||||
public async execAndWaitForLine(
|
||||
commandString: string,
|
||||
regexArg: RegExp,
|
||||
silentArg: boolean = false
|
||||
) {
|
||||
let done = plugins.smartpromise.defer();
|
||||
let execStreamingResult = await this.execStreaming(commandString, silentArg);
|
||||
execStreamingResult.childProcess.stdout.on('data', (stdOutChunk: string) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartexit from '@pushrocks/smartexit';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
import * as smartdelay from '@push.rocks/smartdelay';
|
||||
import * as smartexit from '@push.rocks/smartexit';
|
||||
import * as smartpromise from '@push.rocks/smartpromise';
|
||||
import which from 'which';
|
||||
|
||||
export { smartdelay, smartexit, smartpromise, which };
|
||||
|
@ -3,9 +3,12 @@
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
}
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user