Asher 72bf4547d4
Getting the client to run (#12)
* Clean up workbench and integrate initialization data

* Uncomment Electron fill

* Run server & client together

* Clean up Electron fill & patch

* Bind fs methods

This makes them usable with the promise form:
`promisify(access)(...)`.

* Add space between tag and title to browser logger

* Add typescript dep to server and default __dirname for path

* Serve web files from server

* Adjust some dev options

* Rework workbench a bit to use a class and catch unexpected errors

* No mkdirs for now, fix util fill, use bash with exec

* More fills, make general client abstract

* More fills

* Fix cp.exec

* Fix require calls in fs fill being aliased

* Create data and storage dir

* Implement fs.watch

Using exec for now.

* Implement storage database fill

* Fix os export and homedir

* Add comment to use navigator.sendBeacon

* Fix fs callbacks (some args are optional)

* Make sure data directory exists when passing it back

* Update patch

* Target es5

* More fills

* Add APIs required for bootstrap-fork to function (#15)

* Add bootstrap-fork execution

* Add createConnection

* Bundle bootstrap-fork into cli

* Remove .node directory created from spdlog

* Fix npm start

* Remove unnecessary comment

* Add webpack-hot-middleware if CLI env is not set

* Add restarting to shared process

* Fix starting with yarn
2019-02-05 11:15:50 -06:00

74 lines
1.8 KiB
TypeScript

import * as cp from "child_process";
import { EventEmitter } from "events";
import * as nodePty from "node-pty";
type nodePtyType = typeof nodePty;
/**
* Implementation of nodePty for the browser.
*/
class Pty implements nodePty.IPty {
private readonly emitter: EventEmitter;
public constructor(file: string, args: string[] | string, options: nodePty.IPtyForkOptions) {
this.emitter = new EventEmitter();
const session = wush.execute({
command: `${file} ${Array.isArray(args) ? args.join(" ") : args}`,
directory: options.cwd,
environment: {
...(options.env || {}),
TERM: "xterm-color",
},
size: options && options.cols && options.rows ? {
columns: options.cols,
rows: options.rows,
} : {
columns: 100,
rows: 100,
},
});
this.on("write", (data) => session.sendStdin(data));
this.on("kill", (exitCode) => session.close());
this.on("resize", (columns, rows) => session.setSize({ columns, rows }));
session.onStdout((data) => this.emitter.emit("data", data));
session.onStderr((data) => this.emitter.emit("data", data));
session.onDone((exitCode) => this.emitter.emit("exit", exitCode));
}
public get pid(): number {
return 1;
}
public get process(): string {
return "unknown";
}
public on(event: string, listener: (...args) => void): void {
this.emitter.on(event, listener);
}
public resize(columns: number, rows: number): void {
this.emitter.emit("resize", columns, rows);
}
public write(data: string): void {
this.emitter.emit("write", data);
}
public kill(signal?: string): void {
this.emitter.emit("kill", signal);
}
}
const ptyType: nodePtyType = {
spawn: (file: string, args: string[] | string, options: nodePty.IPtyForkOptions): nodePty.IPty => {
return new Pty(file, args, options);
},
};
exports = ptyType;