57 lines
2.2 KiB
JavaScript
57 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
// DSHWatch: wire the dsh-watch plugin into a DSH profile (web or desktop).
|
|
// Usage: node setup-plugin.mjs [profile] [pluginPath]
|
|
// node setup-plugin.mjs desktop
|
|
// node setup-plugin.mjs web D:/project/DeepSeek_Harness_Watch/dsh-watch
|
|
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
const profile = process.argv[2] || 'desktop';
|
|
const defaultPlugin = path.resolve(here, '..', '..', 'dsh-watch');
|
|
const pluginPath = path.resolve(process.argv[3] || defaultPlugin);
|
|
|
|
const dshHome = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
|
|
const profileDir = path.join(dshHome, 'profiles', profile);
|
|
const pkgPath = path.join(profileDir, 'package.json');
|
|
|
|
if (!fs.existsSync(pkgPath)) {
|
|
console.error('[setup-plugin] profile not found:', pkgPath);
|
|
process.exit(1);
|
|
}
|
|
|
|
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
const depKey = 'dsh-watch';
|
|
const depValue = 'link:' + pluginPath;
|
|
|
|
pkg.dependencies = pkg.dependencies || {};
|
|
if (pkg.dependencies[depKey] !== depValue) pkg.dependencies[depKey] = depValue;
|
|
|
|
pkg.dsh = pkg.dsh || {};
|
|
pkg.dsh.profile = pkg.dsh.profile || {};
|
|
pkg.dsh.profile.bundles = pkg.dsh.profile.bundles || [];
|
|
if (!pkg.dsh.profile.bundles.includes(depKey)) pkg.dsh.profile.bundles.push(depKey);
|
|
|
|
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
|
|
// Create node_modules link so the loader can resolve it without a full pnpm install.
|
|
const nm = path.join(profileDir, 'node_modules');
|
|
const link = path.join(nm, depKey);
|
|
fs.mkdirSync(nm, { recursive: true });
|
|
if (!fs.existsSync(link)) {
|
|
try {
|
|
fs.symlinkSync(pluginPath, link, 'junction');
|
|
} catch (e) {
|
|
// fall back to copy-ish behavior message
|
|
console.error('[setup-plugin] could not link, will need pnpm install:', e.message);
|
|
}
|
|
}
|
|
|
|
console.log('[setup-plugin] wired dsh-watch into profile=' + profile);
|
|
console.log('[setup-plugin] plugin = ' + pluginPath);
|
|
console.log('[setup-plugin] next: restart DSH, then configure mode/userId/token in profile cordis.patch.yml');
|