diff --git a/dist/index.d.ts b/dist/index.d.ts index 2244fc2..f724545 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1,8 +1 @@ -export interface IExecResult { - exitCode: number; - stdout: string; -} -export declare let exec: (commandStringArg: string) => Promise; -export declare let execSilent: (commandStringArg: string) => Promise; -export declare let execSync: () => void; -export declare let execSyncSilent: () => void; +export * from './smartshell.wrap'; diff --git a/dist/index.js b/dist/index.js index 7551285..75053c3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,24 +1,7 @@ "use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} Object.defineProperty(exports, "__esModule", { value: true }); -const plugins = require("./smartshell.plugins"); -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; -}; -exports.execSilent = (commandStringArg) => { - let done = plugins.smartq.defer(); - plugins.shelljs.exec(commandStringArg, {}, () => { - }); - return done.promise; -}; -exports.execSync = () => { -}; -exports.execSyncSilent = () => { -}; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLGdEQUErQztBQVNwQyxRQUFBLElBQUksR0FBRyxDQUFDLGdCQUF3QjtJQUN6QyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzlDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGdCQUFnQixFQUFDLEVBQUMsS0FBSyxFQUFFLElBQUksRUFBQyxFQUFFLENBQUMsSUFBSSxFQUFFLE1BQU0sRUFBRSxNQUFNO1FBQ3hFLElBQUksQ0FBQyxPQUFPLENBQUM7WUFDWCxRQUFRLEVBQUUsSUFBSTtZQUNkLE1BQU0sRUFBRSxNQUFNO1NBQ2YsQ0FBQyxDQUFBO0lBQ0osQ0FBQyxDQUFDLENBQUE7SUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUE7QUFFVSxRQUFBLFVBQVUsR0FBRyxDQUFDLGdCQUF3QjtJQUMvQyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzlDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGdCQUFnQixFQUFDLEVBQUUsRUFBRTtJQUUxQyxDQUFDLENBQUMsQ0FBQTtJQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3JCLENBQUMsQ0FBQTtBQUVVLFFBQUEsUUFBUSxHQUFHO0FBRXRCLENBQUMsQ0FBQTtBQUVVLFFBQUEsY0FBYyxHQUFHO0FBRTVCLENBQUMsQ0FBQSJ9 \ No newline at end of file +__export(require("./smartshell.wrap")); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHVDQUFpQyJ9 \ No newline at end of file diff --git a/dist/smartshell.classes.smartshell.d.ts b/dist/smartshell.classes.smartshell.d.ts new file mode 100644 index 0000000..075ddb5 --- /dev/null +++ b/dist/smartshell.classes.smartshell.d.ts @@ -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; +} diff --git a/dist/smartshell.classes.smartshell.js b/dist/smartshell.classes.smartshell.js new file mode 100644 index 0000000..4039ddc --- /dev/null +++ b/dist/smartshell.classes.smartshell.js @@ -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 \ No newline at end of file diff --git a/dist/smartshell.wrap.d.ts b/dist/smartshell.wrap.d.ts new file mode 100644 index 0000000..1ee0de8 --- /dev/null +++ b/dist/smartshell.wrap.d.ts @@ -0,0 +1,27 @@ +/// +import { ChildProcess } from 'child_process'; +export interface IExecResult { + exitCode: number; + stdout: string; +} +export interface IExecResultStreaming { + childProcess: ChildProcess; + finalPromise: Promise; +} +/** + * executes a given command async + * @param commandStringArg + */ +export declare let exec: (commandStringArg: string) => Promise; +/** + * executes a given command async and silent + * @param commandStringArg + */ +export declare let execSilent: (commandStringArg: string) => Promise; +/** + * executes a command and allws you to stream output + */ +export declare let execStreaming: (commandStringArg: string) => { + childProcess: ChildProcess; + finalPromise: Promise; +}; diff --git a/dist/smartshell.wrap.js b/dist/smartshell.wrap.js new file mode 100644 index 0000000..56a9711 --- /dev/null +++ b/dist/smartshell.wrap.js @@ -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 + }; +}; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRzaGVsbC53cmFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRzaGVsbC53cmFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsZ0RBQStDO0FBZ0IvQzs7O0dBR0c7QUFDUSxRQUFBLElBQUksR0FBRyxDQUFDLGdCQUF3QjtJQUN6QyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzlDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGdCQUFnQixFQUFFLEVBQUUsS0FBSyxFQUFFLElBQUksRUFBRSxFQUFFLENBQUMsSUFBSSxFQUFFLE1BQU0sRUFBRSxNQUFNO1FBQzNFLElBQUksQ0FBQyxPQUFPLENBQUM7WUFDWCxRQUFRLEVBQUUsSUFBSTtZQUNkLE1BQU0sRUFBRSxNQUFNO1NBQ2YsQ0FBQyxDQUFBO0lBQ0osQ0FBQyxDQUFDLENBQUE7SUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtBQUNyQixDQUFDLENBQUE7QUFFRDs7O0dBR0c7QUFDUSxRQUFBLFVBQVUsR0FBRyxDQUFDLGdCQUF3QjtJQUMvQyxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzlDLE9BQU8sQ0FBQyxPQUFPLENBQUMsSUFBSSxDQUFDLGdCQUFnQixFQUFFLEVBQUUsS0FBSyxFQUFFLElBQUksRUFBRSxNQUFNLEVBQUUsSUFBSSxFQUFFLEVBQUUsQ0FBQyxJQUFJLEVBQUUsTUFBTSxFQUFFLE1BQU07UUFDekYsSUFBSSxDQUFDLE9BQU8sQ0FBQztZQUNYLFFBQVEsRUFBRSxJQUFJO1lBQ2QsTUFBTSxFQUFFLE1BQU07U0FDZixDQUFDLENBQUE7SUFDSixDQUFDLENBQUMsQ0FBQTtJQUNGLE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0FBQ3JCLENBQUMsQ0FBQTtBQUVEOztHQUVHO0FBQ1EsUUFBQSxhQUFhLEdBQUcsQ0FBQyxnQkFBd0I7SUFDbEQsSUFBSSxpQkFBaUIsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssRUFBZSxDQUFBO0lBQzNELElBQUksZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsZ0JBQWdCLEVBQUUsRUFBQyxLQUFLLEVBQUUsSUFBSSxFQUFFLE1BQU0sRUFBRSxJQUFJLEVBQUMsRUFBRSxDQUFDLElBQUksRUFBRSxNQUFNLEVBQUUsTUFBTTtRQUM5RyxpQkFBaUIsQ0FBQyxPQUFPLENBQUM7WUFDeEIsUUFBUSxFQUFFLElBQUk7WUFDZCxNQUFNLEVBQUUsTUFBTTtTQUNmLENBQUMsQ0FBQTtJQUNKLENBQUMsQ0FBQyxDQUFBO0lBQ0YsTUFBTSxDQUFDO1FBQ0wsWUFBWSxFQUFFLGdCQUFnQjtRQUM5QixZQUFZLEVBQUUsaUJBQWlCLENBQUMsT0FBTztLQUN4QyxDQUFBO0FBQ0gsQ0FBQyxDQUFBIn0= \ No newline at end of file diff --git a/test/test.js b/test/test.js index 779a2f5..09bd536 100644 --- a/test/test.js +++ b/test/test.js @@ -1,13 +1,26 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("typings-test"); +const smartchai_1 = require("smartchai"); const smartshell = require("../dist/index"); describe('smartshell', function () { it('it should run async', function () { this.timeout(1000000); - return smartshell.exec('npmdocker speedtest').then((execResult) => { - console.log(execResult.stdout); + return smartshell.exec('npm -v').then((execResult) => { + 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 \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSx3QkFBcUI7QUFDckIseUNBQWtDO0FBRWxDLDRDQUEyQztBQUUzQyxRQUFRLENBQUMsWUFBWSxFQUFFO0lBQ3JCLEVBQUUsQ0FBQyxxQkFBcUIsRUFBRT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b/test/test.ts index f2fc0c5..560bf5c 100644 --- a/test/test.ts +++ b/test/test.ts @@ -3,11 +3,23 @@ import { expect } from 'smartchai' import * as smartshell from '../dist/index' -describe('smartshell', function() { - it('it should run async', function() { - this.timeout(1000000) - return smartshell.exec('npmdocker speedtest').then((execResult) => { - console.log(execResult.stdout) - }) +describe('smartshell', function () { + it('it should run async', function () { + this.timeout(1000000) + return smartshell.exec('npm -v').then((execResult) => { + expect(execResult.stdout).to.match(/[0-9\.]*/) }) -}) \ No newline at end of file + }) + 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 + }) +}) diff --git a/ts/smartshell.classes.smartshell.ts b/ts/smartshell.classes.smartshell.ts index b603637..a4158d3 100644 --- a/ts/smartshell.classes.smartshell.ts +++ b/ts/smartshell.classes.smartshell.ts @@ -4,13 +4,26 @@ import * as smartshellWrap from './smartshell.wrap' export type TExecutor = 'sh' | 'bash' export interface ISmartshellContructorOptions { - executor: TExecutor - sourceFiles: string[] + executor: TExecutor + sourceFilePaths: string[] } 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 = [] + } } \ No newline at end of file diff --git a/ts/smartshell.wrap.ts b/ts/smartshell.wrap.ts index f57edc7..2ef5d6c 100644 --- a/ts/smartshell.wrap.ts +++ b/ts/smartshell.wrap.ts @@ -1,13 +1,26 @@ import * as plugins from './smartshell.plugins' +// interfaces +import { ChildProcess } from 'child_process' +import { Deferred } from 'smartq' + export interface IExecResult { exitCode: number, stdout: string } +export interface IExecResultStreaming { + childProcess: ChildProcess, + finalPromise: Promise +} + +/** + * executes a given command async + * @param commandStringArg + */ export let exec = (commandStringArg: string): Promise => { let done = plugins.smartq.defer() - plugins.shelljs.exec(commandStringArg,{async: true}, (code, stdout, stderr) => { + plugins.shelljs.exec(commandStringArg, { async: true }, (code, stdout, stderr) => { done.resolve({ exitCode: code, stdout: stdout @@ -16,9 +29,13 @@ export let exec = (commandStringArg: string): Promise => { return done.promise } +/** + * executes a given command async and silent + * @param commandStringArg + */ export let execSilent = (commandStringArg: string) => { let done = plugins.smartq.defer() - plugins.shelljs.exec(commandStringArg,{async: true, silent: true}, (code, stdout, stderr) => { + plugins.shelljs.exec(commandStringArg, { async: true, silent: true }, (code, stdout, stderr) => { done.resolve({ exitCode: code, stdout: stdout @@ -26,3 +43,20 @@ export let execSilent = (commandStringArg: string) => { }) return done.promise } + +/** + * executes a command and allws you to stream output + */ +export let execStreaming = (commandStringArg: string) => { + 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 + } +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..45052ad --- /dev/null +++ b/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "tslint-config-standard" +}