switch to native ipc to scale down on dependencies

This commit is contained in:
Philipp Kunz 2016-09-28 23:46:28 +02:00
parent 65ab58f727
commit 5ce83601b4
24 changed files with 271 additions and 55 deletions

2
dist/index.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
export * from './smartipc.classes.ipcmaster';
export * from './smartipc.classes.ipcchild';

7
dist/index.js vendored Normal file
View File

@ -0,0 +1,7 @@
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(require("./smartipc.classes.ipcmaster"));
__export(require("./smartipc.classes.ipcchild"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBQUEsa0RBQTRDO0FBQzVDLGlEQUEyQyJ9

10
dist/smartipc.classes.ipcchild.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
import { IpcTarget } from './smartipc.classes.ipctarget';
export interface IpcChildConstructorOptions {
}
/**
* class Ipcclient represents the child process
*/
export declare class IpcChild extends IpcTarget {
constructor(optionsArg: IpcChildConstructorOptions);
call(ipctarget: any, targetFunction: any, dataArg: any): void;
}

15
dist/smartipc.classes.ipcchild.js vendored Normal file
View File

@ -0,0 +1,15 @@
"use strict";
const smartipc_classes_ipctarget_1 = require("./smartipc.classes.ipctarget");
let defaultOptions = {};
/**
* class Ipcclient represents the child process
*/
class IpcChild extends smartipc_classes_ipctarget_1.IpcTarget {
constructor(optionsArg) {
super({ alias: 'child' });
}
call(ipctarget, targetFunction, dataArg) {
}
}
exports.IpcChild = IpcChild;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy5pcGNjaGlsZC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLmNsYXNzZXMuaXBjY2hpbGQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUNBLDZFQUF3RDtBQU14RCxJQUFJLGNBQWMsR0FBK0IsRUFFaEQsQ0FBQTtBQUVEOztHQUVHO0FBQ0gsY0FBc0IsU0FBUSxzQ0FBUztJQUNuQyxZQUFZLFVBQXNDO1FBQzlDLEtBQUssQ0FBQyxFQUFDLEtBQUssRUFBRSxPQUFPLEVBQUMsQ0FBQyxDQUFBO0lBQzNCLENBQUM7SUFDRCxJQUFJLENBQUMsU0FBUyxFQUFDLGNBQWMsRUFBQyxPQUFPO0lBRXJDLENBQUM7Q0FDSjtBQVBELDRCQU9DIn0=

21
dist/smartipc.classes.ipcmaster.d.ts vendored Normal file
View File

@ -0,0 +1,21 @@
import * as plugins from './smartipc.plugins';
import { IpcTarget } from './smartipc.classes.ipctarget';
export interface IIpcServeOptions {
}
export interface IIpcChildProcess {
alias: string;
filePath: string;
childProcess: plugins.childProcess.ChildProcess;
}
/**
* class Ipcserve is represents the master process for any chil processes
*/
export declare class IpcMaster extends IpcTarget {
ipcOptions: IIpcServeOptions;
childProcessArray: IIpcChildProcess[];
constructor(ipcOptionsArg: IIpcServeOptions);
/**
* spawns a child process
*/
spawnProcess(filePath: string, alias: string): void;
}

30
dist/smartipc.classes.ipcmaster.js vendored Normal file
View File

@ -0,0 +1,30 @@
"use strict";
const plugins = require("./smartipc.plugins");
const smartipc_classes_ipctarget_1 = require("./smartipc.classes.ipctarget");
let defaultOptions = {};
/**
* class Ipcserve is represents the master process for any chil processes
*/
class IpcMaster extends smartipc_classes_ipctarget_1.IpcTarget {
constructor(ipcOptionsArg) {
super({ alias: 'master' });
this.ipcOptions = plugins.lodash.merge({}, defaultOptions, ipcOptionsArg);
}
/**
* spawns a child process
*/
spawnProcess(filePath, alias) {
let childProcess = plugins.childProcess.fork('ls', ['-lh', '/usr']);
childProcess.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
childProcess.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});
childProcess.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
}
}
exports.IpcMaster = IpcMaster;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy5pcGNtYXN0ZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLmlwY21hc3Rlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsOENBQTZDO0FBQzdDLDZFQUF3RDtBQU14RCxJQUFJLGNBQWMsR0FBcUIsRUFFdEMsQ0FBQTtBQVFEOztHQUVHO0FBQ0gsZUFBdUIsU0FBUSxzQ0FBUztJQUdwQyxZQUFZLGFBQStCO1FBQ3ZDLEtBQUssQ0FBQyxFQUFDLEtBQUssRUFBRSxRQUFRLEVBQUMsQ0FBQyxDQUFBO1FBQ3hCLElBQUksQ0FBQyxVQUFVLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxLQUFLLENBQUMsRUFBRSxFQUFDLGNBQWMsRUFBQyxhQUFhLENBQUMsQ0FBQTtJQUMzRSxDQUFDO0lBRUQ7O09BRUc7SUFDSCxZQUFZLENBQUMsUUFBZ0IsRUFBRSxLQUFhO1FBRXhDLElBQUksWUFBWSxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLElBQUksRUFBRSxDQUFDLEtBQUssRUFBRSxNQUFNLENBQUMsQ0FBQyxDQUFBO1FBRW5FLFlBQVksQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLE1BQU0sRUFBRSxDQUFDLElBQUk7WUFDcEMsT0FBTyxDQUFDLEdBQUcsQ0FBQyxXQUFXLElBQUksRUFBRSxDQUFDLENBQUE7UUFDOUIsQ0FBQyxDQUFDLENBQUE7UUFFRixZQUFZLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsQ0FBQyxJQUFJO1lBQ3BDLE9BQU8sQ0FBQyxHQUFHLENBQUMsV0FBVyxJQUFJLEVBQUUsQ0FBQyxDQUFBO1FBQzlCLENBQUMsQ0FBQyxDQUFBO1FBRUYsWUFBWSxDQUFDLEVBQUUsQ0FBQyxPQUFPLEVBQUUsQ0FBQyxJQUFJO1lBQzlCLE9BQU8sQ0FBQyxHQUFHLENBQUMsa0NBQWtDLElBQUksRUFBRSxDQUFDLENBQUE7UUFDckQsQ0FBQyxDQUFDLENBQUE7SUFDTixDQUFDO0NBQ0o7QUEzQkQsOEJBMkJDIn0=

15
dist/smartipc.classes.ipctarget.d.ts vendored Normal file
View File

@ -0,0 +1,15 @@
export interface ITargetConstructorOptions {
alias: string;
}
/**
*
*/
export declare class IpcTarget {
alias: string;
private funcArray;
constructor(optionsArg: ITargetConstructorOptions);
/**
* registers a function
*/
register(funcArrayArg: any[]): void;
}

19
dist/smartipc.classes.ipctarget.js vendored Normal file
View File

@ -0,0 +1,19 @@
"use strict";
/**
*
*/
class IpcTarget {
constructor(optionsArg) {
this.alias = optionsArg.alias;
}
/**
* registers a function
*/
register(funcArrayArg) {
for (let funcItem of funcArrayArg) {
this.funcArray.push(funcItem);
}
}
}
exports.IpcTarget = IpcTarget;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMuY2xhc3Nlcy5pcGN0YXJnZXQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGlwYy5jbGFzc2VzLmlwY3RhcmdldC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBTUE7O0dBRUc7QUFDSDtJQUlJLFlBQVksVUFBcUM7UUFDN0MsSUFBSSxDQUFDLEtBQUssR0FBRyxVQUFVLENBQUMsS0FBSyxDQUFBO0lBQ2pDLENBQUM7SUFFRDs7T0FFRztJQUNILFFBQVEsQ0FBQyxZQUFtQjtRQUN4QixHQUFHLENBQUMsQ0FBQyxJQUFJLFFBQVEsSUFBSSxZQUFZLENBQUMsQ0FBQSxDQUFDO1lBQy9CLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxDQUFBO1FBQ2pDLENBQUM7SUFDTCxDQUFDO0NBRUo7QUFqQkQsOEJBaUJDIn0=

4
dist/smartipc.plugins.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
import 'typings-global';
export import beautylog = require('beautylog');
export import lodash = require('lodash');
export import childProcess = require('child_process');

6
dist/smartipc.plugins.js vendored Normal file
View File

@ -0,0 +1,6 @@
"use strict";
require("typings-global");
exports.beautylog = require("beautylog");
exports.lodash = require("lodash");
exports.childProcess = require("child_process");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRpcGMucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0aXBjLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBCQUF1QjtBQUN2Qix5Q0FBOEM7QUFDOUMsbUNBQXdDO0FBQ3hDLGdEQUFxRCJ9

7
npmextra.json Normal file
View File

@ -0,0 +1,7 @@
{
"npmts": {
"testTs": {
"./test/*.ts": "./test/"
}
}
}

View File

@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "smart subprocess handling",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "(npmts)"
},
@ -21,5 +22,10 @@
"beautylog": "^5.0.23",
"lodash": "^4.16.2",
"typings-global": "^1.0.14"
},
"devDependencies": {
"@types/should": "^8.1.30",
"should": "^11.1.0",
"typings-test": "^1.0.3"
}
}

3
test/child.ts Normal file
View File

@ -0,0 +1,3 @@
import * as smartipc from '../dist/index'
let localChild = new smartipc.IpcChild({})

View File

@ -1,2 +0,0 @@
export * from './smartipc.classes.ipcserver'
export * from './smartipc.classes.ipcclient'

View File

@ -1,7 +0,0 @@
import * as plugins from './smartipc.plugins'
export calss IpcClient {
constructor() {
}
}

View File

@ -1,44 +0,0 @@
import * as plugins from './smartipc.plugins'
interface IIpcServeOptions {
appspace?: string
socketRoot?: string
id?: string
networkHost?: string //should resolve to 127.0.0.1 or ::1 see the table below related to this
networkPort?: number
encoding?: string
rawBuffer?: boolean
sync?: boolean
silent?: boolean
logInColor?: boolean
logDepth?: number
maxConnections?: number
retry?: number
maxRetries?: boolean
stopRetrying?: boolean
}
let defaultOptions: IIpcServeOptions = {
appspace: 'app.',
socketRoot: '/tmp/',
id: plugins.os.hostname(),
networkHost: 'localhost', //should resolve to 127.0.0.1 or ::1 see the table below related to this
networkPort: 8000,
encoding: 'utf8',
rawBuffer: false,
sync: false,
silent: false,
logInColor: true,
logDepth: 5,
maxConnections: 100,
retry: 500,
maxRetries: false,
stopRetrying: false
}
export class IpcServe {
ipcOptions: IIpcServeOptions
constructor(ipcOptionsArg: IIpcServeOptions) {
this.ipcOptions = plugins.lodash.merge({},defaultOptions,ipcOptionsArg)
}
}

1
test/test.d.ts vendored Normal file
View File

@ -0,0 +1 @@
import 'typings-test';

12
test/test.js Normal file
View File

@ -0,0 +1,12 @@
"use strict";
require("typings-test");
const should = require("should");
const smartipc = require("../dist/index");
let testIpcMaster;
describe('smartipc', function () {
it('should create an instance of IpcMaster', function () {
testIpcMaster = new smartipc.IpcMaster({});
should(testIpcMaster).be.instanceof(smartipc.IpcMaster);
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMsMENBQXlDO0FBRXpDLElBQUksYUFBaUMsQ0FBQTtBQUVyQyxRQUFRLENBQUMsVUFBVSxFQUFDO0lBQ2hCLEVBQUUsQ0FBQyx3Q0FBd0MsRUFBQztRQUN4QyxhQUFhLEdBQUcsSUFBSSxRQUFRLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQyxDQUFBO1FBQzFDLE1BQU0sQ0FBQyxhQUFhLENBQUMsQ0FBQyxFQUFFLENBQUMsVUFBVSxDQUFDLFFBQVEsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUMzRCxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

13
test/test.ts Normal file
View File

@ -0,0 +1,13 @@
import 'typings-test'
import * as should from 'should'
import * as smartipc from '../dist/index'
let testIpcMaster: smartipc.IpcMaster
describe('smartipc',function(){
it('should create an instance of IpcMaster',function(){
testIpcMaster = new smartipc.IpcMaster({})
should(testIpcMaster).be.instanceof(smartipc.IpcMaster)
})
})

2
ts/index.ts Normal file
View File

@ -0,0 +1,2 @@
export * from './smartipc.classes.ipcmaster'
export * from './smartipc.classes.ipcchild'

View File

@ -0,0 +1,22 @@
import * as plugins from './smartipc.plugins'
import { IpcTarget } from './smartipc.classes.ipctarget'
export interface IpcChildConstructorOptions {
}
let defaultOptions: IpcChildConstructorOptions = {
}
/**
* class Ipcclient represents the child process
*/
export class IpcChild extends IpcTarget {
constructor(optionsArg: IpcChildConstructorOptions) {
super({alias: 'child'})
}
call(ipctarget,targetFunction,dataArg) {
}
}

View File

@ -0,0 +1,48 @@
import * as plugins from './smartipc.plugins'
import { IpcTarget } from './smartipc.classes.ipctarget'
export interface IIpcServeOptions {
}
let defaultOptions: IIpcServeOptions = {
}
export interface IIpcChildProcess {
alias: string
filePath: string
childProcess: plugins.childProcess.ChildProcess
}
/**
* class Ipcserve is represents the master process for any chil processes
*/
export class IpcMaster extends IpcTarget {
ipcOptions: IIpcServeOptions
childProcessArray: IIpcChildProcess[]
constructor(ipcOptionsArg: IIpcServeOptions) {
super({alias: 'master'})
this.ipcOptions = plugins.lodash.merge({},defaultOptions,ipcOptionsArg)
}
/**
* spawns a child process
*/
spawnProcess(filePath: string, alias: string) {
let childProcess = plugins.childProcess.fork('ls', ['-lh', '/usr'])
childProcess.stdout.on('data', (data) => {
console.log(`stdout: ${data}`)
})
childProcess.stderr.on('data', (data) => {
console.log(`stderr: ${data}`)
})
childProcess.on('close', (code) => {
console.log(`child process exited with code ${code}`)
})
}
}

View File

@ -0,0 +1,27 @@
import * as plugins from './smartipc.plugins'
export interface ITargetConstructorOptions {
alias: string
}
/**
*
*/
export class IpcTarget {
alias: string
private funcArray: any[]
constructor(optionsArg: ITargetConstructorOptions) {
this.alias = optionsArg.alias
}
/**
* registers a function
*/
register(funcArrayArg: any[]) {
for (let funcItem of funcArrayArg){
this.funcArray.push(funcItem)
}
}
}

View File

@ -1,5 +1,4 @@
import 'typings-global'
export import beautylog = require('beautylog')
export import lodash = require('lodash')
export let nodeIpc = require('node-ipc')
export import os = require('os')
export import childProcess = require('child_process')