@webflow/webflow-cli 1.8.5 → 1.8.6
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/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -113,7 +113,7 @@ ${a instanceof Error?a.message:String(a)}`)}),process.exit(1)),o&&(a instanceof
|
|
|
113
113
|
export default { ${[o,a,s].filter(Boolean).join(", ")} };`}function c9(e,t){let r={},n="./tmp_entry/Client.js",i="./tmp_entry/Server.js";r[n]=u9([{name:"ClientRenderer",path:e,exportKey:"Renderer",type:"internal"}],fs.Environment.Client),r[i]=u9([{name:"ServerRenderer",path:e,exportKey:"Renderer",type:"internal"},...Object.entries(t).map(([a,s])=>({name:a,path:s,exportKey:a,isDefaultExport:!0,type:"component"}))],fs.Environment.Server);let o={[fs.Environment.Client]:n,[fs.Environment.Server]:i};return{vol:l9.Volume.fromJSON(r),paths:o}}var k9=require("memfs/lib/volume");var _be=w(require("fs")),f9=require("unionfs"),d9=require("webpack");async function ds({config:e,sourceVolumes:t=[],outputVolume:r,outputPath:n}){let i=t.reduce((o,a)=>(o.use(a),o),new f9.Union().use(_be));return new Promise((o,a)=>{let s=(0,d9.webpack)(e);s.inputFileSystem=i,r&&(s.outputFileSystem=r),n&&(s.outputPath=n),s.run((u,l)=>{s.close(c=>{u||c?a(u||c):l?.hasErrors()?a(new Error(l.toString("errors-only"))):l?o(l):a(new Error("Webpack stats are undefined"))})})})}var p9=w(require("module")),h9=require("memfs/lib/volume"),x9=w(require("webpack-merge")),wo=require("@webflow/data-types");function wbe(e,t){let r=`/${t}.js`,n=e.readFileSync(`/${t}.js`,"utf-8"),i=new p9.default(r,module);i._compile(n,r);let o=i.exports.default||i.exports;if(o&&typeof o=="object")try{let{name:a,description:s,group:u,props:l,options:c}=(0,wo.parseComponentData)(o);return{displayName:a,description:s,group:u,props:Object.entries(l||{}).map(([d,h])=>({...h,name:d,defaultValue:typeof h.defaultValue!="string"?JSON.stringify(h.defaultValue):h.defaultValue})),options:c}}catch(a){throw new Error(`Error parsing component data for ${t}: ${a.message}`)}throw new Error(`Could not get declaration for ${t}`)}async function Ebe({declarations:e,sources:t}){let r=new h9.Volume;return await ds({config:(0,x9.default)(rd({entry:e,env:wo.Environment.Client,publicPath:"/",libraryName:"metadata"}),td(),{entry:e,mode:"development",output:{path:"/",library:{type:"commonjs2"}},target:"node"}),sourceVolumes:t?[t]:[],outputVolume:r}),r}async function m9({declarations:e,sources:t}){let r=await Ebe({declarations:e,sources:t});return Object.keys(e).reduce((n,i)=>(n[i]=wbe(r,i),n),{})}function b9(e,{clientModuleUrl:t,framework:r}){return Object.keys(e).reduce((n,i)=>(n[i]={...e[i],id:i,clientModuleUrl:t,framework:r,exportPath:"default",loaderType:wo.ModuleLoader.FEDERATION},n),{})}var Eo=w(require("webpack-merge"));function g9(e,t){let r=Object.entries(e).filter(([n])=>!t.includes(n));return Object.fromEntries(r)}function v9(e,t){let r=["entry","output","mode","target"];Object.keys(t).some(s=>r.includes(s))&&I.warn(`Cannot override blocked properties: ${r.join(", ")}`);let n=g9(t,[...r,"module","plugins"]),i=(0,Eo.default)(e,{...n,module:g9(t.module??{},["rules"])}),{plugins:o}=(0,Eo.mergeWithCustomize)({customizeArray:(0,Eo.unique)("plugins",["ModuleFederationPlugin","MiniCssExtractPlugin"],s=>s.constructor&&s.constructor.name)})({plugins:t.plugins},{plugins:e.plugins});i.plugins=o;let a=t.module?.rules;return a&&typeof a=="function"&&(i.module={...i.module,rules:a(e.module?.rules??[])}),i}var y9=require("@webflow/data-types");function _9(){return{title:_f,content:JSON.stringify({version:1,type:y9.ModuleLoader.FEDERATION,entry:dk,renderer:wf})}}function w9(e,t){return{title:pk,content:JSON.stringify({spec:{identifier:e,entrypoint:Ef,type:"esm"},metadata:{annotations:t||{}}})}}var E9=w(require("archiver")),Do=require("path");async function D9(e,t,r,n){let i=!1;return new Promise(async(o,a)=>{t.length===0&&a(new Error("No assets to bundle"));let s=`/Server/${Tm}`,u=(0,E9.default)("tar",{gzip:!1}),l=r.createWriteStream(s);u.on("error",h=>(i=!0,a(h))),l.on("close",()=>{if(!i)try{let h={type:"asset",name:Tm,info:{},size:u.pointer(),emitted:!0,comparedForEmit:!1,cached:!1};return t.forEach(x=>{let m=(0,Do.resolve)((0,Do.join)("/Server",x.name));r.existsSync(m)&&r.rmSync(m)}),o(h)}catch(h){return a(h)}finally{i=!0}}),u.pipe(l);let{title:c,content:d}=w9(e,n);u.append(d,{name:c}),t.forEach(h=>{try{let x=(0,Do.resolve)((0,Do.join)("/Server",h.name)),m=r.readFileSync(x,"utf8");u.append(m,{name:h.name})}catch(x){return i=!0,a(x)}}),await u.finalize()})}var C9={[Sn.Framework.React]:td};async function nd(e,t){I.debug("Looking for declaration files...");let r=await i9(e.components||[],{cwd:(0,Co.dirname)(t.manifestPath)});if(!Object.keys(r).length)throw new Error("No declaration files found");I.debug(JSON.stringify(r,null,2)),I.debug("Generating entry points...");let{vol:n,paths:i}=await c9(e.renderer,r);I.debug("Reading dependencies...");let o=await Dbe();I.debug("Collecting metadata...");let a=await m9({declarations:r});I.debug(`Metadata: ${JSON.stringify(a,null,2)}`),I.debug("Generating bundles...");let s=k9.Volume.fromJSON({"/Server":null,"/Client":null});I.debug("Generating bundling config...");let u=e.bundleConfig?require((0,Co.resolve)(process.cwd(),e.bundleConfig)):{};Object.keys(u).length&&I.debug("Found config overrides. Merging...");let l=v=>{let g=v9(Cbe({dependencies:o,env:v,framework:e.framework,publicPath:t.publicPath,components:r,entryPaths:i,libraryName:t.libraryIdentifier}),u);return t?.debugBundler&&(I.info(`Webpack config for env ${v}:`),I.dir(g)),g},[c,d]=await Promise.all([ds({config:l(Sn.Environment.Server),sourceVolumes:[n],outputVolume:s,outputPath:"/Server"}),ds({config:l(Sn.Environment.Client),sourceVolumes:[n],outputVolume:s,outputPath:"/Client"})]);I.debug(s.toTree()),I.debug(`Server Bundler Stats:
|
|
114
114
|
${c.toString("errors-warnings")}`),I.debug(`Client Bundler Stats:
|
|
115
115
|
${d.toString("errors-warnings")}`),I.debug("Packaging server bundle...");let h=await D9(t.libraryIdentifier,c.toJson().assets||[],s,{framework:e.framework}),x=v=>g=>[g,v],m=[[h,Sn.Environment.Server],...(d.toJson().assets||[]).map(x(Sn.Environment.Client))];I.debug("Generating Webflow manifest...");let b=_9();return{outputFiles:m,outputVolume:s,metadata:a,webflowManifest:b}}async function Dbe(){return JSON.parse((0,F9.readFileSync)((0,Co.join)(process.cwd(),"package.json"),"utf8")).dependencies}function Cbe({env:e,framework:t,publicPath:r,components:n,dependencies:i,entryPaths:o,shared:a,libraryName:s,outputPath:u}){if(C9[t]){let l=Object.entries({[wf]:o[e],...n}).reduce((x,[m,b])=>({...x,[`./${m}`]:b}),{}),c=rd({entry:o[e],env:e,publicPath:r,libraryName:s,outputPath:u}),d=C9[t](e),h=s9({dependencies:i,exposes:l,env:e,shared:a,libraryName:s});return(0,S9.default)(c,d,h)}else throw new Error(`Unknown framework: ${t}`)}var O9=require("@webflow/data-types"),id={renderer:"@webflow/react",components:["**/*.webflow.@(js|jsx|mjs|ts|tsx)"],framework:O9.Framework.React};var A9=w(require("@dotenvx/dotenvx"));async function q9(e){let t=e?.apiToken||process.env.WEBFLOW_WORKSPACE_API_TOKEN;if(!t&&e?.input){let r=await Ie.prompt([{type:"password",name:"workspaceApiToken",message:"Enter a Workspace API Token"}]);r.workspaceApiToken&&(t=r.workspaceApiToken,A9.default.set("WEBFLOW_WORKSPACE_API_TOKEN",r.workspaceApiToken,{encrypt:!1}))}if(!t?.trim())throw new Error("Workspace API Token is required.");return t}var T9=require("@webflow/data-types");async function Jb(e){let t={workspaceApiToken:await q9(e)};I.debug("Looking for manifest...");let{manifest:r,manifestPath:n}=Re(e?.manifest);I.debug(JSON.stringify(r,null,2)),I.debug("Parsing library config...");let i={...id,...yn(r,"library")};I.debug("Initializing code library...");let{resourceId:o,profileSlug:a,s3Url:s,cdnUrl:u}=await $b({name:i.name,slug:i.id,description:i.description,options:t});I.debug(JSON.stringify({resourceId:o,profileSlug:a,s3Url:s,cdnUrl:u},null,2)),i.id||(I.debug("Updating library config..."),Ht({library:{id:a}}));let{outputFiles:l,outputVolume:c,metadata:d,webflowManifest:h}=await nd(i,{libraryIdentifier:`_${o}`,manifestPath:n,publicPath:u,debugBundler:e?.debugBundler});I.debug("Uploading files...");let x=l.map(([g,E])=>{let j=(0,od.resolve)((0,od.join)(`/${E}`,`${g.name}`));return yo(c.readFileSync(j,"utf8").toString(),j,{bundleEnvironment:E})});x.push(yo(h.content,h.title,{bundleEnvironment:T9.Environment.Client}));let{signatures:m}=await Vb({resourceId:o,files:x.map(({meta:g})=>g),options:t});await Promise.all(m.map(async g=>{let E=x.find(j=>j.meta.fileHash===g.hash);if(!E)throw new Error(`File not found: ${g.hash}`);await zb(E,g.value)})),I.debug("Sharing library...");let b=await b9(d,{clientModuleUrl:u+_f,framework:i.framework}),{taskId:v}=await Gb({resourceId:o,components:Object.values(b),options:t});I.debug(JSON.stringify({taskId:v},null,2))}var Jt=require("path");var ps=w(require("fs")),P9=require("@webflow/data-types");function Sbe(e){return e.replace(/[-_]+/," ").replace(/\w\S*/g,t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()).replace(/\s+/g,"")}async function Qb(e){I.debug("Looking for manifest...");let{manifest:t,manifestPath:r}=Re();I.debug(JSON.stringify(t,null,2)),I.debug("Parsing library config...");let n={...id,...yn(t,"library")},{outputFiles:i,outputVolume:o,webflowManifest:a}=await nd(n,{libraryIdentifier:`_${Sbe(n.name)}`,publicPath:e.publicPath,manifestPath:r,debugBundler:e?.debugBundler});i.forEach(([s,u])=>{let l=(0,Jt.resolve)((0,Jt.join)(`/${u}`,`${s.name}`)),c=yo(o.readFileSync(l,"utf8").toString(),l,{bundleEnvironment:u}),d=(0,Jt.join)(process.cwd(),e.outputPath);ps.default.existsSync((0,Jt.join)(d,`${u}`))||ps.default.mkdirSync((0,Jt.join)(d,`${u}`),{recursive:!0}),ps.default.writeFileSync((0,Jt.join)(d,l),c.value)}),ps.default.writeFileSync((0,Jt.join)(process.cwd(),e.outputPath,P9.Environment.Client,a.title),a.content)}var j9=e=>{let t=e.command("library").description("CLI for managing your Webflow libraries of Code Components. Make sure WEBFLOW_WORKSPACE_API_TOKEN is set in your .env file or pass them as argument --api-token");t.command("share").description("Share a library of Code Components to your Webflow Workspace.").option("--manifest <path>","Path to the webflow.json file. Default: scan current directory.").option("--api-token <token>","Workspace API token. Default: value set in WEBFLOW_WORKSPACE_API_TOKEN env variable.").option("--debug-bundler","Display final bundler configurations for debugging purposes.").option("--no-input","Avoid prompting or doing anything interactive. Use this for CI/CD pipelines.").action(Jb),process.env.BUILD_ENV==="development"&&t.command("bundle").description("Bundle a library of Code Components for local development. Does not share to Webflow.").requiredOption("--public-path <path>","Override the public path for the bundle.").option("--output-path <path>","Override the output path for the bundle. Default is './dist'","dist").option("--debug-bundler","Display final bundler configurations for debugging purposes.").action(Qb)};var Ne=w(require("fs")),Se=w(require("path"));var ad="nextjs",Xb="cloud-scaffolds";var B9="package.json",M9="webflow.json",I9="wf-placeholder-name",R9="CLOUD_MOUNT_PATH",L9="gitignore";var Zb=async(e,t,r=ad,n,i,o)=>{try{let a=n[r];if(!a)throw new Error(`Scaffold "${r}" not found`);for(let s of a)try{let u=Se.join(e,s.split(Se.join(Xb,r))[1]?.substring(1)||""),l=s.includes("next.config.ts"),c=s.includes("astro.config.mjs"),d=l||c;if(s.includes(B9)||s.includes(M9)){let x=(await Ne.promises.readFile(s,"utf8")).replace(I9,e);await hs(u,x)}else if(d){let h=await Ne.promises.readFile(s,"utf8");await hs(u,h.replace(R9,t))}else if(Se.basename(u).toLowerCase()===L9){let h=await Ne.promises.readFile(s,"utf8"),x=Se.join(Se.dirname(u),".gitignore");await hs(x,h)}else{let h=await Ne.promises.readFile(s);await hs(u,h)}}catch(u){console.error(`Error processing file ${s}:`,u)}if(i&&o)try{let s=Se.join(e,".env"),u=`WEBFLOW_SITE_ID=${i}
|
|
116
|
-
WEBFLOW_SITE_API_TOKEN=${o}`;await hs(s,u)}catch(s){console.error("Error creating .env file:",s)}}catch(a){throw console.error("Error applying scaffold:",a),a}},e1=async()=>{try{let e={},t=Se.join(Se.resolve(__dirname),Xb);if(!Ne.existsSync(t))throw new Error(`Scaffolds directory not found at: ${t}`);let r=await Ne.promises.readdir(t);for(let n of r)try{let i=Se.join(t,n);e[n]=await N9(i)}catch(i){console.error(`Error processing scaffold ${n}:`,i)}return e}catch(e){throw console.error("Error getting available scaffolds:",e),e}},N9=async e=>{let t=[];try{if(!Ne.existsSync(e))throw new Error(`Directory not found: ${e}`);let r=await Ne.promises.readdir(e);for(let n of r)try{let i=Se.join(e,n);(await Ne.promises.stat(i)).isDirectory()?t.push(...await N9(i)):t.push(i)}catch(i){console.error(`Error processing path ${n}:`,i)}}catch(r){throw console.error(`Error reading directory ${e}:`,r),r}return t},hs=async(e,t)=>{try{await Ne.promises.mkdir(Se.dirname(e),{recursive:!0}),await Ne.promises.writeFile(e,t)}catch(r){throw console.error(`Error writing file ${e}:`,r),r}};var K9=require("webflow-api");var Fbe=process.env.BUILD_ENV==="development"?"753099c5e55bb37a31730092be0eb82d930c7ac80888c8ed591a2b21470cecdc":process.env.BUILD_ENV==="acceptance"?"1523a726fdc4e2be0fd575642dfe426a778cf0b173b6db7a24c92bae78bcb555":"4e98f8e35a62b288d79dd0973ed7683d0886506ba6413ee1795c2805bb5dff51",xs={clientId:Fbe,serverUrl:qm,authUrl:`${qm}/oauth/authorize`,tokenUrl:`${Ot}/oauth/access_token`,timeoutMs:5*60*1e3,scope:encodeURIComponent("sites:read sites:write authorized_user:read")};var U9=require("crypto"),W9=w(require("open"));var z9=e=>{let t=new Uint8Array(e);return U9.webcrypto.getRandomValues(t),Array.from(t,r=>r.toString(16).padStart(2,"0")).join("")},$9=e=>`${xs.serverUrl}/api/webflow/oauth/initiate?pollId=${e}`,kbe=e=>`${xs.serverUrl}/api/webflow/oauth/poll?pollId=${e}`,V9=async e=>{try{await(0,W9.default)(e),console.log("Browser opened for authentication. Please follow the instructions in your browser.")}catch{console.warn("Could not automatically open browser. Please open this URL manually:",e)}},Obe=async e=>{let t=kbe(e),r=await fetch(t);if(!r.ok){let n=`Failed to poll for authentication status (${r.status})`;try{let i=await r.json();i&&i.error&&(n+=`: ${i.error}`)}catch{}throw new Error(n)}return r.json()},G9=(e,t)=>new Promise((r,n)=>{let i=setTimeout(()=>{clearTimeout(i),clearInterval(o),n(new Error("Authentication timed out. Please try again."))},t),o=setInterval(async()=>{try{let a=await Obe(e);a.status==="success"&&a.accessToken?(clearTimeout(i),clearInterval(o),console.log("Authentication successful! You can close the browser window."),r(a.accessToken)):a.status==="error"&&(clearTimeout(i),clearInterval(o),n(new Error(a.error||"Authentication failed")))}catch(a){clearTimeout(i),clearInterval(o),n(a instanceof Error?a:new Error(String(a)))}},2e3)});async function H9(){let e=z9(16);try{let t=$9(e);return await V9(t),console.log("Waiting for authentication..."),await G9(e,xs.timeoutMs)}catch(t){throw t instanceof Error?t:new Error(String(t))}}async function Y9(e){try{let r=await new K9.WebflowClient({accessToken:e}).sites.list();if(!r||typeof r!="object"||!r.sites||!Array.isArray(r.sites))throw new Error("Invalid response from Webflow API");return r.sites.map(n=>({id:n.id,displayName:n.displayName,shortName:n.shortName||n.displayName.toLowerCase().replace(/\s+/g,"-")}))}catch(t){throw console.error("Error fetching Webflow sites:",t),new Error("Failed to fetch Webflow sites. Please check your authorization.")}}async function J9(e){let{selectedSite:t}=await Ie.prompt([{type:"list",name:"selectedSite",message:"Select the Webflow site you want to connect:",choices:e.map(r=>({name:r.displayName,value:r}))}]);return t}var Ur=w(require("fs")),t1=w(require("path")),sd={angular:{package_identifier:"@angular/ssr",build_command:"ng build",config_template_path:"templates/angular/angular.json.template",wrangler_template_path:"templates/angular/wrangler.angular.json",assets_path:"dist/browser",deployment_type:"ssr",entrypoint_path:"./server.js"},astro:{package_identifier:"@astrojs/cloudflare",build_command:"astro build",config_template_path:"templates/astro/astro.config.mjs.template",wrangler_template_path:"templates/astro/wrangler.astro.json",assets_path:"dist",deployment_type:"ssr",assets_exclude_path:"_worker.js",entrypoint_path:"./index.js"},docusaurus:{package_identifier:"@docusaurus/core",build_command:"docusaurus build",config_template_path:"templates/docusaurus/docusaurus.config.js.template",wrangler_template_path:"templates/docusaurus/wrangler.docusaurus.json",assets_path:"build",deployment_type:"ssg",entrypoint_path:"./no-op-worker.js"},gatsby:{package_identifier:"gatsby",build_command:"gatsby build",wrangler_template_path:"templates/gatsby/wrangler.gatsby.json",assets_path:"public",deployment_type:"ssg",entrypoint_path:"./no-op-worker.js"},nextjs:{package_identifier:"@opennextjs/cloudflare",build_command:"opennextjs-cloudflare build",config_template_path:"templates/nextjs/next.config.ts.template",wrangler_template_path:"templates/nextjs/wrangler.nextjs.json",assets_path:".open-next/assets",entrypoint_path:"./worker.js",deployment_type:"ssr"},nuxt:{package_identifier:"nuxt",build_command:"nuxt build",config_template_path:"templates/nuxt/nuxt.config.ts.template",wrangler_template_path:"templates/nuxt/wrangler.nuxt.json",assets_path:".output/public",entrypoint_path:"./index.js",deployment_type:"ssr"},qwik:{package_identifier:"@builder.io/qwik",build_command:"qwik build",config_template_path:"templates/qwik/vite.config.ts.template",wrangler_template_path:"templates/qwik/wrangler.qwik.json",assets_path:"dist",deployment_type:"ssr",entrypoint_path:"./_worker.js"},react:{package_identifier:"@vitejs/plugin-react",build_command:"tsc -b && vite build",config_template_path:"templates/react/vite.config.ts.template",wrangler_template_path:"templates/react/wrangler.react.json",assets_path:"dist",deployment_type:"spa",entrypoint_path:"./index.js"},remix:{package_identifier:"@remix-run/cloudflare",build_command:"remix vite:build",config_template_path:"templates/remix/vite.config.ts.template",wrangler_template_path:"templates/remix/wrangler.remix.json",assets_path:"build/client",deployment_type:"ssr",entrypoint_path:"./server.js"},solid:{package_identifier:"@solidjs/start",build_command:"vinxi build",config_template_path:"templates/solid/app.config.ts.template",wrangler_template_path:"templates/solid/wrangler.solid.json",assets_path:".output/public",deployment_type:"ssr",entrypoint_path:"./index.js"},svelte:{package_identifier:"@sveltejs/vite-plugin-svelte",build_command:"vite build",config_template_path:"templates/svelte/vite.config.ts.template",wrangler_template_path:"templates/svelte/wrangler.svelte.json",assets_path:".svelte-kit/cloudflare",deployment_type:"ssr",entrypoint_path:"./_worker.js"},vue:{package_identifier:"@vitejs/plugin-vue",build_command:"vue-tsc --build && vite build",config_template_path:"templates/vue/vite.config.ts.template",wrangler_template_path:"templates/vue/wrangler.vue.json",assets_path:"dist",deployment_type:"spa",entrypoint_path:"./index.js"}},ud=["nextjs","astro","remix"];async function Q9(e=process.cwd()){let t=t1.join(e,"package.json"),r=t1.join(e,"webflow.json");if(!Ur.existsSync(t))throw new Error("No package.json file found");let n=null;if(Ur.existsSync(r))try{let o=JSON.parse(Ur.readFileSync(r,"utf8")).cloud?.framework;if(o){if(!sd[o]){let a=Object.keys(sd).join(", ");throw new Error(`Framework '${o}' from webflow.json is not supported. Must be one of: ${a}`)}if(!ud.includes(o))throw new Error(`Framework '${o}' is not currently supported. Must be one of: ${ud.join(", ")}`);n=o,console.log(`Using framework type from webflow.json: ${n}`)}else throw new Error("webflow.json exists but doesn't contain valid framework information under the 'cloud' key")}catch(i){throw i instanceof SyntaxError?new Error("webflow.json contains invalid JSON"):i}if(!n)try{let i=JSON.parse(Ur.readFileSync(t,"utf8"));for(let a of ud){let u=sd[a].package_identifier;if(i.dependencies?.[u]||i.devDependencies?.[u]){n=a;break}}if(!n)throw new Error(`Framework not detected or not supported. Only ${ud.join(", ")} are currently supported.`);console.log(`Detected framework: ${n}`),Ur.writeFileSync(r,JSON.stringify({cloud:{framework:n}},null,2))}catch(i){throw i instanceof SyntaxError?new Error("package.json contains invalid JSON"):i}return{framework:n,config:sd[n]}}var K=w(require("fs")),ae=w(require("path")),Fn=require("child_process");async function X9(e,t={}){let r=t.projectPath||process.cwd(),n=Date.now(),i=ae.join(r,".tmp",`webflow-build-${n}`),o=t.outputDir||ae.join(i,"output"),a=t.mountPath||"/app";return K.mkdirSync(i,{recursive:!0}),console.log("\u{1F4E6} Installing dependencies..."),await Abe(r,e.framework),console.log("\u{1F527} Setting up framework configuration..."),await qbe(r,e,a),console.log(`\u{1F3D7}\uFE0F Building using ${e.config.build_command}...`),await Tbe(r,e.config.build_command),console.log("\u{1F9EA} Creating wrangler dry-run..."),await Pbe(r,o),console.log("\u{1F4C1} Copying assets..."),await jbe(r,o,e,a),console.log("\u{1F4E6} Creating tarball..."),await Bbe(o)}function Z9(e){try{let t=ae.dirname(e);t.includes(".tmp/webflow-build-")&&(console.log("\u{1F9F9} Cleaning up build artifacts..."),K.rmSync(t,{recursive:!0,force:!0}))}catch(t){console.warn("Warning: Failed to clean up build artifacts:",t)}}async function Abe(e,t){let r=["--no-update-notifier","--no-progress"];if(t==="astro"){let i=ae.join(e,"package.json"),o=JSON.parse(K.readFileSync(i,"utf8"));o.dependencies?.["@astrojs/react"]||o.devDependencies?.["@astrojs/react"]||(console.log("Warning: cosmic astro integration requires @astrojs/react and this project doesn't require it. Installing now..."),(0,Fn.execSync)("npm install --save @astrojs/react",{cwd:e,stdio:"inherit"}))}let n=ae.join(e,"package-lock.json");K.existsSync(n)?(console.log("Running npm ci..."),(0,Fn.execSync)(`npm ci ${r.join(" ")}`,{cwd:e,stdio:"inherit"})):(console.log("Warning: No package-lock.json found, installing dependencies with npm install"),(0,Fn.execSync)(`npm install ${r.join(" ")}`,{cwd:e,stdio:"inherit"}))}async function qbe(e,t,r){console.log(`Framework: ${t.framework}`),console.log(`Mount path: ${r}`),console.log(`Deployment type: ${t.config.deployment_type}`)}async function Tbe(e,t){try{(0,Fn.execSync)(`npx ${t}`,{cwd:e,stdio:"inherit"})}catch{throw new Error(`Build command failed: ${t}`)}}async function Pbe(e,t){K.mkdirSync(t,{recursive:!0});try{let r=ae.join(e,"wrangler.json");if(!K.existsSync(r)){console.log("Warning: No wrangler.json found, skipping wrangler dry-run");return}(0,Fn.execSync)(`npx wrangler deploy --dry-run --outdir="${t}"`,{cwd:e,stdio:"inherit"})}catch(r){console.warn("Wrangler dry-run failed, continuing anyway:",r instanceof Error?r.message:r)}}async function jbe(e,t,r,n){let i=r.config.assets_path,o=r.config.assets_exclude_path,a=n.replace(/\/+$/,"").replace(/^\/+/,"");if(r.framework==="nextjs"||r.framework==="astro"){let c=ae.join(e,i);if(K.existsSync(c)&&K.statSync(c).isDirectory()){let h=K.readdirSync(c,{withFileTypes:!0}).find(x=>!(!x.isDirectory()||o&&x.name===o||r.framework==="astro"&&(x.name==="_routes.json"||x.name==="_worker.js")));h&&(i=`${i}/${h.name}`)}}let s=ae.join(t,"assets",a||"");K.mkdirSync(s,{recursive:!0});let u=ae.join(e,i);if(K.existsSync(u)&&K.statSync(u).isDirectory()){console.log(`Copying assets from ${i} to output/assets...`);try{o?(console.log(`Excluding ${o}`),tq(u,s,o)):eq(u,s)}catch(c){console.error("Failed to copy assets:",c)}}else console.log("No assets to copy or assets directory not found");let l=ae.join(e,"webflow.json");K.existsSync(l)&&K.copyFileSync(l,ae.join(t,"webflow.json"))}async function Bbe(e){let t=`${e}.tar.gz`;try{return(0,Fn.execSync)(`tar -czf "${t}" -C "${ae.dirname(e)}" "${ae.basename(e)}"`,{stdio:"inherit"}),console.log(`Tarball created: ${t}`),t}catch{throw new Error("Failed to create tarball")}}function eq(e,t){K.mkdirSync(t,{recursive:!0});let r=K.readdirSync(e,{withFileTypes:!0});for(let n of r){let i=ae.join(e,n.name),o=ae.join(t,n.name);n.isDirectory()?eq(i,o):K.copyFileSync(i,o)}}function tq(e,t,r){K.mkdirSync(t,{recursive:!0});let n=K.readdirSync(e,{withFileTypes:!0});for(let i of n){if(i.name===r)continue;let o=ae.join(e,i.name),a=ae.join(t,i.name);i.isDirectory()?tq(o,a,r):K.copyFileSync(o,a)}}var Mbe="DUPLICATE_ENVIRONMENT_MOUNT",Ibe="ENVIRONMENT_MOUNT_MISMATCH",Rbe="DUPLICATE_ENVIRONMENT_BRANCH",Lbe="INVALID_MOUNT_PATH_FORMAT",Nbe="INVALID_PROJECT_ID",rq={[Mbe]:"An environment with this mount path already exists for this site. Please choose a different mount path.",[Ibe]:"This environment already exists with a different mount path. Please create a new environment or use the existing environment's mount path.",[Rbe]:"An environment with this branch already exists for this project.",[Lbe]:"Mount path format is invalid. It must start with a / and be followed by at least one character (e.g., /app).",[Nbe]:"Invalid project ID. This project may have been deleted or belongs to a different site. Please remove the 'project_id' from your webflow.json file and redeploy to create a new project."};function nq(e){let t=e?.msg||"";for(let r in rq)if(t.includes(r))return rq[r];return"An unknown error occurred"}var So=w(require("fs")),iq=104857600;function oq(e){if(e===0)return"0 B";let t=1024,r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/Math.pow(t,n)).toFixed(1))} ${r[n]}`}async function r1(e,t){let r=process.env.WEBFLOW_SITE_ID,n=process.env.WEBFLOW_SITE_API_TOKEN;(!r||!n)&&(console.error("Error: Missing required environment variables:"),console.error("- WEBFLOW_SITE_ID"),console.error("- WEBFLOW_SITE_API_TOKEN"),console.error(`
|
|
116
|
+
WEBFLOW_SITE_API_TOKEN=${o}`;await hs(s,u)}catch(s){console.error("Error creating .env file:",s)}}catch(a){throw console.error("Error applying scaffold:",a),a}},e1=async()=>{try{let e={},t=Se.join(Se.resolve(__dirname),Xb);if(!Ne.existsSync(t))throw new Error(`Scaffolds directory not found at: ${t}`);let r=await Ne.promises.readdir(t);for(let n of r)try{let i=Se.join(t,n);e[n]=await N9(i)}catch(i){console.error(`Error processing scaffold ${n}:`,i)}return e}catch(e){throw console.error("Error getting available scaffolds:",e),e}},N9=async e=>{let t=[];try{if(!Ne.existsSync(e))throw new Error(`Directory not found: ${e}`);let r=await Ne.promises.readdir(e);for(let n of r)try{let i=Se.join(e,n);(await Ne.promises.stat(i)).isDirectory()?t.push(...await N9(i)):t.push(i)}catch(i){console.error(`Error processing path ${n}:`,i)}}catch(r){throw console.error(`Error reading directory ${e}:`,r),r}return t},hs=async(e,t)=>{try{await Ne.promises.mkdir(Se.dirname(e),{recursive:!0}),await Ne.promises.writeFile(e,t)}catch(r){throw console.error(`Error writing file ${e}:`,r),r}};var K9=require("webflow-api");var Fbe=process.env.BUILD_ENV==="development"?"753099c5e55bb37a31730092be0eb82d930c7ac80888c8ed591a2b21470cecdc":process.env.BUILD_ENV==="acceptance"?"1523a726fdc4e2be0fd575642dfe426a778cf0b173b6db7a24c92bae78bcb555":"4e98f8e35a62b288d79dd0973ed7683d0886506ba6413ee1795c2805bb5dff51",xs={clientId:Fbe,serverUrl:qm,authUrl:`${qm}/oauth/authorize`,tokenUrl:`${Ot}/oauth/access_token`,timeoutMs:5*60*1e3,scope:encodeURIComponent("sites:read sites:write authorized_user:read")};var U9=require("crypto"),W9=w(require("open"));var z9=e=>{let t=new Uint8Array(e);return U9.webcrypto.getRandomValues(t),Array.from(t,r=>r.toString(16).padStart(2,"0")).join("")},$9=e=>`${xs.serverUrl}/oauth/webflow/initiate?pollId=${e}`,kbe=e=>`${xs.serverUrl}/oauth/webflow/poll?pollId=${e}`,V9=async e=>{try{await(0,W9.default)(e),console.log("Browser opened for authentication. Please follow the instructions in your browser.")}catch{console.warn("Could not automatically open browser. Please open this URL manually:",e)}},Obe=async e=>{let t=kbe(e),r=await fetch(t);if(!r.ok){let n=`Failed to poll for authentication status (${r.status})`;try{let i=await r.json();i&&i.error&&(n+=`: ${i.error}`)}catch{}throw new Error(n)}return r.json()},G9=(e,t)=>new Promise((r,n)=>{let i=setTimeout(()=>{clearTimeout(i),clearInterval(o),n(new Error("Authentication timed out. Please try again."))},t),o=setInterval(async()=>{try{let a=await Obe(e);a.status==="success"&&a.accessToken?(clearTimeout(i),clearInterval(o),console.log("Authentication successful! You can close the browser window."),r(a.accessToken)):a.status==="error"&&(clearTimeout(i),clearInterval(o),n(new Error(a.error||"Authentication failed")))}catch(a){clearTimeout(i),clearInterval(o),n(a instanceof Error?a:new Error(String(a)))}},2e3)});async function H9(){let e=z9(16);try{let t=$9(e);return await V9(t),console.log("Waiting for authentication..."),await G9(e,xs.timeoutMs)}catch(t){throw t instanceof Error?t:new Error(String(t))}}async function Y9(e){try{let r=await new K9.WebflowClient({accessToken:e}).sites.list();if(!r||typeof r!="object"||!r.sites||!Array.isArray(r.sites))throw new Error("Invalid response from Webflow API");return r.sites.map(n=>({id:n.id,displayName:n.displayName,shortName:n.shortName||n.displayName.toLowerCase().replace(/\s+/g,"-")}))}catch(t){throw console.error("Error fetching Webflow sites:",t),new Error("Failed to fetch Webflow sites. Please check your authorization.")}}async function J9(e){let{selectedSite:t}=await Ie.prompt([{type:"list",name:"selectedSite",message:"Select the Webflow site you want to connect:",choices:e.map(r=>({name:r.displayName,value:r}))}]);return t}var Ur=w(require("fs")),t1=w(require("path")),sd={angular:{package_identifier:"@angular/ssr",build_command:"ng build",config_template_path:"templates/angular/angular.json.template",wrangler_template_path:"templates/angular/wrangler.angular.json",assets_path:"dist/browser",deployment_type:"ssr",entrypoint_path:"./server.js"},astro:{package_identifier:"@astrojs/cloudflare",build_command:"astro build",config_template_path:"templates/astro/astro.config.mjs.template",wrangler_template_path:"templates/astro/wrangler.astro.json",assets_path:"dist",deployment_type:"ssr",assets_exclude_path:"_worker.js",entrypoint_path:"./index.js"},docusaurus:{package_identifier:"@docusaurus/core",build_command:"docusaurus build",config_template_path:"templates/docusaurus/docusaurus.config.js.template",wrangler_template_path:"templates/docusaurus/wrangler.docusaurus.json",assets_path:"build",deployment_type:"ssg",entrypoint_path:"./no-op-worker.js"},gatsby:{package_identifier:"gatsby",build_command:"gatsby build",wrangler_template_path:"templates/gatsby/wrangler.gatsby.json",assets_path:"public",deployment_type:"ssg",entrypoint_path:"./no-op-worker.js"},nextjs:{package_identifier:"@opennextjs/cloudflare",build_command:"opennextjs-cloudflare build",config_template_path:"templates/nextjs/next.config.ts.template",wrangler_template_path:"templates/nextjs/wrangler.nextjs.json",assets_path:".open-next/assets",entrypoint_path:"./worker.js",deployment_type:"ssr"},nuxt:{package_identifier:"nuxt",build_command:"nuxt build",config_template_path:"templates/nuxt/nuxt.config.ts.template",wrangler_template_path:"templates/nuxt/wrangler.nuxt.json",assets_path:".output/public",entrypoint_path:"./index.js",deployment_type:"ssr"},qwik:{package_identifier:"@builder.io/qwik",build_command:"qwik build",config_template_path:"templates/qwik/vite.config.ts.template",wrangler_template_path:"templates/qwik/wrangler.qwik.json",assets_path:"dist",deployment_type:"ssr",entrypoint_path:"./_worker.js"},react:{package_identifier:"@vitejs/plugin-react",build_command:"tsc -b && vite build",config_template_path:"templates/react/vite.config.ts.template",wrangler_template_path:"templates/react/wrangler.react.json",assets_path:"dist",deployment_type:"spa",entrypoint_path:"./index.js"},remix:{package_identifier:"@remix-run/cloudflare",build_command:"remix vite:build",config_template_path:"templates/remix/vite.config.ts.template",wrangler_template_path:"templates/remix/wrangler.remix.json",assets_path:"build/client",deployment_type:"ssr",entrypoint_path:"./server.js"},solid:{package_identifier:"@solidjs/start",build_command:"vinxi build",config_template_path:"templates/solid/app.config.ts.template",wrangler_template_path:"templates/solid/wrangler.solid.json",assets_path:".output/public",deployment_type:"ssr",entrypoint_path:"./index.js"},svelte:{package_identifier:"@sveltejs/vite-plugin-svelte",build_command:"vite build",config_template_path:"templates/svelte/vite.config.ts.template",wrangler_template_path:"templates/svelte/wrangler.svelte.json",assets_path:".svelte-kit/cloudflare",deployment_type:"ssr",entrypoint_path:"./_worker.js"},vue:{package_identifier:"@vitejs/plugin-vue",build_command:"vue-tsc --build && vite build",config_template_path:"templates/vue/vite.config.ts.template",wrangler_template_path:"templates/vue/wrangler.vue.json",assets_path:"dist",deployment_type:"spa",entrypoint_path:"./index.js"}},ud=["nextjs","astro","remix"];async function Q9(e=process.cwd()){let t=t1.join(e,"package.json"),r=t1.join(e,"webflow.json");if(!Ur.existsSync(t))throw new Error("No package.json file found");let n=null;if(Ur.existsSync(r))try{let o=JSON.parse(Ur.readFileSync(r,"utf8")).cloud?.framework;if(o){if(!sd[o]){let a=Object.keys(sd).join(", ");throw new Error(`Framework '${o}' from webflow.json is not supported. Must be one of: ${a}`)}if(!ud.includes(o))throw new Error(`Framework '${o}' is not currently supported. Must be one of: ${ud.join(", ")}`);n=o,console.log(`Using framework type from webflow.json: ${n}`)}else throw new Error("webflow.json exists but doesn't contain valid framework information under the 'cloud' key")}catch(i){throw i instanceof SyntaxError?new Error("webflow.json contains invalid JSON"):i}if(!n)try{let i=JSON.parse(Ur.readFileSync(t,"utf8"));for(let a of ud){let u=sd[a].package_identifier;if(i.dependencies?.[u]||i.devDependencies?.[u]){n=a;break}}if(!n)throw new Error(`Framework not detected or not supported. Only ${ud.join(", ")} are currently supported.`);console.log(`Detected framework: ${n}`),Ur.writeFileSync(r,JSON.stringify({cloud:{framework:n}},null,2))}catch(i){throw i instanceof SyntaxError?new Error("package.json contains invalid JSON"):i}return{framework:n,config:sd[n]}}var K=w(require("fs")),ae=w(require("path")),Fn=require("child_process");async function X9(e,t={}){let r=t.projectPath||process.cwd(),n=Date.now(),i=ae.join(r,".tmp",`webflow-build-${n}`),o=t.outputDir||ae.join(i,"output"),a=t.mountPath||"/app";return K.mkdirSync(i,{recursive:!0}),console.log("\u{1F4E6} Installing dependencies..."),await Abe(r,e.framework),console.log("\u{1F527} Setting up framework configuration..."),await qbe(r,e,a),console.log(`\u{1F3D7}\uFE0F Building using ${e.config.build_command}...`),await Tbe(r,e.config.build_command),console.log("\u{1F9EA} Creating wrangler dry-run..."),await Pbe(r,o),console.log("\u{1F4C1} Copying assets..."),await jbe(r,o,e,a),console.log("\u{1F4E6} Creating tarball..."),await Bbe(o)}function Z9(e){try{let t=ae.dirname(e);t.includes(".tmp/webflow-build-")&&(console.log("\u{1F9F9} Cleaning up build artifacts..."),K.rmSync(t,{recursive:!0,force:!0}))}catch(t){console.warn("Warning: Failed to clean up build artifacts:",t)}}async function Abe(e,t){let r=["--no-update-notifier","--no-progress"];if(t==="astro"){let i=ae.join(e,"package.json"),o=JSON.parse(K.readFileSync(i,"utf8"));o.dependencies?.["@astrojs/react"]||o.devDependencies?.["@astrojs/react"]||(console.log("Warning: cosmic astro integration requires @astrojs/react and this project doesn't require it. Installing now..."),(0,Fn.execSync)("npm install --save @astrojs/react",{cwd:e,stdio:"inherit"}))}let n=ae.join(e,"package-lock.json");K.existsSync(n)?(console.log("Running npm ci..."),(0,Fn.execSync)(`npm ci ${r.join(" ")}`,{cwd:e,stdio:"inherit"})):(console.log("Warning: No package-lock.json found, installing dependencies with npm install"),(0,Fn.execSync)(`npm install ${r.join(" ")}`,{cwd:e,stdio:"inherit"}))}async function qbe(e,t,r){console.log(`Framework: ${t.framework}`),console.log(`Mount path: ${r}`),console.log(`Deployment type: ${t.config.deployment_type}`)}async function Tbe(e,t){try{(0,Fn.execSync)(`npx ${t}`,{cwd:e,stdio:"inherit"})}catch{throw new Error(`Build command failed: ${t}`)}}async function Pbe(e,t){K.mkdirSync(t,{recursive:!0});try{let r=ae.join(e,"wrangler.json");if(!K.existsSync(r)){console.log("Warning: No wrangler.json found, skipping wrangler dry-run");return}(0,Fn.execSync)(`npx wrangler deploy --dry-run --outdir="${t}"`,{cwd:e,stdio:"inherit"})}catch(r){console.warn("Wrangler dry-run failed, continuing anyway:",r instanceof Error?r.message:r)}}async function jbe(e,t,r,n){let i=r.config.assets_path,o=r.config.assets_exclude_path,a=n.replace(/\/+$/,"").replace(/^\/+/,"");if(r.framework==="nextjs"||r.framework==="astro"){let c=ae.join(e,i);if(K.existsSync(c)&&K.statSync(c).isDirectory()){let h=K.readdirSync(c,{withFileTypes:!0}).find(x=>!(!x.isDirectory()||o&&x.name===o||r.framework==="astro"&&(x.name==="_routes.json"||x.name==="_worker.js")));h&&(i=`${i}/${h.name}`)}}let s=ae.join(t,"assets",a||"");K.mkdirSync(s,{recursive:!0});let u=ae.join(e,i);if(K.existsSync(u)&&K.statSync(u).isDirectory()){console.log(`Copying assets from ${i} to output/assets...`);try{o?(console.log(`Excluding ${o}`),tq(u,s,o)):eq(u,s)}catch(c){console.error("Failed to copy assets:",c)}}else console.log("No assets to copy or assets directory not found");let l=ae.join(e,"webflow.json");K.existsSync(l)&&K.copyFileSync(l,ae.join(t,"webflow.json"))}async function Bbe(e){let t=`${e}.tar.gz`;try{return(0,Fn.execSync)(`tar -czf "${t}" -C "${ae.dirname(e)}" "${ae.basename(e)}"`,{stdio:"inherit"}),console.log(`Tarball created: ${t}`),t}catch{throw new Error("Failed to create tarball")}}function eq(e,t){K.mkdirSync(t,{recursive:!0});let r=K.readdirSync(e,{withFileTypes:!0});for(let n of r){let i=ae.join(e,n.name),o=ae.join(t,n.name);n.isDirectory()?eq(i,o):K.copyFileSync(i,o)}}function tq(e,t,r){K.mkdirSync(t,{recursive:!0});let n=K.readdirSync(e,{withFileTypes:!0});for(let i of n){if(i.name===r)continue;let o=ae.join(e,i.name),a=ae.join(t,i.name);i.isDirectory()?tq(o,a,r):K.copyFileSync(o,a)}}var Mbe="DUPLICATE_ENVIRONMENT_MOUNT",Ibe="ENVIRONMENT_MOUNT_MISMATCH",Rbe="DUPLICATE_ENVIRONMENT_BRANCH",Lbe="INVALID_MOUNT_PATH_FORMAT",Nbe="INVALID_PROJECT_ID",rq={[Mbe]:"An environment with this mount path already exists for this site. Please choose a different mount path.",[Ibe]:"This environment already exists with a different mount path. Please create a new environment or use the existing environment's mount path.",[Rbe]:"An environment with this branch already exists for this project.",[Lbe]:"Mount path format is invalid. It must start with a / and be followed by at least one character (e.g., /app).",[Nbe]:"Invalid project ID. This project may have been deleted or belongs to a different site. Please remove the 'project_id' from your webflow.json file and redeploy to create a new project."};function nq(e){let t=e?.msg||"";for(let r in rq)if(t.includes(r))return rq[r];return"An unknown error occurred"}var So=w(require("fs")),iq=104857600;function oq(e){if(e===0)return"0 B";let t=1024,r=["B","KB","MB","GB"],n=Math.floor(Math.log(e)/Math.log(t));return`${parseFloat((e/Math.pow(t,n)).toFixed(1))} ${r[n]}`}async function r1(e,t){let r=process.env.WEBFLOW_SITE_ID,n=process.env.WEBFLOW_SITE_API_TOKEN;(!r||!n)&&(console.error("Error: Missing required environment variables:"),console.error("- WEBFLOW_SITE_ID"),console.error("- WEBFLOW_SITE_API_TOKEN"),console.error(`
|
|
117
117
|
Please set these environment variables and try again.`),process.exit(1));let i=await fetch(`${Ot}${e}`,{method:t.method,headers:{Authorization:`Bearer ${n}`,"Content-Type":"application/json"},body:t.body?JSON.stringify(t.body):void 0});if(!i.ok){let o=await i.text(),a;try{a=JSON.parse(o)}catch{a={msg:o}}let s=nq(a);throw new Error(s)}return i.json()}async function aq(e,t){let{manifest:r}=Re(),n=r.cloud||{},i=n.project_id,o=n.framework;o||(console.error("Error: No framework specified in webflow.json"),console.error("Please ensure your webflow.json has a cloud.framework property"),process.exit(1));let a=process.env.WEBFLOW_SITE_ID,s=process.env.WEBFLOW_SITE_API_TOKEN;(!a||!s)&&(console.error("Error: Missing required environment variables:"),console.error("- WEBFLOW_SITE_ID"),console.error("- WEBFLOW_SITE_API_TOKEN"),console.error(`
|
|
118
118
|
Please set these environment variables and try again.`),process.exit(1));let u=await Ube({siteId:a,apiToken:s,framework:o,mountPath:t,environment:e,projectId:i});return!i&&u.project_id&&(console.log("\u{1F4DD} Updating webflow.json with project ID..."),Ht({cloud:{...n,project_id:u.project_id}})),u}async function Ube(e){let{siteId:t,framework:r,mountPath:n,environment:i,projectId:o}=e,a={framework:r,mount_path:n,environment:i};return o&&(a.project_id=o),r1(`/cosmic/${t}/cli-deploy-init`,{method:"POST",body:a})}async function sq(e){let t=process.env.WEBFLOW_SITE_ID;return t||(console.error("Error: Missing required environment variable WEBFLOW_SITE_ID"),process.exit(1)),r1(`/cosmic/${t}/cli-project-environments/${e}`,{method:"GET"})}async function uq(){let e=process.env.WEBFLOW_SITE_ID;return e||(console.error("Error: Missing required environment variable WEBFLOW_SITE_ID"),process.exit(1)),r1(`/cosmic/${e}/cli-projects`,{method:"GET"})}async function lq(e,t){if(!So.existsSync(e))throw new Error(`Tarball not found at ${e}`);let r=So.statSync(e);if(r.size>iq)throw new Error(`Build output is too large (${oq(r.size)}). Maximum allowed size is ${oq(iq)}.`);let n=So.readFileSync(e),i=JSON.parse(t);if(!i.fields)throw new Error("Upload URL is missing fields property");let o=new FormData;Object.entries(i.fields).forEach(([u,l])=>{o.append(u,l)});let a=new Blob([n],{type:"application/gzip"});o.append("file",a,"output.tar.gz");let s=await fetch(i.url,{method:"POST",body:o});if(!s.ok){let u=await s.text();throw console.error(`\u274C Upload failed with response: ${u}`),new Error(`Failed to upload tarball: ${s.status} ${s.statusText}`)}}async function cq(e){if(!e||e==="undefined")throw new Error("Completion URL is undefined or invalid");let t=await fetch(e,{method:"GET"});if(!t.ok)throw new Error(`Failed to trigger deployment: ${t.status} ${t.statusText}`)}var ld=async()=>{try{let e=await e1();return Object.keys(e)}catch(e){return console.error("Failed to get available scaffolds:",e),[]}},n1=async(e,t,r=ad)=>{let n=`./${e}`,i=await e1();try{let o=await H9(),a=await Y9(o);a.length===0&&(console.error("Error: No Webflow sites found in your account."),console.error("Please make sure you have at least one site in your Webflow account."),process.exit(1));let s=await J9(a);await Zb(e,t,r,i,s.id,o),process.chdir(n),console.log("Running devlink sync to fetch your Webflow components..."),await Wbe({site:s.id,apiToken:o}),fq(e)}catch(o){console.error("Error during Webflow authentication:"),console.error(o),await Zb(e,t,r,i),process.chdir(n),console.error("Project scaffold was created, but authentication failed."),console.log("You can manually set up the Webflow credentials in .env file later."),fq(e),process.exit(1)}},Wbe=async e=>{try{await ed(void 0,e),console.log("Webflow components synced successfully!")}catch(t){console.error("Failed to run devlink sync:",t),console.log("You can manually run 'npx webflow devlink sync' later to sync your components.")}},dq=async(e,t)=>{let r=null,n=null;try{console.log("\u{1F527} Detecting framework...");let i=await Q9();console.log(`Framework: ${i.framework}`),console.log(`Build command: ${i.config.build_command}`),console.log(`
|
|
119
119
|
\u{1F3D7}\uFE0F Building project...`),n=await X9(i,{mountPath:t}),console.log(`Starting deployment process for environment: ${e} at mount path: ${t}`),r=await aq(e,t),console.log("\u{1F4E4} Uploading build artifacts..."),await lq(n,r.upload_url)}catch(i){console.error("Error during deployment initialization:"),console.error(i instanceof Error?i.message:i)}finally{if(n&&Z9(n),r)try{await cq(r.completion_url),console.log(`
|
|
@@ -122,7 +122,7 @@ Please set these environment variables and try again.`),process.exit(1));let u=a
|
|
|
122
122
|
Get started with the following commands:`),console.log(` cd ${e}`),console.log(" npm install / yarn install / pnpm install"),console.log(` npm run dev
|
|
123
123
|
|
|
124
124
|
`),console.log("Run the following command to sync Webflow components when they update:"),console.log(` webflow devlink sync
|
|
125
|
-
`),console.log("--- ")};var pq=e=>{let t=e.command("cloud").description("Create and manage Webflow Cloud projects");t.command("create").description("Create a new Webflow Cloud project").argument("<name>","Project name").option("-f, --framework <framework>","Framework to use","next").action(async(r,n)=>{let{framework:i}=n;if(!(await ld()).find(s=>s===i)){console.error(`Framework ${i} not found`);return}await n1(r,i,i)}),t.command("list").description("Get list of project templates that can be used for `init`").action(async()=>{let r=await ld();console.log("Available project templates:"),r.length>0?r.forEach(n=>console.log(`- ${n}`)):console.log("No templates found.")}),t.command("init").description("Bootstrap a new Webflow Cloud project").action(async()=>{let r=await ld(),n=await Ie.prompt([{type:"input",name:"projectName",message:"What would you like to name your project?",validate:i=>i.trim()===""?"Project name cannot be empty":!0},{type:"list",name:"scaffoldName",message:"Which framework would you like to use?",choices:r,default:"nextjs"},{type:"input",name:"mountPath",message:"What path should your primary environment be mounted at? (e.g., /app)",default:"/app",validate:i=>i.match(/^\/[^/].+$/)?!0:'Mount path must be "/" followed by one or more characters'}]);await n1(n.projectName,n.mountPath,n.scaffoldName)}),t.command("deploy").description("Deploy your Webflow Cloud project").option("-e, --environment <environment>","Environment name").option("-m, --mount <mount>","Mount path (e.g., /app)").action(async r=>{try{let{manifest:n}=Re(),o=(n.cloud||{}).project_id,a,s;if(r.environment&&r.mount)a=r.environment,s=r.mount,s.match(/^\/[^/].+$/)||(console.error('Error: Mount path must be "/" followed by one or more characters'),process.exit(1));else{let u=[];if(!o)try{let c=await uq();if(c.projects.length>0){let{selectedProject:d}=await Ie.prompt([{type:"list",name:"selectedProject",message:"Select a project to deploy to:",choices:[...c.projects.map(h=>({name:`${h.name} (${h.description||"No description"})`,value:h.id})),{name:"Create new project",value:null}]}]);d?(o=d,console.log("\u{1F4DD} Updating webflow.json with project ID..."),Ht({cloud:{project_id:d}})):console.log("Creating a new project will be handled during deployment.")}else console.log("No existing projects found. A new project will be created during deployment.")}catch(c){console.warn("Could not fetch existing projects. A new project will be created during deployment."),console.warn(c instanceof Error?c.message:c)}if(o)try{let d=(await sq(o)).environments.map(h=>({name:`${h.branch} (${h.mount})`,value:{branch:h.branch,mount:h.mount}}));u.push(...d)}catch(c){console.error("Error fetching project environments:"),console.error(c instanceof Error?c.message:c),process.exit(1)}u.push({name:"Create new environment",value:null});let{selectedEnvironment:l}=await Ie.prompt([{type:"list",name:"selectedEnvironment",message:"Select an environment to deploy to:",choices:u}]);if(l)a=l.branch,s=l.mount;else{let c=[];r.environment||c.push({type:"input",name:"environment",message:"What environment would you like to deploy to?",default:"main",validate:h=>h.trim()===""?"Environment cannot be empty":!0}),r.mount||c.push({type:"input",name:"mountPath",message:"What path should this environment be mounted at? (e.g., /app)",default:"/app",validate:h=>h.match(/^\/[^/].+$/)?!0:'Mount path must be "/" followed by one or more characters'});let d=await Ie.prompt(c);a=r.environment||d.environment,s=r.mount||d.mountPath}}await dq(a,s)}catch(n){console.error("Error during deployment setup:"),console.error(n instanceof Error?n.message:n),process.exit(1)}})};var hq={name:"@webflow/webflow-cli",version:"1.8.
|
|
125
|
+
`),console.log("--- ")};var pq=e=>{let t=e.command("cloud").description("Create and manage Webflow Cloud projects");t.command("create").description("Create a new Webflow Cloud project").argument("<name>","Project name").option("-f, --framework <framework>","Framework to use","next").action(async(r,n)=>{let{framework:i}=n;if(!(await ld()).find(s=>s===i)){console.error(`Framework ${i} not found`);return}await n1(r,i,i)}),t.command("list").description("Get list of project templates that can be used for `init`").action(async()=>{let r=await ld();console.log("Available project templates:"),r.length>0?r.forEach(n=>console.log(`- ${n}`)):console.log("No templates found.")}),t.command("init").description("Bootstrap a new Webflow Cloud project").action(async()=>{let r=await ld(),n=await Ie.prompt([{type:"input",name:"projectName",message:"What would you like to name your project?",validate:i=>i.trim()===""?"Project name cannot be empty":!0},{type:"list",name:"scaffoldName",message:"Which framework would you like to use?",choices:r,default:"nextjs"},{type:"input",name:"mountPath",message:"What path should your primary environment be mounted at? (e.g., /app)",default:"/app",validate:i=>i.match(/^\/[^/].+$/)?!0:'Mount path must be "/" followed by one or more characters'}]);await n1(n.projectName,n.mountPath,n.scaffoldName)}),t.command("deploy").description("Deploy your Webflow Cloud project").option("-e, --environment <environment>","Environment name").option("-m, --mount <mount>","Mount path (e.g., /app)").action(async r=>{try{let{manifest:n}=Re(),o=(n.cloud||{}).project_id,a,s;if(r.environment&&r.mount)a=r.environment,s=r.mount,s.match(/^\/[^/].+$/)||(console.error('Error: Mount path must be "/" followed by one or more characters'),process.exit(1));else{let u=[];if(!o)try{let c=await uq();if(c.projects.length>0){let{selectedProject:d}=await Ie.prompt([{type:"list",name:"selectedProject",message:"Select a project to deploy to:",choices:[...c.projects.map(h=>({name:`${h.name} (${h.description||"No description"})`,value:h.id})),{name:"Create new project",value:null}]}]);d?(o=d,console.log("\u{1F4DD} Updating webflow.json with project ID..."),Ht({cloud:{project_id:d}})):console.log("Creating a new project will be handled during deployment.")}else console.log("No existing projects found. A new project will be created during deployment.")}catch(c){console.warn("Could not fetch existing projects. A new project will be created during deployment."),console.warn(c instanceof Error?c.message:c)}if(o)try{let d=(await sq(o)).environments.map(h=>({name:`${h.branch} (${h.mount})`,value:{branch:h.branch,mount:h.mount}}));u.push(...d)}catch(c){console.error("Error fetching project environments:"),console.error(c instanceof Error?c.message:c),process.exit(1)}u.push({name:"Create new environment",value:null});let{selectedEnvironment:l}=await Ie.prompt([{type:"list",name:"selectedEnvironment",message:"Select an environment to deploy to:",choices:u}]);if(l)a=l.branch,s=l.mount;else{let c=[];r.environment||c.push({type:"input",name:"environment",message:"What environment would you like to deploy to?",default:"main",validate:h=>h.trim()===""?"Environment cannot be empty":!0}),r.mount||c.push({type:"input",name:"mountPath",message:"What path should this environment be mounted at? (e.g., /app)",default:"/app",validate:h=>h.match(/^\/[^/].+$/)?!0:'Mount path must be "/" followed by one or more characters'});let d=await Ie.prompt(c);a=r.environment||d.environment,s=r.mount||d.mountPath}}await dq(a,s)}catch(n){console.error("Error during deployment setup:"),console.error(n instanceof Error?n.message:n),process.exit(1)}})};var hq={name:"@webflow/webflow-cli",version:"1.8.6",license:"MIT",bin:{webflow:"./dist/index.js"},scripts:{build:"rm -fr ./dist; tsup",dev:"tsup",lint:"eslint .",test:"jest tests --ci","test:local":"jest tests"},files:["CHANGELOG.md","dist/**/*"],publishConfig:{access:"public"},dependencies:{"@babel/preset-env":"^7.26.9","@babel/preset-react":"^7.26.3","@babel/preset-typescript":"^7.27.0","@dotenvx/dotenvx":"^1.44.1","@module-federation/enhanced":"^0.13.1","@webflow/data-types":"*",ajv:"^8.17.1",archiver:"^5.3.1","babel-loader":"^10.0.0",commander:"^10.0.0",cosmiconfig:"^8.2.0","css-loader":"^7.1.2","css-tree":"^2.3.1",dotenv:"^16.0.3","fast-glob":"^3.3.3","form-data":"4.0.0",inquirer:"^9.1.4",md5:"^2.2.1",memfs:"^4.17.0","mime-types":"^2.1.35","mini-css-extract-plugin":"^2.9.2","node-fetch":"^2.6.7",open:"^8.4.2",prettier:"^2.7.1","serve-handler":"^6.1.5",unionfs:"^4.5.4","webflow-api":"^3.1.1",webpack:"^5.99.7","webpack-merge":"^6.0.1"},devDependencies:{"@types/archiver":"^5.3.2","@types/css-tree":"^2.3.1","@types/express":"^4.17.13","@types/inquirer":"^9.0.8","@types/jest":"^29.2.3","@types/md5":"^2.3.2","@types/mime-types":"^2.1.4","@types/nock":"^8.0.33","@types/node":"^18.16.0","@types/node-fetch":"^2.6.3","@types/prettier":"^2.7.1","@types/serve-handler":"^6.1.1","eslint-config-custom":"*",express:"^4.18.1",jest:"^29.3.1",nock:"13.3.1",tar:"^7.4.3","ts-jest":"^29.0.3","ts-node":"^10.9.1",tsconfig:"*",tsup:"^8.4.0",typescript:"^4.9.3"},engines:{node:">=18.16.0"}};var Fo=new xq.Command,$be=hq.version,Vbe=new bs("@webflow/webflow-cli");Fo.name("webflow").description("Webflow CLI").version($be,"--version","output the current version").hook("postAction",()=>{let e=Vbe.checkForUpdates();e&&I.warn(e)});fk(Fo);XA(Fo);pq(Fo);process.env.BUILD_ENV==="development"&&j9(Fo);Fo.parse();
|
|
126
126
|
/*! Bundled license information:
|
|
127
127
|
|
|
128
128
|
safe-buffer/index.js:
|