Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cfw

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cfw - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

readme.md

2

lib/index.js

@@ -1,1 +0,1 @@

var e=require("kleur"),t=require("fs"),n=require("premove"),r=require("klona/lite"),o=require("path"),i=require("os"),a=require("util"),s=require("httpie");const l={resolve:{mainFields:["worker","browser","module","jsnext","main"]}},c={output:{format:"esm",sourcemap:!1},treeshake:{propertyReadSideEffects:!1,moduleSideEffects:"no-external",tryCatchDeoptimization:!1},plugins:[]},u=" ~> ",d=" ".repeat(6),f=e.bold("[CFW]");function p(t,n){console.log(e[t](f),n.includes("\n")?n.replace(/(\r?\n)/g,"$1"+d):n)}const g=e=>p("white",e),m=e=>p("green",e),w=e=>p("yellow",e);function y(e,t=1){p("red",e),process.exit(t)}const h=e.dim().bold;function $(e,t){return(t.only||t.ignore)&&(e+=`\nPerhaps the ${h("--only")} or ${h("--ignore")} flag needs adjusting`),w(e)}function k(t){return e.italic().dim(` (${t}ms)`)}function v(t,n,r){let o="•",i=e.dim,a=null!=n?k(n):"";r?(o="+",i=e.green().dim):null!=r&&(o="-",i=e.red().dim),console.log(i(d+o+` "${t}"`)+a)}const E=a.promisify(t.writeFile),b=a.promisify(t.readFile),_=(e,t)=>!!e||y(t),D=(e,n)=>t.existsSync(e)||y(n);function O(e){return Array.isArray(e)?e:e.split(",")}function C(e,n){return e=o.resolve(n||".",e),t.existsSync(e)&&require(e)}function A(e){let t;return(t=C("cfw.js",e))||(t=C("cfw.json",e))?t:(t=C("package.json",e))?t.cfw:void 0}function L(e,t,n){let r=n?e:o.join(e,t),i=A(r)||{};return{cfw:i,name:i.name||t,input:o.join(r,i.entry||"index.js"),abs:r}}function x(e,n){n.cwd=o.resolve(n.cwd);let r,i,a=o.resolve(n.cwd,e);D(a,`Workers directory does not exist: "${a}"`);let{cwd:s,single:l,only:c,ignore:u}=n;if(l){let e=n.dir;"."===e&&(e=o.parse(s).base);let t=L(a,e,!0);return(i=A(s))&&(Object.assign(t.cfw,i),i.name&&(t.name=i.name),n.profile&&(t.cfw.profile=n.profile)),[t]}let d=t.readdirSync(a).map((e=>L(a,e)));return c?(r=O(c),d.filter((e=>r.includes(e.name)))):u?(r=O(u),d.filter((e=>!r.includes(e.name)))):d}async function N(e,t){let{CLOUDFLARE_ZONEID:n,CLOUDFLARE_ACCOUNTID:r,CLOUDFLARE_AUTH_EMAIL:a,CLOUDFLARE_AUTH_KEY:s,CLOUDFLARE_TOKEN:l}=process.env,c=a||e.email,u=s||e.authkey,d=r||e.accountid,f=n||e.zoneid,p=l||e.token;if((p||u&&c)&&d&&f)return{authkey:u,accountid:d,email:c,token:p,zoneid:f};if(e.profile){let t=await async function(e="default"){let t=o.join(i.homedir(),".cfw","config");D(t,`Missing "${t}" config file`);let n,r,a=(await b(t,"utf8")).split(/\n+/g),s={},l=0,c=/^\[(.*)\]$/;for(;l<a.length;l++)if(a[l].startsWith("#")||!a[l].trim().length);else if(c.test(a[l]))r=c.exec(a[l])[1],n=s[r]={};else{let[e,t]=a[l].split(/\s*=\s*/);n[e]=t}let u=s[e];return _(u,`The "${e}" profile is not defined`),u}(e.profile);Object.keys(t).forEach((e=>{!c&&/CLOUDFLARE_AUTH_EMAIL/i.test(e)&&(c=t[e]),!d&&/CLOUDFLARE_ACCOUNTID/i.test(e)&&(d=t[e]),!u&&/CLOUDFLARE_AUTH_KEY/i.test(e)&&(u=t[e]),!f&&/CLOUDFLARE_ZONEID/i.test(e)&&(f=t[e]),!p&&/CLOUDFLARE_TOKEN/i.test(e)&&(p=t[e])}))}return _(f||t,'Missing Cloudflare "zoneid" value!'),_(d,'Missing Cloudflare "accountid" value!'),p||u&&c||(u||c?(_(c,'Missing Cloudflare "email" value!'),_(u,'Missing Cloudflare "authkey" value!')):y('Missing Cloudflare "token" value or "email" + "authkey" combo!')),{authkey:u,accountid:d,email:c,token:p,zoneid:f}}const T=()=>Math.random().toString(36).slice(2);function j(e,t={}){return e.token?t.Authorization="Bearer "+e.token:(t["X-Auth-Key"]=e.authkey,t["X-Auth-Email"]=e.email),t}function U(e,t,n={}){return s.send(e,"https://api.cloudflare.com/client/v4"+t,n).then((e=>e.data))}function S(e,t,n){return U("POST",`/zones/${e.zoneid}/workers/routes`,{headers:j(e,{"Content-Type":"application/javascript"}),body:{pattern:t,script:n}}).catch((e=>{let{data:n,message:r}=e;n&&n.errors&&10020===n.errors[0].code||y(`Error setting "${t}" route pattern!\n${JSON.stringify(n||r,null,2)}`)}))}async function R(e,t,n,r){const o="----"+T()+T(),i=function(e,t){let n,r,o="",i="\r\n",a="--"+e;for(n in t)r=t[n],o+=a+i,o+=`Content-Disposition: form-data; name="${n}"`,r.filename&&(o+=`; filename="${r.filename}"`),r.type&&(o+="\r\nContent-Type: "+r.type),o+=i+i+r.value+i;return o+a+"--"}(o,{script:{type:"application/javascript",value:n},metadata:{type:"application/json",value:r?JSON.stringify(r):'{"body_part": "script","bindings":[]}'}});return U("PUT",`/accounts/${e.accountid}/workers/scripts/${t}`,{headers:j(e,{"Content-Type":"multipart/form-data; boundary="+o}),body:i}).catch((e=>{y(`Error uploading "${t}" script!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}const F={env:"plain_text",wasm:"wasm_module",secret:"secret_text",kv:"kv_namespace"};function q(e,t){let n=t.indexOf(":"),r=t.substring(0,n),o=t.substring(n+1),i=F[r.toLowerCase()];return i||y(`Unknown binding hint: "${r}"`),"wasm_module"===i?{type:i,name:e,part:"wasm"}:"kv_namespace"===i?{type:i,name:e,namespace_id:o}:{type:i,name:e,text:o}}function K(e){let t,n=[];for(t in e)n.push(q(t,e[t]));if(n.length)return{body_part:"script",bindings:n}}function J(e,t){return U("GET",`/accounts/${e.accountid}/workers/scripts/${t}/secrets`,{headers:j(e)}).catch((e=>{y(`Error fetching "${t}" secrets!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}function M(e,t,n,r){return U("PUT",`/accounts/${e.accountid}/workers/scripts/${t}/secrets`,{headers:j(e),body:{type:"secret_text",text:r,name:n}}).catch((e=>{y(`Error creating new "${t}" secret!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}function z(e,t,n,r){return U("DELETE",`/accounts/${e.accountid}/workers/scripts/${t}/secrets/${n}`,{headers:j(e)}).catch((e=>{let{data:o,message:i}=e;if(r&&o&&o.errors&&10056===o.errors[0].code)return o;y(`Error deleting "${t}/${n}" secret!\n${JSON.stringify(o||i,null,2)}`)}))}var I={__proto__:null,list:async function(t){let n=x(t.dir,t);if(!n.length)return $("No workers found!",t);let r=e.bold(n.length),o=1===n.length?"":"s";g(`Fetching secrets for ${r} worker${o}:`);let i=e.cyan(u);for(let r of n){let{name:n,cfw:o}=r;o.profile=o.profile||t.profile;let a=await N(o),s=await J(a,n);if(console.log(i+`"${n}" secrets:`),s.result.length)for(let e of s.result)v(e.name);else console.log(d+e.italic().dim(" None"))}m(`Retrieved worker${o?"s'":"'s"} secrets`)},create:async function(t,n,r){let o=x(r.dir,r);if(!o.length)return $("No workers found!",r);let i=e.cyan(u),a=e.bold(o.length),s=1===o.length?"":"s",l=[];g(`Adding secret "${t}" value to ${a} worker${s}:`);for(let e of o){let{name:o,cfw:a}=e;a.profile=a.profile||r.profile;let s=await N(a);l.push((()=>{let e=Date.now();return M(s,o,t,n).then((t=>{t.success&&console.log(i+o+k(Date.now()-e))}))}))}await Promise.all(l.map((e=>e()))),m("Added secret to worker"+s)},destroy:async function(t,n){let r=x(n.dir,n);if(!r.length)return $("No workers found!",n);let o=e.bold(r.length),i=1===r.length?"":"s",a=[];g(`Removing "${t}" secret from ${o} worker${i}:`);for(let o of r){let{name:r,cfw:i}=o;i.profile=i.profile||n.profile;let s=await N(i);a.push((()=>{let o=Date.now();return z(s,r,t,!!n.quiet).then((t=>{let n=(t.success?e.cyan:e.red)(u);console.log(n+r+k(Date.now()-o))}))}))}await Promise.all(a.map((e=>e()))),m("Removed secret from worker"+i)}};var P={__proto__:null,list:async function(t){const n=await N(t,!0);g("Retrieving KV namespaces:");const r=await function(e){return U("GET",`/accounts/${e.accountid}/storage/kv/namespaces?per_page=100&order=title`,{headers:j(e)})}(n),o=" ",i=e.dim().bold().italic;m(i("ID")+" ".repeat(30)+o+i("Title"));let a=0,s=r.result,l="";for(;a<s.length;a++)l&&(l+="\n"),l+=(s[a].supports_url_encoding?e.cyan:e.red)(u),l+=s[a].id+o+s[a].title;console.log(l)},create:async function(t,n){const r=await N(n,!0);g("Creating new KV namespace:");const o=await function(e,t){return U("POST",`/accounts/${e.accountid}/storage/kv/namespaces`,{headers:j(e),body:{title:t}}).catch((e=>{y(`Error creating "${t}" namespace!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}(r,t);if(!o)return y("Error creating namespace");console.log(e.cyan(u)+`"${o.result.title}" `+e.italic().dim(`(ID: ${o.result.id})`)),m("KV namespace created!")},destroy:async function(e,t){const n=await N(t,!0);w("Deleting KV namespace");const r=await function(e,t){return U("DELETE",`/accounts/${e.accountid}/storage/kv/namespaces/${t}`,{headers:j(e)}).catch((e=>{y(`Error removing "${t}" namespace!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}(n,e);if(!r||!r.success)return y("Error deleting namespace");m("KV namespace deleted!")}};exports.build=async function(i,a,s){s.dir=i||s.dir;let d=x(s.dir,s);if(!d.length)return $("Nothing to build!",s);let f=a||"build";i=o.resolve(s.cwd,s.dir),a=o.resolve(s.cwd,f),t.existsSync(a)&&(w(`Removing existing "${f}" directory`),await n.premove(a));const{rollup:p}=require("rollup");let y=e.cyan(u),h=e.bold(d.length),v=1===d.length?"":"s";g(`Building ${h} worker${v}:`);for(let e of d){let{name:t,input:n,cfw:i}=e,u=r.klona(l),d={input:n,...c},f=o.join(a,s.single?"":t);d.output.file=o.join(f,"index.js"),"function"==typeof i.build&&(d=r.klona(d),i.build(d,u)),d.plugins.push(require("@rollup/plugin-node-resolve").default(u.resolve));let g=Date.now();await p(d).then((e=>e.write(d.output))),await E(o.join(f,"cfw.json"),JSON.stringify({name:t,...i},null,2)),console.log(y+t+k(Date.now()-g))}m(`Build complete!\nYour worker${v} ${1===d.length?"is":"are"} ready for deployment 🎉`)},exports.deploy=async function(t,n){let r=t||"build",o=x(r,n);if(!o.length)return $("Nothing to deploy!",n);let i=e.cyan(u),a=e.bold(o.length),s=1===o.length?"":"s";g(`Deploying ${a} worker${s}:`);for(let e of o){let{name:t,input:r,cfw:o}=e;o.profile=o.profile||n.profile,D(r,`Worker input does not exist: "${r}"`);let a=await N(o),s=o.globals&&K(o.globals),l=await b(r),c=Date.now();await R(a,t,l,s),console.log(i+t+k(Date.now()-c)),o.routes&&await Promise.all(o.routes.map((e=>{let n=Date.now(),r=e.startsWith("!"),o=e.substring(+r);return S(a,o,r?null:t).then((()=>{v(o,Date.now()-n,!r)}))})))}m(`Deployment complete!\nAll items within "${r}" uploaded 🎉`)},exports.ns=P,exports.secret=I;
var e=require("kleur"),t=require("fs"),n=require("premove"),r=require("klona/lite"),o=require("path"),i=require("os"),a=require("util"),s=require("httpie");const l={resolve:{mainFields:["worker","browser","module","jsnext","main"]}},c={output:{format:"esm",sourcemap:!1},treeshake:{propertyReadSideEffects:!1,moduleSideEffects:"no-external",tryCatchDeoptimization:!1},plugins:[]},u=" ~> ",d=" ".repeat(6),f=e.bold("[CFW]");function p(t,n){console.log(e[t](f),n.includes("\n")?n.replace(/(\r?\n)/g,"$1"+d):n)}const m=e=>p("white",e),g=e=>p("green",e),w=e=>p("yellow",e);function y(e,t=1){p("red",e),process.exit(t)}const h=e.dim().bold;function $(e,t){return(t.only||t.ignore)&&(e+=`\nPerhaps the ${h("--only")} or ${h("--ignore")} flag needs adjusting`),w(e)}function k(t){return e.italic().dim(` (${t}ms)`)}function v(t,n,r){let o="•",i=e.dim,a=null!=n?k(n):"";r?(o="+",i=e.green().dim):null!=r&&(o="-",i=e.red().dim),console.log(i(d+o+` "${t}"`)+a)}const E=a.promisify(t.writeFile),b=a.promisify(t.readFile),_=(e,t)=>!!e||y(t),D=(e,n)=>t.existsSync(e)||y(n);function O(e){return Array.isArray(e)?e:e.split(",")}function C(e,n){return e=o.resolve(n||".",e),t.existsSync(e)&&require(e)}function A(e){let t;return(t=C("cfw.js",e))||(t=C("cfw.json",e))?t:(t=C("package.json",e))?t.cfw:void 0}function L(e,t,n){let r=n?e:o.join(e,t),i=A(r)||{};return{cfw:i,name:i.name||t,input:o.join(r,i.entry||"index.js"),abs:r}}function x(e,n){n.cwd=o.resolve(n.cwd);let r,i,a=o.resolve(n.cwd,e);D(a,`Workers directory does not exist: "${a}"`);let{cwd:s,single:l,only:c,ignore:u}=n;if(l){let e=n.dir;"."===e&&(e=o.parse(s).base);let t=L(a,e,!0);return(i=A(s))&&(Object.assign(t.cfw,i),i.name&&(t.name=i.name),n.profile&&(t.cfw.profile=n.profile)),[t]}let d=t.readdirSync(a).map((e=>L(a,e)));return c?(r=O(c),d.filter((e=>r.includes(e.name)))):u?(r=O(u),d.filter((e=>!r.includes(e.name)))):d}async function N(e,t){let{CLOUDFLARE_ZONEID:n,CLOUDFLARE_ACCOUNTID:r,CLOUDFLARE_AUTH_EMAIL:a,CLOUDFLARE_AUTH_KEY:s,CLOUDFLARE_TOKEN:l}=process.env,c=a||e.email,u=s||e.authkey,d=r||e.accountid,f=n||e.zoneid,p=l||e.token;if((p||u&&c)&&d&&f)return{authkey:u,accountid:d,email:c,token:p,zoneid:f};if(e.profile){let t=await async function(e="default"){let t=o.join(i.homedir(),".cfw","config");D(t,`Missing "${t}" config file`);let n,r,a={},s=0,l=/^\[(.*)\]$/,c=(await b(t,"utf8")).split(/(\r?\n)+/g);for(;s<c.length;s++)if(c[s].startsWith("#")||!c[s].trim().length);else if(l.test(c[s]))r=l.exec(c[s])[1],n=a[r]={};else{let[e,t]=c[s].split("=");n[e.trim()]=t.trim()}let u=a[e];return _(u,`The "${e}" profile is not defined`),u}(e.profile);Object.keys(t).forEach((e=>{!c&&/CLOUDFLARE_AUTH_EMAIL/i.test(e)&&(c=t[e]),!d&&/CLOUDFLARE_ACCOUNTID/i.test(e)&&(d=t[e]),!u&&/CLOUDFLARE_AUTH_KEY/i.test(e)&&(u=t[e]),!f&&/CLOUDFLARE_ZONEID/i.test(e)&&(f=t[e]),!p&&/CLOUDFLARE_TOKEN/i.test(e)&&(p=t[e])}))}return _(f||t,'Missing Cloudflare "zoneid" value!'),_(d,'Missing Cloudflare "accountid" value!'),p||u&&c||(u||c?(_(c,'Missing Cloudflare "email" value!'),_(u,'Missing Cloudflare "authkey" value!')):y('Missing Cloudflare "token" value or "email" + "authkey" combo!')),{authkey:u,accountid:d,email:c,token:p,zoneid:f}}const T=()=>Math.random().toString(36).slice(2);function j(e,t={}){return e.token?t.Authorization="Bearer "+e.token:(t["X-Auth-Key"]=e.authkey,t["X-Auth-Email"]=e.email),t}function U(e,t,n={}){return s.send(e,"https://api.cloudflare.com/client/v4"+t,n).then((e=>e.data))}function S(e,t,n){return U("POST",`/zones/${e.zoneid}/workers/routes`,{headers:j(e,{"Content-Type":"application/javascript"}),body:{pattern:t,script:n}}).catch((e=>{let{data:n,message:r}=e;n&&n.errors&&10020===n.errors[0].code||y(`Error setting "${t}" route pattern!\n${JSON.stringify(n||r,null,2)}`)}))}async function R(e,t,n,r){const o="----"+T()+T(),i=function(e,t){let n,r,o="",i="\r\n",a="--"+e;for(n in t)r=t[n],o+=a+i,o+=`Content-Disposition: form-data; name="${n}"`,r.filename&&(o+=`; filename="${r.filename}"`),r.type&&(o+="\r\nContent-Type: "+r.type),o+=i+i+r.value+i;return o+a+"--"}(o,{script:{type:"application/javascript",value:n},metadata:{type:"application/json",value:r?JSON.stringify(r):'{"body_part": "script","bindings":[]}'}});return U("PUT",`/accounts/${e.accountid}/workers/scripts/${t}`,{headers:j(e,{"Content-Type":"multipart/form-data; boundary="+o}),body:i}).catch((e=>{y(`Error uploading "${t}" script!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}const F={env:"plain_text",wasm:"wasm_module",secret:"secret_text",kv:"kv_namespace"};function q(e,t){let n=t.indexOf(":"),r=t.substring(0,n),o=t.substring(n+1),i=F[r.toLowerCase()];return i||y(`Unknown binding hint: "${r}"`),"wasm_module"===i?{type:i,name:e,part:"wasm"}:"kv_namespace"===i?{type:i,name:e,namespace_id:o}:{type:i,name:e,text:o}}function K(e){let t,n=[];for(t in e)n.push(q(t,e[t]));if(n.length)return{body_part:"script",bindings:n}}function J(e,t){return U("GET",`/accounts/${e.accountid}/workers/scripts/${t}/secrets`,{headers:j(e)}).catch((e=>{y(`Error fetching "${t}" secrets!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}function M(e,t,n,r){return U("PUT",`/accounts/${e.accountid}/workers/scripts/${t}/secrets`,{headers:j(e),body:{type:"secret_text",text:r,name:n}}).catch((e=>{y(`Error creating new "${t}" secret!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}function z(e,t,n,r){return U("DELETE",`/accounts/${e.accountid}/workers/scripts/${t}/secrets/${n}`,{headers:j(e)}).catch((e=>{let{data:o,message:i}=e;if(r&&o&&o.errors&&10056===o.errors[0].code)return o;y(`Error deleting "${t}/${n}" secret!\n${JSON.stringify(o||i,null,2)}`)}))}var I={__proto__:null,list:async function(t){let n=x(t.dir,t);if(!n.length)return $("No workers found!",t);let r=e.bold(n.length),o=1===n.length?"":"s";m(`Fetching secrets for ${r} worker${o}:`);let i=e.cyan(u);for(let r of n){let{name:n,cfw:o}=r;o.profile=o.profile||t.profile;let a=await N(o),s=await J(a,n);if(console.log(i+`"${n}" secrets:`),s.result.length)for(let e of s.result)v(e.name);else console.log(d+e.italic().dim(" None"))}g(`Retrieved worker${o?"s'":"'s"} secrets`)},create:async function(t,n,r){let o=x(r.dir,r);if(!o.length)return $("No workers found!",r);let i=e.cyan(u),a=e.bold(o.length),s=1===o.length?"":"s",l=[];m(`Adding secret "${t}" value to ${a} worker${s}:`);for(let e of o){let{name:o,cfw:a}=e;a.profile=a.profile||r.profile;let s=await N(a);l.push((()=>{let e=Date.now();return M(s,o,t,n).then((t=>{t.success&&console.log(i+o+k(Date.now()-e))}))}))}await Promise.all(l.map((e=>e()))),g("Added secret to worker"+s)},destroy:async function(t,n){let r=x(n.dir,n);if(!r.length)return $("No workers found!",n);let o=e.bold(r.length),i=1===r.length?"":"s",a=[];m(`Removing "${t}" secret from ${o} worker${i}:`);for(let o of r){let{name:r,cfw:i}=o;i.profile=i.profile||n.profile;let s=await N(i);a.push((()=>{let o=Date.now();return z(s,r,t,!!n.quiet).then((t=>{let n=(t.success?e.cyan:e.red)(u);console.log(n+r+k(Date.now()-o))}))}))}await Promise.all(a.map((e=>e()))),g("Removed secret from worker"+i)}};var P={__proto__:null,list:async function(t){const n=await N(t,!0);m("Retrieving KV namespaces:");const r=await function(e){return U("GET",`/accounts/${e.accountid}/storage/kv/namespaces?per_page=100&order=title`,{headers:j(e)})}(n),o=" ",i=e.dim().bold().italic;g(i("ID")+" ".repeat(30)+o+i("Title"));let a=0,s=r.result,l="";for(;a<s.length;a++)l&&(l+="\n"),l+=(s[a].supports_url_encoding?e.cyan:e.red)(u),l+=s[a].id+o+s[a].title;console.log(l)},create:async function(t,n){const r=await N(n,!0);m("Creating new KV namespace:");const o=await function(e,t){return U("POST",`/accounts/${e.accountid}/storage/kv/namespaces`,{headers:j(e),body:{title:t}}).catch((e=>{y(`Error creating "${t}" namespace!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}(r,t);if(!o)return y("Error creating namespace");console.log(e.cyan(u)+`"${o.result.title}" `+e.italic().dim(`(ID: ${o.result.id})`)),g("KV namespace created!")},destroy:async function(e,t){const n=await N(t,!0);w("Deleting KV namespace");const r=await function(e,t){return U("DELETE",`/accounts/${e.accountid}/storage/kv/namespaces/${t}`,{headers:j(e)}).catch((e=>{y(`Error removing "${t}" namespace!\n${JSON.stringify(e.data||e.message,null,2)}`)}))}(n,e);if(!r||!r.success)return y("Error deleting namespace");g("KV namespace deleted!")}};exports.build=async function(i,a,s){s.dir=i||s.dir;let d=x(s.dir,s);if(!d.length)return $("Nothing to build!",s);let f=a||"build";i=o.resolve(s.cwd,s.dir),a=o.resolve(s.cwd,f),t.existsSync(a)&&(w(`Removing existing "${f}" directory`),await n.premove(a));const{rollup:p}=require("rollup");let y=e.cyan(u),h=e.bold(d.length),v=1===d.length?"":"s";m(`Building ${h} worker${v}:`);for(let e of d){let{name:t,input:n,cfw:i}=e,u=r.klona(l),d={input:n,...c},f=o.join(a,s.single?"":t);d.output.file=o.join(f,"index.js"),"function"==typeof i.build&&(d=r.klona(d),i.build(d,u)),d.plugins.push(require("@rollup/plugin-node-resolve").default(u.resolve));let m=Date.now();await p(d).then((e=>e.write(d.output))),await E(o.join(f,"cfw.json"),JSON.stringify({name:t,...i},null,2)),console.log(y+t+k(Date.now()-m))}g(`Build complete!\nYour worker${v} ${1===d.length?"is":"are"} ready for deployment 🎉`)},exports.deploy=async function(t,n){let r=t||"build",o=x(r,n);if(!o.length)return $("Nothing to deploy!",n);let i=e.cyan(u),a=e.bold(o.length),s=1===o.length?"":"s";m(`Deploying ${a} worker${s}:`);for(let e of o){let{name:t,input:r,cfw:o}=e;o.profile=o.profile||n.profile,D(r,`Worker input does not exist: "${r}"`);let a=await N(o),s=o.globals&&K(o.globals),l=await b(r),c=Date.now();await R(a,t,l,s),console.log(i+t+k(Date.now()-c)),o.routes&&await Promise.all(o.routes.map((e=>{let n=Date.now(),r=e.startsWith("!"),o=e.substring(+r);return S(a,o,r?null:t).then((()=>{v(o,Date.now()-n,!r)}))})))}g(`Deployment complete!\nAll items within "${r}" uploaded 🎉`)},exports.ns=P,exports.secret=I;
{
"name": "cfw",
"version": "0.0.8",
"version": "0.0.9",
"repository": "lukeed/cfw",

@@ -5,0 +5,0 @@ "description": "WIP",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc