apps relink: after a machine move, missing app folders are pointed at the same app here (last path parts, else the config's app name), ids kept; apps folders hints it; apps add names an app after its config app name

This commit is contained in:
CRTkafa 2026-10-22 06:22:08 +08:00
parent 9a907d87e5
commit cd0110527c
5 changed files with 134 additions and 5 deletions

View file

@ -9,6 +9,7 @@
// the same list as the desktop app's App folders)
// storebound apps add [<folder>] | apps remove <folder> add / remove a folder in that list (the folder itself stays)
// storebound apps add --store apple|play --app-id <id> [--account <profile>] [--name <n>] [--bundle-id <id>]
// storebound apps relink [--root <folder>]... [--dry] after a move: "folder not found" entries -> the same app here
// a store app with no project on this machine: the
// desktop shows it read-only ("no local project");
// apps remove apple:<id> | <entry id> takes it out
@ -17,7 +18,7 @@ import { ascKey, playServiceAccount } from './lib/credentials';
import type { AccountCheck, AppsListResult } from './lib/desktop-protocol';
import { PLAY_SCOPE, REPORTING_SCOPE, tokenSource } from './lib/google-auth';
import { errorBody } from './lib/http';
import { log, printJson, warn } from './lib/log';
import { done, log, printJson, warn } from './lib/log';
import { appleCheck, type Bytes, dataUrl, type Get, isServiceDisabled, listAppleApps, listPlayApps, localPlayApps, MAX_ICON_BYTES, playCheck } from './lib/store-apps';
import { textTable } from './lib/table';
import { ascClient } from './apple/asc';
@ -26,7 +27,8 @@ import * as rt from './lib/rt';
import { existsSync, readFileSync } from 'node:fs';
import { basename, join, resolve } from 'node:path';
import { CONFIG_NAMES } from './lib/config';
import { addFolder, addStoreApp, readRegistry, registryFile, removeFolder, removeStoreApp } from './lib/registry';
import { addFolder, addStoreApp, applyRelink, configAppName, configFolders, readRegistry, registryFile, relinkPlan, removeFolder, removeStoreApp } from './lib/registry';
import { homedir } from 'node:os';
type Store = 'apple' | 'play';
@ -175,6 +177,8 @@ async function folders(sub: string, args: Args): Promise<void> {
}
if (!r.projects.length) { console.log(`no app folders yet (${tilde(registryFile())}): storebound apps add, in an app folder (or storebound desktop there)`); return; }
console.log(textTable(['app', 'folder', ''], r.projects.map(p => [p.name, tilde(p.path), existsSync(p.path) ? '' : 'folder not found'])));
const missing = r.projects.filter(p => !existsSync(p.path)).length;
if (missing) console.log(`\n${missing} folder(s) not found (moved to another computer or folder?): storebound apps relink --dry finds them by path and app name`);
console.log(`
${tilde(registryFile())}: the same list as the desktop app's App folders`);
return;
@ -218,10 +222,25 @@ ${tilde(registryFile())}: the same list as the desktop app's App folders`);
log('apps', removed ? `removed ${tilde(removed.path)} from the list (the folder and its files stay)` : `${tilde(dir)} is not in the list`);
}
/** apps relink: point "folder not found" entries at the same app on this machine (after a move); ids stay. */
function relink(args: Args): void {
const home = homedir();
const roots = args.list('root').length ? args.list('root').map(r => resolve(r))
: [join(home, 'Documents', 'Visual Studio Workspaces'), join(home, 'Documents'), join(home, 'Desktop'), join(home, 'Projects'), join(home, 'code')].filter(d => existsSync(d));
const plan = relinkPlan(readRegistry(), configFolders(roots), existsSync, configAppName);
if (args.has('json')) { printJson({ roots, plan, dry: args.has('dry') }); }
else if (!plan.length) log('apps', `nothing to relink (looked under ${roots.map(tilde).join(', ')}; --root <folder> to look elsewhere)`);
else for (const s of plan) log('apps', `${s.name}: ${s.from} -> ${tilde(s.to)}`);
if (!plan.length || args.has('dry')) { if (plan.length) done('apps', `dry run: ${plan.length} folder(s) would be relinked`); return; }
applyRelink(plan);
done('apps', `${plan.length} folder(s) relinked (the desktop app picks them up on its next start)`);
}
export async function run(args: Args): Promise<void> {
const sub = args._[0];
const root = process.cwd();
const json = args.has('json');
if (sub === 'relink') return relink(args);
if (sub === 'folders' || sub === 'add' || sub === 'remove') return folders(sub, args);
if (sub === 'list') {
const out: AppsListResult[] = [];