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:
parent
9a907d87e5
commit
cd0110527c
5 changed files with 134 additions and 5 deletions
33
tests/registry-relink.test.ts
Normal file
33
tests/registry-relink.test.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// After a machine move the app folder list points at the old computer; relink finds each app here and keeps its id.
|
||||
import { describe, expect, test } from 'bun:test';
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import { configAppName, configFolders, relinkPlan } from '../cli/lib/registry';
|
||||
|
||||
function app(root: string, rel: string, name: string): string {
|
||||
const d = join(root, rel); mkdirSync(d, { recursive: true });
|
||||
writeFileSync(join(d, 'storebound.config.ts'), `export default { app: { name: '${name}' } };\n`);
|
||||
return d;
|
||||
}
|
||||
|
||||
describe('apps relink', () => {
|
||||
test('by the last path parts, else by the app name; ids stay; a taken folder is not reused', () => {
|
||||
const root = mkdtempSync(join(tmpdir(), 'sb-relink-'));
|
||||
const game = app(root, 'game-one', 'Game One');
|
||||
const front = app(root, 'Studio/frontend', 'Studio');
|
||||
const renamed = app(root, 'NewName/app', 'Old App');
|
||||
mkdirSync(join(root, 'node_modules/x'), { recursive: true }); writeFileSync(join(root, 'node_modules/x/storebound.config.ts'), '');
|
||||
const found = configFolders([root]);
|
||||
expect(found.sort()).toEqual([game, front, renamed].sort());
|
||||
expect(configAppName(front)).toBe('Studio');
|
||||
const r = { version: 1 as const, projects: [
|
||||
{ id: 'a', path: '/Users/old/Desktop/game-one', name: 'Game One', added: '' },
|
||||
{ id: 'b', path: '/Users/old/Work/Studio/frontend', name: 'frontend', added: '' },
|
||||
{ id: 'c', path: '/Users/old/Work/OldName/app', name: 'Old App', added: '' },
|
||||
{ id: 'd', path: '/Users/old/gone', name: 'Gone', added: '' },
|
||||
] };
|
||||
const plan = relinkPlan(r, found, () => false, configAppName);
|
||||
expect(plan.map(p => [p.id, p.to])).toEqual([['a', game], ['b', front], ['c', renamed]]);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue