mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Add idempotent local dev service management
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
cadfcd1bc6
commit
6793dde597
8 changed files with 1448 additions and 35 deletions
44
scripts/dev-service.ts
Normal file
44
scripts/dev-service.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env -S node --import tsx
|
||||
import { listLocalServiceRegistryRecords, removeLocalServiceRegistryRecord, terminateLocalService } from "../server/src/services/local-service-supervisor.ts";
|
||||
import { repoRoot } from "./dev-service-profile.ts";
|
||||
|
||||
function toDisplayLines(records: Awaited<ReturnType<typeof listLocalServiceRegistryRecords>>) {
|
||||
return records.map((record) => {
|
||||
const childPid = typeof record.metadata?.childPid === "number" ? ` child=${record.metadata.childPid}` : "";
|
||||
const url = typeof record.metadata?.url === "string" ? ` url=${record.metadata.url}` : "";
|
||||
return `${record.serviceName} pid=${record.pid}${childPid} cwd=${record.cwd}${url}`;
|
||||
});
|
||||
}
|
||||
|
||||
const command = process.argv[2] ?? "list";
|
||||
const records = await listLocalServiceRegistryRecords({
|
||||
profileKind: "paperclip-dev",
|
||||
metadata: { repoRoot },
|
||||
});
|
||||
|
||||
if (command === "list") {
|
||||
if (records.length === 0) {
|
||||
console.log("No Paperclip dev services registered for this repo.");
|
||||
process.exit(0);
|
||||
}
|
||||
for (const line of toDisplayLines(records)) {
|
||||
console.log(line);
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (command === "stop") {
|
||||
if (records.length === 0) {
|
||||
console.log("No Paperclip dev services registered for this repo.");
|
||||
process.exit(0);
|
||||
}
|
||||
for (const record of records) {
|
||||
await terminateLocalService(record);
|
||||
await removeLocalServiceRegistryRecord(record.serviceKey);
|
||||
console.log(`Stopped ${record.serviceName} (pid ${record.pid})`);
|
||||
}
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
console.error(`Unknown dev-service command: ${command}`);
|
||||
process.exit(1);
|
||||
Loading…
Add table
Add a link
Reference in a new issue