@stacksjs/actions 0.74.28 → 0.74.31
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/dev/api.js +1 -1
- package/dist/discover-packages.d.ts +20 -0
- package/dist/discover-packages.js +2 -2
- package/dist/generate/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/make.js +1 -1
- package/dist/serve/api.js +1 -1
- package/package.json +38 -38
package/dist/dev/api.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{existsSync}from"node:fs";import process from"node:process";import{parseOptions}from"@stacksjs/cli";import{config,overridesReady}from"@stacksjs/config";import{path}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{autoImportsAreStale,generateAutoImportFiles,generateServerAutoImportTypes,injectGlobalAutoImports}from"@stacksjs/server";import{resolveApiHost}from"../helpers/api-host";import{exitWithParent}from"./exit-with-parent";const _options=parseOptions();exitWithParent();await generateServerAutoImportTypes();await overridesReady;const port=Number(process.env.PORT_API)||config.ports?.api||3008,hostname=resolveApiHost()
|
|
1
|
+
import{existsSync}from"node:fs";import process from"node:process";import{parseOptions}from"@stacksjs/cli";import{config,overridesReady}from"@stacksjs/config";import{path}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{autoImportsAreStale,generateAutoImportFiles,generateServerAutoImportTypes,injectGlobalAutoImports}from"@stacksjs/server";import{resolveApiHost}from"../helpers/api-host";import{exitWithParent}from"./exit-with-parent";const _options=parseOptions();exitWithParent();await generateServerAutoImportTypes();await overridesReady;const port=Number(process.env.PORT_API)||config.ports?.api||3008,hostname=resolveApiHost();try{const{discoverPackages}=await import("../discover-packages");await discoverPackages()}catch{}const modelsIndex=path.storagePath("framework/auto-imports/models.ts");if(!existsSync(modelsIndex)||autoImportsAreStale())await generateAutoImportFiles();await injectGlobalAutoImports();try{const typesenseDev=path.appPath("Lib/typesense-dev.ts");if(existsSync(typesenseDev)){const mod=await import(typesenseDev);if(typeof mod.ensureTypesenseRunning==="function")await mod.ensureTypesenseRunning()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] search engine bootstrap skipped: ${err.message}`)}try{const listenerPath=path.appPath("Listener.ts");if(existsSync(listenerPath)){const listener=await import(listenerPath);if(typeof listener.handleEvents==="function")await listener.handleEvents()}}catch(err){const{log}=await import("@stacksjs/cli");log.warn(`[api:dev] failed to bootstrap event listeners - dispatched events will be ignored: ${err.message}`)}try{const{startModelMigrationWatcher}=await import("./migrate-watcher");startModelMigrationWatcher()}catch(err){const{log}=await import("@stacksjs/cli");log.debug(`[api:dev] auto-migrate watcher not started: ${err.message}`)}function resolveDefaultsCorsPath(){const published=path.appPath("Middleware/Cors.ts");if(existsSync(published))return published;const vendored=path.frameworkPath("defaults/app/Middleware/Cors.ts");if(existsSync(vendored))return vendored;try{return`${Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd()).replace(/package\.json$/,"")}app/Middleware/Cors.ts`}catch{return vendored}}const corsMod=await import(resolveDefaultsCorsPath()),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());const SAFE_REQUEST_ID=/^[a-zA-Z0-9._-]{8,128}$/;route.use(async(request,next)=>{const inbound=request?.headers?.get?.("x-request-id")||request?.headers?.get?.("X-Request-ID")||"",id=typeof inbound==="string"&&SAFE_REQUEST_ID.test(inbound)?inbound:crypto.randomUUID();request._requestId=id;request._startNs=process.hrtime.bigint();const response=await next();if(response&&response.status===404&&(response.headers.get("content-type")||"").includes("json"))try{const body=await response.clone().json();if(body&&(body.message==="Not Found"||body.error==="Not Found")){const url=new URL(request.url),enriched={...body,path:url.pathname,method:request.method,request_id:id},headers=new Headers(response.headers);headers.set("X-Request-ID",id);return new Response(JSON.stringify(enriched),{status:404,headers})}}catch{}return response});await route.importRoutes();disableViewRouting(route.bunRouter);try{await route.serve({port,hostname});console.log(`
|
|
2
2
|
\u279C API server ready: http://${hostname}:${port}
|
|
3
3
|
`)}catch(err){if((err?.code||err?.errno)==="EADDRINUSE"||String(err?.message||"").includes("EADDRINUSE")){console.error(`
|
|
4
4
|
[dev/api] Port ${port} is already in use. Kill the other process and re-run \`./buddy dev\`, or set PORT_API to another port.
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
import type { StackDirectory } from '@stacksjs/types';
|
|
2
2
|
export declare function discoverPackages(options?: DiscoverPackagesOptions): Promise<DiscoveredPackagesManifest>;
|
|
3
|
+
/**
|
|
4
|
+
* Discover packages, and never fail a boot for it.
|
|
5
|
+
*
|
|
6
|
+
* The production entries call this; `buddy dev` and `buddy package:discover`
|
|
7
|
+
* call `discoverPackages` directly because they want the result or the error.
|
|
8
|
+
*
|
|
9
|
+
* Discovery used to run in exactly two places, `dev/api.ts` and the
|
|
10
|
+
* `package:discover` command, and the manifest it writes is gitignored. A
|
|
11
|
+
* deployed application therefore ran whatever manifest happened to ride along
|
|
12
|
+
* in the tarball from a developer's machine, or none at all - so a package's
|
|
13
|
+
* routes, models and migrations worked in `buddy dev` and silently did not in
|
|
14
|
+
* production. Worse than absent: a manifest naming a package that is no longer
|
|
15
|
+
* installed makes `assertRouteMiddlewareResolvable()` throw during router boot.
|
|
16
|
+
*
|
|
17
|
+
* Swallowing the error is deliberate. An application's own routes and models do
|
|
18
|
+
* not depend on discovery having succeeded, and a server that refuses to start
|
|
19
|
+
* because one dependency shipped an unreadable directory is worse than one that
|
|
20
|
+
* starts without that dependency's routes.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensureDiscoveredPackages(): Promise<void>;
|
|
3
23
|
/**
|
|
4
24
|
* Find the installed packages that extend this application.
|
|
5
25
|
*
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{existsSync}from"node:fs";import{isAbsolute,join,relative}from"node:path";import{projectPath,storagePath}from"@stacksjs/path";async function readManifest(file){try{return await Bun.file(file).json()}catch{return null}}async function directDependencies(projectRoot){const pkg=await readManifest(join(projectRoot,"package.json"));if(!pkg)return[];const names=new Set;for(const field of["dependencies","devDependencies","peerDependencies"]){const block=pkg[field];if(block&&typeof block==="object")for(const name of Object.keys(block))names.add(name)}return[...names].sort()}async function fromNodeModules(projectRoot){const root=join(projectRoot,"node_modules");if(!existsSync(root))return[];const out=[];for(const name of await directDependencies(projectRoot)){const dir=join(root,name),pkg=await readManifest(join(dir,"package.json"));if(!pkg?.name||!pkg.stacks||typeof pkg.stacks!=="object")continue;out.push({name:pkg.name,meta:pkg.stacks,dir})}return out}async function fromPantry(projectRoot){const root=join(projectRoot,"pantry");if(!existsSync(root))return[];const out=[];for(const pattern of["*/package.json","@*/*/package.json"]){const glob=new Bun.Glob(pattern);for await(const file of glob.scan({cwd:root,absolute:!0,onlyFiles:!0})){const pkg=await readManifest(file);if(!pkg?.name||!pkg.stacks||typeof pkg.stacks!=="object")continue;out.push({name:pkg.name,meta:pkg.stacks,dir:join(file,"..")})}}return out.sort((a,b)=>a.name.localeCompare(b.name))}async function dontDiscover(projectRoot){const list=(await readManifest(join(projectRoot,"package.json")))?.stacks?.["dont-discover"];return new Set(Array.isArray(list)?list:[])}export async function discoverPackages(options={}){const projectRoot=options.projectRoot??projectPath(),manifestPath=options.manifestPath??storagePath("framework/discovered-packages.json"),excluded=await dontDiscover(projectRoot),found=[...await fromNodeModules(projectRoot),...await fromPantry(projectRoot)],packages={},shadowed=[],chosen=new Map;for(const candidate of found){if(excluded.has(candidate.name))continue;const root=toRelative(projectRoot,candidate.dir),already=chosen.get(candidate.name);if(already!==void 0){shadowed.push({name:candidate.name,used:already,ignored:root});continue}chosen.set(candidate.name,root);packages[candidate.name]={...candidate.meta,root}}const manifest={generated_at:new Date().toISOString(),packages,...shadowed.length>0?{shadowed}:{}};if(options.dryRun)return manifest;try{const current=await Bun.file(manifestPath).json();if(JSON.stringify(current.packages??{})===JSON.stringify(manifest.packages)&&JSON.stringify(current.shadowed??[])===JSON.stringify(shadowed))return current}catch{}await Bun.write(
|
|
2
|
-
`);return manifest}function toRelative(projectRoot,dir){const rel=relative(projectRoot,dir);return rel&&!rel.startsWith("..")&&!isAbsolute(rel)?rel:dir}
|
|
1
|
+
import{existsSync,renameSync,unlinkSync}from"node:fs";import process from"node:process";import{isAbsolute,join,relative}from"node:path";import{projectPath,storagePath}from"@stacksjs/path";async function readManifest(file){try{return await Bun.file(file).json()}catch{return null}}async function directDependencies(projectRoot){const pkg=await readManifest(join(projectRoot,"package.json"));if(!pkg)return[];const names=new Set;for(const field of["dependencies","devDependencies","peerDependencies"]){const block=pkg[field];if(block&&typeof block==="object")for(const name of Object.keys(block))names.add(name)}return[...names].sort()}async function fromNodeModules(projectRoot){const root=join(projectRoot,"node_modules");if(!existsSync(root))return[];const out=[];for(const name of await directDependencies(projectRoot)){const dir=join(root,name),pkg=await readManifest(join(dir,"package.json"));if(!pkg?.name||!pkg.stacks||typeof pkg.stacks!=="object")continue;out.push({name:pkg.name,meta:pkg.stacks,dir})}return out}async function fromPantry(projectRoot){const root=join(projectRoot,"pantry");if(!existsSync(root))return[];const out=[];for(const pattern of["*/package.json","@*/*/package.json"]){const glob=new Bun.Glob(pattern);for await(const file of glob.scan({cwd:root,absolute:!0,onlyFiles:!0})){const pkg=await readManifest(file);if(!pkg?.name||!pkg.stacks||typeof pkg.stacks!=="object")continue;out.push({name:pkg.name,meta:pkg.stacks,dir:join(file,"..")})}}return out.sort((a,b)=>a.name.localeCompare(b.name))}async function dontDiscover(projectRoot){const list=(await readManifest(join(projectRoot,"package.json")))?.stacks?.["dont-discover"];return new Set(Array.isArray(list)?list:[])}export async function discoverPackages(options={}){const projectRoot=options.projectRoot??projectPath(),manifestPath=options.manifestPath??storagePath("framework/discovered-packages.json"),excluded=await dontDiscover(projectRoot),found=[...await fromNodeModules(projectRoot),...await fromPantry(projectRoot)],packages={},shadowed=[],chosen=new Map;for(const candidate of found){if(excluded.has(candidate.name))continue;const root=toRelative(projectRoot,candidate.dir),already=chosen.get(candidate.name);if(already!==void 0){shadowed.push({name:candidate.name,used:already,ignored:root});continue}chosen.set(candidate.name,root);packages[candidate.name]={...candidate.meta,root}}const manifest={generated_at:new Date().toISOString(),packages,...shadowed.length>0?{shadowed}:{}};if(options.dryRun)return manifest;try{const current=await Bun.file(manifestPath).json();if(JSON.stringify(current.packages??{})===JSON.stringify(manifest.packages)&&JSON.stringify(current.shadowed??[])===JSON.stringify(shadowed))return current}catch{}const temp=`${manifestPath}.${process.pid}.tmp`;try{await Bun.write(temp,`${JSON.stringify(manifest,null,2)}
|
|
2
|
+
`);renameSync(temp,manifestPath)}catch(error){try{unlinkSync(temp)}catch{}throw error}return manifest}export async function ensureDiscoveredPackages(){try{await discoverPackages()}catch(error){const{log}=await import("@stacksjs/logging");log.warn(`[discovery] Could not refresh the package manifest: ${error instanceof Error?error.message:String(error)}`)}}function toRelative(projectRoot,dir){const rel=relative(projectRoot,dir);return rel&&!rel.startsWith("..")&&!isAbsolute(rel)?rel:dir}
|
package/dist/generate/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as fs from"node:fs";import process from"node:process";import{runCommand}from"@stacksjs/cli";import{Action,NpmScript}from"@stacksjs/enums";import{log}from"@stacksjs/logging";import{frameworkPath,projectPath}from"@stacksjs/path";import{ExitCode}from"@stacksjs/types";import{runNpmScript}from"@stacksjs/utils";import{runAction}from"../helpers";import{generateVsCodeCustomData as genVsCodeCustomData,generateWebTypes as genWebTypes}from"../helpers/vscode-custom-data";import{generateProjectImages}from"./images";import{generateRouteNames}from"./action-types";export{generateProjectImages}from"./images";export{generateVSchema}from"./vschema";export async function invoke(options){if(options?.types)await generateTypes(options);else if(options?.entries)await generateLibEntries(options);else if(options?.webTypes)await generateWebTypes();else if(options?.customData)await generateVsCodeCustomData();else if(options?.ideHelpers)await generateIdeHelpers();else if(options?.componentMeta)await generateComponentMeta();else if(options?.coreSymlink)await generateCoreSymlink();else if(options?.openApiSpec)await generateOpenApiSpec();else if(options?.images)await generateProjectImages({verbose:options?.verbose});else await generateEverything(options)}async function generateEverything(options){log.info("Generating types, entry points, component meta and the OpenAPI spec...");await generateTypes({...options,types:!0});await generateLibEntries({...options,entries:!0});await generateOpenApiSpec();log.success("Generated")}export function generate(options){return invoke(options)}export async function generateLibEntries(options){const result=await runAction(Action.GenerateLibraryEntries,{...options,cwd:projectPath()});if(result.isErr){await log.error("There was an error generating your library entry points",result.error);process.exit(ExitCode.FatalError)}log.success("Library entry points generated successfully")}export async function generateWebTypes(){await genWebTypes()}export async function generateVsCodeCustomData(){const result=await genVsCodeCustomData();if(result.isErr){await log.error("There was an error generating the custom-elements.json file.",result.error);process.exit(ExitCode.FatalError)}await runAction(Action.LintFix,{verbose:!0,cwd:projectPath()});log.success("Successfully generated the custom-elements.json file")}export async function generateIdeHelpers(){await genWebTypes();await genVsCodeCustomData();await runAction(Action.LintFix,{verbose:!0,cwd:projectPath()});log.success("Successfully generated IDE helpers")}export async function generateComponentMeta(){const result=await genVsCodeCustomData();if(result.isErr){await log.error("There was an error generating your component meta information.",result.error);process.exit(ExitCode.FatalError)}await runAction(Action.LintFix,{verbose:!0,cwd:projectPath()});log.success("Successfully generated component meta information")}export async function generateTypes(options){try{const{generateAutoImportFiles}=await import("@stacksjs/server");await generateAutoImportFiles()}catch(error){log.debug("[generate:types] Could not refresh the auto-import registries",{error})}await generateRouteNames();try{const previous=process.env.STACKS_CANONICAL_FEATURES;process.env.STACKS_CANONICAL_FEATURES="1";try{const{generateServerAutoImportTypes}=await import("@stacksjs/server");await generateServerAutoImportTypes()}finally{if(previous===void 0)delete process.env.STACKS_CANONICAL_FEATURES;else process.env.STACKS_CANONICAL_FEATURES=previous}}catch(error){log.debug("[generate:types] Could not refresh server auto-import declarations",{error})}const entry=frameworkPath("core/actions/src/generate/types.ts");if(!fs.existsSync(entry)){await import(`./types?t=${Date.now()}`);return}const result=await runNpmScript(NpmScript.GenerateTypes,{cwd:frameworkPath(),...options});if(result.isErr){log.error("There was an error generating your types.",result.error);throw result.error instanceof Error?result.error:Error(String(result.error))}log.success("Types were generated successfully")}export async function watchTypes(options){try{const manifestPath=`${frameworkPath()}/package.json`,text=fs.existsSync(manifestPath)?fs.readFileSync(manifestPath,"utf-8"):"";if(!(text?JSON.parse(text):{})?.scripts?.["generate:types"]){log.warn("[generate:types --watch] no `generate:types` script in framework package.json - type regeneration disabled. dev:api will keep running, but type definitions won't auto-refresh on model/config changes.");return}}catch{}const watched=[...await(async()=>{try{const{autoImportSourceDirs}=await import("@stacksjs/server");return autoImportSourceDirs()}catch{return[]}})(),projectPath("config"),projectPath("database/migrations"),projectPath("app"),projectPath("routes")].filter((dir,index,all)=>all.indexOf(dir)===index);log.info(`[generate:types --watch] watching ${watched.length} directories`);let pending=null,inflight=!1;const trigger=()=>{if(pending)clearTimeout(pending);pending=setTimeout(async()=>{if(inflight)return;inflight=!0;try{log.info("[generate:types --watch] change detected, regenerating\u2026");await generateTypes(options);log.success("[generate:types --watch] types up to date")}catch(err){log.error("[generate:types --watch] regeneration failed:",err)}finally{inflight=!1}},200)},watchers=[];for(const dir of watched)try{if(!fs.existsSync(dir))continue;const w=fs.watch(dir,{recursive:!0},()=>trigger());watchers.push(w)}catch(err){log.warn(`[generate:types --watch] cannot watch ${dir}: ${err}`)}if(watchers.length===0){log.warn("[generate:types --watch] no directories to watch - exiting");return}await new Promise((resolve)=>{process.once("SIGINT",()=>{log.info("[generate:types --watch] stopping");for(const w of watchers)try{w.close()}catch{}resolve()})})}export function generatePantryConfig(){log.success("Successfully generated `./pantry.yaml` based on your config")}export async function generateSeeder(){}export async function generateCoreSymlink(){const link=projectPath(".framework");if(fs.existsSync(link))await runCommand(`rm -f ${link}`);await runCommand(`ln -s ${frameworkPath()} ${link}`)}export async function generateOpenApiSpec(){const{generateOpenApi}=await import("@stacksjs/api");await generateOpenApi();log.success("Successfully generated Open API Spec")}
|
|
1
|
+
import*as fs from"node:fs";import process from"node:process";import{runCommand}from"@stacksjs/cli";import{Action,NpmScript}from"@stacksjs/enums";import{log}from"@stacksjs/logging";import{frameworkPath,projectPath}from"@stacksjs/path";import{ExitCode}from"@stacksjs/types";import{runNpmScript}from"@stacksjs/utils";import{runAction}from"../helpers";import{generateVsCodeCustomData as genVsCodeCustomData,generateWebTypes as genWebTypes}from"../helpers/vscode-custom-data";import{generateProjectImages}from"./images";import{generateRouteNames}from"./action-types";export{generateProjectImages}from"./images";export{generateVSchema}from"./vschema";export async function invoke(options){if(options?.types)await generateTypes(options);else if(options?.entries)await generateLibEntries(options);else if(options?.webTypes)await generateWebTypes();else if(options?.customData)await generateVsCodeCustomData();else if(options?.ideHelpers)await generateIdeHelpers();else if(options?.componentMeta)await generateComponentMeta();else if(options?.coreSymlink)await generateCoreSymlink();else if(options?.openApiSpec)await generateOpenApiSpec();else if(options?.images)await generateProjectImages({verbose:options?.verbose});else await generateEverything(options)}async function generateEverything(options){log.info("Generating types, entry points, component meta and the OpenAPI spec...");try{const{discoverPackages}=await import("../discover-packages");await discoverPackages()}catch{}await generateTypes({...options,types:!0});await generateLibEntries({...options,entries:!0});await generateOpenApiSpec();log.success("Generated")}export function generate(options){return invoke(options)}export async function generateLibEntries(options){const result=await runAction(Action.GenerateLibraryEntries,{...options,cwd:projectPath()});if(result.isErr){await log.error("There was an error generating your library entry points",result.error);process.exit(ExitCode.FatalError)}log.success("Library entry points generated successfully")}export async function generateWebTypes(){await genWebTypes()}export async function generateVsCodeCustomData(){const result=await genVsCodeCustomData();if(result.isErr){await log.error("There was an error generating the custom-elements.json file.",result.error);process.exit(ExitCode.FatalError)}await runAction(Action.LintFix,{verbose:!0,cwd:projectPath()});log.success("Successfully generated the custom-elements.json file")}export async function generateIdeHelpers(){await genWebTypes();await genVsCodeCustomData();await runAction(Action.LintFix,{verbose:!0,cwd:projectPath()});log.success("Successfully generated IDE helpers")}export async function generateComponentMeta(){const result=await genVsCodeCustomData();if(result.isErr){await log.error("There was an error generating your component meta information.",result.error);process.exit(ExitCode.FatalError)}await runAction(Action.LintFix,{verbose:!0,cwd:projectPath()});log.success("Successfully generated component meta information")}export async function generateTypes(options){try{const{generateAutoImportFiles}=await import("@stacksjs/server");await generateAutoImportFiles()}catch(error){log.debug("[generate:types] Could not refresh the auto-import registries",{error})}await generateRouteNames();try{const previous=process.env.STACKS_CANONICAL_FEATURES;process.env.STACKS_CANONICAL_FEATURES="1";try{const{generateServerAutoImportTypes}=await import("@stacksjs/server");await generateServerAutoImportTypes()}finally{if(previous===void 0)delete process.env.STACKS_CANONICAL_FEATURES;else process.env.STACKS_CANONICAL_FEATURES=previous}}catch(error){log.debug("[generate:types] Could not refresh server auto-import declarations",{error})}const entry=frameworkPath("core/actions/src/generate/types.ts");if(!fs.existsSync(entry)){await import(`./types?t=${Date.now()}`);return}const result=await runNpmScript(NpmScript.GenerateTypes,{cwd:frameworkPath(),...options});if(result.isErr){log.error("There was an error generating your types.",result.error);throw result.error instanceof Error?result.error:Error(String(result.error))}log.success("Types were generated successfully")}export async function watchTypes(options){try{const manifestPath=`${frameworkPath()}/package.json`,text=fs.existsSync(manifestPath)?fs.readFileSync(manifestPath,"utf-8"):"";if(!(text?JSON.parse(text):{})?.scripts?.["generate:types"]){log.warn("[generate:types --watch] no `generate:types` script in framework package.json - type regeneration disabled. dev:api will keep running, but type definitions won't auto-refresh on model/config changes.");return}}catch{}const watched=[...await(async()=>{try{const{autoImportSourceDirs}=await import("@stacksjs/server");return autoImportSourceDirs()}catch{return[]}})(),projectPath("config"),projectPath("database/migrations"),projectPath("app"),projectPath("routes")].filter((dir,index,all)=>all.indexOf(dir)===index);log.info(`[generate:types --watch] watching ${watched.length} directories`);let pending=null,inflight=!1;const trigger=()=>{if(pending)clearTimeout(pending);pending=setTimeout(async()=>{if(inflight)return;inflight=!0;try{log.info("[generate:types --watch] change detected, regenerating\u2026");await generateTypes(options);log.success("[generate:types --watch] types up to date")}catch(err){log.error("[generate:types --watch] regeneration failed:",err)}finally{inflight=!1}},200)},watchers=[];for(const dir of watched)try{if(!fs.existsSync(dir))continue;const w=fs.watch(dir,{recursive:!0},()=>trigger());watchers.push(w)}catch(err){log.warn(`[generate:types --watch] cannot watch ${dir}: ${err}`)}if(watchers.length===0){log.warn("[generate:types --watch] no directories to watch - exiting");return}await new Promise((resolve)=>{process.once("SIGINT",()=>{log.info("[generate:types --watch] stopping");for(const w of watchers)try{w.close()}catch{}resolve()})})}export function generatePantryConfig(){log.success("Successfully generated `./pantry.yaml` based on your config")}export async function generateSeeder(){}export async function generateCoreSymlink(){const link=projectPath(".framework");if(fs.existsSync(link))await runCommand(`rm -f ${link}`);await runCommand(`ln -s ${frameworkPath()} ${link}`)}export async function generateOpenApiSpec(){const{generateOpenApi}=await import("@stacksjs/api");await generateOpenApi();log.success("Successfully generated Open API Spec")}
|
package/dist/index.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export {
|
|
|
68
68
|
make as runMake,
|
|
69
69
|
setDryRun,
|
|
70
70
|
} from './make';
|
|
71
|
-
export { discoverPackages } from './discover-packages';
|
|
71
|
+
export { discoverPackages, ensureDiscoveredPackages } from './discover-packages';
|
|
72
72
|
export { parseFields, scaffoldCrud } from './scaffold-crud';
|
|
73
73
|
export { installStack, uninstallStack, listStacks } from './stacks';
|
|
74
74
|
export { makeJob } from './make-job';
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{setActionRunner}from"@stacksjs/action-runner";import{runAction}from"./helpers";setActionRunner((action,options)=>runAction(action,options));export*from"./action";export{add as runAdd}from"./add";export{BlogAdminError,deleteBlogPost,getBlogPost,listBlogPosts,saveBlogPost,slugify as blogSlugify}from"./blog-admin";export{commit as runCommit}from"./commit";export*from"./dev";export*from"./generate";export*from"./helpers";export*from"./library";export{formatProject,lintFix,lintProject}from"./lint/lint";export{DEFAULT_STX_LINT_CONFIG,loadStxLintConfig,runStxLint}from"./lint/stx-gate";export{measureDefaultsDrift,summarizeStructureChanges}from"./upgrade/package-project";export*from"./setup";export{createComponent,createDatabase,createFactory,createFunction,createLanguage,createMiddleware,createMigration,createModel,createMail,createNotification,createPage,isDryRunActive,makeAction,makeCertificate,makeComponent,makeDatabase,makeFunction,makeLanguage,makeMail,makeNotification,makePage,makeQueueTable,makeStack,make as runMake,setDryRun}from"./make";export{discoverPackages}from"./discover-packages";export{parseFields,scaffoldCrud}from"./scaffold-crud";export{installStack,uninstallStack,listStacks}from"./stacks";export{makeJob}from"./make-job";export{makeCommand}from"./make-command";export{makePolicy}from"./make-policy";export{makeResource}from"./make-resource";
|
|
1
|
+
import{setActionRunner}from"@stacksjs/action-runner";import{runAction}from"./helpers";setActionRunner((action,options)=>runAction(action,options));export*from"./action";export{add as runAdd}from"./add";export{BlogAdminError,deleteBlogPost,getBlogPost,listBlogPosts,saveBlogPost,slugify as blogSlugify}from"./blog-admin";export{commit as runCommit}from"./commit";export*from"./dev";export*from"./generate";export*from"./helpers";export*from"./library";export{formatProject,lintFix,lintProject}from"./lint/lint";export{DEFAULT_STX_LINT_CONFIG,loadStxLintConfig,runStxLint}from"./lint/stx-gate";export{measureDefaultsDrift,summarizeStructureChanges}from"./upgrade/package-project";export*from"./setup";export{createComponent,createDatabase,createFactory,createFunction,createLanguage,createMiddleware,createMigration,createModel,createMail,createNotification,createPage,isDryRunActive,makeAction,makeCertificate,makeComponent,makeDatabase,makeFunction,makeLanguage,makeMail,makeNotification,makePage,makeQueueTable,makeStack,make as runMake,setDryRun}from"./make";export{discoverPackages,ensureDiscoveredPackages}from"./discover-packages";export{parseFields,scaffoldCrud}from"./scaffold-crud";export{installStack,uninstallStack,listStacks}from"./stacks";export{makeJob}from"./make-job";export{makeCommand}from"./make-command";export{makePolicy}from"./make-policy";export{makeResource}from"./make-resource";
|
package/dist/make.js
CHANGED
|
@@ -3,7 +3,7 @@ import process from"node:process";import{existsSync}from"node:fs";import{italic,
|
|
|
3
3
|
`),truncated=lines.length>60?`
|
|
4
4
|
${italic(`\u2026 ${lines.length-60} more lines elided`)}`:"";log.info(`[dry-run] would write ${path} (${lines.length} lines)`);process.stdout.write(`${preview}${truncated}
|
|
5
5
|
|
|
6
|
-
`);return}await writeTextFile({path,data})}async function createFileWithTemplate(path,templateKey,...args){await writeOrPreview(path,generateCode(templateKey,...args))}export async function invoke(options){if(options.component)await makeComponent(options);if(options.database)makeDatabase(options);if(options.function)await makeFunction(options);if(options.language)await makeLanguage(options);if(options.middleware)await createMiddleware(options);if(options.notification)await makeNotification(options);if(options.page)await makePage(options);if(options.stack)await makeStack(options)}export async function make(options){return await invoke(options)}function requireName(options,what){const name=options.name?.trim();if(!name){console.error(`A name is required to create a ${what}. Pass one with --name.`);process.exit(ExitCode.InvalidArgument)}return name}export async function makeAction(options){try{const name=requireName(options,"action");log.info("Creating your action...");await createAction(options);log.success(`Created ${italic(name)} action`)}catch(error){await log.error("There was an error creating your action",error);process.exit(ExitCode.FatalError)}}export async function makeComponent(options){try{const name=requireName(options,"component");log.info("Creating your component...");await createComponent(options);log.success(`Created ${italic(name)} component`)}catch(error){await log.error("There was an error creating your component",error);process.exit(ExitCode.FatalError)}}export async function createAction(options){const name=requireName(options,"
|
|
6
|
+
`);return}await writeTextFile({path,data})}async function createFileWithTemplate(path,templateKey,...args){await writeOrPreview(path,generateCode(templateKey,...args))}export async function invoke(options){if(options.component)await makeComponent(options);if(options.database)makeDatabase(options);if(options.function)await makeFunction(options);if(options.language)await makeLanguage(options);if(options.middleware)await createMiddleware(options);if(options.notification)await makeNotification(options);if(options.page)await makePage(options);if(options.stack)await makeStack(options)}export async function make(options){return await invoke(options)}function requireName(options,what){const name=options.name?.trim();if(!name){console.error(`A name is required to create a ${what}. Pass one with --name.`);process.exit(ExitCode.InvalidArgument)}return name}export async function makeAction(options){try{const name=requireName(options,"action");log.info("Creating your action...");await createAction(options);log.success(`Created ${italic(name)} action`)}catch(error){await log.error("There was an error creating your action",error);process.exit(ExitCode.FatalError)}}export async function makeComponent(options){try{const name=requireName(options,"component");log.info("Creating your component...");await createComponent(options);log.success(`Created ${italic(name)} component`)}catch(error){await log.error("There was an error creating your component",error);process.exit(ExitCode.FatalError)}}export async function createAction(options){const name=requireName(options,"action"),opts=options,wantsValidation=Boolean(opts.withValidation||options["with-validation"]),wantsAuth=Boolean(opts.withAuth||options["with-auth"]),templateKey=wantsValidation&&wantsAuth?"actionWithBoth":wantsValidation?"actionWithValidation":wantsAuth?"actionWithAuth":"action";await createFileWithTemplate(p.userActionsPath(`${name}.ts`),templateKey,name)}export async function createComponent(options){const name=requireName(options,"component");await createFileWithTemplate(p.userComponentsPath(componentFileName(name)),"component",name)}export function componentFileName(name){return`${name}.stx`}export function makeDatabase(options){try{createDatabase(options)}catch(error){console.error("There was an error creating your database",error);process.exit(ExitCode.FatalError)}}export function createDatabase(options){const name=pascalCase(options.name||"MyModel");console.log(`
|
|
7
7
|
Stacks manages the database through models and migrations, so there is no separate database to create.
|
|
8
8
|
|
|
9
9
|
To add a "${name}" table:
|
package/dist/serve/api.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync}from"node:fs";import{dirname,join}from"node:path";import process from"node:process";import{config,overridesReady}from"@stacksjs/config";import{log}from"@stacksjs/logging";import{appPath,frameworkPath}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{resolveApiHost}from"../helpers/api-host";function resolveDefaultsFile(rel){if(rel.startsWith("app/")){const published=appPath(rel.slice(4));if(existsSync(published))return published}const vendored=frameworkPath(`defaults/${rel}`);if(existsSync(vendored))return vendored;try{const pkgJson=Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd());return join(dirname(pkgJson),rel)}catch{return vendored}}await overridesReady;const port=Number(process.env.PORT)||config.ports?.api||3008,hostname=resolveApiHost();log.info("[Stacks API] Starting server...");log.info(`[Stacks API] Environment: ${process.env.APP_ENV||"development"}`);const corsMod=await import(resolveDefaultsFile("app/Middleware/Cors.ts")),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());await route.importRoutes();try{const{describeUnforwardableRoutes,resolveApiProxyRules,unforwardableRoutes}=await import("@stacksjs/server"),{listRootMountedAppRoutes}=await import("@stacksjs/router"),unreachable=unforwardableRoutes(listRootMountedAppRoutes().filter((entry)=>entry.method==="GET"||entry.method==="HEAD"),resolveApiProxyRules(config.server?.proxy));if(unreachable.length>0)log.warn(describeUnforwardableRoutes(unreachable))}catch(error){log.debug(`[Stacks API] Route reachability check skipped: ${error instanceof Error?error.message:String(error)}`)}disableViewRouting(route.bunRouter);const isDeployed=["production","staging","development"].includes((process.env.APP_ENV||"").toLowerCase()),server=await route.serve({port,hostname,reusePort:isDeployed});process.on("SIGTERM",()=>{const graceMs=Number(process.env.SHUTDOWN_GRACE_MS)||15000;setTimeout(()=>process.exit(0),graceMs).unref();Promise.resolve(server?.stop()).then(()=>process.exit(0))});log.info(`[Stacks API] Server running at http://${hostname}:${port}`);
|
|
1
|
+
import{existsSync}from"node:fs";import{dirname,join}from"node:path";import process from"node:process";import{config,overridesReady}from"@stacksjs/config";import{log}from"@stacksjs/logging";import{appPath,frameworkPath}from"@stacksjs/path";import{disableViewRouting,route}from"@stacksjs/router";import{ensureDiscoveredPackages}from"../discover-packages";import{resolveApiHost}from"../helpers/api-host";function resolveDefaultsFile(rel){if(rel.startsWith("app/")){const published=appPath(rel.slice(4));if(existsSync(published))return published}const vendored=frameworkPath(`defaults/${rel}`);if(existsSync(vendored))return vendored;try{const pkgJson=Bun.resolveSync("@stacksjs/defaults/package.json",process.cwd());return join(dirname(pkgJson),rel)}catch{return vendored}}await overridesReady;const port=Number(process.env.PORT)||config.ports?.api||3008,hostname=resolveApiHost();log.info("[Stacks API] Starting server...");log.info(`[Stacks API] Environment: ${process.env.APP_ENV||"development"}`);const corsMod=await import(resolveDefaultsFile("app/Middleware/Cors.ts")),corsMiddleware=corsMod.default;route.use(corsMiddleware.toRouterHandler());await ensureDiscoveredPackages();const{autoImportsAreStale,generateAutoImportFiles,injectGlobalAutoImports}=await import("@stacksjs/server");try{if(autoImportsAreStale()){log.info("[Stacks API] Installed packages moved since the auto-import barrel was written; rebuilding it.");await generateAutoImportFiles({declarations:!1})}}catch(error){log.warn(`[Stacks API] Could not refresh the auto-import barrel: ${error instanceof Error?error.message:String(error)}`)}await injectGlobalAutoImports();await route.importRoutes();try{const{describeUnforwardableRoutes,resolveApiProxyRules,unforwardableRoutes}=await import("@stacksjs/server"),{listRootMountedAppRoutes}=await import("@stacksjs/router"),unreachable=unforwardableRoutes(listRootMountedAppRoutes().filter((entry)=>entry.method==="GET"||entry.method==="HEAD"),resolveApiProxyRules(config.server?.proxy));if(unreachable.length>0)log.warn(describeUnforwardableRoutes(unreachable))}catch(error){log.debug(`[Stacks API] Route reachability check skipped: ${error instanceof Error?error.message:String(error)}`)}disableViewRouting(route.bunRouter);const isDeployed=["production","staging","development"].includes((process.env.APP_ENV||"").toLowerCase()),server=await route.serve({port,hostname,reusePort:isDeployed});process.on("SIGTERM",()=>{const graceMs=Number(process.env.SHUTDOWN_GRACE_MS)||15000;setTimeout(()=>process.exit(0),graceMs).unref();Promise.resolve(server?.stop()).then(()=>process.exit(0))});log.info(`[Stacks API] Server running at http://${hostname}:${port}`);
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/actions",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.74.
|
|
5
|
+
"version": "0.74.31",
|
|
6
6
|
"description": "The Stacks actions.",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"contributors": [
|
|
@@ -60,51 +60,51 @@
|
|
|
60
60
|
"prepublishOnly": "bun run build"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@stacksjs/action-runner": "0.74.
|
|
64
|
-
"@stacksjs/ai": "0.74.
|
|
65
|
-
"@stacksjs/analytics": "0.74.
|
|
66
|
-
"@stacksjs/api": "0.74.
|
|
67
|
-
"@stacksjs/auth": "0.74.
|
|
68
|
-
"@stacksjs/build": "0.74.
|
|
63
|
+
"@stacksjs/action-runner": "0.74.31",
|
|
64
|
+
"@stacksjs/ai": "0.74.31",
|
|
65
|
+
"@stacksjs/analytics": "0.74.31",
|
|
66
|
+
"@stacksjs/api": "0.74.31",
|
|
67
|
+
"@stacksjs/auth": "0.74.31",
|
|
68
|
+
"@stacksjs/build": "0.74.31",
|
|
69
69
|
"@stacksjs/bumpx": "^0.2.6",
|
|
70
70
|
"@stacksjs/bunpress": "^0.2.8",
|
|
71
|
-
"@stacksjs/cli": "0.74.
|
|
72
|
-
"@stacksjs/cloud": "0.74.
|
|
73
|
-
"@stacksjs/cms": "0.74.
|
|
74
|
-
"@stacksjs/config": "0.74.
|
|
75
|
-
"@stacksjs/database": "0.74.
|
|
76
|
-
"@stacksjs/desktop-build": "0.74.
|
|
77
|
-
"@stacksjs/dns": "0.74.
|
|
78
|
-
"@stacksjs/enums": "0.74.
|
|
79
|
-
"@stacksjs/env": "0.74.
|
|
80
|
-
"@stacksjs/error-handling": "0.74.
|
|
71
|
+
"@stacksjs/cli": "0.74.31",
|
|
72
|
+
"@stacksjs/cloud": "0.74.31",
|
|
73
|
+
"@stacksjs/cms": "0.74.31",
|
|
74
|
+
"@stacksjs/config": "0.74.31",
|
|
75
|
+
"@stacksjs/database": "0.74.31",
|
|
76
|
+
"@stacksjs/desktop-build": "0.74.31",
|
|
77
|
+
"@stacksjs/dns": "0.74.31",
|
|
78
|
+
"@stacksjs/enums": "0.74.31",
|
|
79
|
+
"@stacksjs/env": "0.74.31",
|
|
80
|
+
"@stacksjs/error-handling": "0.74.31",
|
|
81
81
|
"@stacksjs/gitit": "^0.2.5",
|
|
82
|
-
"@stacksjs/i18n": "0.74.
|
|
83
|
-
"@stacksjs/image": "0.74.
|
|
84
|
-
"@stacksjs/logging": "0.74.
|
|
82
|
+
"@stacksjs/i18n": "0.74.31",
|
|
83
|
+
"@stacksjs/image": "0.74.31",
|
|
84
|
+
"@stacksjs/logging": "0.74.31",
|
|
85
85
|
"@stacksjs/logsmith": "^0.2.3",
|
|
86
|
-
"@stacksjs/orm": "0.74.
|
|
87
|
-
"@stacksjs/path": "0.74.
|
|
88
|
-
"@stacksjs/payments": "0.74.
|
|
89
|
-
"@stacksjs/queue": "0.74.
|
|
90
|
-
"@stacksjs/registry": "0.74.
|
|
91
|
-
"@stacksjs/router": "0.74.
|
|
86
|
+
"@stacksjs/orm": "0.74.31",
|
|
87
|
+
"@stacksjs/path": "0.74.31",
|
|
88
|
+
"@stacksjs/payments": "0.74.31",
|
|
89
|
+
"@stacksjs/queue": "0.74.31",
|
|
90
|
+
"@stacksjs/registry": "0.74.31",
|
|
91
|
+
"@stacksjs/router": "0.74.31",
|
|
92
92
|
"@stacksjs/rpx": "^0.11.42",
|
|
93
|
-
"@stacksjs/scheduler": "0.74.
|
|
94
|
-
"@stacksjs/search-engine": "0.74.
|
|
95
|
-
"@stacksjs/security": "0.74.
|
|
96
|
-
"@stacksjs/server": "0.74.
|
|
97
|
-
"@stacksjs/sites": "0.74.
|
|
98
|
-
"@stacksjs/storage": "0.74.
|
|
99
|
-
"@stacksjs/strings": "0.74.
|
|
93
|
+
"@stacksjs/scheduler": "0.74.31",
|
|
94
|
+
"@stacksjs/search-engine": "0.74.31",
|
|
95
|
+
"@stacksjs/security": "0.74.31",
|
|
96
|
+
"@stacksjs/server": "0.74.31",
|
|
97
|
+
"@stacksjs/sites": "0.74.31",
|
|
98
|
+
"@stacksjs/storage": "0.74.31",
|
|
99
|
+
"@stacksjs/strings": "0.74.31",
|
|
100
100
|
"@stacksjs/stx": "^0.2.274",
|
|
101
101
|
"@stacksjs/tlsx": "^0.13.19",
|
|
102
102
|
"@stacksjs/ts-cloud": "^0.12.15",
|
|
103
103
|
"@stacksjs/ts-md": "^0.1.1",
|
|
104
|
-
"@stacksjs/tunnel": "0.74.
|
|
105
|
-
"@stacksjs/types": "0.74.
|
|
106
|
-
"@stacksjs/utils": "0.74.
|
|
107
|
-
"@stacksjs/whois": "0.74.
|
|
104
|
+
"@stacksjs/tunnel": "0.74.31",
|
|
105
|
+
"@stacksjs/types": "0.74.31",
|
|
106
|
+
"@stacksjs/utils": "0.74.31",
|
|
107
|
+
"@stacksjs/whois": "0.74.31",
|
|
108
108
|
"bun-plugin-stx": "^0.2.279"
|
|
109
109
|
},
|
|
110
110
|
"peerDependencies": {
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
122
|
"devDependencies": {
|
|
123
|
-
"@stacksjs/validation": "0.74.
|
|
123
|
+
"@stacksjs/validation": "0.74.31",
|
|
124
124
|
"better-dx": "^0.2.24"
|
|
125
125
|
}
|
|
126
126
|
}
|