Compare commits
No commits in common. "48f2503807a6f7ad7eb45388524bccb505889fa3" and "9ff5ab5aa6da6d412ce5a98e1424af995260ec34" have entirely different histories.
48f2503807
...
9ff5ab5aa6
|
@ -191,12 +191,6 @@
|
||||||
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"builtin-modules": {
|
|
||||||
"version": "3.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.2.0.tgz",
|
|
||||||
"integrity": "sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==",
|
|
||||||
"dev": true
|
|
||||||
},
|
|
||||||
"cacheable-request": {
|
"cacheable-request": {
|
||||||
"version": "6.1.0",
|
"version": "6.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz",
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
"@snowpack/plugin-svelte": "^3.5.2",
|
"@snowpack/plugin-svelte": "^3.5.2",
|
||||||
"@snowpack/plugin-typescript": "^1.2.1",
|
"@snowpack/plugin-typescript": "^1.2.1",
|
||||||
"@tsconfig/svelte": "^1.0.10",
|
"@tsconfig/svelte": "^1.0.10",
|
||||||
"@types/node": "^14.14.28",
|
|
||||||
"builtin-modules": "^3.2.0",
|
|
||||||
"concurrently": "^5.3.0",
|
"concurrently": "^5.3.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"electron": "^11.2.3",
|
"electron": "^11.2.3",
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
/** @type {import("snowpack").SnowpackUserConfig } */
|
/** @type {import("snowpack").SnowpackUserConfig } */
|
||||||
const builtinModules = require('builtin-modules')
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mount: {
|
mount: {
|
||||||
/* ... */
|
/* ... */
|
||||||
|
@ -24,7 +22,6 @@ module.exports = {
|
||||||
},
|
},
|
||||||
packageOptions: {
|
packageOptions: {
|
||||||
/* ... */
|
/* ... */
|
||||||
external: [...builtinModules.filter((external) => external !== 'process'), 'electron'],
|
|
||||||
},
|
},
|
||||||
devOptions: {
|
devOptions: {
|
||||||
/* ... */
|
/* ... */
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import { createServiceBroker, ServiceBroker } from './service/spawner'
|
const { spawn } = require('child_process')
|
||||||
import AppHeader from './components/AppHeader.svelte'
|
import AppHeader from './components/AppHeader.svelte'
|
||||||
|
|
||||||
let count: number = 0
|
let count: number = 0
|
||||||
let serviceBroker: ServiceBroker
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(() => {
|
||||||
const interval = setInterval(() => count++, 1000)
|
const interval = setInterval(() => count++, 1000)
|
||||||
serviceBroker = await createServiceBroker("../../service/service")
|
|
||||||
// TODO: Spin up service
|
// TODO: Spin up service
|
||||||
return () => {
|
return () => {
|
||||||
serviceBroker.close()
|
|
||||||
clearInterval(interval)
|
clearInterval(interval)
|
||||||
// TODO: Close service
|
// TODO: Close service
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
let { TransformOptions, Transform, Readable, Writable } = require('stream')
|
|
||||||
//import { TransformOptions, Transform, Readable, Writable } from 'stream'
|
|
||||||
|
|
||||||
class JSONReader extends Transform {
|
|
||||||
constructor(options: typeof TransformOptions) {
|
|
||||||
super(options)
|
|
||||||
}
|
|
||||||
_transform(data: string, encoding: string, cb: (chunk:any, err?:any) => void) {
|
|
||||||
try {
|
|
||||||
cb(null, JSON.parse(data))
|
|
||||||
} catch(err) {
|
|
||||||
// Silently fail as this means the stream presumably hasn't finished writing yet.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ServiceBroker {
|
|
||||||
|
|
||||||
protected jsonWriter: typeof Transform = new Transform({
|
|
||||||
objectMode: true,
|
|
||||||
})
|
|
||||||
protected errorReader: typeof Transform = new Transform({ })
|
|
||||||
protected jsonReader: JSONReader = new JSONReader({
|
|
||||||
objectMode: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
constructor(input: typeof Readable, output: typeof Writable, error: typeof Readable) {
|
|
||||||
// Set up our reader callback.
|
|
||||||
this.jsonReader.on("data", (json: any) => {
|
|
||||||
// TODO: Something with our object
|
|
||||||
console.log("got json data: ", json)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Pipe the input(process's stdout) to our JSONReader.
|
|
||||||
input.pipe(this.jsonReader)
|
|
||||||
|
|
||||||
// Send our immediate message to enable JSON mode.
|
|
||||||
output.write(JSON.stringify({enableJSON: true}))
|
|
||||||
|
|
||||||
//this.jsonWriter.pipe(output)
|
|
||||||
//error.pipe(this.errorReader)
|
|
||||||
/*this.errorReader.on("data", (chunk) => {
|
|
||||||
console.log("got error data: ", chunk)
|
|
||||||
})*/
|
|
||||||
input.once('close', () => {
|
|
||||||
// ...
|
|
||||||
})
|
|
||||||
output.once('close', () => {
|
|
||||||
this.close()
|
|
||||||
})
|
|
||||||
|
|
||||||
// stdinCb: (arg0: string) => void, StdoutCb: (arg0: string) => void, StderrCb: (arg0: string) => void) {
|
|
||||||
}
|
|
||||||
onInput(d: string): void {
|
|
||||||
}
|
|
||||||
close(): void {
|
|
||||||
console.log('should close')
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
let { spawn } = require('child_process')
|
|
||||||
let os = require('os')
|
|
||||||
/*import { spawn } from 'child_process'
|
|
||||||
import os from 'os'*/
|
|
||||||
//import path from 'path'
|
|
||||||
let path = require('path')
|
|
||||||
import { ServiceBroker } from './ServiceBroker'
|
|
||||||
|
|
||||||
export async function createServiceBroker(exe = "service" + (os.platform()==='win32'?'.exe':'')): Promise<ServiceBroker> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
let broker: ServiceBroker
|
|
||||||
let process = spawn(exe, {
|
|
||||||
cwd: '',
|
|
||||||
})
|
|
||||||
|
|
||||||
// We're keeping track of if an error happened so we can check if the process actually spawned...
|
|
||||||
let hadError: Error
|
|
||||||
process.once('error', (err: Error) => {
|
|
||||||
hadError = err
|
|
||||||
if (broker) {
|
|
||||||
broker.close()
|
|
||||||
}
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
|
|
||||||
// FIXME: This timeout is super-hacky, but Electron uses node 12 which does not provide the 'spawn' event for the ChildProcess type.
|
|
||||||
setTimeout(() => {
|
|
||||||
if (hadError) {
|
|
||||||
reject(hadError)
|
|
||||||
} else {
|
|
||||||
process.once('close', (code: number) => {
|
|
||||||
if (broker) {
|
|
||||||
broker.close()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
broker = new ServiceBroker(process.stdout, process.stdin, process.stderr)
|
|
||||||
resolve(broker)
|
|
||||||
}
|
|
||||||
}, 100)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export { ServiceBroker }
|
|
|
@ -1,18 +1,21 @@
|
||||||
{
|
{
|
||||||
"extends": "@tsconfig/svelte/tsconfig.json",
|
"include": ["src", "types"],
|
||||||
"include": [
|
|
||||||
"./src/**/*.ts",
|
|
||||||
"types",
|
|
||||||
"node_modules/@types",
|
|
||||||
],
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
|
"target": "esnext",
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"jsx": "preserve",
|
||||||
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
},
|
},
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
|
"strict": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"useDefineForClassFields": true,
|
"useDefineForClassFields": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"importsNotUsedAsValues": "error",
|
"importsNotUsedAsValues": "error"
|
||||||
}
|
},
|
||||||
|
"extends": "@tsconfig/svelte/tsconfig.json"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue