@crossdelta/platform-sdk 0.19.14 → 0.20.0

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/bin/cli.mjs CHANGED
@@ -574,7 +574,7 @@ ${e.message}`)}},ye=()=>D().reduce((t,r)=>(r.initial&&t.push(r.name),t),[]),Od=e
574
574
  `);throw new Error(`Policy violation(s) detected:
575
575
  ${o}`)}e.forEach(ag)},lg=async(e,t,r)=>{let{projectName:n,serviceType:o,hasEvents:s,streams:i}=e,a=n.split("/").pop()||n,l=Vs({type:o==="hono"?"hono-micro":"nest",name:a,path:n,hasEvents:s,streams:i}),p=l.effects.filter(y=>y.kind==="file:write"),m=ig(o);cg(p,m),e.assignedPort=l.port,e.elapsedTime+=r(),t.title=`Generated ${a} (port ${l.port}, ${e.elapsedTime}s)`},Bt={title:"Generating service",task:async(e,t)=>M(t,async r=>{await lg(e,t,r)})};var mg=e=>{let t=(e||"my-hono-service").trim();return t.includes("/")||t.startsWith(".")?t:`${E().services}/${t}`},dg=async(e,t)=>{let{valid:r,config:n,error:o}=de();if(!r||!n){$(new Error(o||"AI configuration is invalid"),{exit:!1});return}let s=mg(e.name),i=t.packageManager||b(),a=await ht(t.description);if(yt(s,n,a),await vt({servicePath:s,description:a,serviceType:"hono",packageManager:i},n))d.breakLine().success("Service generated successfully!").breakLine().log(oe.dim("Next steps:")).log(oe.dim(` ${oe.cyan("pf dev")} - Start all services`)).log(oe.dim(` ${oe.cyan(`cd ${s} && bun dev`)} - Start this service only`)).breakLine();else throw new Error("Service generation failed")},mi=J({name:"hono-micro",description:"Create a new Hono microservice with the Crossdelta setup. Use --ai for AI-powered generation.",arguments:[["[name]","Name or path of the service"]],options:[["-P, --package-manager <manager>","Specify the package manager (e.g., npm, yarn, pnpm, bun)"],["-y, --yes","Skip all prompts and use default values"],["--ai","Use AI to generate service code based on a description"],["-d, --description <description>","Service description for AI generation (requires --ai)"],["--remove-dir","Remove existing directory before creating (used internally)"]],exampleUsage:'platform new hono-micro my-service --ai -d "Payment processing service"',shouldSkipWorkflow:(e,t)=>!!t.ai,onSkipWorkflow:dg,buildContext:async(e,t)=>{let r=(e.name??"my-hono-service").trim();!r.includes("/")&&!r.startsWith(".")&&(r=`${E().services}/${r}`);let n=O(r),o=t.packageManager??(t.yes&&b()),s=D(),i=t.yes?ye():[],a=t.packageManager==="bun",c=!!t.yes||!!e.name&&e.name!=="my-hono-service";return{cwd:n,projectName:r,packageManager:o,shouldInstallBun:a,availableIntegrations:s,selectedIntegrations:i,serviceType:"hono",elapsedTime:0,userConfirmed:!!t.yes,skipInputPrompts:c,removeDir:!!t.removeDir||!!t.yes}},prompts:[Pe,xe,Ce,Se,_t,ve],actions:[we,ke,Bt,Mt,jt,Wt],onComplete:({projectName:e,packageManager:t,selectedIntegrations:r,assignedPort:n})=>{d.breakLine().log(oe.bold.green("Hono Microservice created successfully!")),Ft(r),Xs(pg(e),n??8080);let o=t??b();d.breakLine().log(`To start the project, run:
576
576
  ${oe.bold(`cd ${e} && ${o} run dev`)}`).breakLine().log("Happy shipping with Hono! \u26A1\uFE0F").breakLine()}});import se from"chalk";f();v();var gg=e=>{let t=(e||"my-nest-service").trim();return t.includes("/")||t.startsWith(".")?t:`${E().services}/${t}`},ug=async(e,t)=>{let{valid:r,config:n,error:o}=de();if(!r||!n){$(new Error(o||"AI configuration is invalid"),{exit:!1});return}let s=gg(e.name),i=t.packageManager||b(),a=await ht(t.description);if(yt(s,n,a),await vt({servicePath:s,description:a,serviceType:"nest",packageManager:i},n))d.breakLine().success("Service generated successfully!").breakLine().log(se.dim("Next steps:")).log(se.dim(` ${se.cyan("pf dev")} - Start all services`)).log(se.dim(` ${se.cyan(`cd ${s} && bun run start:dev`)} - Start this service only`)).breakLine();else throw new Error("Service generation failed")},di=J({name:"nest-micro",description:"Create a new NestJS microservice with the Crossdelta setup. Use --ai for AI-powered generation.",arguments:[["[name]","Name or path of the service"]],options:[["-P, --package-manager <manager>","Specify the package manager (e.g., npm, yarn, pnpm, bun)"],["-y, --yes","Skip all prompts and use default values"],["--ai","Use AI to generate service code based on a description"],["-d, --description <description>","Service description for AI generation (requires --ai)"],["--remove-dir","Remove existing directory before creating (used internally)"]],exampleUsage:'platform new nest-micro my-service --ai -d "User authentication service"',shouldSkipWorkflow:(e,t)=>!!t.ai,onSkipWorkflow:ug,buildContext:async(e,t)=>{let r=(e.name??"my-nest-service").trim();!r.includes("/")&&!r.startsWith(".")&&(r=`${E().services}/${r}`);let n=O(r),o=t.packageManager??(t.yes&&b()),s=t.packageManager==="bun",i=D(),a=t.yes?ye():[],c=!!t.yes||!!e.name;return{cwd:n,projectName:r,shouldInstallBun:s,packageManager:o,availableIntegrations:i,selectedIntegrations:a,serviceType:"nest",elapsedTime:0,userConfirmed:!!t.yes,skipInputPrompts:c,removeDir:!!t.removeDir||!!t.yes}},prompts:[Pe,xe,Ce,Se,_t,ve],actions:[we,ke,Bt,Mt,Lt,ii,jt,Wt],onComplete:({projectName:e,packageManager:t,selectedIntegrations:r})=>{d.breakLine().log(se.bold.green("NestJS Microservice created successfully!")),Ft(r),d.breakLine().log(`To start the project, run:
577
- ${se.bold(`cd ${e} && ${t} run start:dev`)}`).breakLine().log("Happy coding! \u{1F389}").breakLine()}});import j from"chalk";v();import{spawnSync as yg}from"child_process";import{chmodSync as vg,existsSync as tn,mkdirSync as kg,readFileSync as Cg,writeFileSync as rn}from"fs";import{dirname as xg,join as nn}from"path";import{existsSync as fg}from"fs";import{join as Gt}from"path";var hg=()=>typeof import.meta?.url=="string"?W(import.meta.url):typeof __dirname=="string"?__dirname:process.cwd(),en=()=>{let e=hg(),t=ee();return fe([Gt(e,"templates","workspace"),Gt(e,"..","..","..","..","templates","workspace"),Gt(t,"bin","templates","workspace")],"Workspace templates directory not found.")},gi=()=>{let e=en(),t=Gt(e,"packages","contracts");if(!fg(t))throw new Error(`Contracts templates directory not found at: ${t}`);return t},Ut=(e,t)=>Br(e,t);var ui=e=>{e.endsWith(".sh")&&vg(e,493)},wg=[{template:"package.json.hbs",output:"package.json"},{template:"tsconfig.json.hbs",output:"tsconfig.json"},{template:"pnpm-workspace.yaml.hbs",output:"pnpm-workspace.yaml",forPackageManager:"pnpm"},{template:"biome.json.hbs",output:"biome.json"},{template:"turbo.json.hbs",output:"turbo.json"},{template:"bunfig.toml.hbs",output:"bunfig.toml"},{template:"gitignore.hbs",output:".gitignore"},{template:"editorconfig.hbs",output:".editorconfig"},{template:"npmrc.hbs",output:".npmrc"},{template:".vscode/settings.json",output:".vscode/settings.json",isStatic:!0},{template:".vscode/extensions.json",output:".vscode/extensions.json",isStatic:!0},{template:"infra/package.json.hbs",output:"infra/package.json"},{template:"infra/index.ts.hbs",output:"infra/index.ts"},{template:"infra/tsconfig.json.hbs",output:"infra/tsconfig.json"},{template:"infra/Pulumi.yaml.hbs",output:"infra/Pulumi.yaml"},{template:"infra/Pulumi.dev.yaml.hbs",output:"infra/Pulumi.dev.yaml"},{template:"apps/.gitkeep",output:"apps/.gitkeep",isStatic:!0},{template:"services/.gitkeep",output:"services/.gitkeep",isStatic:!0},{template:"packages/.gitkeep",output:"packages/.gitkeep",isStatic:!0},{template:"docs/.gitkeep",output:"docs/.gitkeep",isStatic:!0},{template:"infra/services/.gitkeep",output:"infra/services/.gitkeep",isStatic:!0},{template:".github/README.md",output:".github/README.md",isStatic:!0,isGitHubCI:!0},{template:".github/dependabot.yml",output:".github/dependabot.yml",isStatic:!0,isGitHubCI:!0},{template:".github/workflows/lint-and-tests.yml.hbs",output:".github/workflows/lint-and-tests.yml",isGitHubCI:!0},{template:".github/workflows/build-and-deploy.yml.hbs",output:".github/workflows/build-and-deploy.yml",isGitHubCI:!0},{template:".github/workflows/publish-packages.yml",output:".github/workflows/publish-packages.yml",isStatic:!0,isGitHubCI:!0},{template:".github/actions/setup-bun-install/action.yml.hbs",output:".github/actions/setup-bun-install/action.yml",isGitHubCI:!0},{template:".github/actions/check-image-tag-exists/action.yml",output:".github/actions/check-image-tag-exists/action.yml",isStatic:!0,isGitHubCI:!0},{template:".github/actions/check-image-tag-exists/index.js",output:".github/actions/check-image-tag-exists/index.js",isStatic:!0,isGitHubCI:!0},{template:".github/actions/generate-scope-matrix/action.yml",output:".github/actions/generate-scope-matrix/action.yml",isStatic:!0,isGitHubCI:!0},{template:".github/actions/generate-scope-matrix/index.js",output:".github/actions/generate-scope-matrix/index.js",isStatic:!0,isGitHubCI:!0},{template:".github/actions/prepare-build-context/action.yml",output:".github/actions/prepare-build-context/action.yml",isStatic:!0,isGitHubCI:!0},{template:".github/copilot-instructions.md",output:".github/copilot-instructions.md",isStatic:!0},{template:".github/instructions/code-style.instructions.md",output:".github/instructions/code-style.instructions.md",isStatic:!0},{template:".github/instructions/testing.instructions.md",output:".github/instructions/testing.instructions.md",isStatic:!0},{template:".github/instructions/cloudevents.instructions.md",output:".github/instructions/cloudevents.instructions.md",isStatic:!0}],fi={title:"Creating workspace structure",task:async(e,t)=>{if(tn(e.cwd)){t.title="Workspace directory already exists, skipping...";return}let r=en(),n=e.includeGitHubCI??!0,o=e.packageManager||"bun",s=c=>{try{let m=yg(c,["--version"],{encoding:"utf-8",timeout:5e3}).stdout?.trim();if(m&&/^\d+\.\d+/.test(m))return`${c}@${m}`}catch{}return{bun:"bun@1.2.7",npm:"npm@10.9.2",yarn:"yarn@4.6.0",pnpm:"pnpm@9.15.2"}[c]||`${c}@latest`},i={projectName:e.projectName,scope:`@${e.projectName}`,githubOwner:e.githubOwner||"",pulumiStackBase:e.pulumiStackBase||e.projectName,packageManager:o,packageManagerVersion:s(o)},a=wg.filter(c=>!(c.isGitHubCI&&!n||c.forPackageManager&&c.forPackageManager!==o));for(let c of a){let l=nn(e.cwd,c.output),p=xg(l);if(tn(p)||kg(p,{recursive:!0}),c.isStatic){let m=nn(r,c.template);tn(m)?rn(l,Cg(m)):rn(l,""),ui(l)}else{let m=nn(r,c.template),y=Ut(m,i);rn(l,y),ui(l)}}t.title="Workspace structure created"}};f();import{existsSync as yi,mkdirSync as hi,readFileSync as Pg,writeFileSync as Sg}from"fs";import{join as zt}from"path";import bg from"chalk";var Eg=()=>{let e=zt(process.cwd(),"package.json");if(!yi(e))throw new Error("Root package.json not found. Please run this command from the workspace root.");let r=JSON.parse(Pg(e,"utf-8")).name;if(!r)throw new Error('package.json must have a "name" field');return r.startsWith("@")?r:`@${r}`},Tg=()=>{let e=Eg(),{relativePath:t,packagePath:r}=x();if(yi(r))throw new Error(`${t} already exists. Remove it first if you want to regenerate.`);let n=gi(),o={scope:e,workspaceName:e.replace("@","").replace("/","-")};hi(r,{recursive:!0}),hi(zt(r,"src","events"),{recursive:!0});let s=[{template:"package.json.hbs",output:"package.json"},{template:"tsconfig.json.hbs",output:"tsconfig.json"},{template:"README.md.hbs",output:"README.md"},{template:"src/index.ts",output:"src/index.ts"},{template:"src/stream-policies.ts.hbs",output:"src/stream-policies.ts"},{template:"src/events/index.ts",output:"src/events/index.ts"}];for(let i of s){let a=zt(n,i.template),c=zt(r,i.output),l=Ut(a,o);Sg(c,l,"utf-8")}},vi={title:"Initializing contracts package",task:(e,t)=>{let r=process.cwd();try{process.chdir(e.cwd),Tg(),t.title="Contracts package initialized"}catch(n){throw t.title=bg.red(`Contracts package failed: ${n.message}`),n}finally{process.chdir(r)}}};import $g from"chalk";var ki={title:"Registering shell completion",task:async(e,t)=>{let r=process.cwd();try{process.chdir(e.cwd),await He(),t.title="Shell completion registered"}catch{t.title=$g.dim("Shell completion skipped")}finally{process.chdir(r)}}};var Ci=J({name:"workspace",description:"Create a new workspace with infrastructure setup",arguments:[["[name]","Name or path of the workspace"]],options:[["-P, --package-manager <manager>","Specify the package manager (e.g., npm, yarn, pnpm, bun)"],["-y, --yes","Skip all prompts and use default values"],["-o, --github-owner <owner>","GitHub organization or username"],["-s, --pulumi-stack <name>","Pulumi stack base name (org/project)"],["--no-github","Skip GitHub CI/CD workflows"],["--remove-dir","Remove existing directory before creating (internal use)"]],exampleUsage:"pf new workspace my-platform -o my-org",buildContext:(e,t)=>{let r=(e.name??"my-platform").trim(),n=O(r),o=!!t.yes,s=t.packageManager??(o?b():void 0),i=t.packageManager==="bun",a=t.githubOwner??(o?"my-org":void 0),c=t.pulumiStack??(o?`${a}/${r}`:void 0),l=t.github===!1?!1:o?!0:void 0,p=!!e.name,m=t.removeDir||o;return{cwd:n,projectName:r,shouldInstallBun:i,packageManager:s,elapsedTime:0,userConfirmed:o,skipInputPrompts:p&&!o,removeDir:m,githubOwner:a,pulumiStackBase:c,includeGitHubCI:l}},prompts:[{enabled:e=>!e.userConfirmed,task:async(e,t)=>{try{let r=g();if(!await C(t).toggle({message:`\u26A0\uFE0F You are inside an existing workspace (${r}). Create a nested workspace anyway?`,initial:!1}))throw new Error("Workspace creation cancelled - already inside a workspace");t.title=j.yellow("Warning: Creating nested workspace")}catch(r){if(X(r)&&r.message?.includes("cancelled"))throw r;t.title="No existing workspace detected"}}},Pe,xe,ci,li,pi,Ce,Se,ve],actions:[we,ke,fi,vi,Lt,ni,ki],onComplete:({projectName:e,includeGitHubCI:t})=>{d.breakLine().log(j.bold.green("Workspace created successfully!")),d.breakLine().log(j.bold("Next steps:")).log(` 1. ${j.cyan(`cd ${e}`)}`).log(` 2. ${j.cyan("exec $SHELL")} ${j.dim("(enable tab completion)")}`),t&&d.breakLine().log(j.bold("GitHub Setup:")).log(" Configure these secrets in your GitHub repository:").log(` \u2022 ${j.yellow("PULUMI_ACCESS_TOKEN")} - Pulumi Cloud access token`).log(` \u2022 ${j.yellow("DIGITALOCEAN_TOKEN")} - DigitalOcean API token`).log(` \u2022 ${j.yellow("NPM_TOKEN")} - (optional) NPM token for private packages`),d.breakLine().log(j.bold("Structure created:")).log(" apps/ # Frontend applications").log(" services/ # Backend microservices").log(" packages/").log(" \u2514\u2500\u2500 contracts/ # Shared event contracts").log(" infra/").log(" \u251C\u2500\u2500 index.ts # Pulumi entry point").log(" \u251C\u2500\u2500 services/ # Service configs").log(" \u251C\u2500\u2500 Pulumi.yaml # Pulumi project config").log(" \u2514\u2500\u2500 Pulumi.dev.yaml # Dev stack config"),t&&d.log(" .github/").log(" \u251C\u2500\u2500 workflows/ # CI/CD workflows").log(" \u2514\u2500\u2500 actions/ # Custom actions"),d.breakLine().log("Happy coding! \u{1F389}").breakLine()}});var ze=[{name:"Hono Microservice",value:"hono-micro",command:mi,supportsAi:!0},{name:"Nest Microservice",value:"nest-micro",command:di,supportsAi:!0},{name:"Workspace (Infrastructure)",value:"workspace",command:Ci,supportsAi:!1}],xi=()=>{let e=J({name:"new",description:"Create a new project",arguments:[["[type]","Type of the project (e.g., nest-micro, hono-micro, workspace)"]],exampleUsage:"platform new hono-micro test-service",buildContext:t=>({projectType:t.type??"",useAi:!1,aiDescription:"",elapsedTime:0,cwd:process.cwd()}),prompts:[{enabled:t=>!t.projectType,task:async(t,r)=>{let o=await C(r).select({message:"Select Project type",choices:ze});t.projectType=ze.find(s=>s.name===o)?.value||"",r.title=`Using ${q.bold(o)}`}},{enabled:t=>t.projectType!=="workspace"&&t.projectType!=="",task:async(t,r)=>{try{g(),r.title="Workspace detected"}catch{let n=["Not in a workspace directory","",`Current directory: ${process.cwd()}`,"","This command must be run from within a workspace created with pf new workspace","","To create a new workspace, run:",""," pf new workspace my-platform"].join(`
577
+ ${se.bold(`cd ${e} && ${t} run start:dev`)}`).breakLine().log("Happy coding! \u{1F389}").breakLine()}});import j from"chalk";v();import{spawnSync as yg}from"child_process";import{chmodSync as vg,existsSync as tn,mkdirSync as kg,readFileSync as Cg,writeFileSync as rn}from"fs";import{dirname as xg,join as nn}from"path";import{existsSync as fg}from"fs";import{join as Gt}from"path";var hg=()=>typeof import.meta?.url=="string"?W(import.meta.url):typeof __dirname=="string"?__dirname:process.cwd(),en=()=>{let e=hg(),t=ee();return fe([Gt(e,"templates","workspace"),Gt(e,"..","..","..","..","templates","workspace"),Gt(t,"bin","templates","workspace")],"Workspace templates directory not found.")},gi=()=>{let e=en(),t=Gt(e,"packages","contracts");if(!fg(t))throw new Error(`Contracts templates directory not found at: ${t}`);return t},Ut=(e,t)=>Br(e,t);var ui=e=>{e.endsWith(".sh")&&vg(e,493)},wg=[{template:"package.json.hbs",output:"package.json"},{template:"tsconfig.json.hbs",output:"tsconfig.json"},{template:"pnpm-workspace.yaml.hbs",output:"pnpm-workspace.yaml",forPackageManager:"pnpm"},{template:"biome.json.hbs",output:"biome.json"},{template:"turbo.json.hbs",output:"turbo.json"},{template:"bunfig.toml.hbs",output:"bunfig.toml"},{template:"gitignore.hbs",output:".gitignore"},{template:"editorconfig.hbs",output:".editorconfig"},{template:"npmrc.hbs",output:".npmrc"},{template:".vscode/settings.json",output:".vscode/settings.json",isStatic:!0},{template:".vscode/extensions.json",output:".vscode/extensions.json",isStatic:!0},{template:"infra/package.json.hbs",output:"infra/package.json"},{template:"infra/index.ts.hbs",output:"infra/index.ts"},{template:"infra/tsconfig.json.hbs",output:"infra/tsconfig.json"},{template:"infra/Pulumi.yaml.hbs",output:"infra/Pulumi.yaml"},{template:"infra/Pulumi.dev.yaml.hbs",output:"infra/Pulumi.dev.yaml"},{template:"apps/.gitkeep",output:"apps/.gitkeep",isStatic:!0},{template:"services/.gitkeep",output:"services/.gitkeep",isStatic:!0},{template:"packages/.gitkeep",output:"packages/.gitkeep",isStatic:!0},{template:"docs/.gitkeep",output:"docs/.gitkeep",isStatic:!0},{template:"infra/services/.gitkeep",output:"infra/services/.gitkeep",isStatic:!0},{template:".github/README.md",output:".github/README.md",isStatic:!0,isGitHubCI:!0},{template:".github/dependabot.yml",output:".github/dependabot.yml",isStatic:!0,isGitHubCI:!0},{template:".github/workflows/lint-and-tests.yml.hbs",output:".github/workflows/lint-and-tests.yml",isGitHubCI:!0},{template:".github/workflows/build-and-deploy.yml.hbs",output:".github/workflows/build-and-deploy.yml",isGitHubCI:!0},{template:".github/workflows/publish-packages.yml",output:".github/workflows/publish-packages.yml",isStatic:!0,isGitHubCI:!0},{template:".github/actions/setup-bun-install/action.yml.hbs",output:".github/actions/setup-bun-install/action.yml",isGitHubCI:!0},{template:".github/actions/check-image-tag-exists/action.yml",output:".github/actions/check-image-tag-exists/action.yml",isStatic:!0,isGitHubCI:!0},{template:".github/actions/check-image-tag-exists/index.js",output:".github/actions/check-image-tag-exists/index.js",isStatic:!0,isGitHubCI:!0},{template:".github/actions/generate-scope-matrix/action.yml",output:".github/actions/generate-scope-matrix/action.yml",isStatic:!0,isGitHubCI:!0},{template:".github/actions/generate-scope-matrix/index.js",output:".github/actions/generate-scope-matrix/index.js",isStatic:!0,isGitHubCI:!0},{template:".github/actions/prepare-build-context/action.yml",output:".github/actions/prepare-build-context/action.yml",isStatic:!0,isGitHubCI:!0},{template:".github/copilot-instructions.md",output:".github/copilot-instructions.md",isStatic:!0},{template:".github/instructions/code-style.instructions.md",output:".github/instructions/code-style.instructions.md",isStatic:!0},{template:".github/instructions/testing.instructions.md",output:".github/instructions/testing.instructions.md",isStatic:!0},{template:".github/instructions/cloudevents.instructions.md",output:".github/instructions/cloudevents.instructions.md",isStatic:!0}],fi={title:"Creating workspace structure",task:async(e,t)=>{if(tn(e.cwd)){t.title="Workspace directory already exists, skipping...";return}let r=en(),n=e.includeGitHubCI??!0,o=e.packageManager||"bun",s=c=>{try{let m=yg(c,["--version"],{encoding:"utf-8",timeout:5e3}).stdout?.trim();if(m&&/^\d+\.\d+/.test(m))return`${c}@${m}`}catch{}return{bun:"bun@1.2.7",npm:"npm@10.9.2",yarn:"yarn@4.6.0",pnpm:"pnpm@9.15.2"}[c]||`${c}@latest`},i={projectName:e.projectName,scope:`@${e.projectName}`,githubOwner:e.githubOwner||"",pulumiStackBase:e.pulumiStackBase||e.projectName,packageManager:o,packageManagerVersion:s(o)},a=wg.filter(c=>!(c.isGitHubCI&&!n||c.forPackageManager&&c.forPackageManager!==o));for(let c of a){let l=nn(e.cwd,c.output),p=xg(l);if(tn(p)||kg(p,{recursive:!0}),c.isStatic){let m=nn(r,c.template);tn(m)?rn(l,Cg(m)):rn(l,""),ui(l)}else{let m=nn(r,c.template),y=Ut(m,i);rn(l,y),ui(l)}}t.title="Workspace structure created"}};f();import{existsSync as yi,mkdirSync as hi,readFileSync as Pg,writeFileSync as Sg}from"fs";import{join as zt}from"path";import bg from"chalk";var Eg=()=>{let e=zt(process.cwd(),"package.json");if(!yi(e))throw new Error("Root package.json not found. Please run this command from the workspace root.");let r=JSON.parse(Pg(e,"utf-8")).name;if(!r)throw new Error('package.json must have a "name" field');return r.startsWith("@")?r:`@${r}`},Tg=()=>{let e=Eg(),{relativePath:t,packagePath:r}=x();if(yi(r))throw new Error(`${t} already exists. Remove it first if you want to regenerate.`);let n=gi(),o={scope:e,workspaceName:e.replace("@","").replace("/","-")};hi(r,{recursive:!0}),hi(zt(r,"src","events"),{recursive:!0});let s=[{template:"package.json.hbs",output:"package.json"},{template:"tsconfig.json.hbs",output:"tsconfig.json"},{template:"tsup.config.ts",output:"tsup.config.ts"},{template:"README.md.hbs",output:"README.md"},{template:"src/index.ts",output:"src/index.ts"},{template:"src/stream-policies.ts.hbs",output:"src/stream-policies.ts"},{template:"src/events/index.ts",output:"src/events/index.ts"}];for(let i of s){let a=zt(n,i.template),c=zt(r,i.output),l=Ut(a,o);Sg(c,l,"utf-8")}},vi={title:"Initializing contracts package",task:(e,t)=>{let r=process.cwd();try{process.chdir(e.cwd),Tg(),t.title="Contracts package initialized"}catch(n){throw t.title=bg.red(`Contracts package failed: ${n.message}`),n}finally{process.chdir(r)}}};import $g from"chalk";var ki={title:"Registering shell completion",task:async(e,t)=>{let r=process.cwd();try{process.chdir(e.cwd),await He(),t.title="Shell completion registered"}catch{t.title=$g.dim("Shell completion skipped")}finally{process.chdir(r)}}};var Ci=J({name:"workspace",description:"Create a new workspace with infrastructure setup",arguments:[["[name]","Name or path of the workspace"]],options:[["-P, --package-manager <manager>","Specify the package manager (e.g., npm, yarn, pnpm, bun)"],["-y, --yes","Skip all prompts and use default values"],["-o, --github-owner <owner>","GitHub organization or username"],["-s, --pulumi-stack <name>","Pulumi stack base name (org/project)"],["--no-github","Skip GitHub CI/CD workflows"],["--remove-dir","Remove existing directory before creating (internal use)"]],exampleUsage:"pf new workspace my-platform -o my-org",buildContext:(e,t)=>{let r=(e.name??"my-platform").trim(),n=O(r),o=!!t.yes,s=t.packageManager??(o?b():void 0),i=t.packageManager==="bun",a=t.githubOwner??(o?"my-org":void 0),c=t.pulumiStack??(o?`${a}/${r}`:void 0),l=t.github===!1?!1:o?!0:void 0,p=!!e.name,m=t.removeDir||o;return{cwd:n,projectName:r,shouldInstallBun:i,packageManager:s,elapsedTime:0,userConfirmed:o,skipInputPrompts:p&&!o,removeDir:m,githubOwner:a,pulumiStackBase:c,includeGitHubCI:l}},prompts:[{enabled:e=>!e.userConfirmed,task:async(e,t)=>{try{let r=g();if(!await C(t).toggle({message:`\u26A0\uFE0F You are inside an existing workspace (${r}). Create a nested workspace anyway?`,initial:!1}))throw new Error("Workspace creation cancelled - already inside a workspace");t.title=j.yellow("Warning: Creating nested workspace")}catch(r){if(X(r)&&r.message?.includes("cancelled"))throw r;t.title="No existing workspace detected"}}},Pe,xe,ci,li,pi,Ce,Se,ve],actions:[we,ke,fi,vi,Lt,ni,ki],onComplete:({projectName:e,includeGitHubCI:t})=>{d.breakLine().log(j.bold.green("Workspace created successfully!")),d.breakLine().log(j.bold("Next steps:")).log(` 1. ${j.cyan(`cd ${e}`)}`).log(` 2. ${j.cyan("exec $SHELL")} ${j.dim("(enable tab completion)")}`),t&&d.breakLine().log(j.bold("GitHub Setup:")).log(" Configure these secrets in your GitHub repository:").log(` \u2022 ${j.yellow("PULUMI_ACCESS_TOKEN")} - Pulumi Cloud access token`).log(` \u2022 ${j.yellow("DIGITALOCEAN_TOKEN")} - DigitalOcean API token`).log(` \u2022 ${j.yellow("NPM_TOKEN")} - (optional) NPM token for private packages`),d.breakLine().log(j.bold("Structure created:")).log(" apps/ # Frontend applications").log(" services/ # Backend microservices").log(" packages/").log(" \u2514\u2500\u2500 contracts/ # Shared event contracts").log(" infra/").log(" \u251C\u2500\u2500 index.ts # Pulumi entry point").log(" \u251C\u2500\u2500 services/ # Service configs").log(" \u251C\u2500\u2500 Pulumi.yaml # Pulumi project config").log(" \u2514\u2500\u2500 Pulumi.dev.yaml # Dev stack config"),t&&d.log(" .github/").log(" \u251C\u2500\u2500 workflows/ # CI/CD workflows").log(" \u2514\u2500\u2500 actions/ # Custom actions"),d.breakLine().log("Happy coding! \u{1F389}").breakLine()}});var ze=[{name:"Hono Microservice",value:"hono-micro",command:mi,supportsAi:!0},{name:"Nest Microservice",value:"nest-micro",command:di,supportsAi:!0},{name:"Workspace (Infrastructure)",value:"workspace",command:Ci,supportsAi:!1}],xi=()=>{let e=J({name:"new",description:"Create a new project",arguments:[["[type]","Type of the project (e.g., nest-micro, hono-micro, workspace)"]],exampleUsage:"platform new hono-micro test-service",buildContext:t=>({projectType:t.type??"",useAi:!1,aiDescription:"",elapsedTime:0,cwd:process.cwd()}),prompts:[{enabled:t=>!t.projectType,task:async(t,r)=>{let o=await C(r).select({message:"Select Project type",choices:ze});t.projectType=ze.find(s=>s.name===o)?.value||"",r.title=`Using ${q.bold(o)}`}},{enabled:t=>t.projectType!=="workspace"&&t.projectType!=="",task:async(t,r)=>{try{g(),r.title="Workspace detected"}catch{let n=["Not in a workspace directory","",`Current directory: ${process.cwd()}`,"","This command must be run from within a workspace created with pf new workspace","","To create a new workspace, run:",""," pf new workspace my-platform"].join(`
578
578
  `);throw new Error(n)}}},{enabled:t=>t.projectType==="workspace",task:async(t,r)=>{try{let n=g();if(!await C(r).toggle({message:`\u26A0\uFE0F You are inside an existing workspace (${n}). Create a nested workspace anyway?`,initial:!1}))throw new Error("Workspace creation cancelled - already inside a workspace");r.title=q.yellow("Warning: Creating nested workspace")}catch(n){if(X(n)&&n.message?.includes("cancelled"))throw n;r.title="No existing workspace detected"}}},{enabled:t=>!!t.projectType,task:async(t,r)=>{let o={"hono-micro":"services/my-hono-service","nest-micro":"services/my-nest-service",workspace:"my-platform"}[t.projectType]||"my-project",s=t.projectType==="workspace"?"\u{1F4E6} Workspace name:":"\u{1F4E6} Service path (e.g., services/my-service):",a=await C(r).input({message:s,initial:o});t.servicePath=a.trim(),r.title=`Path: ${q.dim(a)}`}},{enabled:t=>!!ze.find(n=>n.value===t.projectType)?.supportsAi&&de().valid,task:async(t,r)=>{let o=await C(r).toggle({message:"Use AI to generate service code?",initial:!1});t.useAi=o,r.title=o?q.cyan("\u{1F916} AI-powered generation"):"Standard scaffolding"}},{enabled:t=>t.useAi,task:async(t,r)=>{let o=await C(r).input({message:"Describe what this service should do:"});t.aiDescription=o,r.title=`Description: ${q.dim(o.slice(0,50))}${o.length>50?"...":""}`}},{enabled:t=>{if(!t.servicePath)return!1;let r=O(t.servicePath);return!et(r)},task:async(t,r)=>{if(!await C(r).toggle({message:q.bold("\u26A0\uFE0F Overwrite existing directory?"),initial:!1}))throw new Error("Project creation was canceled by the user.");t.shouldRemoveDir=!0,r.title=q.yellow("Will overwrite existing directory")}},{title:"Confirm creation",enabled:t=>t.projectType!=="workspace",task:async(t,r)=>{if(!await C(r).toggle({message:"\u{1F680} Ready to launch your project?",initial:!0}))throw new Error("Project creation was canceled by the user.")}}],actions:[],onComplete:async t=>{ze.find(s=>s.value===t.projectType)||e.error(q.red(`Project type ${t.projectType} is not supported.`));let r=e.commands.find(s=>s.name()===t.projectType),n={};t.projectType!=="workspace"&&(n.yes=!0);let o=[];t.servicePath&&o.push("servicePath"),t.shouldRemoveDir&&(n.removeDir=!0),t.useAi&&(n.ai=!0,n.description=t.aiDescription),await ri(r,t,n,o)}});for(let t of ze)e.addCommand(t.command);return e};import{Command as jg}from"commander";v();import{createHash as Ag}from"crypto";import{existsSync as ie,readdirSync as wi,readFileSync as Pi,unlinkSync as Ig,writeFileSync as Rg}from"fs";import{join as Y}from"path";import Ng from"chokidar";f();v();var Fg=e=>{let t=Y(e,"infra","services");if(!ie(t))return[];let r=wi(t).filter(a=>a.endsWith(".ts")&&a!=="index.ts").map(a=>a.replace(".ts","")),n=E(e),o=a=>{let c=Y(e,a);return ie(c)?wi(c).filter(l=>ie(Y(c,l,"package.json"))):[]},s=[...o(n.services),...o(n.apps)],i=r.filter(a=>!s.includes(a));for(let a of i)Ig(Y(t,`${a}.ts`));return i},Si=".install-hash",bi=e=>{let t=Pi(e);return Ag("sha256").update(t).digest("hex")},Og=e=>{let t=Y(e,"node_modules",Si),r=Y(e,"bun.lock");return!ie(r)||!ie(t)?!0:Pi(t,"utf-8")!==bi(r)},Mg=e=>{let t=Y(e,"bun.lock"),r=Y(e,"node_modules",Si);ie(t)&&Rg(r,bi(t),"utf-8")},on=async e=>{let t=Fg(e);t.length>0&&console.log(`\u{1F9F9} Cleaned ${t.length} orphaned infra config(s): ${t.join(", ")}`),Og(e)&&(await L({cwd:e,quiet:!0}),Mg(e)),await Fe("generate-env",{cwd:e})},sn=async e=>{await Js()&&await Yr(e)},Ei=e=>{let{eventsPath:t}=x(e);if(!ie(t))return async()=>{};let r=ae(async()=>{console.log(`
579
579
  \u{1F4E6} Contracts changed, updating streams...`),await Yr(e)},500),n=Ng.watch(`${t}/**/*.ts`,{ignoreInitial:!0,ignored:["**/index.ts","**/*.test.ts","**/*.spec.ts"]});return n.on("add",r).on("change",r),async()=>{await n.close()}};Ze();import Ti from"chalk";f();var an=e=>new Promise(t=>setTimeout(t,e)),$i=e=>process.stdout.write(`${e}
580
580
  `),Dg=()=>{process.stdout.write("\x1B[2J\x1B[3J\x1B[H"),process.stdout.isTTY&&process.stdout.write("\x1Bc")},Ai=()=>({turboProcess:null,isRestarting:!1,isShuttingDown:!1}),cn=async(e,t)=>{let r=Jn(".env.local",t);r.length>0&&(await Yn(r),await an(50));let{dev:n}=Ie(t),o=n.filter.flatMap(s=>["--filter",s]);$i(Ti.cyan("\u{1F525} Starting services...")),$i(Ti.dim(` Command: turbo run ${Yt} --continue${o.length?` ${o.join(" ")}`:""}`)),e.isShuttingDown=!1,e.isRestarting=!1,e.turboProcess=qn("turbo",["run",Yt,"--continue","--no-daemon",...o],{cwd:t,envFile:".env.local",onExit:s=>{e.isRestarting||e.isShuttingDown||s===1&&process.exit(w.SUCCESS)}})},Vt=async e=>{let t=e.turboProcess?.pid;if(t){e.isShuttingDown=!0;try{try{process.kill(-t,"SIGTERM")}catch{e.turboProcess?.kill("SIGTERM")}await an(200);try{process.kill(-t,"SIGKILL")}catch{}await an(30)}catch{}e.turboProcess=null,Dg()}};var Ii=new jg("dev").description("Start development mode with auto-reload").action(async()=>{let e;try{e=g()}catch(a){$(a);return}let t=Ai(),r=async()=>{await on(e),await sn(e),await cn(t,e)},o=ae(async()=>{if(!(t.isRestarting||t.isShuttingDown)){t.isRestarting=!0,console.log(`
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'tsup'
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.ts'],
5
+ format: ['esm', 'cjs'],
6
+ dts: true,
7
+ clean: true,
8
+ sourcemap: true,
9
+ minify: false,
10
+ target: 'node18',
11
+ external: [
12
+ '@crossdelta/cloudevents',
13
+ '@crossdelta/infrastructure',
14
+ 'zod',
15
+ ],
16
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossdelta/platform-sdk",
3
- "version": "0.19.14",
3
+ "version": "0.20.0",
4
4
  "description": "Platform toolkit for event-driven microservices — keeping code and infrastructure in lockstep.",
5
5
  "keywords": [
6
6
  "cli",