Some small refactoring

This commit is contained in:
Gregory Schier
2024-07-21 22:18:45 -07:00
parent 3cd7c1ef2e
commit 19280c3bbc
4 changed files with 16 additions and 16 deletions

View File

@@ -76,12 +76,12 @@ async function* errorHandlingMiddleware<Request, Response>(
server = server.use(errorHandlingMiddleware);
server.add(PluginRuntimeDefinition, new PluginRuntimeService());
// Start on random port if GRPC_PORT_FILE_PATH is set, or :4000
const addr = process.env.GRPC_PORT_FILE_PATH ? 'localhost:0' : 'localhost:4000';
// Start on random port if YAAK_GRPC_PORT_FILE_PATH is set, or :4000
const addr = process.env.YAAK_GRPC_PORT_FILE_PATH ? 'localhost:0' : 'localhost:4000';
server.listen(addr).then((port) => {
console.log('gRPC server listening on', `http://localhost:${port}`);
if (process.env.GRPC_PORT_FILE_PATH) {
console.log('Wrote port file to', process.env.GRPC_PORT_FILE_PATH);
fs.writeFileSync(process.env.GRPC_PORT_FILE_PATH, JSON.stringify({ port }, null, 2));
if (process.env.YAAK_GRPC_PORT_FILE_PATH) {
console.log('Wrote port file to', process.env.YAAK_GRPC_PORT_FILE_PATH);
fs.writeFileSync(process.env.YAAK_GRPC_PORT_FILE_PATH, JSON.stringify({ port }, null, 2));
}
});

View File

@@ -9,7 +9,7 @@ export interface PluginInfo {
}
export function loadPlugins(): PluginHandle[] {
const pluginsDir = process.env.PLUGINS_DIR;
const pluginsDir = process.env.YAAK_PLUGINS_DIR;
if (!pluginsDir) throw new Error('PLUGINS_DIR is not set');
console.log('Loading plugins from', pluginsDir);

View File

@@ -1,20 +1,20 @@
const {readdirSync, cpSync} = require("node:fs");
const path = require("node:path");
const {execSync} = require("node:child_process");
const PLUGINS_DIR = process.env.YAAK_PLUGINS_DIR;
if (!PLUGINS_DIR) {
const pluginsDir = process.env.YAAK_PLUGINS_DIR;
if (!pluginsDir) {
console.log("YAAK_PLUGINS_DIR is not set");
process.exit(1);
}
console.log('Installing Yaak plugins dependencies', PLUGINS_DIR);
execSync('npm ci', {cwd: PLUGINS_DIR});
console.log('Building Yaak plugins', PLUGINS_DIR);
execSync('npm run build', {cwd: PLUGINS_DIR});
console.log('Installing Yaak plugins dependencies', pluginsDir);
execSync('npm ci', {cwd: pluginsDir});
console.log('Building Yaak plugins', pluginsDir);
execSync('npm run build', {cwd: pluginsDir});
console.log('Copying Yaak plugins to', PLUGINS_DIR);
console.log('Copying Yaak plugins to', pluginsDir);
const pluginsRoot = path.join(PLUGINS_DIR, 'plugins');
const pluginsRoot = path.join(pluginsDir, 'plugins');
for (const name of readdirSync(pluginsRoot)) {
const dir = path.join(pluginsRoot, name);
if (name.startsWith('.')) continue;

View File

@@ -45,8 +45,8 @@ pub async fn node_start<R: Runtime>(app: &AppHandle<R>, temp_dir: &PathBuf) -> S
.shell()
.sidecar("node")
.unwrap()
.env("GRPC_PORT_FILE_PATH", port_file_path.clone())
.env("PLUGINS_DIR", plugins_dir)
.env("YAAK_GRPC_PORT_FILE_PATH", port_file_path.clone())
.env("YAAK_PLUGINS_DIR", plugins_dir)
.args(&[plugin_runtime_dir.join("index.cjs")])
.spawn()
.unwrap();