followMirror
uses process
Before a command: a mirror's files changed outside tcm (by hand, a git pull or checkout) are imported first, so the command sees them. Files that don't import yet (an edit half made) wait, and so does writing back to them. What it says goes to stderr: a command's output is its own.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { importProject } from "#codebase/tcmts/cli/main"; import { changedFiles, loadMirror, onMirrorBranch } from "#codebase/tcmts/cli/mirror"; import { dim } from "#codebase/tcmts/cli/style"; export function followMirror(cb: Codebase) { const m = loadMirror(cb); // (a session on another branch doesn't take the files' changes: they're the mirror's branch's) const changed = m && onMirrorBranch(cb, m) ? changedFiles(m) : []; if (!m || !changed.length) return; const log = console.log; const write = process.stdout.write; console.log = console.error; process.stdout.write = process.stderr.write.bind(process.stderr) as typeof process.stdout.write; try { console.log(dim(`mirror: ${changed.slice(0, 3).join(", ")}${changed.length > 3 ? `, and ${changed.length - 3} more,` : ""} changed outside tcm; importing ${changed.length > 1 ? "them" : "it"}`)); importProject(cb, m.dir, "update", m.into, false, m.exclude, m.tests, false); } finally { console.log = log; process.stdout.write = write; } }
uses
- tcmts.cli.codebase.Codebase
- tcmts.cli.main.importProject
- tcmts.cli.mirror.changedFiles
- tcmts.cli.mirror.loadMirror
- tcmts.cli.mirror.onMirrorBranch
- tcmts.cli.style.dim