@stacksjs/buddy 0.75.638 → 0.75.639
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/dist/commands/daemon.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import{existsSync,readFileSync}from"node:fs";import process from"node:process";import{bold,dim,green,onUnknownSubcommand}from"@stacksjs/cli";import{ExitCode}from"@stacksjs/types";function uptime(since){const minutes=Math.max(0,Math.round((Date.now()-Date.parse(since))/60000));if(minutes<1)return"just now";if(minutes<60)return`${minutes}m`;return`${Math.floor(minutes/60)}h ${minutes%60}m`}function memoryMb(pid){const result=Bun.spawnSync(["ps","-o","rss=","-p",String(pid)],{stdout:"pipe",stderr:"ignore"});const kilobytes=Number(result.stdout.toString().trim());return result.exitCode===0&&kilobytes>0?Math.round(kilobytes/1024):null}export function daemon(buddy){const descriptions={status:"Show whether buddy is running in the background and what it is running",start:"Start buddy in the background",stop:"Stop background generation and the dashboards buddy started",restart:"Restart the background buddy",logs:"Print the background buddy's log",json:"Print the status as JSON"};async function status(options){const{daemonStatus}=await import("@stacksjs/actions/daemon/client");const running=await daemonStatus();if(options.json){process.stdout.write(`${JSON.stringify(running,null,2)}
|
|
2
|
-
`);return}if(!running){console.log(`buddy is not running in the background. ${dim("It starts when something needs it: buddy dashboard")}`);return}const memory=memoryMb(running.pid);console.log(`${green("●")} buddy is running in the background ${dim(`(pid ${running.pid}, up ${uptime(running.startedAt)}${memory?`, ${memory} MB`:""})`)}`);if(running.generation){const{watched,queued,running:active,failures}=running.generation;console.log(` Generation ${watched} watched, ${queued} queued${active?`, running for ${active}`:""}`);for(const failure of failures)console.log(` ${failure.path} ${failure.error}`)}if(running.dashboards.length===0){console.log(dim(" No dashboards running."));return}const width=Math.max(...running.dashboards.map((dashboard)=>dashboard.name.length));for(const dashboard of running.dashboards){const state=dashboard.state==="ready"?dashboard.url:dim("starting");console.log(` ${bold(dashboard.name.padEnd(width))} ${state} ${dim(`up ${uptime(dashboard.startedAt)}`)}`)}}for(const name of["daemon","daemon:status"]){buddy.command(name,descriptions.status).option("--json",descriptions.json,{default:false}).action(async(options)=>{await status(options);process.exit(ExitCode.Success)})}buddy.command("daemon:start",descriptions.start).action(async()=>{const{startDaemon}=await import("@stacksjs/actions/daemon/client");const{status:running,started}=await startDaemon();console.log(started?`${green("●")} buddy is now running in the background ${dim(`(pid ${running.pid})`)}`:`buddy is already running in the background ${dim(`(pid ${running.pid})`)}`);process.exit(ExitCode.Success)});buddy.command("daemon:stop",descriptions.stop).action(async()=>{const{stopDaemon}=await import("@stacksjs/actions/daemon/client");console.log(await stopDaemon()?"Stopped the background buddy.":"buddy was not running in the background.");process.exit(ExitCode.Success)});buddy.command("daemon:restart",descriptions.restart).action(async()=>{const{startDaemon,stopDaemon}=await import("@stacksjs/actions/daemon/client");await stopDaemon();const{status:running}=await startDaemon();console.log(`${green("●")} buddy is running in the background ${dim(`(pid ${running.pid})`)}`);process.exit(ExitCode.Success)});buddy.command("daemon:logs",descriptions.logs).option("--lines <count>","How many lines from the end to print",{default:50}).action(async(options)=>{const{daemonLogFile}=await import("@stacksjs/actions/daemon/paths");const file=daemonLogFile();if(!existsSync(file)){console.log("The background buddy has not written a log yet.");process.exit(ExitCode.Success)}const lines=readFileSync(file,"utf8").trimEnd().split(`
|
|
2
|
+
`);return}if(!running){console.log(`buddy is not running in the background. ${dim("It starts when something needs it: buddy dashboard")}`);return}const memory=memoryMb(running.pid);console.log(`${green("●")} buddy is running in the background ${dim(`(pid ${running.pid}, up ${uptime(running.startedAt)}${memory?`, ${memory} MB`:""})`)}`);if(running.generation){const{watched,queued,running:active,failures}=running.generation;console.log(` Generation ${watched} watched, ${queued} queued${active?`, running for ${active}`:""}`);for(const failure of failures)console.log(` ${failure.path} ${failure.error}`);for(const approval of running.generation.approvals??[])console.log(` Approval ${approval.path} ${approval.files} generated file${approval.files===1?"":"s"} awaiting review`)}if(running.dashboards.length===0){console.log(dim(" No dashboards running."));return}const width=Math.max(...running.dashboards.map((dashboard)=>dashboard.name.length));for(const dashboard of running.dashboards){const state=dashboard.state==="ready"?dashboard.url:dim("starting");console.log(` ${bold(dashboard.name.padEnd(width))} ${state} ${dim(`up ${uptime(dashboard.startedAt)}`)}`)}}for(const name of["daemon","daemon:status"]){buddy.command(name,descriptions.status).option("--json",descriptions.json,{default:false}).action(async(options)=>{await status(options);process.exit(ExitCode.Success)})}buddy.command("daemon:start",descriptions.start).action(async()=>{const{startDaemon}=await import("@stacksjs/actions/daemon/client");const{status:running,started}=await startDaemon();console.log(started?`${green("●")} buddy is now running in the background ${dim(`(pid ${running.pid})`)}`:`buddy is already running in the background ${dim(`(pid ${running.pid})`)}`);process.exit(ExitCode.Success)});buddy.command("daemon:stop",descriptions.stop).action(async()=>{const{stopDaemon}=await import("@stacksjs/actions/daemon/client");console.log(await stopDaemon()?"Stopped the background buddy.":"buddy was not running in the background.");process.exit(ExitCode.Success)});buddy.command("daemon:restart",descriptions.restart).action(async()=>{const{startDaemon,stopDaemon}=await import("@stacksjs/actions/daemon/client");await stopDaemon();const{status:running}=await startDaemon();console.log(`${green("●")} buddy is running in the background ${dim(`(pid ${running.pid})`)}`);process.exit(ExitCode.Success)});buddy.command("daemon:logs",descriptions.logs).option("--lines <count>","How many lines from the end to print",{default:50}).action(async(options)=>{const{daemonLogFile}=await import("@stacksjs/actions/daemon/paths");const file=daemonLogFile();if(!existsSync(file)){console.log("The background buddy has not written a log yet.");process.exit(ExitCode.Success)}const lines=readFileSync(file,"utf8").trimEnd().split(`
|
|
3
3
|
`);process.stdout.write(`${lines.slice(-(Number(options.lines)||50)).join(`
|
|
4
4
|
`)}
|
|
5
5
|
`);process.exit(ExitCode.Success)});onUnknownSubcommand(buddy,"daemon")}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { GenerationFileGuard } from '@stacksjs/path';
|
|
1
2
|
import type { GenerationTask } from '@stacksjs/actions/daemon/generation-config';
|
|
2
|
-
|
|
3
|
+
/** Generation and approved commits share the proposal and its working-tree files. */
|
|
4
|
+
export declare function withApprovalLock<T>(root: string, run: () => T | Promise<T>): Promise<T>;
|
|
5
|
+
export declare function prepareCommitApproval(root: string, task: GenerationTask, enabledTasks: GenerationTask[]): { guard: GenerationFileGuard, finish: (success: boolean) => void } | undefined;
|
|
3
6
|
export declare function reviewGeneratedCommit(root: string, review: (diff: string) => Promise<boolean>): Promise<string | 'empty' | 'pending'>;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import{
|
|
2
|
-
|
|
3
|
-
end run`;const message=`${basename(root)} has ${count} generated ${count===1?"file":"files"} ready for review. Run ./buddy generate:review in the project.`;const result=spawnSync("/usr/bin/osascript",["-e",script,"--",message],{encoding:"utf8",timeout:15000});if(result.status!==0)console.warn(`[buddy:notification] Could not submit the desktop alert. Run ./buddy generate:review in ${root}.`)}export function prepareCommitApproval(root,tasks,enabledTasks,notify=notifyApproval){const revision=generationRevision(root);if(!revision||!revision.includes(`
|
|
4
|
-
refs/heads/`))return;const path=approvalPath(root);const{read,eligible}=generatedChanges(root,enabledTasks,true);const{eligible:selected}=generatedChanges(root,tasks,true);const before=read();const previous=readApproval(path);const owned=new Map(Object.entries(previous?.revision===revision?previous.files:{}));const carried=new Set([...owned].filter(([file,hash])=>before.has(file)&&eligible(file,before.get(file))&&fingerprint(root,file)===hash).map(([file])=>file));return()=>{const current=readApproval(path);if(gitRevision(root)!==revision||JSON.stringify(current)!==JSON.stringify(previous))return;const files=new Map;for(const[file,status]of[...read()].sort(([a],[b])=>a.localeCompare(b))){if(!eligible(file,status)||before.has(file)&&!carried.has(file))continue;const hash=fingerprint(root,file);if(owned.get(file)===hash||selected(file,status))files.set(file,hash)}const proposal={revision,files:Object.fromEntries(files)};if(JSON.stringify(proposal)===JSON.stringify(previous)||files.size===0&&!previous)return;if(files.size===0){rmSync(path,{force:true});return}mkdirSync(dirname(path),{recursive:true,mode:448});const temp=`${path}.${randomUUID()}`;try{writeFileSync(temp,JSON.stringify(proposal),{flag:"wx",mode:384});renameSync(temp,path)}finally{rmSync(temp,{force:true})}notify(root,files.size)}}function commitReviewedTree(root,revision,files,tree,workIndex,validate){const[head,branch]=revision.trim().split(`
|
|
1
|
+
import{createHash}from"node:crypto";import{closeSync,existsSync,fsyncSync,lstatSync,mkdirSync,mkdtempSync,openSync,readFileSync,renameSync,rmSync,writeFileSync}from"node:fs";import{dirname,join,relative}from"node:path";import{approvalPath,readApproval,writeApprovalState}from"@stacksjs/actions/daemon/approval-state";import{readGenerationConfig}from"@stacksjs/actions/daemon/generation-config";import{acquireMigrationLock}from"@stacksjs/database/migration-lock";import{generatedChanges,generationRevision,git,gitCommand,gitRevision}from"./generation-changes";const staleApproval="The proposal changed. Run buddy generate:project and review the current changes again.";const commitMessage="chore: regenerate Stacks artifacts";function fingerprint(root,file){const path=join(root,file);const stat=lstatSync(path,{throwIfNoEntry:false});if(!stat)return;if(!stat.isFile())return"not a regular file";return createHash("sha256").update(`${stat.mode}:`).update(readFileSync(path)).digest("hex")}function branchOf(revision){const branch=revision?.trim().split(`
|
|
2
|
+
`)[1];return branch?.startsWith("refs/heads/")?branch:undefined}export async function withApprovalLock(root,run){const path=approvalPath(root);mkdirSync(dirname(path),{recursive:true,mode:448});const lock=await acquireMigrationLock("sqlite",null,{sqliteLockPath:`${path}.lock`});try{return await run()}finally{await lock.release()}}export function prepareCommitApproval(root,task,enabledTasks){const revision=generationRevision(root);const branch=branchOf(revision);if(!revision)return;const path=approvalPath(root);const{read,eligible}=generatedChanges(root,enabledTasks,true);const selected=generatedChanges(root,[task],true);const before=read();const previous=readApproval(path);const sameBranch=branch!==undefined&&branchOf(previous?.revision)===branch;const pending=new Map(Object.entries(sameBranch?previous?.files??{}:{}));const incomplete=new Map(Object.entries(sameBranch?previous?.incomplete??{}:{}));const expected=new Map([...selected.writable].map((file)=>[file,fingerprint(root,file)]));const writes=new Map;const guard={beforeWrite(path){const file=relative(root,path);if(!selected.writable.has(file))return;const hash=fingerprint(root,file);const status=before.get(file);const owned=hash!==undefined&&(pending.get(file)===hash||incomplete.get(file)===hash||writes.get(file)===hash);if(expected.get(file)!==hash||hash==="not a regular file"||status&&!(owned&&eligible(file,status))){throw new Error(`Local edits in ${file}. Resolve them before Buddy regenerates this file.`)}},afterWrite(path){const file=relative(root,path);const hash=fingerprint(root,file);if(hash&&hash!=="not a regular file"){writes.set(file,hash);expected.set(file,hash)}}};return{guard,finish(success){if(!branch||branchOf(gitRevision(root))!==branch||JSON.stringify(readApproval(path))!==JSON.stringify(previous))return;const files={};const unfinished={};for(const[file,status]of[...read()].sort(([a],[b])=>a.localeCompare(b))){if(!eligible(file,status))continue;const hash=fingerprint(root,file);if(!hash||hash==="not a regular file")continue;if(writes.get(file)===hash||incomplete.get(file)===hash){if(success&&selected.eligible(file,status))files[file]=hash;else unfinished[file]=hash}else if(pending.get(file)===hash){files[file]=hash}}if(Object.keys(files).length+Object.keys(unfinished).length===0){if(previous&&sameBranch)rmSync(path,{force:true});return}const proposal={revision,files,notify:true,...Object.keys(unfinished).length?{incomplete:unfinished}:{}};if(JSON.stringify(proposal)!==JSON.stringify(previous))writeApprovalState(path,proposal)}}}function commitReviewedTree(root,revision,files,tree,workIndex,validate){const[head,branch]=revision.trim().split(`
|
|
5
3
|
`);if(!head||!branch?.startsWith("refs/heads/"))throw new Error(staleApproval);const ongoing=["MERGE_HEAD","CHERRY_PICK_HEAD","REVERT_HEAD","rebase-apply","rebase-merge","sequencer","BISECT_START"];if(ongoing.some((state)=>existsSync(git(root,"rev-parse","--path-format=absolute","--git-path",state).trim())))throw new Error("Finish the current Git operation before approving generated changes.");const index=git(root,"rev-parse","--path-format=absolute","--git-path","index").trim();const indexLock=`${index}.lock`;const fd=openSync(indexLock,"wx",lstatSync(index).mode&511);let installed=false;try{validate();writeFileSync(workIndex,readFileSync(index));const entries=git(root,"ls-tree","-rz",tree,"--",...files);gitCommand(root,["update-index","-z","--index-info"],{env:{...process.env,GIT_INDEX_FILE:workIndex},input:entries});const sign=git(root,"config","--type=bool","--default=false","--get","commit.gpgSign").trim()==="true";const commit=git(root,"commit-tree",tree,"-p",head,"-m",commitMessage,...sign?["-S"]:[]).trim();writeFileSync(fd,readFileSync(workIndex));fsyncSync(fd);validate();git(root,"update-ref","-m",`commit: ${commitMessage}`,branch,commit,head);renameSync(indexLock,index);installed=true;return commit}finally{closeSync(fd);if(!installed)rmSync(indexLock,{force:true})}}export async function reviewGeneratedCommit(root,review){const config=readGenerationConfig(root);if(!config?.commitApproval)throw new Error("Enable generation.commitApproval in config/buddy.json to review generated commits.");const path=approvalPath(root);const proposal=readApproval(path);if(!proposal||Object.keys(proposal.files).length===0)return"empty";const{read,eligible}=generatedChanges(root,config.tasks,true);const files=Object.keys(proposal.files);const validate=()=>{const latest=readGenerationConfig(root);if(!latest?.commitApproval||latest.tasks.join()!==config.tasks.join()||gitRevision(root)!==proposal.revision||!proposal.revision.includes(`
|
|
6
4
|
refs/heads/`)||JSON.stringify(readApproval(path))!==JSON.stringify(proposal))throw new Error(staleApproval);const status=read();for(const file of files){const state=status.get(file);if(!state||!eligible(file,state)||fingerprint(root,file)!==proposal.files[file])throw new Error(staleApproval)}};const workspace=mkdtempSync(join(dirname(path),"review-"));try{const previewIndex=join(workspace,"preview-index");const preview=(...args)=>gitCommand(root,args,{env:{...process.env,GIT_INDEX_FILE:previewIndex}});validate();const[head]=proposal.revision.split(`
|
|
7
|
-
`);preview("read-tree",head);preview("add","--force","--",...files);const tree=preview("write-tree").trim();const diff=git(root,"diff","--binary","--no-ext-diff","--no-textconv","--no-color",head,tree,"--");validate();if(!diff)return"empty";if(!await review(diff))return"pending";const commit=commitReviewedTree(root,proposal.revision,files,tree,join(workspace,"real-index"),validate);if(
|
|
5
|
+
`);preview("read-tree",head);preview("add","--force","--",...files);const tree=preview("write-tree").trim();const diff=git(root,"diff","--binary","--no-ext-diff","--no-textconv","--no-color",head,tree,"--");validate();if(!diff)return"empty";if(!await review(diff))return"pending";return await withApprovalLock(root,()=>{const commit=commitReviewedTree(root,proposal.revision,files,tree,join(workspace,"real-index"),validate);if(proposal.incomplete)writeApprovalState(path,{...proposal,revision:gitRevision(root),files:{}});else rmSync(path,{force:true});return commit})}finally{rmSync(workspace,{recursive:true,force:true})}}
|
|
@@ -6,7 +6,8 @@ export declare function gitRevision(root: string): string;
|
|
|
6
6
|
export declare function generationRevision(root: string): string | undefined;
|
|
7
7
|
export declare function generatedChanges(root: string, tasks: GenerationTask[], includeIgnored?: boolean): {
|
|
8
8
|
read: __dtsx_return_0.__dtsx_return_0_result_0;
|
|
9
|
-
eligible: __dtsx_return_0.__dtsx_return_0_result_1
|
|
9
|
+
eligible: __dtsx_return_0.__dtsx_return_0_result_1;
|
|
10
|
+
writable: __dtsx_return_0.__dtsx_return_0_result_2
|
|
10
11
|
};
|
|
11
12
|
/** Commit only clean-before paths whose contents the requested generators own. */
|
|
12
13
|
export declare function prepareAutomaticCommit(root: string, tasks: GenerationTask[]): (() => void) | undefined;
|
|
@@ -14,16 +15,20 @@ declare namespace __dtsx_return_0 {
|
|
|
14
15
|
/** @defaultValue `[...(tasks.includes('imports') ? importFiles : []), ...(tasks.includes('types') ? typeFiles : [])]` */
|
|
15
16
|
const files: unknown[];
|
|
16
17
|
const migrations: ReturnType<typeof tasks.includes>;
|
|
18
|
+
const writable: Set<any>;
|
|
17
19
|
/** @defaultValue `[...files, ...(migrations ? migrationDirectories : [])]` */
|
|
18
20
|
const scope: ((typeof files)[number] | unknown)[];
|
|
19
21
|
const read: () => Map<any, any>;
|
|
22
|
+
const generatedSql: (file: string) => unknown;
|
|
20
23
|
const eligible: (file: string, status: string) => boolean;
|
|
21
24
|
namespace __dtsx_return_0_scope_0 {
|
|
22
25
|
type __dtsx_return_0_result_0 = typeof read
|
|
23
26
|
type __dtsx_return_0_result_1 = typeof eligible
|
|
27
|
+
type __dtsx_return_0_result_2 = typeof writable
|
|
24
28
|
}
|
|
25
29
|
type __dtsx_return_0_result_0 = __dtsx_return_0_scope_0.__dtsx_return_0_result_0
|
|
26
30
|
type __dtsx_return_0_result_1 = __dtsx_return_0_scope_0.__dtsx_return_0_result_1
|
|
31
|
+
type __dtsx_return_0_result_2 = __dtsx_return_0_scope_0.__dtsx_return_0_result_2
|
|
27
32
|
|
|
28
33
|
}
|
|
29
34
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{spawnSync}from"node:child_process";import{lstatSync}from"node:fs";import{basename,dirname,join}from"node:path";import{isGeneratedMigration}from"@stacksjs/database/generated-migration-marker";const importFiles=["RUNTIME.md","actions.ts","controllers.ts","emails.ts","functions.ts","globals.ts","index.ts","jobs.ts","listeners.ts","middleware.ts","models.ts","policies.ts","sources.json"].map((file)=>`storage/framework/auto-imports/${file}`).concat(["storage/framework/types/browser-auto-imports.d.ts","storage/framework/types/server-auto-imports.d.ts","storage/framework/browser-auto-imports.json","storage/framework/server-auto-imports.json"]);const typeFiles=["storage/framework/auto-imports/routes.ts","database/types.d.ts"];const migrationDirectories=["database/migrations","storage/framework/database"];export function gitCommand(root,args,options){const result=spawnSync("git",["--literal-pathspecs",...args],{cwd:root,encoding:"utf8",timeout:30000,maxBuffer:32*1024*1024,...options});if(result.status!==0)throw new Error(result.error?.message??(result.stderr.trim()||`git ${args[0]} failed`));return result.stdout}export function git(root,...args){return gitCommand(root,args)}export function gitRevision(root){return git(root,"rev-parse","HEAD","--symbolic-full-name","HEAD")}export function generationRevision(root){try{if(!git(root,"rev-parse","--show-prefix").trim())return gitRevision(root)}catch{}}export function generatedChanges(root,tasks,includeIgnored=false){const files=[...tasks.includes("imports")?importFiles:[],...tasks.includes("types")?typeFiles:[]];const migrations=tasks.includes("migrations");const scope=[...files,...migrations?migrationDirectories:[]];const read=()=>{const status=git(root,"--no-optional-locks","status","--porcelain=v1","-z","--no-renames","--untracked-files=all",...includeIgnored&&migrations?["--ignored=traditional"]:[],"--",...scope);return new Map(status.split("\x00").filter(Boolean).map((entry)=>[entry.slice(3),entry.slice(0,2)]))};const
|
|
1
|
+
import{spawnSync}from"node:child_process";import{lstatSync}from"node:fs";import{basename,dirname,join}from"node:path";import{isGeneratedMigration}from"@stacksjs/database/generated-migration-marker";const importFiles=["RUNTIME.md","actions.ts","controllers.ts","emails.ts","functions.ts","globals.ts","index.ts","jobs.ts","listeners.ts","middleware.ts","models.ts","policies.ts","sources.json"].map((file)=>`storage/framework/auto-imports/${file}`).concat(["storage/framework/types/browser-auto-imports.d.ts","storage/framework/types/server-auto-imports.d.ts","storage/framework/browser-auto-imports.json","storage/framework/server-auto-imports.json"]);const typeFiles=["storage/framework/auto-imports/routes.ts","database/types.d.ts"];const migrationDirectories=["database/migrations","storage/framework/database"];const snapshotFiles=["sqlite","mysql","postgres","singlestore","vitess"].map((dialect)=>`storage/framework/database/model-snapshot.${dialect}.json`);export function gitCommand(root,args,options){const result=spawnSync("git",["--literal-pathspecs",...args],{cwd:root,encoding:"utf8",timeout:30000,maxBuffer:32*1024*1024,...options});if(result.status!==0)throw new Error(result.error?.message??(result.stderr.trim()||`git ${args[0]} failed`));return result.stdout}export function git(root,...args){return gitCommand(root,args)}export function gitRevision(root){return git(root,"rev-parse","HEAD","--symbolic-full-name","HEAD")}export function generationRevision(root){try{if(!git(root,"rev-parse","--show-prefix").trim())return gitRevision(root)}catch{}}export function generatedChanges(root,tasks,includeIgnored=false){const files=[...tasks.includes("imports")?importFiles:[],...tasks.includes("types")?typeFiles:[]];const migrations=tasks.includes("migrations");const writable=new Set([...files,...migrations?snapshotFiles:[]]);const scope=[...files,...migrations?migrationDirectories:[]];const read=()=>{const status=git(root,"--no-optional-locks","status","--porcelain=v1","-z","--no-renames","--untracked-files=all",...includeIgnored&&migrations?["--ignored=traditional"]:[],"--",...scope);return new Map(status.split("\x00").filter(Boolean).map((entry)=>[entry.slice(3),entry.slice(0,2)]))};const generatedSql=(file)=>{const fullPath=join(root,file);return migrations&&/^database\/migrations\/(?:[^/]+\/)?\d{10}-.+\.sql$/.test(file)&&isGeneratedMigration(dirname(fullPath),basename(fullPath))};const eligible=(file,status)=>{if(status==="!!"?!generatedSql(file):!writable.has(file)&&!generatedSql(file))return false;return(status===" M"||status==="??"||status==="!!")&&lstatSync(join(root,file),{throwIfNoEntry:false})?.isFile()===true};return{read,eligible,writable}}export function prepareAutomaticCommit(root,tasks){const revision=generationRevision(root);if(!revision)return;const{read,eligible}=generatedChanges(root,tasks);const before=read();return()=>{if(gitRevision(root)!==revision)return;const changes=[...read()].filter(([file,status])=>!before.has(file)&&eligible(file,status));if(changes.length===0)return;const newFiles=changes.filter(([,status])=>status==="??").map(([file])=>file);if(newFiles.length>0)git(root,"add","--intent-to-add","--",...newFiles);git(root,"commit","--only","-m","chore: regenerate Stacks artifacts","--",...changes.map(([file])=>file))}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{generationTasks,readGenerationConfig}from"@stacksjs/actions/daemon/generation-config";import{prepareCommitApproval}from"./generation-approval";import{prepareAutomaticCommit}from"./generation-changes";import{resultError,resultFailed}from"./result";export async function generateProject(root,selection){const config=readGenerationConfig(root);if(!config)return;const requested=new Set(selection.split(","));const tasks=generationTasks.filter((task)=>requested.has(task)&&config.tasks.includes(task));if(tasks.length===0)return;const commit=config.autoCommit?prepareAutomaticCommit(root,tasks):undefined;const
|
|
2
|
-
`));
|
|
1
|
+
import{generationTasks,readGenerationConfig}from"@stacksjs/actions/daemon/generation-config";import{prepareCommitApproval,withApprovalLock}from"./generation-approval";import{prepareAutomaticCommit}from"./generation-changes";import{resultError,resultFailed}from"./result";export async function generateProject(root,selection){const config=readGenerationConfig(root);if(!config)return;const requested=new Set(selection.split(","));const tasks=generationTasks.filter((task)=>requested.has(task)&&config.tasks.includes(task));if(tasks.length===0)return;if(config.commitApproval)await withApprovalLock(root,()=>runGeneration(root,tasks,config));else await runGeneration(root,tasks,config)}async function runGeneration(root,tasks,config){const commit=config.autoCommit?prepareAutomaticCommit(root,tasks):undefined;const failures=[];for(const task of tasks){const firstFailure=failures.length;const approval=config.commitApproval?prepareCommitApproval(root,task,config.tasks):undefined;const guard=approval?.guard;try{if(task==="imports"){const{generateAutoImportFiles}=await import("@stacksjs/server");await generateAutoImportFiles({guard})}else if(task==="migrations"){const{generateMigrations,siblingMigrationDialects}=await import("@stacksjs/database");for(const dialect of[undefined,...await siblingMigrationDialects()]){const result=await generateMigrations({dialect,fromDb:false,allowDestructive:false,trackIgnored:false,guard});if(resultFailed(result))failures.push(`${dialect??"configured dialect"} migrations: ${resultError(result)}`)}}else{const{generateRouteNames}=await import("@stacksjs/actions/generate/action-types");const{buildDatabaseSchema}=await import("@stacksjs/orm");await generateRouteNames({strict:true,guard});const{errors}=await buildDatabaseSchema({strict:true,guard});failures.push(...errors.map((error)=>`${error.file}: ${error.error}`))}}catch(error){failures.push(`${task}: ${error instanceof Error?error.message:String(error)}`)}if(approval){const current=readGenerationConfig(root);approval.finish(failures.length===firstFailure&¤t?.commitApproval===true&¤t.tasks.includes(task))}}if(failures.length>0)throw new Error(failures.join(`
|
|
2
|
+
`));if(readGenerationConfig(root)?.autoCommit)commit?.()}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/buddy",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.639",
|
|
6
6
|
"description": "Meet Buddy. The Stacks runtime.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -95,71 +95,71 @@
|
|
|
95
95
|
"prepublishOnly": "bun run build"
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@stacksjs/actions": "0.75.
|
|
99
|
-
"@stacksjs/docs": "0.75.
|
|
100
|
-
"@stacksjs/ai": "0.75.
|
|
101
|
-
"@stacksjs/alias": "0.75.
|
|
102
|
-
"@stacksjs/analytics": "0.75.
|
|
103
|
-
"@stacksjs/api": "0.75.
|
|
104
|
-
"@stacksjs/arrays": "0.75.
|
|
105
|
-
"@stacksjs/auth": "0.75.
|
|
106
|
-
"@stacksjs/browser-extension": "0.75.
|
|
107
|
-
"@stacksjs/build": "0.75.
|
|
98
|
+
"@stacksjs/actions": "0.75.639",
|
|
99
|
+
"@stacksjs/docs": "0.75.639",
|
|
100
|
+
"@stacksjs/ai": "0.75.639",
|
|
101
|
+
"@stacksjs/alias": "0.75.639",
|
|
102
|
+
"@stacksjs/analytics": "0.75.639",
|
|
103
|
+
"@stacksjs/api": "0.75.639",
|
|
104
|
+
"@stacksjs/arrays": "0.75.639",
|
|
105
|
+
"@stacksjs/auth": "0.75.639",
|
|
106
|
+
"@stacksjs/browser-extension": "0.75.639",
|
|
107
|
+
"@stacksjs/build": "0.75.639",
|
|
108
108
|
"@stacksjs/bumpx": "^0.2.32",
|
|
109
|
-
"@stacksjs/cache": "0.75.
|
|
110
|
-
"@stacksjs/chat": "0.75.
|
|
109
|
+
"@stacksjs/cache": "0.75.639",
|
|
110
|
+
"@stacksjs/chat": "0.75.639",
|
|
111
111
|
"@stacksjs/clapp": "^0.2.17",
|
|
112
|
-
"@stacksjs/cli": "0.75.
|
|
113
|
-
"@stacksjs/cloud": "0.75.
|
|
114
|
-
"@stacksjs/cms": "0.75.
|
|
115
|
-
"@stacksjs/collections": "0.75.
|
|
116
|
-
"@stacksjs/commerce": "0.75.
|
|
117
|
-
"@stacksjs/config": "0.75.
|
|
118
|
-
"@stacksjs/database": "0.75.
|
|
119
|
-
"@stacksjs/desktop-build": "0.75.
|
|
120
|
-
"@stacksjs/dns": "0.75.
|
|
112
|
+
"@stacksjs/cli": "0.75.639",
|
|
113
|
+
"@stacksjs/cloud": "0.75.639",
|
|
114
|
+
"@stacksjs/cms": "0.75.639",
|
|
115
|
+
"@stacksjs/collections": "0.75.639",
|
|
116
|
+
"@stacksjs/commerce": "0.75.639",
|
|
117
|
+
"@stacksjs/config": "0.75.639",
|
|
118
|
+
"@stacksjs/database": "0.75.639",
|
|
119
|
+
"@stacksjs/desktop-build": "0.75.639",
|
|
120
|
+
"@stacksjs/dns": "0.75.639",
|
|
121
121
|
"@stacksjs/dnsx": "^0.2.3",
|
|
122
|
-
"@stacksjs/email": "0.75.
|
|
123
|
-
"@stacksjs/enums": "0.75.
|
|
124
|
-
"@stacksjs/env": "0.75.
|
|
125
|
-
"@stacksjs/error-handling": "0.75.
|
|
126
|
-
"@stacksjs/events": "0.75.
|
|
127
|
-
"@stacksjs/features": "0.75.
|
|
128
|
-
"@stacksjs/git": "0.75.
|
|
122
|
+
"@stacksjs/email": "0.75.639",
|
|
123
|
+
"@stacksjs/enums": "0.75.639",
|
|
124
|
+
"@stacksjs/env": "0.75.639",
|
|
125
|
+
"@stacksjs/error-handling": "0.75.639",
|
|
126
|
+
"@stacksjs/events": "0.75.639",
|
|
127
|
+
"@stacksjs/features": "0.75.639",
|
|
128
|
+
"@stacksjs/git": "0.75.639",
|
|
129
129
|
"@stacksjs/gitit": "^0.2.5",
|
|
130
|
-
"@stacksjs/health": "0.75.
|
|
131
|
-
"@stacksjs/hq": "0.75.
|
|
130
|
+
"@stacksjs/health": "0.75.639",
|
|
131
|
+
"@stacksjs/hq": "0.75.639",
|
|
132
132
|
"@stacksjs/httx": "^0.1.10",
|
|
133
|
-
"@stacksjs/image": "0.75.
|
|
134
|
-
"@stacksjs/lint": "0.75.
|
|
135
|
-
"@stacksjs/logging": "0.75.
|
|
136
|
-
"@stacksjs/notifications": "0.75.
|
|
137
|
-
"@stacksjs/objects": "0.75.
|
|
138
|
-
"@stacksjs/orm": "0.75.
|
|
139
|
-
"@stacksjs/path": "0.75.
|
|
140
|
-
"@stacksjs/payments": "0.75.
|
|
141
|
-
"@stacksjs/realtime": "0.75.
|
|
142
|
-
"@stacksjs/router": "0.75.
|
|
133
|
+
"@stacksjs/image": "0.75.639",
|
|
134
|
+
"@stacksjs/lint": "0.75.639",
|
|
135
|
+
"@stacksjs/logging": "0.75.639",
|
|
136
|
+
"@stacksjs/notifications": "0.75.639",
|
|
137
|
+
"@stacksjs/objects": "0.75.639",
|
|
138
|
+
"@stacksjs/orm": "0.75.639",
|
|
139
|
+
"@stacksjs/path": "0.75.639",
|
|
140
|
+
"@stacksjs/payments": "0.75.639",
|
|
141
|
+
"@stacksjs/realtime": "0.75.639",
|
|
142
|
+
"@stacksjs/router": "0.75.639",
|
|
143
143
|
"@stacksjs/rpx": "^0.11.54",
|
|
144
|
-
"@stacksjs/scheduler": "0.75.
|
|
145
|
-
"@stacksjs/search-engine": "0.75.
|
|
146
|
-
"@stacksjs/security": "0.75.
|
|
147
|
-
"@stacksjs/server": "0.75.
|
|
148
|
-
"@stacksjs/sites": "0.75.
|
|
149
|
-
"@stacksjs/skills": "0.75.
|
|
150
|
-
"@stacksjs/socials": "0.75.
|
|
151
|
-
"@stacksjs/storage": "0.75.
|
|
152
|
-
"@stacksjs/strings": "0.75.
|
|
144
|
+
"@stacksjs/scheduler": "0.75.639",
|
|
145
|
+
"@stacksjs/search-engine": "0.75.639",
|
|
146
|
+
"@stacksjs/security": "0.75.639",
|
|
147
|
+
"@stacksjs/server": "0.75.639",
|
|
148
|
+
"@stacksjs/sites": "0.75.639",
|
|
149
|
+
"@stacksjs/skills": "0.75.639",
|
|
150
|
+
"@stacksjs/socials": "0.75.639",
|
|
151
|
+
"@stacksjs/storage": "0.75.639",
|
|
152
|
+
"@stacksjs/strings": "0.75.639",
|
|
153
153
|
"@stacksjs/stx": "^0.2.908",
|
|
154
|
-
"@stacksjs/testing": "0.75.
|
|
155
|
-
"@stacksjs/tinker": "0.75.
|
|
154
|
+
"@stacksjs/testing": "0.75.639",
|
|
155
|
+
"@stacksjs/tinker": "0.75.639",
|
|
156
156
|
"@stacksjs/tlsx": "^0.13.19",
|
|
157
157
|
"@stacksjs/ts-cloud": "^0.16.144",
|
|
158
|
-
"@stacksjs/tunnel": "0.75.
|
|
159
|
-
"@stacksjs/types": "0.75.
|
|
160
|
-
"@stacksjs/ui": "0.75.
|
|
161
|
-
"@stacksjs/utils": "0.75.
|
|
162
|
-
"@stacksjs/validation": "0.75.
|
|
158
|
+
"@stacksjs/tunnel": "0.75.639",
|
|
159
|
+
"@stacksjs/types": "0.75.639",
|
|
160
|
+
"@stacksjs/ui": "0.75.639",
|
|
161
|
+
"@stacksjs/utils": "0.75.639",
|
|
162
|
+
"@stacksjs/validation": "0.75.639",
|
|
163
163
|
"ajv": "^8.20.0",
|
|
164
164
|
"ajv-formats": "^3.0.1",
|
|
165
165
|
"bun-plugin-stx": "^0.2.908",
|