@jmanuelcorral/bond-app 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +280 -23
- package/app/brand/TOKENS.md +5 -5
- package/app/layouts/bond.json +10 -14
- package/app/mods/bond-agents/api.js +35 -0
- package/app/mods/bond-agents/branch.svg +1 -0
- package/app/mods/bond-agents/brand.js +53 -2
- package/app/mods/bond-agents/config.js +4 -0
- package/app/mods/bond-agents/eye-off.svg +1 -0
- package/app/mods/bond-agents/eye.svg +1 -0
- package/app/mods/bond-agents/main.js +308 -327
- package/app/mods/bond-agents/model.js +376 -5
- package/app/mods/bond-board/api.js +35 -0
- package/app/mods/bond-board/branch.svg +1 -0
- package/app/mods/bond-board/brand.js +53 -2
- package/app/mods/bond-board/config.js +4 -0
- package/app/mods/bond-board/main.js +1000 -449
- package/app/mods/bond-board/model.js +170 -28
- package/app/mods/bond-pane/close.svg +1 -0
- package/app/mods/bond-pane/hide.svg +1 -0
- package/app/mods/bond-pane/main.js +103 -0
- package/app/mods/bond-pane/mod.json +1 -0
- package/app/mods/bond-pane/model.js +18 -0
- package/app/mods/bond-pane/split-down.svg +1 -0
- package/app/mods/bond-pane/split-right.svg +1 -0
- package/app/mods/bond-pane/unzoom.svg +1 -0
- package/app/mods/bond-pane/zoom.svg +1 -0
- package/app/mods/bond-settings/api.js +35 -0
- package/app/mods/bond-settings/brand.js +53 -2
- package/app/mods/bond-settings/config.js +4 -0
- package/app/mods/bond-settings/main.js +1216 -272
- package/app/mods/bond-settings/mod.json +1 -1
- package/app/mods/bond-status/api.js +35 -0
- package/app/mods/bond-status/brand.js +53 -2
- package/app/mods/bond-status/config.js +4 -0
- package/app/mods/bond-status/main.js +37 -15
- package/app/mods/bond-status/model.js +19 -1
- package/app/mods/bond-tabs/brand.js +53 -2
- package/app/mods/bond-tabs/main.js +45 -3
- package/app/mods/bond-titlebar/brand.js +53 -2
- package/app/mods/bond-titlebar/main.js +85 -29
- package/app/mods/bond-titlebar/version.js +3 -0
- package/app/themes/bond-dark.json +5 -5
- package/app/themes/bond-light.json +5 -5
- package/package.json +1 -1
- package/runner/Dockerfile +16 -2
- package/runner/SPIKE-BOND.md +6 -2
- package/runner/entrypoint.sh +16 -0
- package/runner/setup.sh +439 -8
- package/runner/versions.env +32 -1
- package/scripts/app-install.ts +322 -27
- package/src/cli.ts +562 -21
- package/src/config.ts +15 -3
- package/src/core/agy-login.ts +683 -0
- package/src/core/delivery.ts +125 -6
- package/src/core/doctor.ts +748 -0
- package/src/core/hub-session.ts +108 -91
- package/src/core/hub.ts +40 -8
- package/src/core/orchestrator.ts +1481 -187
- package/src/core/paths.ts +107 -0
- package/src/core/permissions.ts +143 -0
- package/src/core/pr-source.ts +147 -0
- package/src/core/repo-host.ts +60 -0
- package/src/core/service-windows.ts +180 -0
- package/src/core/service.ts +861 -0
- package/src/core/setup-install.ts +1380 -0
- package/src/core/setup.ts +62 -1
- package/src/core/watchdog.ts +6 -6
- package/src/db/database.ts +54 -7
- package/src/db/settings-repo.ts +332 -7
- package/src/db/ticket-repo.ts +73 -25
- package/src/index.ts +4 -4
- package/src/runner/azure-devops-client.ts +273 -0
- package/src/runner/docker-client.ts +93 -9
- package/src/runner/github-client.ts +148 -3
- package/src/runner/hc-client.ts +33 -5
- package/src/runner/image-builder.ts +123 -5
- package/src/runner/jira-client.ts +368 -0
- package/src/runner/tool-catalog.ts +84 -0
- package/src/server/app.ts +467 -8
- package/src/types.ts +140 -2
package/scripts/app-install.ts
CHANGED
|
@@ -23,12 +23,17 @@
|
|
|
23
23
|
* on each installed mod), --skip-version-check, --force, --launcher, --remove-launcher.
|
|
24
24
|
*/
|
|
25
25
|
import fs from 'node:fs';
|
|
26
|
-
import os from 'node:os';
|
|
27
26
|
import path from 'node:path';
|
|
28
27
|
import crypto from 'node:crypto';
|
|
29
28
|
import { execFileSync } from 'node:child_process';
|
|
30
29
|
import { fileURLToPath } from 'node:url';
|
|
31
30
|
import { MIN_HC_VERSION, MIN_HERDR_APP_VERSION, compareVersions } from '../src/runner/hc-client.ts';
|
|
31
|
+
import {
|
|
32
|
+
defaultDataDir,
|
|
33
|
+
defaultHerdrAppHome,
|
|
34
|
+
defaultLauncherDataHome,
|
|
35
|
+
windowsStartMenuShortcutPath,
|
|
36
|
+
} from '../src/core/paths.ts';
|
|
32
37
|
|
|
33
38
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
34
39
|
const appDir = path.join(repoRoot, 'app');
|
|
@@ -44,10 +49,14 @@ export interface InstallOptions {
|
|
|
44
49
|
skipVersionCheck: boolean;
|
|
45
50
|
force: boolean;
|
|
46
51
|
launcher: boolean;
|
|
47
|
-
/** Where the launcher goes ($XDG_DATA_HOME
|
|
52
|
+
/** Where the launcher goes ($XDG_DATA_HOME / ~/.local/share on POSIX, %APPDATA% on Windows). */
|
|
48
53
|
dataHome: string;
|
|
49
54
|
/** --home or HERDR_APP_HOME given: the launcher passes it on to herdr-app. */
|
|
50
55
|
customHome: boolean;
|
|
56
|
+
/** Target platform override (for testing). */
|
|
57
|
+
platform?: NodeJS.Platform;
|
|
58
|
+
/** Injectable command runner (for testing Windows PowerShell shortcut creation). */
|
|
59
|
+
runCommand?: (cmd: string, args: string[]) => void;
|
|
51
60
|
}
|
|
52
61
|
|
|
53
62
|
export interface InstallResult {
|
|
@@ -76,9 +85,9 @@ export function parseInstallArgs(argv: string[]): InstallOptions {
|
|
|
76
85
|
};
|
|
77
86
|
const port = process.env.BOND_APP_PORT || '3000';
|
|
78
87
|
const homeArg = get('--home') || process.env.HERDR_APP_HOME || null;
|
|
79
|
-
const dataDir = process.env.BOND_APP_DATA_DIR
|
|
88
|
+
const dataDir = process.env.BOND_APP_DATA_DIR ? defaultDataDir() : null;
|
|
80
89
|
return {
|
|
81
|
-
home: homeArg ||
|
|
90
|
+
home: homeArg || defaultHerdrAppHome(),
|
|
82
91
|
api: get('--api') || `http://127.0.0.1:${port}/api/v1`,
|
|
83
92
|
tokenFile: get('--token-file') || (dataDir ? path.join(dataDir, 'token') : null),
|
|
84
93
|
check: argv.includes('--check'),
|
|
@@ -91,8 +100,7 @@ export function parseInstallArgs(argv: string[]): InstallOptions {
|
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
function dataHome(): string {
|
|
94
|
-
|
|
95
|
-
return xdg && path.isAbsolute(xdg) ? xdg : path.join(os.homedir(), '.local', 'share');
|
|
103
|
+
return defaultLauncherDataHome();
|
|
96
104
|
}
|
|
97
105
|
|
|
98
106
|
function versionOf(cmd: string): string | null {
|
|
@@ -122,6 +130,60 @@ function validateApi(api: string): void {
|
|
|
122
130
|
}
|
|
123
131
|
}
|
|
124
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The layout bond-app installed may hold `bond-runterm` blocks that the Agents panel used
|
|
135
|
+
* to write in PANELES before it became native splits (plan bond-app-pestanas-paneles E2).
|
|
136
|
+
* Without them, re-serialised as the mod did (JSON, 2 spaces, with or without the final
|
|
137
|
+
* newline), it is still our copy: these are the hashes that prove it.
|
|
138
|
+
*/
|
|
139
|
+
export function layoutHashes(file: string): string[] {
|
|
140
|
+
const hashes = [sha256(file)];
|
|
141
|
+
try {
|
|
142
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
143
|
+
// Only a layout that carries those blocks: any other edit, even whitespace, is the person's.
|
|
144
|
+
if (!text.includes('"bond-runterm"')) return hashes;
|
|
145
|
+
const doc = JSON.parse(text);
|
|
146
|
+
const strip = (n: { children?: unknown[] }) => {
|
|
147
|
+
if (n && Array.isArray(n.children)) {
|
|
148
|
+
n.children = n.children.filter((c) => (c as { id?: string })?.id !== 'bond-runterm');
|
|
149
|
+
n.children.forEach((c) => strip(c as { children?: unknown[] }));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
strip(doc);
|
|
153
|
+
const out = JSON.stringify(doc, null, 2);
|
|
154
|
+
for (const text of [out, `${out}\n`]) hashes.push(crypto.createHash('sha256').update(text).digest('hex'));
|
|
155
|
+
} catch {
|
|
156
|
+
// Not JSON: only its own hash.
|
|
157
|
+
}
|
|
158
|
+
return hashes;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** bond-app's version (package.json), for the title bar chip. */
|
|
162
|
+
export function appVersion(): string {
|
|
163
|
+
try {
|
|
164
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8')) as { version?: unknown };
|
|
165
|
+
return typeof pkg.version === 'string' && pkg.version ? pkg.version : 'dev';
|
|
166
|
+
} catch {
|
|
167
|
+
return 'dev';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function versionJs(version: string): string {
|
|
172
|
+
return [
|
|
173
|
+
'// Written by `npm run app:install` (bond-app) from package.json.',
|
|
174
|
+
`export const VERSION = ${JSON.stringify(version)};`,
|
|
175
|
+
'',
|
|
176
|
+
].join('\n');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** The command that starts the orchestrator these mods talk to (same node, same bin). */
|
|
180
|
+
export function startArgv(api: string, tokenFile: string | null): string[] {
|
|
181
|
+
const url = new URL(api);
|
|
182
|
+
const argv = [process.execPath, path.join(repoRoot, 'bin', 'bond-app.js'), 'start', '--port', url.port || '80'];
|
|
183
|
+
if (tokenFile) argv.push('--data-dir', path.dirname(path.resolve(tokenFile)));
|
|
184
|
+
return argv;
|
|
185
|
+
}
|
|
186
|
+
|
|
125
187
|
function configJs(api: string, tokenFile: string | null): string {
|
|
126
188
|
return [
|
|
127
189
|
'// Written by `npm run app:install` (bond-app). The token itself is never written here:',
|
|
@@ -133,6 +195,8 @@ function configJs(api: string, tokenFile: string | null): string {
|
|
|
133
195
|
' // registrando cost_usd, pero la UI no lo muestra hasta que una configuración',
|
|
134
196
|
' // en Ajustes lo active. Entonces esto será el valor de esa configuración.',
|
|
135
197
|
' costs: false,',
|
|
198
|
+
' // How to start the orchestrator (Ajustes «Arrancar orquestador»).',
|
|
199
|
+
` start: ${JSON.stringify(startArgv(api, tokenFile))},`,
|
|
136
200
|
'};',
|
|
137
201
|
'',
|
|
138
202
|
].join('\n');
|
|
@@ -202,7 +266,9 @@ export function install(opts: InstallOptions): InstallResult {
|
|
|
202
266
|
}
|
|
203
267
|
}
|
|
204
268
|
for (const [dest, key] of [[layoutDest, 'layout_sha256'], [previewDest, 'preview_sha256']] as const) {
|
|
205
|
-
if (fs.existsSync(dest)
|
|
269
|
+
if (!fs.existsSync(dest) || opts.force) continue;
|
|
270
|
+
const ours = key === 'layout_sha256' ? layoutHashes(dest) : [sha256(dest)];
|
|
271
|
+
if (!ours.includes(previous?.[key] ?? '')) {
|
|
206
272
|
throw new Error(`${dest} exists and is not the copy bond-app installed (edited, or someone else's): use --force to replace it`);
|
|
207
273
|
}
|
|
208
274
|
}
|
|
@@ -216,7 +282,8 @@ export function install(opts: InstallOptions): InstallResult {
|
|
|
216
282
|
throw new Error(`${dest} exists and is not the copy bond-app installed (edited, or someone else's): use --force to replace it`);
|
|
217
283
|
}
|
|
218
284
|
}
|
|
219
|
-
|
|
285
|
+
const platform = opts.platform ?? process.platform;
|
|
286
|
+
if (opts.launcher) checkLauncher(opts.dataHome, opts.force, platform);
|
|
220
287
|
|
|
221
288
|
fs.mkdirSync(modsDest, { recursive: true });
|
|
222
289
|
fs.mkdirSync(layoutsDest, { recursive: true });
|
|
@@ -246,6 +313,7 @@ export function install(opts: InstallOptions): InstallResult {
|
|
|
246
313
|
for (const f of fs.readdirSync(path.join(appDir, 'brand')).filter((n) => n.endsWith('.svg'))) {
|
|
247
314
|
fs.copyFileSync(path.join(appDir, 'brand', f), path.join(dest, 'brand', f));
|
|
248
315
|
}
|
|
316
|
+
fs.writeFileSync(path.join(dest, 'version.js'), versionJs(appVersion()));
|
|
249
317
|
}
|
|
250
318
|
// Only mods that talk to the API carry a config.js (bond-titlebar doesn't).
|
|
251
319
|
if (fs.existsSync(path.join(modsSrc, name, 'config.js'))) {
|
|
@@ -272,9 +340,101 @@ export function install(opts: InstallOptions): InstallResult {
|
|
|
272
340
|
return { home: opts.home, mods: modNames, layout: layoutDest, versions, checked, themes: themeNames, launcher };
|
|
273
341
|
}
|
|
274
342
|
|
|
343
|
+
export interface AppIntegrationCheckResult {
|
|
344
|
+
installed: boolean;
|
|
345
|
+
upToDate: boolean;
|
|
346
|
+
missing: string[];
|
|
347
|
+
outdated: string[];
|
|
348
|
+
foreign: string[];
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Read-only check of layout, mods and themes in `home` against the copies in `app/`.
|
|
353
|
+
* Never writes or modifies files in `home`.
|
|
354
|
+
*/
|
|
355
|
+
export function checkAppInstalled(home: string): AppIntegrationCheckResult {
|
|
356
|
+
const modsSrc = path.join(appDir, 'mods');
|
|
357
|
+
const modNames = fs.readdirSync(modsSrc).filter((n) => n.startsWith('bond-')).sort();
|
|
358
|
+
const modsDest = path.join(home, 'mods');
|
|
359
|
+
const layoutsDest = path.join(home, 'layouts');
|
|
360
|
+
const themesSrc = path.join(appDir, 'themes');
|
|
361
|
+
const themesDest = path.join(home, 'themes');
|
|
362
|
+
const themeNames = fs.readdirSync(themesSrc).filter((n) => n.endsWith('.json')).sort();
|
|
363
|
+
|
|
364
|
+
const missing: string[] = [];
|
|
365
|
+
const outdated: string[] = [];
|
|
366
|
+
const foreign: string[] = [];
|
|
367
|
+
|
|
368
|
+
const layoutSrc = path.join(appDir, 'layouts', `${LAYOUT}.json`);
|
|
369
|
+
const layoutDest = path.join(layoutsDest, `${LAYOUT}.json`);
|
|
370
|
+
if (!fs.existsSync(layoutDest)) {
|
|
371
|
+
missing.push(`layout:${LAYOUT}`);
|
|
372
|
+
} else if (!layoutHashes(layoutDest).includes(sha256(layoutSrc))) {
|
|
373
|
+
outdated.push(`layout:${LAYOUT}`);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
for (const name of themeNames) {
|
|
377
|
+
const dest = path.join(themesDest, name);
|
|
378
|
+
if (!fs.existsSync(dest)) {
|
|
379
|
+
missing.push(`theme:${name}`);
|
|
380
|
+
} else if (sha256(dest) !== sha256(path.join(themesSrc, name))) {
|
|
381
|
+
outdated.push(`theme:${name}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const expectedVersion = appVersion();
|
|
386
|
+
for (const name of modNames) {
|
|
387
|
+
const srcMod = path.join(modsSrc, name);
|
|
388
|
+
const destMod = path.join(modsDest, name);
|
|
389
|
+
if (!fs.existsSync(destMod)) {
|
|
390
|
+
missing.push(`mod:${name}`);
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if (!readMarker(destMod)) {
|
|
394
|
+
foreign.push(`mod:${name}`);
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (name === 'bond-titlebar') {
|
|
398
|
+
const verFile = path.join(destMod, 'version.js');
|
|
399
|
+
if (!fs.existsSync(verFile) || fs.readFileSync(verFile, 'utf8') !== versionJs(expectedVersion)) {
|
|
400
|
+
outdated.push(`mod:${name}`);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (!dirFilesMatch(srcMod, destMod)) {
|
|
405
|
+
outdated.push(`mod:${name}`);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const installed = missing.length === 0;
|
|
410
|
+
const upToDate = installed && outdated.length === 0 && foreign.length === 0;
|
|
411
|
+
return { installed, upToDate, missing, outdated, foreign };
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
function dirFilesMatch(src: string, dest: string): boolean {
|
|
415
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
416
|
+
if (SKIP.has(entry.name) || entry.name === 'config.js') continue;
|
|
417
|
+
const from = path.join(src, entry.name);
|
|
418
|
+
const to = path.join(dest, entry.name);
|
|
419
|
+
if (entry.isDirectory()) {
|
|
420
|
+
if (!fs.existsSync(to) || !dirFilesMatch(from, to)) return false;
|
|
421
|
+
} else if (entry.isFile()) {
|
|
422
|
+
if (!fs.existsSync(to) || sha256(from) !== sha256(to)) return false;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
|
|
275
428
|
// ---- P6: the opt-in «bond» desktop launcher ----
|
|
276
429
|
|
|
277
|
-
export function launcherPaths(dataDir: string): LauncherPaths {
|
|
430
|
+
export function launcherPaths(dataDir: string, platform: NodeJS.Platform = process.platform): LauncherPaths {
|
|
431
|
+
if (platform === 'win32') {
|
|
432
|
+
return {
|
|
433
|
+
desktop: windowsStartMenuShortcutPath({ env: { APPDATA: dataDir } }),
|
|
434
|
+
icon: path.join(dataDir, 'bond-app', 'bond-app.svg'),
|
|
435
|
+
script: path.join(dataDir, 'bond-app', 'bond-launch.cmd'),
|
|
436
|
+
};
|
|
437
|
+
}
|
|
278
438
|
return {
|
|
279
439
|
desktop: path.join(dataDir, 'applications', 'bond-app.desktop'),
|
|
280
440
|
icon: path.join(dataDir, 'icons', 'hicolor', 'scalable', 'apps', 'bond-app.svg'),
|
|
@@ -333,11 +493,15 @@ function ours(file: string, manifest: Record<string, string>, dataDir?: string):
|
|
|
333
493
|
* a symlink at any of our paths or their intermediate directories, or a file there that is not
|
|
334
494
|
* the copy bond-app wrote (someone else's, or edited: --force replaces an edited one).
|
|
335
495
|
*/
|
|
336
|
-
function checkLauncher(dataDir: string, force: boolean): void {
|
|
337
|
-
if (
|
|
496
|
+
function checkLauncher(dataDir: string, force: boolean, platform: NodeJS.Platform = process.platform): void {
|
|
497
|
+
if (platform === 'win32') {
|
|
498
|
+
if (/[\r\n\0]/.test(dataDir)) {
|
|
499
|
+
throw new Error(`the Windows data dir '${dataDir}' contains invalid control characters: not writing a launcher there`);
|
|
500
|
+
}
|
|
501
|
+
} else if (!/^[A-Za-z0-9/._ -]+$/.test(dataDir)) {
|
|
338
502
|
throw new Error(`the XDG data dir '${dataDir}' has characters a .desktop file would need escaped: not writing a launcher there`);
|
|
339
503
|
}
|
|
340
|
-
const p = launcherPaths(dataDir);
|
|
504
|
+
const p = launcherPaths(dataDir, platform);
|
|
341
505
|
const manifest = readManifest(dataDir);
|
|
342
506
|
const filesToCheck = [p.desktop, p.icon, p.script, manifestPath(dataDir)];
|
|
343
507
|
const checkedDirs = new Set<string>();
|
|
@@ -358,18 +522,19 @@ function checkLauncher(dataDir: string, force: boolean): void {
|
|
|
358
522
|
}
|
|
359
523
|
|
|
360
524
|
/** herdr-app's absolute path on PATH, so the launcher works from a desktop session's PATH. */
|
|
361
|
-
function herdrAppPath(): string {
|
|
525
|
+
function herdrAppPath(platform: NodeJS.Platform = process.platform): string {
|
|
526
|
+
const exe = platform === 'win32' ? 'herdr-app.exe' : 'herdr-app';
|
|
362
527
|
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
|
|
363
528
|
if (!path.isAbsolute(dir)) continue; // a relative entry would resolve against the session's cwd
|
|
364
|
-
const candidate = path.join(dir,
|
|
529
|
+
const candidate = path.join(dir, exe);
|
|
365
530
|
try {
|
|
366
|
-
fs.accessSync(candidate, fs.constants.X_OK);
|
|
531
|
+
fs.accessSync(candidate, platform === 'win32' ? fs.constants.F_OK : fs.constants.X_OK);
|
|
367
532
|
return candidate;
|
|
368
533
|
} catch {
|
|
369
534
|
// next
|
|
370
535
|
}
|
|
371
536
|
}
|
|
372
|
-
return
|
|
537
|
+
return exe;
|
|
373
538
|
}
|
|
374
539
|
|
|
375
540
|
/** Single-quote for sh. */
|
|
@@ -414,24 +579,141 @@ function desktopEntry(p: LauncherPaths): string {
|
|
|
414
579
|
].join('\n');
|
|
415
580
|
}
|
|
416
581
|
|
|
582
|
+
function psQuote(value: string): string {
|
|
583
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function windowsLaunchScript(herdrApp: string, home: string | null): string {
|
|
587
|
+
return [
|
|
588
|
+
'@echo off',
|
|
589
|
+
'setlocal',
|
|
590
|
+
`if not defined HERDR_APP set "HERDR_APP=${herdrApp}"`,
|
|
591
|
+
...(home ? [`set "HERDR_APP_HOME=${home}"`] : []),
|
|
592
|
+
'"%HERDR_APP%" status >nul 2>&1',
|
|
593
|
+
'if errorlevel 1 (',
|
|
594
|
+
' start "" "%HERDR_APP%"',
|
|
595
|
+
' for /l %%i in (1,1,50) do (',
|
|
596
|
+
' "%HERDR_APP%" status >nul 2>&1 && goto :switch',
|
|
597
|
+
' powershell -NoProfile -Command "Start-Sleep -Milliseconds 200" >nul 2>&1',
|
|
598
|
+
' )',
|
|
599
|
+
')',
|
|
600
|
+
':switch',
|
|
601
|
+
'"%HERDR_APP%" do layout.switch --name bond',
|
|
602
|
+
'',
|
|
603
|
+
].join('\r\n');
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function buildWindowsShortcutPs(lnkPath: string, targetPath: string): string {
|
|
607
|
+
return [
|
|
608
|
+
'$ws = New-Object -ComObject WScript.Shell',
|
|
609
|
+
`$s = $ws.CreateShortcut(${psQuote(lnkPath)})`,
|
|
610
|
+
`$s.TargetPath = ${psQuote(targetPath)}`,
|
|
611
|
+
`$s.WorkingDirectory = ${psQuote(path.dirname(targetPath))}`,
|
|
612
|
+
'$s.WindowStyle = 7',
|
|
613
|
+
"$s.Description = 'bond-app: tickets en hub-contenedores con agentes de código (herdr-app, layout bond)'",
|
|
614
|
+
'$s.Save()',
|
|
615
|
+
].join('; ');
|
|
616
|
+
}
|
|
617
|
+
|
|
417
618
|
function writeLauncher(opts: InstallOptions): LauncherPaths {
|
|
418
|
-
const
|
|
619
|
+
const platform = opts.platform ?? process.platform;
|
|
620
|
+
const p = launcherPaths(opts.dataHome, platform);
|
|
419
621
|
for (const f of [p.desktop, p.icon, p.script]) fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
420
622
|
fs.copyFileSync(path.join(appDir, 'brand', 'bond-app.svg'), p.icon);
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
623
|
+
const herdrBin = herdrAppPath(platform);
|
|
624
|
+
if (platform === 'win32') {
|
|
625
|
+
fs.writeFileSync(p.script, windowsLaunchScript(herdrBin, opts.customHome ? opts.home : null), 'utf8');
|
|
626
|
+
const psScript = buildWindowsShortcutPs(p.desktop, p.script);
|
|
627
|
+
const run = opts.runCommand ?? ((cmd: string, args: string[]) => execFileSync(cmd, args, { stdio: 'pipe', timeout: 15_000 }));
|
|
628
|
+
run('powershell', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', psScript]);
|
|
629
|
+
} else {
|
|
630
|
+
fs.writeFileSync(p.script, launchScript(herdrBin, opts.customHome ? opts.home : null), { mode: 0o755 });
|
|
631
|
+
fs.chmodSync(p.script, 0o755);
|
|
632
|
+
fs.writeFileSync(p.desktop, desktopEntry(p));
|
|
633
|
+
}
|
|
634
|
+
const files = Object.fromEntries(
|
|
635
|
+
[p.desktop, p.icon, p.script].filter((f) => fs.existsSync(f)).map((f) => [f, sha256(f)])
|
|
636
|
+
);
|
|
425
637
|
fs.writeFileSync(manifestPath(opts.dataHome), JSON.stringify({ installed_by: 'bond-app', files }, null, 2) + '\n');
|
|
426
638
|
return p;
|
|
427
639
|
}
|
|
428
640
|
|
|
641
|
+
/**
|
|
642
|
+
* Remove layout, mods and themes that bond-app installed in `home`.
|
|
643
|
+
* Never removes foreign mods, edited layouts, or themes not matching bond-app's marker.
|
|
644
|
+
*/
|
|
645
|
+
export function removeApp(home: string): { removed: string[]; kept: string[] } {
|
|
646
|
+
const modsSrc = path.join(appDir, 'mods');
|
|
647
|
+
const modsDest = path.join(home, 'mods');
|
|
648
|
+
const layoutsDest = path.join(home, 'layouts');
|
|
649
|
+
const themesSrc = path.join(appDir, 'themes');
|
|
650
|
+
const themesDest = path.join(home, 'themes');
|
|
651
|
+
|
|
652
|
+
const srcModNames = fs.existsSync(modsSrc)
|
|
653
|
+
? fs.readdirSync(modsSrc).filter((n) => n.startsWith('bond-')).sort()
|
|
654
|
+
: [];
|
|
655
|
+
const destModNames = fs.existsSync(modsDest)
|
|
656
|
+
? fs.readdirSync(modsDest).filter((n) => n.startsWith('bond-')).sort()
|
|
657
|
+
: [];
|
|
658
|
+
const modNames = [...new Set([...srcModNames, ...destModNames])].sort();
|
|
659
|
+
|
|
660
|
+
const previous = modNames.map((n) => readMarker(path.join(modsDest, n))).find((m) => m) ?? null;
|
|
661
|
+
|
|
662
|
+
const removed: string[] = [];
|
|
663
|
+
const kept: string[] = [];
|
|
664
|
+
|
|
665
|
+
for (const name of modNames) {
|
|
666
|
+
const dest = path.join(modsDest, name);
|
|
667
|
+
if (!fs.existsSync(dest) && !isSymlink(dest)) continue;
|
|
668
|
+
if (!isSymlink(dest) && readMarker(dest)) {
|
|
669
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
670
|
+
removed.push(dest);
|
|
671
|
+
} else {
|
|
672
|
+
kept.push(dest);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const layoutDest = path.join(layoutsDest, `${LAYOUT}.json`);
|
|
677
|
+
const previewDest = path.join(layoutsDest, `${LAYOUT}.svg`);
|
|
678
|
+
for (const [dest, key] of [[layoutDest, 'layout_sha256'], [previewDest, 'preview_sha256']] as const) {
|
|
679
|
+
if (!fs.existsSync(dest) && !isSymlink(dest)) continue;
|
|
680
|
+
if (!isSymlink(dest) && previous?.[key]) {
|
|
681
|
+
const ours = key === 'layout_sha256' ? layoutHashes(dest) : [sha256(dest)];
|
|
682
|
+
if (ours.includes(previous[key]!)) {
|
|
683
|
+
fs.rmSync(dest);
|
|
684
|
+
removed.push(dest);
|
|
685
|
+
continue;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
kept.push(dest);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const srcThemeNames = fs.existsSync(themesSrc)
|
|
692
|
+
? fs.readdirSync(themesSrc).filter((n) => n.endsWith('.json'))
|
|
693
|
+
: [];
|
|
694
|
+
const markerThemeNames = Object.keys(previous?.themes_sha256 ?? {});
|
|
695
|
+
const themeNames = [...new Set([...srcThemeNames, ...markerThemeNames])].sort();
|
|
696
|
+
for (const name of themeNames) {
|
|
697
|
+
const dest = path.join(themesDest, name);
|
|
698
|
+
if (!fs.existsSync(dest) && !isSymlink(dest)) continue;
|
|
699
|
+
if (!isSymlink(dest) && previous?.themes_sha256?.[name] === sha256(dest)) {
|
|
700
|
+
fs.rmSync(dest);
|
|
701
|
+
removed.push(dest);
|
|
702
|
+
} else {
|
|
703
|
+
kept.push(dest);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
return { removed, kept };
|
|
708
|
+
}
|
|
709
|
+
|
|
429
710
|
/**
|
|
430
711
|
* Remove what --launcher wrote: only the exact copies in its manifest. An edited or foreign
|
|
431
712
|
* file stays (and is listed in `kept`).
|
|
432
713
|
*/
|
|
433
|
-
export function removeLauncher(dataDir: string): { removed: string[]; kept: string[] } {
|
|
434
|
-
const
|
|
714
|
+
export function removeLauncher(dataDir: string, opts: { platform?: NodeJS.Platform } = {}): { removed: string[]; kept: string[] } {
|
|
715
|
+
const platform = opts.platform ?? process.platform;
|
|
716
|
+
const p = launcherPaths(dataDir, platform);
|
|
435
717
|
const manifest = readManifest(dataDir);
|
|
436
718
|
const removed: string[] = [];
|
|
437
719
|
const kept: string[] = [];
|
|
@@ -455,10 +737,23 @@ export function removeLauncher(dataDir: string): { removed: string[]; kept: stri
|
|
|
455
737
|
if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
|
|
456
738
|
try {
|
|
457
739
|
const argv = process.argv.slice(2);
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (
|
|
740
|
+
const wantsRemove = argv.includes('--remove');
|
|
741
|
+
const wantsRemoveLauncher = argv.includes('--remove-launcher');
|
|
742
|
+
if (wantsRemove || wantsRemoveLauncher) {
|
|
743
|
+
if (wantsRemove) {
|
|
744
|
+
const homeArg = (() => {
|
|
745
|
+
const i = argv.indexOf('--home');
|
|
746
|
+
return i !== -1 && argv[i + 1] ? argv[i + 1] : null;
|
|
747
|
+
})() || process.env.HERDR_APP_HOME || defaultHerdrAppHome();
|
|
748
|
+
const { removed, kept } = removeApp(homeArg);
|
|
749
|
+
console.log(removed.length ? `bond-app: app integration removed:\n ${removed.join('\n ')}` : 'bond-app: no bond-app integration to remove');
|
|
750
|
+
if (kept.length) console.log(` kept (edited, or not bond-app's):\n ${kept.join('\n ')}`);
|
|
751
|
+
}
|
|
752
|
+
if (wantsRemoveLauncher) {
|
|
753
|
+
const { removed, kept } = removeLauncher(dataHome());
|
|
754
|
+
console.log(removed.length ? `bond-app: launcher removed:\n ${removed.join('\n ')}` : 'bond-app: no bond launcher to remove');
|
|
755
|
+
if (kept.length) console.log(` kept (edited, or not bond-app's):\n ${kept.join('\n ')}`);
|
|
756
|
+
}
|
|
462
757
|
process.exit(0);
|
|
463
758
|
}
|
|
464
759
|
const res = install(parseInstallArgs(argv));
|