mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-07 00:13:41 +02:00
Refactor desktop app into separate client and proxy apps
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
const version = process.env.YAAK_VERSION?.replace('v', '');
|
||||
const version = process.env.YAAK_VERSION?.replace("v", "");
|
||||
if (!version) {
|
||||
throw new Error('YAAK_VERSION environment variable not set')
|
||||
throw new Error("YAAK_VERSION environment variable not set");
|
||||
}
|
||||
|
||||
const tauriConfigPath = path.join(__dirname, '../crates-tauri/yaak-app/tauri.conf.json');
|
||||
const tauriConfig = JSON.parse(fs.readFileSync(tauriConfigPath, 'utf8'));
|
||||
const tauriConfigPath = path.join(
|
||||
__dirname,
|
||||
"../crates-tauri/yaak-app-client/tauri.conf.json",
|
||||
);
|
||||
const tauriConfig = JSON.parse(fs.readFileSync(tauriConfigPath, "utf8"));
|
||||
|
||||
tauriConfig.version = version;
|
||||
|
||||
console.log('Writing version ' + version + ' to ' + tauriConfigPath)
|
||||
console.log("Writing version " + version + " to " + tauriConfigPath);
|
||||
fs.writeFileSync(tauriConfigPath, JSON.stringify(tauriConfig, null, 2));
|
||||
|
||||
@@ -1,32 +1,39 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Runs `npm run dev` in parallel for all workspaces that have a dev script.
|
||||
* Runs `npm run dev` in parallel for the provided workspaces, or all
|
||||
* workspaces with a dev script when none are specified.
|
||||
* Handles cleanup of child processes on exit.
|
||||
*/
|
||||
|
||||
import { spawn } from 'child_process';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { spawn } from "child_process";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const rootDir = path.join(__dirname, '..');
|
||||
const rootDir = path.join(__dirname, "..");
|
||||
|
||||
// Read root package.json to get workspaces
|
||||
const rootPkg = JSON.parse(fs.readFileSync(path.join(rootDir, 'package.json'), 'utf8'));
|
||||
const rootPkg = JSON.parse(
|
||||
fs.readFileSync(path.join(rootDir, "package.json"), "utf8"),
|
||||
);
|
||||
const workspaces = rootPkg.workspaces || [];
|
||||
|
||||
// Find all workspaces with a dev script
|
||||
const workspacesWithDev = workspaces.filter((ws) => {
|
||||
const pkgPath = path.join(rootDir, ws, 'package.json');
|
||||
const requestedWorkspaces = process.argv.slice(2);
|
||||
const workspaceCandidates =
|
||||
requestedWorkspaces.length > 0 ? requestedWorkspaces : workspaces;
|
||||
|
||||
// Find all candidate workspaces with a dev script
|
||||
const workspacesWithDev = workspaceCandidates.filter((ws) => {
|
||||
const pkgPath = path.join(rootDir, ws, "package.json");
|
||||
if (!fs.existsSync(pkgPath)) return false;
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
||||
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
||||
return pkg.scripts?.dev != null;
|
||||
});
|
||||
|
||||
if (workspacesWithDev.length === 0) {
|
||||
console.log('No workspaces with dev script found');
|
||||
console.log("No workspaces with dev script found");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
@@ -37,13 +44,13 @@ const children = [];
|
||||
// Spawn all dev processes
|
||||
for (const ws of workspacesWithDev) {
|
||||
const cwd = path.join(rootDir, ws);
|
||||
const child = spawn('npm', ['run', 'dev'], {
|
||||
const child = spawn("npm", ["run", "dev"], {
|
||||
cwd,
|
||||
stdio: 'inherit',
|
||||
shell: process.platform === 'win32',
|
||||
stdio: "inherit",
|
||||
shell: process.platform === "win32",
|
||||
});
|
||||
|
||||
child.on('error', (err) => {
|
||||
child.on("error", (err) => {
|
||||
console.error(`Error in ${ws}:`, err.message);
|
||||
});
|
||||
|
||||
@@ -55,27 +62,27 @@ function cleanup() {
|
||||
for (const { ws, child } of children) {
|
||||
if (child.exitCode === null) {
|
||||
// Process still running
|
||||
if (process.platform === 'win32') {
|
||||
spawn('taskkill', ['/pid', child.pid, '/f', '/t'], { shell: true });
|
||||
if (process.platform === "win32") {
|
||||
spawn("taskkill", ["/pid", child.pid, "/f", "/t"], { shell: true });
|
||||
} else {
|
||||
child.kill('SIGTERM');
|
||||
child.kill("SIGTERM");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle various exit signals
|
||||
process.on('SIGINT', () => {
|
||||
process.on("SIGINT", () => {
|
||||
cleanup();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
process.on("SIGTERM", () => {
|
||||
cleanup();
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('exit', cleanup);
|
||||
process.on("exit", cleanup);
|
||||
|
||||
// Keep the process running
|
||||
process.stdin.resume();
|
||||
|
||||
@@ -1,31 +1,37 @@
|
||||
const { readdirSync, cpSync, existsSync, mkdirSync } = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const { readdirSync, cpSync, existsSync, mkdirSync } = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
const pluginsDir = path.join(__dirname, '..', 'plugins');
|
||||
const externalPluginsDir = path.join(__dirname, '..', 'plugins-external');
|
||||
const pluginsDir = path.join(__dirname, "..", "plugins");
|
||||
const externalPluginsDir = path.join(__dirname, "..", "plugins-external");
|
||||
|
||||
// Get list of external (non-bundled) plugins
|
||||
const externalPlugins = new Set();
|
||||
if (existsSync(externalPluginsDir)) {
|
||||
for (const name of readdirSync(externalPluginsDir)) {
|
||||
if (!name.startsWith('.')) {
|
||||
if (!name.startsWith(".")) {
|
||||
externalPlugins.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Copying Yaak plugins to', pluginsDir);
|
||||
console.log("Copying Yaak plugins to", pluginsDir);
|
||||
|
||||
for (const name of readdirSync(pluginsDir)) {
|
||||
const dir = path.join(pluginsDir, name);
|
||||
if (name.startsWith('.')) continue;
|
||||
if (name.startsWith(".")) continue;
|
||||
if (externalPlugins.has(name)) {
|
||||
console.log(`Skipping ${name} (external plugin)`);
|
||||
continue;
|
||||
}
|
||||
const destDir = path.join(__dirname, '../crates-tauri/yaak-app/vendored/plugins/', name);
|
||||
const destDir = path.join(
|
||||
__dirname,
|
||||
"../crates-tauri/yaak-app-client/vendored/plugins/",
|
||||
name,
|
||||
);
|
||||
mkdirSync(destDir, { recursive: true });
|
||||
console.log(`Copying ${name} to ${destDir}`);
|
||||
cpSync(path.join(dir, 'package.json'), path.join(destDir, 'package.json'));
|
||||
cpSync(path.join(dir, 'build'), path.join(destDir, 'build'), { recursive: true });
|
||||
cpSync(path.join(dir, "package.json"), path.join(destDir, "package.json"));
|
||||
cpSync(path.join(dir, "build"), path.join(destDir, "build"), {
|
||||
recursive: true,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user