effing-cloud 0.2.1 → 0.3.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.
Files changed (2) hide show
  1. package/dist/cli.js +4 -3
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as U}from"module";import{Command as K}from"commander";function w(t){t.command("login").description("Authenticate with Effing Cloud").action(()=>{console.log("Login is not yet implemented.")})}import u from"process";import d from"path";import y from"fs";import{pathToFileURL as x}from"url";import{randomBytes as S}from"crypto";import{build as D}from"esbuild";import{z as g}from"zod";var h=g.union([g.string(),g.array(g.string())]),F=g.object({project:g.string().min(1),images:h.optional(),annies:h.optional(),effies:h.optional()});var L=["effing-cloud.config.ts","effing-cloud.config.mts","effing-cloud.config.js"];function P(t,n){if(n){let i=d.isAbsolute(n)?n:d.resolve(t,n);if(!y.existsSync(i))throw new Error(`Config file not found: ${i}`);return i}for(let i of L){let e=d.resolve(t,i);if(y.existsSync(e))return e}throw new Error(`No effing-cloud.config.ts found in ${t}. Create one with \`export default defineConfig({ project: "...", ... })\` or pass --config <path>.`)}function v(){return{name:"effing-cloud-stub",setup(t){t.onResolve({filter:/^effing-cloud$/},n=>({path:n.path,namespace:"effing-cloud-stub"})),t.onLoad({filter:/.*/,namespace:"effing-cloud-stub"},()=>({contents:"export const defineConfig = (c) => c;",loader:"js"}))}}}async function C(t,n){let i=P(t,n),e=d.dirname(i),f=d.join(e,`.effing-cloud.config.${S(4).toString("hex")}.mjs`);try{await D({entryPoints:[i],outfile:f,bundle:!0,format:"esm",platform:"node",target:"node22",packages:"external",plugins:[v()],logLevel:"silent"});let s=await import(x(f).href),o=F.safeParse(s.default);if(!o.success)throw new Error(`Invalid config in ${i}:
3
- ${o.error.message}`);return{config:o.data,configPath:i,configDir:e}}finally{await y.promises.unlink(f).catch(()=>{})}}import A from"path";import{build as j}from"esbuild";import{glob as N}from"tinyglobby";var R={image:"images",annie:"annies",effie:"effies"};async function $(t){let{configDir:n,config:i}=t,e={image:await b(n,i.images),annie:await b(n,i.annies),effie:await b(n,i.effies)};if(e.image.length+e.annie.length+e.effie.length===0)throw new Error(`No modules matched the globs in the config. Set images/annies/effies to paths that exist relative to ${n}.`);let s=B(e),o=await j({stdin:{contents:s,resolveDir:n,loader:"ts",sourcefile:"effing-entry.ts"},bundle:!0,format:"esm",platform:"node",target:"node22",external:["node:*","@napi-rs/canvas","@effing/fn"],write:!1,logLevel:"silent"});if(o.outputFiles.length!==1)throw new Error(`esbuild produced ${o.outputFiles.length} output files; expected 1`);let r=o.outputFiles[0].contents,m=new ArrayBuffer(r.byteLength),l=new Uint8Array(m);l.set(r);let c={modules:{image:e.image.map(a=>a.id),annie:e.annie.map(a=>a.id),effie:e.effie.map(a=>a.id)}};return{bundle:l,manifest:c}}async function b(t,n){if(!n)return[];let i=Array.isArray(n)?n:[n],e=await N(i,{cwd:t,absolute:!0}),f=new Map;for(let s of e){let o=A.basename(s).split(".")[0],r=f.get(o);if(r&&r!==s)throw new Error(`Duplicate module id "${o}" \u2014 matched by both ${r} and ${s}. Module ids must be unique per kind.`);f.set(o,s)}return[...f.entries()].map(([s,o])=>({id:s,absPath:o})).sort((s,o)=>s.id.localeCompare(o.id))}function B(t){let n=[],i=(e,f)=>`_${e}_${f}`;for(let e of["image","annie","effie"])t[e].forEach((f,s)=>{let o=i(e,s);n.push(`import { propsSchema as ${o}_ps, previewProps as ${o}_pp, runner as ${o}_r } from ${JSON.stringify(f.absPath)};`)});for(let e of["image","annie","effie"]){let f=R[e];n.push(`export const ${f} = {`),t[e].forEach((s,o)=>{let r=i(e,o);n.push(` ${JSON.stringify(s.id)}: { propsSchema: ${r}_ps, previewProps: ${r}_pp, runner: ${r}_r },`)}),n.push("};")}return n.join(`
4
- `)}var I="https://fn.effing.dev";function E(t){t.command("deploy").description("Bundle and deploy your @effing/fn functions to Effing Cloud").option("-c, --config <path>","path to the effing-cloud.config.ts file").option("--dry-run","bundle without uploading \u2014 prints the manifest and bundle size",!1).action(async n=>{try{await O(n)}catch(i){console.error(i.message),u.exitCode=1}})}async function O(t){let n=u.env.EFFING_CLOUD_API_KEY;if(!t.dryRun&&!n)throw new Error("EFFING_CLOUD_API_KEY is not set. Export your API key or pass --dry-run to bundle without uploading.");let i=(u.env.EFFING_CLOUD_FN_BASE_URL??I).replace(/\/$/,""),{config:e,configDir:f,configPath:s}=await C(u.cwd(),t.config);console.log(`Loaded config from ${s}`);let{bundle:o,manifest:r}=await $({configDir:f,config:e}),m=r.modules.image.length+r.modules.annie.length+r.modules.effie.length;if(console.log(`Bundled ${m} module(s) \u2014 image: ${r.modules.image.length}, annie: ${r.modules.annie.length}, effie: ${r.modules.effie.length} (${o.byteLength} bytes)`),t.dryRun){console.log("Dry run \u2014 skipping upload. Manifest:"),console.log(JSON.stringify(r,null,2));return}let l=new FormData;l.append("projectSlug",e.project),l.append("manifest",JSON.stringify(r)),l.append("bundle",new Blob([o],{type:"application/javascript"}),"bundle.js");let c=await fetch(`${i}/-/deploy`,{method:"POST",headers:{Authorization:`Bearer ${n}`},body:l});if(c.status!==201){let _=await c.text();throw new Error(`Deploy failed \u2014 ${c.status} ${c.statusText}: ${_}`)}let a=await c.json();console.log(`Deployed ${e.project} \u2014 version ${a.version}, deployment ${a.deploymentId}, hash ${a.bundleHash}, ${a.bundleSize} bytes`)}var k=U(import.meta.url),{version:z}=k("../package.json"),p=new K;p.name("effing-cloud").description("CLI for the Effing Cloud platform").version(z);w(p);E(p);p.parse();
2
+ import{createRequire as G}from"module";import{Command as T}from"commander";function $(t){t.command("login").description("Authenticate with Effing Cloud").action(()=>{console.log("Login is not yet implemented.")})}import S from"process";import d from"path";import b from"fs";import{pathToFileURL as j}from"url";import{randomBytes as P}from"crypto";import{build as A}from"esbuild";import{z as l}from"zod";var w=l.union([l.string(),l.array(l.string())]),L=l.object({project:l.string().min(1),images:w.optional(),annies:w.optional(),effies:w.optional()});var R=["effing-cloud.config.ts","effing-cloud.config.mts","effing-cloud.config.js"];function D(t,n){if(n){let i=d.isAbsolute(n)?n:d.resolve(t,n);if(!b.existsSync(i))throw new Error(`Config file not found: ${i}`);return i}for(let i of R){let o=d.resolve(t,i);if(b.existsSync(o))return o}throw new Error(`No effing-cloud.config.ts found in ${t}. Create one with \`export default defineConfig({ project: "...", ... })\` or pass --config <path>.`)}function K(){return{name:"effing-cloud-stub",setup(t){t.onResolve({filter:/^effing-cloud$/},n=>({path:n.path,namespace:"effing-cloud-stub"})),t.onLoad({filter:/.*/,namespace:"effing-cloud-stub"},()=>({contents:"export const defineConfig = (c) => c;",loader:"js"}))}}}async function p(t,n){let i=D(t,n),o=d.dirname(i),s=d.join(o,`.effing-cloud.config.${P(4).toString("hex")}.mjs`);try{await A({entryPoints:[i],outfile:s,bundle:!0,format:"esm",platform:"node",target:"node22",packages:"external",plugins:[K()],logLevel:"silent"});let r=await import(j(s).href),e=L.safeParse(r.default);if(!e.success)throw new Error(`Invalid config in ${i}:
3
+ ${e.error.message}`);return{config:e.data,configPath:i,configDir:o}}finally{await b.promises.unlink(s).catch(()=>{})}}import U from"path";import{build as N}from"esbuild";import{glob as B}from"tinyglobby";var I={image:"images",annie:"annies",effie:"effies"};async function E(t){let{configDir:n,config:i}=t,o={image:await C(n,i.images),annie:await C(n,i.annies),effie:await C(n,i.effies)};if(o.image.length+o.annie.length+o.effie.length===0)throw new Error(`No modules matched the globs in the config. Set images/annies/effies to paths that exist relative to ${n}.`);let r=O(o),e=await N({stdin:{contents:r,resolveDir:n,loader:"ts",sourcefile:"effing-entry.ts"},bundle:!0,format:"esm",platform:"node",target:"node22",external:["node:*","@napi-rs/canvas","@effing/fn"],write:!1,logLevel:"silent"});if(e.outputFiles.length!==1)throw new Error(`esbuild produced ${e.outputFiles.length} output files; expected 1`);let f=e.outputFiles[0].contents,g=new ArrayBuffer(f.byteLength),y=new Uint8Array(g);y.set(f);let a={modules:{image:o.image.map(c=>c.id),annie:o.annie.map(c=>c.id),effie:o.effie.map(c=>c.id)}};return{bundle:y,manifest:a}}async function C(t,n){if(!n)return[];let i=Array.isArray(n)?n:[n],o=await B(i,{cwd:t,absolute:!0}),s=new Map;for(let r of o){let e=U.basename(r).split(".")[0],f=s.get(e);if(f&&f!==r)throw new Error(`Duplicate module id "${e}" \u2014 matched by both ${f} and ${r}. Module ids must be unique per kind.`);s.set(e,r)}return[...s.entries()].map(([r,e])=>({id:r,absPath:e})).sort((r,e)=>r.id.localeCompare(e.id))}function O(t){let n=[],i=(o,s)=>`_${o}_${s}`;for(let o of["image","annie","effie"])t[o].forEach((s,r)=>{let e=i(o,r);n.push(`import { propsSchema as ${e}_ps, previewProps as ${e}_pp, runner as ${e}_r } from ${JSON.stringify(s.absPath)};`)});for(let o of["image","annie","effie"]){let s=I[o];n.push(`export const ${s} = {`),t[o].forEach((r,e)=>{let f=i(o,e);n.push(` ${JSON.stringify(r.id)}: { propsSchema: ${f}_ps, previewProps: ${f}_pp, runner: ${f}_r },`)}),n.push("};")}return n.join(`
4
+ `)}import x from"process";var k="https://fn.effing.dev";function q(){return(x.env.EFFING_CLOUD_FN_BASE_URL??k).replace(/\/$/,"")}function m(){let t=x.env.EFFING_CLOUD_API_KEY;if(!t)throw new Error("EFFING_CLOUD_API_KEY is not set.");return t}async function h(t,n){let{apiKey:i,expectedStatus:o=200,headers:s,...r}=n,e=await fetch(`${q()}${t}`,{...r,headers:{...s,Authorization:`Bearer ${i}`}});if(e.status!==o){let f=await e.text();throw new Error(`Request failed \u2014 ${e.status} ${e.statusText}: ${f}`)}return e}function _(t){t.command("deploy").description("Bundle and deploy your @effing/fn functions to Effing Cloud").option("-c, --config <path>","path to the effing-cloud.config.ts file").option("--dry-run","bundle without uploading \u2014 prints the manifest and bundle size",!1).action(async n=>{try{await z(n)}catch(i){console.error(i.message),S.exitCode=1}})}async function z(t){let n=t.dryRun?"":m(),{config:i,configDir:o,configPath:s}=await p(S.cwd(),t.config);console.log(`Loaded config from ${s}`);let{bundle:r,manifest:e}=await E({configDir:o,config:i}),f=e.modules.image.length+e.modules.annie.length+e.modules.effie.length;if(console.log(`Bundled ${f} module(s) \u2014 image: ${e.modules.image.length}, annie: ${e.modules.annie.length}, effie: ${e.modules.effie.length} (${r.byteLength} bytes)`),t.dryRun){console.log("Dry run \u2014 skipping upload. Manifest:"),console.log(JSON.stringify(e,null,2));return}let g=new FormData;g.append("project",i.project),g.append("manifest",JSON.stringify(e)),g.append("bundle",new Blob([r],{type:"application/javascript"}),"bundle.js");let a=await(await h("/-/deployments",{method:"POST",body:g,apiKey:n,expectedStatus:201})).json();if(console.log(`Deployed ${i.project} \u2014 version ${a.version}, deployment ${a.id}, hash ${a.bundleHash}, ${a.bundleSize} bytes`),a.previews&&a.previews.length>0){console.log(`
5
+ Previews:`);for(let c of a.previews)console.log(` ${c.kind}/${c.id} ${c.url}`)}}import v from"process";function F(t){t.command("url-secret [project]").description("Print the URL-signing secret for a project").option("-c, --config <path>","path to the effing-cloud.config.ts file").action(async(n,i)=>{try{await M(n,i)}catch(o){console.error(o.message),v.exitCode=1}})}async function M(t,n){let i=m(),o=t;if(!o){let{config:e}=await p(v.cwd(),n.config);o=e.project}let r=await(await h(`/-/projects/${encodeURIComponent(o)}/url-secret`,{apiKey:i})).json();if(typeof r.urlSecret!="string")throw new Error("Response missing urlSecret");console.log(r.urlSecret)}var J=G(import.meta.url),{version:Y}=J("../package.json"),u=new T;u.name("effing-cloud").description("CLI for the Effing Cloud platform").version(Y);$(u);_(u);F(u);u.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effing-cloud",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {