switch to native ipc to scale down on dependencies
This commit is contained in:
2
ts/index.ts
Normal file
2
ts/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './smartipc.classes.ipcmaster'
|
||||
export * from './smartipc.classes.ipcchild'
|
22
ts/smartipc.classes.ipcchild.ts
Normal file
22
ts/smartipc.classes.ipcchild.ts
Normal 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) {
|
||||
|
||||
}
|
||||
}
|
48
ts/smartipc.classes.ipcmaster.ts
Normal file
48
ts/smartipc.classes.ipcmaster.ts
Normal 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}`)
|
||||
})
|
||||
}
|
||||
}
|
27
ts/smartipc.classes.ipctarget.ts
Normal file
27
ts/smartipc.classes.ipctarget.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
4
ts/smartipc.plugins.ts
Normal file
4
ts/smartipc.plugins.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import 'typings-global'
|
||||
export import beautylog = require('beautylog')
|
||||
export import lodash = require('lodash')
|
||||
export import childProcess = require('child_process')
|
Reference in New Issue
Block a user