bootstrap Smartshell class
This commit is contained in:
parent
2b48edf5b7
commit
a91938e463
9
dist/index.d.ts
vendored
9
dist/index.d.ts
vendored
@ -1,8 +1 @@
|
|||||||
export interface IExecResult {
|
export * from './smartshell.wrap';
|
||||||
exitCode: number;
|
|
||||||
stdout: string;
|
|
||||||
}
|
|
||||||
export declare let exec: (commandStringArg: string) => Promise<IExecResult>;
|
|
||||||
export declare let execSilent: (commandStringArg: string) => Promise<IExecResult>;
|
|
||||||
export declare let execSync: () => void;
|
|
||||||
export declare let execSyncSilent: () => void;
|
|
||||||
|
27
dist/index.js
vendored
27
dist/index.js
vendored
@ -1,24 +1,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
function __export(m) {
|
||||||
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||||
|
}
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const plugins = require("./smartshell.plugins");
|
__export(require("./smartshell.wrap"));
|
||||||
exports.exec = (commandStringArg) => {
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHVDQUFpQyJ9
|
||||||
let done = plugins.smartq.defer();
|
|
||||||
plugins.shelljs.exec(commandStringArg, { async: true }, (code, stdout, stderr) => {
|
|
||||||
done.resolve({
|
|
||||||
exitCode: code,
|
|
||||||
stdout: stdout
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
exports.execSilent = (commandStringArg) => {
|
|
||||||
let done = plugins.smartq.defer();
|
|
||||||
plugins.shelljs.exec(commandStringArg, {}, () => {
|
|
||||||
});
|
|
||||||
return done.promise;
|
|
||||||
};
|
|
||||||
exports.execSync = () => {
|
|
||||||
};
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UMsQ0FBQSJ9
|
|
11
dist/smartshell.classes.smartshell.d.ts
vendored
Normal file
11
dist/smartshell.classes.smartshell.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export declare type TExecutor = 'sh' | 'bash';
|
||||||
|
export interface ISmartshellContructorOptions {
|
||||||
|
executor: TExecutor;
|
||||||
|
sourceFilePaths: string[];
|
||||||
|
}
|
||||||
|
export declare class Smartshell {
|
||||||
|
sourceFiles: string[];
|
||||||
|
constructor(optionsArg: ISmartshellContructorOptions);
|
||||||
|
addSourceFiles(sourceFilePathsArray: string[]): void;
|
||||||
|
cleanSourceFiles(): void;
|
||||||
|
}
|
20
dist/smartshell.classes.smartshell.js
vendored
Normal file
20
dist/smartshell.classes.smartshell.js
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
class Smartshell {
|
||||||
|
constructor(optionsArg) {
|
||||||
|
this.sourceFiles = [];
|
||||||
|
for (let sourceFilePath of optionsArg.sourceFilePaths) {
|
||||||
|
this.sourceFiles.push(sourceFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
addSourceFiles(sourceFilePathsArray) {
|
||||||
|
for (let sourceFilePath of sourceFilePathsArray) {
|
||||||
|
this.sourceFiles.push(sourceFilePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cleanSourceFiles() {
|
||||||
|
this.sourceFiles = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.Smartshell = Smartshell;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzaGVsbC5jbGFzc2VzLnNtYXJ0c2hlbGwuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHNoZWxsLmNsYXNzZXMuc21hcnRzaGVsbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQVdBO0lBRUUsWUFBYSxVQUF3QztRQURyRCxnQkFBVyxHQUFhLEVBQUUsQ0FBQTtRQUV4QixHQUFHLENBQUMsQ0FBQyxJQUFJLGNBQWMsSUFBSSxVQUFVLENBQUMsZUFBZSxDQUFDLENBQUMsQ0FBQztZQUN0RCxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxjQUFjLENBQUMsQ0FBQTtRQUN2QyxDQUFDO0lBQ0gsQ0FBQztJQUVELGNBQWMsQ0FBQyxvQkFBOEI7UUFDM0MsR0FBRyxDQUFBLENBQUMsSUFBSSxjQUFjLElBQUksb0JBQW9CLENBQUMsQ0FBQyxDQUFDO1lBQy9DLElBQUksQ0FBQyxXQUFXLENBQUMsSUFBSSxDQUFDLGNBQWMsQ0FBQyxDQUFBO1FBQ3ZDLENBQUM7SUFDSCxDQUFDO0lBRUQsZ0JBQWdCO1FBQ2QsSUFBSSxDQUFDLFdBQVcsR0FBRyxFQUFFLENBQUE7SUFDdkIsQ0FBQztDQUNGO0FBakJELGdDQWlCQyJ9
|
27
dist/smartshell.wrap.d.ts
vendored
Normal file
27
dist/smartshell.wrap.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/// <reference types="node" />
|
||||||
|
import { ChildProcess } from 'child_process';
|
||||||
|
export interface IExecResult {
|
||||||
|
exitCode: number;
|
||||||
|
stdout: string;
|
||||||
|
}
|
||||||
|
export interface IExecResultStreaming {
|
||||||
|
childProcess: ChildProcess;
|
||||||
|
finalPromise: Promise<IExecResult>;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* executes a given command async
|
||||||
|
* @param commandStringArg
|
||||||
|
*/
|
||||||
|
export declare let exec: (commandStringArg: string) => Promise<IExecResult>;
|
||||||
|
/**
|
||||||
|
* executes a given command async and silent
|
||||||
|
* @param commandStringArg
|
||||||
|
*/
|
||||||
|
export declare let execSilent: (commandStringArg: string) => Promise<IExecResult>;
|
||||||
|
/**
|
||||||
|
* executes a command and allws you to stream output
|
||||||
|
*/
|
||||||
|
export declare let execStreaming: (commandStringArg: string) => {
|
||||||
|
childProcess: ChildProcess;
|
||||||
|
finalPromise: Promise<IExecResult>;
|
||||||
|
};
|
48
dist/smartshell.wrap.js
vendored
Normal file
48
dist/smartshell.wrap.js
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const plugins = require("./smartshell.plugins");
|
||||||
|
/**
|
||||||
|
* executes a given command async
|
||||||
|
* @param commandStringArg
|
||||||
|
*/
|
||||||
|
exports.exec = (commandStringArg) => {
|
||||||
|
let done = plugins.smartq.defer();
|
||||||
|
plugins.shelljs.exec(commandStringArg, { async: true }, (code, stdout, stderr) => {
|
||||||
|
done.resolve({
|
||||||
|
exitCode: code,
|
||||||
|
stdout: stdout
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* executes a given command async and silent
|
||||||
|
* @param commandStringArg
|
||||||
|
*/
|
||||||
|
exports.execSilent = (commandStringArg) => {
|
||||||
|
let done = plugins.smartq.defer();
|
||||||
|
plugins.shelljs.exec(commandStringArg, { async: true, silent: true }, (code, stdout, stderr) => {
|
||||||
|
done.resolve({
|
||||||
|
exitCode: code,
|
||||||
|
stdout: stdout
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return done.promise;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* executes a command and allws you to stream output
|
||||||
|
*/
|
||||||
|
exports.execStreaming = (commandStringArg) => {
|
||||||
|
let childProcessEnded = plugins.smartq.defer();
|
||||||
|
let execChildProcess = plugins.shelljs.exec(commandStringArg, { async: true, silent: true }, (code, stdout, stderr) => {
|
||||||
|
childProcessEnded.resolve({
|
||||||
|
exitCode: code,
|
||||||
|
stdout: stdout
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
childProcess: execChildProcess,
|
||||||
|
finalPromise: childProcessEnded.promise
|
||||||
|
};
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BRSxJQUFJO1lBQ2QsTUFBTSxFQUFFLE1BQU07U0FDZixDQUFDLENBQUE7SUFDSixDQUFDLENBQUMsQ0FBQTtJQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3JCLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsUUFBQSxhQUFhLEdBQUcsQ0FBQyxnQkFBd0I7SUFDbEQsSUFBSSxpQkFBaUIsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzNELElBQUksZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLEVBQUUsRUFBQyxLQUFLLEVBQUUsSUFBSSxFQUFFLE1BQU0sRUFBRSxJQUFJLEVBQUMsRUFBRSxDQUFDLElBQUksRUFBRSxNQUFNLEVBQUUsTUFBTTtRQUM5RyxpQkFBaUIsQ0FBQyxPQUFPLENBQUM7WUFDeEIsUUFBUSxFQUFFLElBQUk7WUFDZCxNQUFNLEVBQUUsTUFBTTtTQUNmLENBQUMsQ0FBQTtJQUNKLENBQUMsQ0FBQyxDQUFBO0lBQ0YsTUFBTSxDQUFDO1FBQ0wsWUFBWSxFQUFFLGdCQUFnQjtRQUM5QixZQUFZLEVBQUUsaUJBQWlCLENBQUMsT0FBTztLQUN4QyxDQUFBO0FBQ0gsQ0FBQyxDQUFBIn0=
|
19
test/test.js
19
test/test.js
@ -1,13 +1,26 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
require("typings-test");
|
require("typings-test");
|
||||||
|
const smartchai_1 = require("smartchai");
|
||||||
const smartshell = require("../dist/index");
|
const smartshell = require("../dist/index");
|
||||||
describe('smartshell', function () {
|
describe('smartshell', function () {
|
||||||
it('it should run async', function () {
|
it('it should run async', function () {
|
||||||
this.timeout(1000000);
|
this.timeout(1000000);
|
||||||
return smartshell.exec('npmdocker speedtest').then((execResult) => {
|
return smartshell.exec('npm -v').then((execResult) => {
|
||||||
console.log(execResult.stdout);
|
smartchai_1.expect(execResult.stdout).to.match(/[0-9\.]*/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('should run async and silent', function () {
|
||||||
|
return smartshell.execSilent('npm -v').then((execResult) => {
|
||||||
|
smartchai_1.expect(execResult.stdout).to.match(/[0-9\.]*/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should stream a shell execution', function () {
|
||||||
|
let execStreamingResponse = smartshell.execStreaming('npm -v');
|
||||||
|
execStreamingResponse.childProcess.stdout.on('data', (data) => {
|
||||||
|
console.log('Received ' + data);
|
||||||
|
});
|
||||||
|
return execStreamingResponse.finalPromise;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx3QkFBcUI7QUFHckIsNENBQTJDO0FBRTNDLFFBQVEsQ0FBQyxZQUFZLEVBQUU7SUFDbkIsRUFBRSxDQUFDLHFCQUFxQixFQUFFO1FBQ3RCLElBQUksQ0FBQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUE7UUFDckIsTUFBTSxDQUFDLFVBQVUsQ0FBQyxJQUFJLENBQUMscUJBQXFCLENBQUMsQ0FBQyxJQUFJLENBQUMsQ0FBQyxVQUFVO1lBQzFELE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVSxDQUFDLE1BQU0sQ0FBQyxDQUFBO1FBQ2xDLENBQUMsQ0FBQyxDQUFBO0lBQ04sQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozL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BQ3hELE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxHQUFHLElBQUksQ0FBQyxDQUFBO1FBQ2pDLENBQUMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLHFCQUFxQixDQUFDLFlBQVksQ0FBQTtJQUMzQyxDQUFDLENBQUMsQ0FBQTtBQUNKLENBQUMsQ0FBQyxDQUFBIn0=
|
26
test/test.ts
26
test/test.ts
@ -3,11 +3,23 @@ import { expect } from 'smartchai'
|
|||||||
|
|
||||||
import * as smartshell from '../dist/index'
|
import * as smartshell from '../dist/index'
|
||||||
|
|
||||||
describe('smartshell', function() {
|
describe('smartshell', function () {
|
||||||
it('it should run async', function() {
|
it('it should run async', function () {
|
||||||
this.timeout(1000000)
|
this.timeout(1000000)
|
||||||
return smartshell.exec('npmdocker speedtest').then((execResult) => {
|
return smartshell.exec('npm -v').then((execResult) => {
|
||||||
console.log(execResult.stdout)
|
expect(execResult.stdout).to.match(/[0-9\.]*/)
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
it('should run async and silent', function() {
|
||||||
|
return smartshell.execSilent('npm -v').then((execResult) => {
|
||||||
|
expect(execResult.stdout).to.match(/[0-9\.]*/)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
it('should stream a shell execution', function() {
|
||||||
|
let execStreamingResponse = smartshell.execStreaming('npm -v')
|
||||||
|
execStreamingResponse.childProcess.stdout.on('data', (data) => {
|
||||||
|
console.log('Received ' + data)
|
||||||
|
})
|
||||||
|
return execStreamingResponse.finalPromise
|
||||||
|
})
|
||||||
|
})
|
||||||
|
@ -4,13 +4,26 @@ import * as smartshellWrap from './smartshell.wrap'
|
|||||||
export type TExecutor = 'sh' | 'bash'
|
export type TExecutor = 'sh' | 'bash'
|
||||||
|
|
||||||
export interface ISmartshellContructorOptions {
|
export interface ISmartshellContructorOptions {
|
||||||
executor: TExecutor
|
executor: TExecutor
|
||||||
sourceFiles: string[]
|
sourceFilePaths: string[]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Smartshell {
|
export class Smartshell {
|
||||||
constructor() {
|
sourceFiles: string[] = []
|
||||||
|
constructor (optionsArg: ISmartshellContructorOptions) {
|
||||||
|
for (let sourceFilePath of optionsArg.sourceFilePaths) {
|
||||||
|
this.sourceFiles.push(sourceFilePath)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addSourceFiles(sourceFilePathsArray: string[]) {
|
||||||
|
for(let sourceFilePath of sourceFilePathsArray) {
|
||||||
|
this.sourceFiles.push(sourceFilePath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanSourceFiles () {
|
||||||
|
this.sourceFiles = []
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,13 +1,26 @@
|
|||||||
import * as plugins from './smartshell.plugins'
|
import * as plugins from './smartshell.plugins'
|
||||||
|
|
||||||
|
// interfaces
|
||||||
|
import { ChildProcess } from 'child_process'
|
||||||
|
import { Deferred } from 'smartq'
|
||||||
|
|
||||||
export interface IExecResult {
|
export interface IExecResult {
|
||||||
exitCode: number,
|
exitCode: number,
|
||||||
stdout: string
|
stdout: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IExecResultStreaming {
|
||||||
|
childProcess: ChildProcess,
|
||||||
|
finalPromise: Promise<IExecResult>
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executes a given command async
|
||||||
|
* @param commandStringArg
|
||||||
|
*/
|
||||||
export let exec = (commandStringArg: string): Promise<IExecResult> => {
|
export let exec = (commandStringArg: string): Promise<IExecResult> => {
|
||||||
let done = plugins.smartq.defer<IExecResult>()
|
let done = plugins.smartq.defer<IExecResult>()
|
||||||
plugins.shelljs.exec(commandStringArg,{async: true}, (code, stdout, stderr) => {
|
plugins.shelljs.exec(commandStringArg, { async: true }, (code, stdout, stderr) => {
|
||||||
done.resolve({
|
done.resolve({
|
||||||
exitCode: code,
|
exitCode: code,
|
||||||
stdout: stdout
|
stdout: stdout
|
||||||
@ -16,9 +29,13 @@ export let exec = (commandStringArg: string): Promise<IExecResult> => {
|
|||||||
return done.promise
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executes a given command async and silent
|
||||||
|
* @param commandStringArg
|
||||||
|
*/
|
||||||
export let execSilent = (commandStringArg: string) => {
|
export let execSilent = (commandStringArg: string) => {
|
||||||
let done = plugins.smartq.defer<IExecResult>()
|
let done = plugins.smartq.defer<IExecResult>()
|
||||||
plugins.shelljs.exec(commandStringArg,{async: true, silent: true}, (code, stdout, stderr) => {
|
plugins.shelljs.exec(commandStringArg, { async: true, silent: true }, (code, stdout, stderr) => {
|
||||||
done.resolve({
|
done.resolve({
|
||||||
exitCode: code,
|
exitCode: code,
|
||||||
stdout: stdout
|
stdout: stdout
|
||||||
@ -26,3 +43,20 @@ export let execSilent = (commandStringArg: string) => {
|
|||||||
})
|
})
|
||||||
return done.promise
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* executes a command and allws you to stream output
|
||||||
|
*/
|
||||||
|
export let execStreaming = (commandStringArg: string) => {
|
||||||
|
let childProcessEnded = plugins.smartq.defer<IExecResult>()
|
||||||
|
let execChildProcess = plugins.shelljs.exec(commandStringArg, {async: true, silent: true}, (code, stdout, stderr) => {
|
||||||
|
childProcessEnded.resolve({
|
||||||
|
exitCode: code,
|
||||||
|
stdout: stdout
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return {
|
||||||
|
childProcess: execChildProcess,
|
||||||
|
finalPromise: childProcessEnded.promise
|
||||||
|
}
|
||||||
|
}
|
||||||
|
3
tslint.json
Normal file
3
tslint.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"extends": "tslint-config-standard"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user