@lightspeed/crane 1.0.1 → 1.0.2

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/app.mjs CHANGED
@@ -1 +1 @@
1
- import{getCurrentInstance as k,ref as b,computed as o,reactive as d,createSSRApp as x}from"vue";import{renderToString as C}from"vue/server-renderer";const w=new Map;function c(){const t=(r,a,i,u,g)=>{w.set(r._uid,{context:b(a),content:b(i),design:b(u),defaults:b(g)})},n=(r,a,i)=>{const u=w.get(r._uid);u!==void 0&&(u.content.value=a,u.design.value=i)},e=k()?.appContext.app._uid??-1,l=w.get(e);return{init:t,update:n,context:l?.context,content:l?.content,design:l?.design,defaults:l?.defaults}}function h(t){const n=c(),e=o(()=>{const a=n.content.value[t];if(a!==void 0){if(typeof a=="string")return a;throw new Error(`Element ${t} is not inputbox`)}}),l=o(()=>e.value!==void 0),r=o(()=>e.value);return d({hasContent:l,value:r})}function I(t){const n=c(),e=o(()=>{const a=n.content.value[t];if(a!==void 0){if(typeof a=="string")return a;throw new Error(`Element ${t} is not textarea`)}}),l=o(()=>e.value!==void 0),r=o(()=>e.value);return d({hasContent:l,value:r})}function _(t){return"title"in t&&"type"in t}function T(t){const n=c(),e=o(()=>{const u=n.content.value[t];if(u!==void 0){if(_(u))return u;throw new Error(`Element ${t} is not action link`)}}),l=o(()=>e.value?.title),r=o(()=>e.value?.link),a=o(()=>!!l.value),i=o(()=>!!r.value);return d({title:l,link:r,hasTitle:a,hasLink:i,performAction:()=>{if(e.value!==void 0)switch(e.value.buttonType){case"HYPER_LINK":e.value.link&&window.open(e.value.link,"_blank");break;case"GO_TO_STORE_LINK":window.open("/products");break;case"MAIL_LINK":e.value.email&&window.open(`mailto:${e.value.email}`,"_self");break;case"TEL_LINK":e.value.phone&&window.open(`tel:${e.value.phone}`,"_self");break;case"SCROLL_TO_TILE":{if(typeof document>"u")return;const u=e.value.tileId;document.getElementById(`tile-${u}`)?.scrollIntoView();break}default:throw new Error("Unknown ButtonType: ")}}})}function z(t){return"bucket"in t&&"borderInfo"in t&&"set"in t}function m(t,n){const e=new RegExp(/^https?:\/\//);return t!=null&&e.test(t)?t:`${n}/${t}`}function D(t){const n=c(),e=o(()=>{const s=n.content.value[t];if(s!==void 0){if(z(s))return s;throw new Error(`Element ${t} is not image`)}}),l=o(()=>e.value===void 0?"":n.context.value.imageBuckets?.[e.value?.bucket]),r=o(()=>e.value!==void 0),a=o(()=>m(e.value?.set?.["cropped-webp-100x200"]?.url,l.value)),i=o(()=>m(e.value?.set?.["cropped-webp-1000x2000"]?.url,l.value)),u=o(()=>m(e.value?.set?.["webp-200x200"]?.url,l.value)),g=o(()=>m(e.value?.set?.["webp-2000x2000"]?.url,l.value));return d({hasContent:r,lowResolutionMobileImage:a,highResolutionMobileImage:i,lowResolutionDesktopImage:u,highResolutionDesktopImage:g})}function $(t){return"enabled"in t}function L(t){const n=c(),e=o(()=>{const a=n.content.value[t];if(a!==void 0){if($(a))return a;throw new Error(`Element ${t} is not toggle`)}}),l=o(()=>e.value!==void 0),r=o(()=>e.value?.enabled);return d({hasContent:l,value:r})}function S(t){const n=c(),e=o(()=>{const a=n.content.value[t];if(a!==void 0){if(typeof a=="string")return a;throw new Error(`Element ${t} is not selectbox`)}}),l=o(()=>e.value!==void 0),r=o(()=>e.value);return d({hasContent:l,value:r})}function y(t,n){if(n===void 0)return;if(!n.startsWith("global."))return n;const e=n.split(".").at(2);if(e!==void 0)return t.fontFamily[e]}function R(t,n){if(n===void 0)return;if(typeof n!="string"||!n.startsWith("global."))return n;const e=n.split(".").at(2);if(e!==void 0)return t.textSize[e]}function f(t,n){if(n===void 0)return;if(typeof n!="string"||!n.startsWith("global."))return n;const e=n.split(".").at(2);if(e!==void 0)return t.color[e]}function A(t){const n=c(),e=o(()=>{const s=n.design.value[t],v=n.defaults.value[t],p=n.context.value.globalDesign;return{font:s?.font?.replaceAll("_"," ")??y(p,v?.font),size:s?.size??R(p,v?.size),bold:s?.bold??v?.bold,italic:s?.italic??v?.italic,color:s?.color??f(p,v?.color),visible:s?.visible??v?.visible??!1}}),l=o(()=>e.value?.font),r=o(()=>e.value?.size),a=o(()=>e.value?.bold),i=o(()=>e.value?.italic),u=o(()=>e.value?.color),g=o(()=>e.value?.visible);return d({font:l,size:r,bold:a,italic:i,color:u,visible:g})}function B(t){const n=c(),e=o(()=>{const s=n.design.value[t],v=n.defaults.value[t],p=n.context.value.globalDesign;return{appearance:s?.appearance??v?.appearance,font:s?.font??y(p,v?.font),size:s?.size??v?.size,style:s?.style??v?.style,color:s?.color??f(p,v?.color),visible:s?.visible??v?.visible??!1}}),l=o(()=>e.value?.appearance),r=o(()=>e.value?.font),a=o(()=>e.value?.size),i=o(()=>e.value?.style),u=o(()=>e.value?.color),g=o(()=>e.value?.visible);return d({appearance:l,font:r,size:a,style:i,color:u,visible:g})}function O(t){const n=c(),e=o(()=>{const a=n.design.value[t],i=n.defaults.value[t],u=n.context.value.globalDesign;return{overlay:{type:a?.overlay?.type??i?.overlay?.type,solid:{color:a?.overlay?.solid?.color??f(u,i?.overlay?.solid?.color)},gradient:{fromColor:a?.overlay?.gradient?.fromColor??f(u,i?.overlay?.gradient?.fromColor),toColor:a?.overlay?.gradient?.toColor??f(u,i?.overlay?.gradient?.toColor)}},visible:a?.visible??i?.visible??!1}}),l=o(()=>e.value?.overlay),r=o(()=>e.value?.visible);return d({overlay:l,visible:r})}function G(t){const n=c(),e=o(()=>{const r=n.design.value[t],a=n.defaults.value[t];return{enabled:r?.enabled??a?.enabled}}),l=o(()=>e.value?.enabled);return d({enabled:l})}function K(t){const n=c(),e=o(()=>{const r=n.design.value[t],a=n.defaults.value[t];return{value:r?.value??a?.value}}),l=o(()=>e.value?.value);return d({value:l})}function M(t){const n=c(),e=o(()=>{const r=n.design.value[t],a=n.defaults.value[t],i=n.context.value.globalDesign;return{background:{type:r?.background?.type??a?.background?.type,solid:{color:r?.background?.solid?.color??f(i,a?.background?.solid?.color)},gradient:{fromColor:r?.background?.gradient?.fromColor??f(i,a?.background?.gradient?.fromColor),toColor:r?.background?.gradient?.toColor??f(i,a?.background?.gradient?.toColor)}}}}),l=o(()=>e.value?.background);return d({background:l})}function E(t){return{app:x(t)}}function N(t,n){return{init:()=>{const{app:e}=E(t);return n?.init?.(e),{render:async(l,r)=>(c().init(e,l,r.content,r.design,r.defaults),n?.render?.(e,l,r),{html:await C(e,{context:l}),state:{context:l,data:r}})}}}}function V(t,n){return{init:()=>{const{app:e}=E(t);return n?.init?.(e),{mount:(l,r)=>{c().init(e,r.context,r.data.content,r.data.design,r.data.defaults),n?.mount?.(e,l,r),e.mount(l)},update:l=>{c().update(e,l.data.content,l.data.design),n?.update?.(e,l)},unmount:()=>{n?.unmount?.(e),e.unmount()}}}}}export{V as createVueClientApp,N as createVueServerApp,M as useBackgroundElementDesign,T as useButtonElementContent,B as useButtonElementDesign,D as useImageElementContent,O as useImageElementDesign,h as useInputboxElementContent,S as useSelectboxElementContent,K as useSelectboxElementDesign,A as useTextElementDesign,I as useTextareaElementContent,L as useToggleElementContent,G as useToggleElementDesign,c as useVueBaseProps};
1
+ import{getCurrentInstance as k,ref as b,computed as o,reactive as d,createSSRApp as x}from"vue";import{renderToString as C}from"vue/server-renderer";const w=new Map;function c(){const t=(r,a,i,u,g)=>{w.set(r._uid,{context:b(a),content:b(i),design:b(u),defaults:b(g)})},n=(r,a,i)=>{const u=w.get(r._uid);u!==void 0&&(u.content.value=a,u.design.value=i)},e=k()?.appContext.app._uid??-1,l=w.get(e);return{init:t,update:n,context:l?.context,content:l?.content,design:l?.design,defaults:l?.defaults}}function h(t){const n=c(),e=o(()=>{const a=n.content.value[t];if(a!==void 0){if(typeof a=="string")return a;throw new Error(`Element ${t} is not inputbox`)}}),l=o(()=>e.value!==void 0),r=o(()=>e.value);return d({hasContent:l,value:r})}function I(t){const n=c(),e=o(()=>{const a=n.content.value[t];if(a!==void 0){if(typeof a=="string")return a;throw new Error(`Element ${t} is not textarea`)}}),l=o(()=>e.value!==void 0),r=o(()=>e.value);return d({hasContent:l,value:r})}function _(t){return"title"in t&&"type"in t}function T(t){const n=c(),e=o(()=>{const u=n.content.value[t];if(u!==void 0){if(_(u))return u;throw new Error(`Element ${t} is not action link`)}}),l=o(()=>e.value?.title),r=o(()=>e.value?.link),a=o(()=>!!l.value),i=o(()=>!!r.value);return d({title:l,link:r,hasTitle:a,hasLink:i,performAction:()=>{if(e.value!==void 0)switch(e.value.type){case"HYPER_LINK":e.value.link&&window.open(e.value.link,"_blank");break;case"GO_TO_STORE_LINK":window.open("/products");break;case"MAIL_LINK":e.value.email&&window.open(`mailto:${e.value.email}`,"_self");break;case"TEL_LINK":e.value.phone&&window.open(`tel:${e.value.phone}`,"_self");break;case"SCROLL_TO_TILE":{if(typeof document>"u")return;const u=e.value.tileId;document.getElementById(`tile-${u}`)?.scrollIntoView();break}default:throw new Error("Unknown ButtonType: ")}}})}function z(t){return"bucket"in t&&"borderInfo"in t&&"set"in t}function m(t,n){const e=new RegExp(/^https?:\/\//);return t!=null&&e.test(t)?t:`${n}/${t}`}function D(t){const n=c(),e=o(()=>{const s=n.content.value[t];if(s!==void 0){if(z(s))return s;throw new Error(`Element ${t} is not image`)}}),l=o(()=>e.value===void 0?"":n.context.value.imageBuckets?.[e.value?.bucket]),r=o(()=>e.value!==void 0),a=o(()=>m(e.value?.set?.["cropped-webp-100x200"]?.url,l.value)),i=o(()=>m(e.value?.set?.["cropped-webp-1000x2000"]?.url,l.value)),u=o(()=>m(e.value?.set?.["webp-200x200"]?.url,l.value)),g=o(()=>m(e.value?.set?.["webp-2000x2000"]?.url,l.value));return d({hasContent:r,lowResolutionMobileImage:a,highResolutionMobileImage:i,lowResolutionDesktopImage:u,highResolutionDesktopImage:g})}function $(t){return"enabled"in t}function L(t){const n=c(),e=o(()=>{const a=n.content.value[t];if(a!==void 0){if($(a))return a;throw new Error(`Element ${t} is not toggle`)}}),l=o(()=>e.value!==void 0),r=o(()=>e.value?.enabled);return d({hasContent:l,value:r})}function S(t){const n=c(),e=o(()=>{const a=n.content.value[t];if(a!==void 0){if(typeof a=="string")return a;throw new Error(`Element ${t} is not selectbox`)}}),l=o(()=>e.value!==void 0),r=o(()=>e.value);return d({hasContent:l,value:r})}function y(t,n){if(n===void 0)return;if(!n.startsWith("global."))return n;const e=n.split(".").at(2);if(e!==void 0)return t.fontFamily[e]}function R(t,n){if(n===void 0)return;if(typeof n!="string"||!n.startsWith("global."))return n;const e=n.split(".").at(2);if(e!==void 0)return t.textSize[e]}function f(t,n){if(n===void 0)return;if(typeof n!="string"||!n.startsWith("global."))return n;const e=n.split(".").at(2);if(e!==void 0)return t.color[e]}function A(t){const n=c(),e=o(()=>{const s=n.design.value[t],v=n.defaults.value[t],p=n.context.value.globalDesign;return{font:s?.font?.replaceAll("_"," ")??y(p,v?.font),size:s?.size??R(p,v?.size),bold:s?.bold??v?.bold,italic:s?.italic??v?.italic,color:s?.color??f(p,v?.color),visible:s?.visible??v?.visible??!1}}),l=o(()=>e.value?.font),r=o(()=>e.value?.size),a=o(()=>e.value?.bold),i=o(()=>e.value?.italic),u=o(()=>e.value?.color),g=o(()=>e.value?.visible);return d({font:l,size:r,bold:a,italic:i,color:u,visible:g})}function B(t){const n=c(),e=o(()=>{const s=n.design.value[t],v=n.defaults.value[t],p=n.context.value.globalDesign;return{appearance:s?.appearance??v?.appearance,font:s?.font??y(p,v?.font),size:s?.size??v?.size,style:s?.style??v?.style,color:s?.color??f(p,v?.color),visible:s?.visible??v?.visible??!1}}),l=o(()=>e.value?.appearance),r=o(()=>e.value?.font),a=o(()=>e.value?.size),i=o(()=>e.value?.style),u=o(()=>e.value?.color),g=o(()=>e.value?.visible);return d({appearance:l,font:r,size:a,style:i,color:u,visible:g})}function O(t){const n=c(),e=o(()=>{const a=n.design.value[t],i=n.defaults.value[t],u=n.context.value.globalDesign;return{overlay:{type:a?.overlay?.type??i?.overlay?.type,solid:{color:a?.overlay?.solid?.color??f(u,i?.overlay?.solid?.color)},gradient:{fromColor:a?.overlay?.gradient?.fromColor??f(u,i?.overlay?.gradient?.fromColor),toColor:a?.overlay?.gradient?.toColor??f(u,i?.overlay?.gradient?.toColor)}},visible:a?.visible??i?.visible??!1}}),l=o(()=>e.value?.overlay),r=o(()=>e.value?.visible);return d({overlay:l,visible:r})}function G(t){const n=c(),e=o(()=>{const r=n.design.value[t],a=n.defaults.value[t];return{enabled:r?.enabled??a?.enabled}}),l=o(()=>e.value?.enabled);return d({enabled:l})}function K(t){const n=c(),e=o(()=>{const r=n.design.value[t],a=n.defaults.value[t];return{value:r?.value??a?.value}}),l=o(()=>e.value?.value);return d({value:l})}function M(t){const n=c(),e=o(()=>{const r=n.design.value[t],a=n.defaults.value[t],i=n.context.value.globalDesign;return{background:{type:r?.background?.type??a?.background?.type,solid:{color:r?.background?.solid?.color??f(i,a?.background?.solid?.color)},gradient:{fromColor:r?.background?.gradient?.fromColor??f(i,a?.background?.gradient?.fromColor),toColor:r?.background?.gradient?.toColor??f(i,a?.background?.gradient?.toColor)}}}}),l=o(()=>e.value?.background);return d({background:l})}function E(t){return{app:x(t)}}function N(t,n){return{init:()=>{const{app:e}=E(t);return n?.init?.(e),{render:async(l,r)=>(c().init(e,l,r.content,r.design,r.defaults),n?.render?.(e,l,r),{html:await C(e,{context:l}),state:{context:l,data:r}})}}}}function V(t,n){return{init:()=>{const{app:e}=E(t);return n?.init?.(e),{mount:(l,r)=>{c().init(e,r.context,r.data.content,r.data.design,r.data.defaults),n?.mount?.(e,l,r),e.mount(l)},update:l=>{c().update(e,l.data.content,l.data.design),n?.update?.(e,l)},unmount:()=>{n?.unmount?.(e),e.unmount()}}}}}export{V as createVueClientApp,N as createVueServerApp,M as useBackgroundElementDesign,T as useButtonElementContent,B as useButtonElementDesign,D as useImageElementContent,O as useImageElementDesign,h as useInputboxElementContent,S as useSelectboxElementContent,K as useSelectboxElementDesign,A as useTextElementDesign,I as useTextareaElementContent,L as useToggleElementContent,G as useToggleElementDesign,c as useVueBaseProps};
package/dist/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import Pe from"cac";import p from"node:fs";import f from"node:path";import{fileURLToPath as N}from"node:url";import{red as _e,yellow as Ge,green as C}from"kolorist";import{resolve as l,parse as L,dirname as ke,sep as xe}from"path";import{rename as Re,unlink as Be,existsSync as A,writeFileSync as Ue,createReadStream as Xe}from"fs";import{glob as y,globSync as U}from"glob";import{build as D,defineConfig as I}from"vite";import{builtinModules as X}from"module";import F from"@vitejs/plugin-vue";import P from"vite-tsconfig-paths";import Fe from"vite-plugin-checker";import{viteExternalsPlugin as Me}from"vite-plugin-externals";import qe from"ajv/dist/2020.js";import ze from"ajv-formats";import{readFile as M}from"fs/promises";import Ke from"axios";import{inc as Je}from"semver";import*as d from"process";import He from"tinycolor2";import Ve from"prompts";function q(e,t){p.statSync(e).isDirectory()?(p.mkdirSync(t,{recursive:!0}),p.readdirSync(e).forEach(o=>{const n=f.resolve(e,o),s=f.resolve(t,o);q(n,s)})):p.copyFileSync(e,t)}function _(e,t,o,n){const s=f.join(e,n?.[o]??o);q(f.join(t,o),s)}const a={error:e=>console.log(_e(e)),warn:e=>console.log(Ge(e)),info:e=>console.log(C(e))},w="_temp";function G(e){return!!e}async function z(e){try{const t=e,o=process.cwd(),n=f.join(o,t),s=["templates"],i={_gitignore:".gitignore"};if(!p.existsSync(n))p.mkdirSync(n);else{a.error(`App with the name: ${e} already exists. If you'd like to override it, delete previous version first`);return}const r=f.resolve(N(import.meta.url),"../..","template");p.readdirSync(r).filter(b=>b!=="package.json").filter(b=>!s.includes(b)).forEach(async b=>_(n,r,b,i));const m=JSON.parse(p.readFileSync(f.join(r,"package.json"),"utf-8"));m.name=e;const T=f.join(n,"package.json");p.writeFileSync(T,`${JSON.stringify(m,null,2)}
2
- `),a.info(`App ${e} created`)}catch(t){a.error(`Error while creating app: ${t.message}`)}}async function K(e){try{const t=e,o=process.cwd(),n=f.join(o,"sections",t);if(!p.existsSync(n))p.mkdirSync(n);else{a.error(`Section with the name: ${e} already exists. If you'd like to override it, delete previous version first`);return}const s=f.resolve(N(import.meta.url),"../..","template/sections/example-section");p.readdirSync(s).forEach(async i=>_(n,s,i)),a.info(`Section ${e} created`)}catch(t){a.error(`Error while creating block: ${t.message}`)}}async function J(e){try{const t=process.cwd(),o=f.join(t,"templates"),n={"template.ts":`${e}.ts`};if(!p.existsSync(o))p.mkdirSync(o);else if(p.existsSync(f.join(o,`${e}.ts`))){a.error(`Template with the name: ${e} already exists. If you'd like to override it, delete previous version first`);return}const s=f.resolve(N(import.meta.url),"../..","template/templates");p.readdirSync(s).forEach(async i=>_(o,s,i,n)),a.info(`Template descriptor file [${e}.ts] has been created`)}catch(t){a.error(`Error while creating template descriptors: ${t.message}`)}}var u=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.SectionSetting=2]="SectionSetting",e[e.SectionShowcase=3]="SectionShowcase",e[e.SectionAsset=4]="SectionAsset",e[e.TemplateDescriptor=5]="TemplateDescriptor",e))(u||{}),g=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.Misc=2]="Misc",e))(g||{});const We={[g.Server]:[F(),P()],[g.Client]:[F(),P(),V(),Me({vue:"EcVue"})],[g.Misc]:[P(),V()]},H={"process.env":{NODE_ENV:"production"}},$={[u.Server]:{pluginType:g.Server,define:H,ssr:!0,ssrOptions:{noExternal:!0},outDir:e=>`./dist/sections/${e}/js/main/server`,externalOption:[...X,...X.map(e=>`node:${e}`)],entryFileNames:"[name].js"},[u.Client]:{pluginType:g.Client,define:H,ssr:!1,outDir:e=>`./dist/sections/${e}/js/main/client`,entryFileNames:"[name].js",chunkFileNames:"[name].js",assetFileNames:"assets/[name].[ext]"},[u.SectionSetting]:{pluginType:g.Misc,ssr:!1,outDir:e=>`./dist/sections/${e}/js/settings`,entryFileNames:"[name].mjs"},[u.SectionShowcase]:{pluginType:g.Misc,ssr:!1,outDir:e=>`./dist/sections/${e}/js/showcases`,entryFileNames:"[name].mjs"},[u.SectionAsset]:{pluginType:g.Misc,ssr:!1,outDir:e=>`./dist/sections/${e}/assets`,assetFileNames:"[name].[ext]"},[u.TemplateDescriptor]:{pluginType:g.Misc,ssr:!1,outDir:()=>"./dist/template/js",entryFileNames:`[name]${w}.mjs`}};function Ze(e){switch(typeof e){case"string":return[l(process.cwd(),e)];case"object":return e.map(t=>l(process.cwd(),t));default:return[]}}function V(){const e=process.env.npm_lifecycle_event;return Fe({typescript:!0,vueTsc:!1,eslint:{lintCommand:`eslint --max-warnings=0 "./sections/**/*.{js,ts,vue}" --cache --cache-location "./build/eslintcache/${e}.json"`}})}function k(e,t,o){const n=$[o].define,s=$[o].ssrOptions,i=$[o].externalOption,r=$[o].entryFileNames,m=$[o].chunkFileNames,T=$[o].assetFileNames;return{plugins:We[$[o].pluginType],...n!=null&&{define:n},...s!=null&&{ssr:s},resolve:{alias:{"@":"/src"}},build:{ssr:$[o].ssr,outDir:$[o].outDir(e),emptyOutDir:!0,rollupOptions:{...i!=null&&{external:i},preserveEntrySignatures:"strict",input:Ze(t),output:{validate:!0,...r!=null&&{entryFileNames:r},...m!=null&&{chunkFileNames:m},...T!=null&&{assetFileNames:T}}}}}}const W="https://json-schema.org/draft/2020-12/schema",Z="https://lightspeedhq.com/template.schema.json",Y="Custom Template",Q="A custom template enclosing the necessary custom and default blocks",ee="object",te={metadata:{type:"object",properties:{name:{description:"Name of the template",type:"string",minLength:2,maxLength:60},description:{description:"Short description of the template",type:"string",minLength:2,maxLength:150},url:{type:"object",properties:{demo_website:{description:"URL to the demo website",type:"string",format:"uri",pattern:"^(https?|wss?|ftp)://"},cover_image:{description:"URL to the cover image",type:"string",format:"uri",pattern:"^(https?|wss?|ftp)://"}},required:["demo_website","cover_image"]}},required:["name","description","url"]},sections:{description:"List of sections contained by this template",type:"array",items:{type:"object",properties:{type:{description:"Type of the section",type:"string",enum:["custom","default"]}},allOf:[{if:{properties:{type:{const:"default"}}},then:{$ref:"template-default.schema.json#/$defs/default-section"}},{if:{properties:{type:{const:"custom"}}},then:{$ref:"template-custom.schema.json#/$defs/custom-section"}}]},minItems:1,uniqueItems:!1}},oe=["metadata","sections"],Ye={$schema:W,$id:Z,title:Y,description:Q,type:ee,properties:te,required:oe},ne={__proto__:null,$id:Z,$schema:W,default:Ye,description:Q,properties:te,required:oe,title:Y,type:ee},se="https://json-schema.org/draft/2020-12/schema",ie="https://lightspeedhq.com/template-default.schema.json",re="Default Section",ae="Default section for a Custom Template",ce="object",pe={"default-section":{type:"object",properties:{type:{description:"Type of the section",type:"string",enum:["custom","default"]},id:{description:"Identification of the section",type:"string",pattern:"^((header|cover|announcement_bar|slider|special_offer|customer_review|company_info|shipping_payment|location|store|footer)(_\\d{3})?)$"}},required:["type","id"],additionalProperties:!1}},Qe={$schema:se,$id:ie,title:re,description:ae,type:ce,$defs:pe},et={__proto__:null,$defs:pe,$id:ie,$schema:se,default:Qe,description:ae,title:re,type:ce},le="https://json-schema.org/draft/2020-12/schema",de="https://lightspeedhq.com/template-custom.schema.json",fe="Custom Section",ue="Custom section for a Custom Template",me="object",ye={"custom-section":{type:"object",properties:{type:{description:"Type of the section",type:"string",enum:["custom","default"]},id:{description:"Identification of the section",type:"string"},content:{type:"object",patternProperties:{".*":{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]}},allOf:[{if:{properties:{type:{const:"INPUTBOX"}}},then:{$ref:"template-custom-content.schema.json#/$defs/input_box"}},{if:{properties:{type:{const:"TEXTAREA"}}},then:{$ref:"template-custom-content.schema.json#/$defs/text_area"}},{if:{properties:{type:{const:"BUTTON"}}},then:{$ref:"template-custom-content.schema.json#/$defs/button"}},{if:{properties:{type:{const:"IMAGE"}}},then:{$ref:"template-custom-content.schema.json#/$defs/image"}},{if:{properties:{type:{const:"TOGGLE"}}},then:{$ref:"template-custom-content.schema.json#/$defs/toggle"}},{if:{properties:{type:{const:"SELECTBOX"}}},then:{$ref:"template-custom-content.schema.json#/$defs/select_box"}}]}},minProperties:1},design:{type:"object",patternProperties:{".*":{type:"object",properties:{type:{description:"Type of the design configuration element",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]}},allOf:[{if:{properties:{type:{const:"TEXT"}}},then:{$ref:"template-custom-design.schema.json#/$defs/text"}},{if:{properties:{type:{const:"BUTTON"}}},then:{$ref:"template-custom-design.schema.json#/$defs/button"}},{if:{properties:{type:{const:"IMAGE"}}},then:{$ref:"template-custom-design.schema.json#/$defs/image"}},{if:{properties:{type:{const:"TOGGLE"}}},then:{$ref:"template-custom-design.schema.json#/$defs/toggle"}},{if:{properties:{type:{const:"SELECTBOX"}}},then:{$ref:"template-custom-design.schema.json#/$defs/select_box"}},{if:{properties:{type:{const:"BACKGROUND"}}},then:{$ref:"template-custom-design.schema.json#/$defs/background"}}]}},minProperties:1}},required:["type","id"],additionalProperties:!1}},tt={$schema:le,$id:de,title:fe,description:ue,type:me,$defs:ye},ot={__proto__:null,$defs:ye,$id:de,$schema:le,default:tt,description:ue,title:fe,type:me},he="https://json-schema.org/draft/2020-12/schema",ge="https://lightspeedhq.com/template-custom-content.schema.json",$e="Custom Section :: Content Configuration",Ee="Content tab configuration of a Custom Section for a Custom Template",Te="object",be={input_box:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"},placeholder:{description:"Placeholder of the content configuration element",type:"string"}},required:["type","label","placeholder"],additionalProperties:!1},text_area:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"},placeholder:{description:"Placeholder of the content configuration element",type:"string"}},required:["type","label","placeholder"],additionalProperties:!1},button:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"}},required:["type","label"],additionalProperties:!1},image:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"}},required:["type","label"],additionalProperties:!1},toggle:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"},description:{description:"Description of the content configuration element",type:"string"}},required:["type","label"],additionalProperties:!1},select_box:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"},placeholder:{description:"Placeholder of the content configuration element",type:"string"},description:{description:"Description of the content configuration element",type:"string"},options:{description:"Individual options of the content configuration element",type:"array",items:{type:"object",properties:{value:{description:"Value of the option",type:"string"},label:{description:"Label of the option",type:"string"}},required:["value","label"],additionalProperties:!1},minItems:1}},required:["type","label","placeholder","options"],additionalProperties:!1}},nt={$schema:he,$id:ge,title:$e,description:Ee,type:Te,$defs:be},st={__proto__:null,$defs:be,$id:ge,$schema:he,default:nt,description:Ee,title:$e,type:Te},we="https://json-schema.org/draft/2020-12/schema",je="https://lightspeedhq.com/template-custom-design.schema.json",Oe="Custom Section :: Design Configuration",ve="Design tab configuration of a Custom Section for a Custom Template",Se="object",Ce={text:{type:"object",properties:{type:{description:"Type of the text",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the text",type:"string"},colors:{description:"Color options for the text",type:"array",items:{type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"},minItems:1,uniqueItems:!0},sizes:{description:"Size options for the text",type:"array",items:{type:"integer",minimum:0,exclusiveMaximum:100},minItems:1,uniqueItems:!0},defaults:{description:"Default values for the text",type:"object",properties:{font:{description:"Default font for the text",type:"string"},size:{description:"Default size for the text",type:"integer",minimum:1,exclusiveMaximum:50},bold:{description:"Default boldness for the text",type:"boolean"},italic:{description:"Default italic style for the text",type:"boolean"},color:{description:"Default color for the text",type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{6}|[a-fA-F0-9]{3})$"},visible:{description:"Default visibility for the text",type:"boolean"}},required:["font","size","bold","italic","color","visible"],additionalProperties:!1}},required:["type","label","colors","sizes","defaults"],additionalProperties:!1},button:{type:"object",properties:{type:{description:"Type of the button",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the button",type:"string"},colors:{description:"Color options for the button",type:"array",items:{type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"},minItems:1,uniqueItems:!0},defaults:{description:"Default values for the button",type:"object",properties:{font:{description:"Default font for the button",type:"string"},size:{description:"Default size for the button",type:"string",enum:["SMALL","MEDIUM","LARGE"]},appearance:{description:"Default appearance for the button",type:"string",enum:["SOLID","OUTLINE","TEXT"]},shape:{description:"Default shape for the button",type:"string",enum:["ROUND_CORNER","RECTANGLE","PILL"]},color:{description:"Default color for the button",type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"}},required:["font","size","appearance","shape","color"],additionalProperties:!1}},required:["type","label","colors","defaults"],additionalProperties:!1},image:{type:"object",properties:{type:{description:"Type of the image",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the image",type:"string"},colors:{description:"Color options for the image",type:"array",items:{type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"},minItems:1,uniqueItems:!0},defaults:{description:"Default values for the image",type:"object",properties:{overlay:{description:"Default overlay for the image",type:"string",enum:["COLOR","GRADIENT","NONE"]},color:{description:"Default color for the image",type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"}},required:["overlay","color"],additionalProperties:!1}},required:["type","label","colors","defaults"],additionalProperties:!1},toggle:{type:"object",properties:{type:{description:"Type of the toggle",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the toggle",type:"string"},description:{description:"Description of the toggle",type:"string"},defaults:{description:"Default values for the toggle",type:"object",properties:{enabled:{description:"Default enabled status for the toggle",type:"boolean"}},required:["enabled"],additionalProperties:!1}},required:["type","label"],additionalProperties:!1},select_box:{type:"object",properties:{type:{description:"Type of the checkbox",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the checkbox",type:"string"},placeholder:{description:"Placeholder of the checkbox",type:"string"},description:{description:"Description of the checkbox",type:"string"},options:{description:"Individual options of the checkbox",type:"array",items:{type:"object",properties:{value:{description:"Value of the option",type:"string"},label:{description:"Label of the option",type:"string"}},required:["value","label"],additionalProperties:!1},minItems:1},defaults:{description:"Default values for the checkbox",type:"object",properties:{value:{description:"Default option for the checkbox",type:"string"}},required:["value"],additionalProperties:!1}},required:["type","label","placeholder","description","options","defaults"],additionalProperties:!1},background:{type:"object",properties:{type:{description:"Type of the background",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the background",type:"string"},colors:{description:"Color options for the background",type:"array",items:{type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"},minItems:1,uniqueItems:!0},defaults:{description:"Default values for the background",type:"object",properties:{style:{description:"Default style for the background",type:"string",enum:["COLOR","GRADIENT"]},color:{description:"Default color style for the background",type:"string"}},required:["style","color"],additionalProperties:!1}},required:["type","label","colors","defaults"],additionalProperties:!1}},it={$schema:we,$id:je,title:Oe,description:ve,type:Se,$defs:Ce},rt={__proto__:null,$defs:Ce,$id:je,$schema:we,default:it,description:ve,title:Oe,type:Se};async function at(){const e=await y("**/server.{js,ts}",{ignore:["node_modules/**","dist/**"]});return Promise.all(e.map(async t=>{const o=ke(t).split(xe).pop()??"default",n=await y(`**/${o}/client.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),s=await y(`**/${o}/settings/content.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),i=await y(`**/${o}/settings/design.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),r=await y(`**/${o}/settings/translations.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),m=await y(`**/${o}/showcases/*.{js,ts}`,{ignore:["node_modules/**","dist/**",`**/${o}/showcases/translations.{js,ts}`]}),T=await y(`**/${o}/showcases/translations.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),b=await y(`**/${o}/assets/*`,{ignore:["node_modules/**","dist/**"]});return{name:o,serverEntrypoint:t,clientEntrypoint:n.at(0),contentSettingsEntrypoint:s.at(0),designSettingsEntrypoint:i.at(0),settingsTranslationsEntrypoint:r.at(0),showcasesEntrypoints:m,showcasesTranslationsEntrypoint:T.at(0),assetsEntrypoints:b}}))}async function ct(){return{entryPoints:await y("**/templates/**.{js,ts}",{ignore:["node_modules/**","dist/**"]})}}async function x(e,t){try{return(await import(l(process.cwd(),t?`${e}${w}.mjs`:`${e}.mjs`))).default}catch{throw new Error(`File [${e}${w}.mjs] is either invalid or undefined`)}}async function pt(){let e=new qe({allErrors:!0,schemas:[ne,et,ot,st,rt]});return ze(e),e.compile(ne)}async function lt(e,t,o,n){if(e(t)&&n===void 0)new Promise(s=>{Re(`${o}${w}.mjs`,`${o}.mjs`,function(i){i&&s(i)})});else throw new Promise(s=>{Be(`${o}${w}.mjs`,function(i){i&&s(i)})}),new Error(`Invalid file [${L(o).name}].
1
+ import Re from"cac";import h from"node:fs";import $ from"node:path";import{fileURLToPath as _}from"node:url";import*as L from"fs";import{rename as Ue,unlink as Me,existsSync as N,statSync as Fe,writeFileSync as Xe,createReadStream as qe}from"fs";import*as D from"path";import{resolve as l,parse as P,dirname as ze,sep as Ke}from"path";import{red as Je,yellow as He,green as I}from"kolorist";import{glob as u,globSync as M}from"glob";import{build as F,defineConfig as X}from"vite";import{pathToFileURL as j}from"url";import{builtinModules as q}from"module";import z from"@vitejs/plugin-vue";import G from"vite-tsconfig-paths";import Ve from"vite-plugin-checker";import{viteExternalsPlugin as We}from"vite-plugin-externals";import Ze from"ajv/dist/2020.js";import Ye from"ajv-formats";import*as d from"process";import{readFile as K}from"fs/promises";import Qe from"axios";import{inc as et}from"semver";import tt from"tinycolor2";import ot from"prompts";function J(e,t){L.statSync(e).isDirectory()?(L.mkdirSync(t,{recursive:!0}),L.readdirSync(e).forEach(o=>{const s=D.resolve(e,o),n=D.resolve(t,o);J(s,n)})):L.copyFileSync(e,t)}function x(e,t,o,s){const n=D.join(e,s?.[o]??o);J(D.join(t,o),n)}function H(e,t=2){if(!+e)return"0 Bytes";const o=1024,s=t<0?0:t,n=["Bytes","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"],i=Math.floor(Math.log(e)/Math.log(o));return`${parseFloat((e/Math.pow(o,i)).toFixed(s))} ${n[i]}`}const c={error:e=>console.log(Je(e)),warn:e=>console.log(He(e)),info:e=>console.log(I(e))},O="_temp",r="dist/sections",v="dist/templates",V=2*1024*1024;function k(e){return!!e}async function W(e){try{const t=e,o=process.cwd(),s=$.join(o,t),n=["templates"],i={_gitignore:".gitignore"};if(!h.existsSync(s))h.mkdirSync(s);else{c.error(`App with the name: ${e} already exists. If you'd like to override it, delete previous version first`);return}const a=$.resolve(_(import.meta.url),"../..","template");h.readdirSync(a).filter(w=>w!=="package.json").filter(w=>!n.includes(w)).forEach(async w=>x(s,a,w,i));const y=JSON.parse(h.readFileSync($.join(a,"package.json"),"utf-8"));y.name=e;const b=$.join(s,"package.json");h.writeFileSync(b,`${JSON.stringify(y,null,2)}
2
+ `),c.info(`App ${e} created`)}catch(t){c.error(`Error while creating app: ${t.message}`)}}async function Z(e){try{const t=e,o=process.cwd(),s=$.join(o,"sections",t);if(!h.existsSync(s))h.mkdirSync(s);else{c.error(`Section with the name: ${e} already exists. If you'd like to override it, delete previous version first`);return}const n=$.resolve(_(import.meta.url),"../..","template/sections/example-section");h.readdirSync(n).forEach(async i=>x(s,n,i)),c.info(`Section ${e} created`)}catch(t){c.error(`Error while creating section: ${t.message}`)}}async function Y(e){try{const t=process.cwd(),o=$.join(t,"templates"),s={"template.ts":`${e}.ts`};if(!h.existsSync(o))h.mkdirSync(o);else if(h.existsSync($.join(o,`${e}.ts`))){c.error(`Template with the name: ${e} already exists. If you'd like to override it, delete previous version first`);return}const n=$.resolve(_(import.meta.url),"../..","template/templates");h.readdirSync(n).forEach(async i=>x(o,n,i,s)),c.info(`Template descriptor file [${e}.ts] has been created`)}catch(t){c.error(`Error while creating template descriptors: ${t.message}`)}}var f=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.SectionSetting=2]="SectionSetting",e[e.SectionShowcase=3]="SectionShowcase",e[e.SectionAsset=4]="SectionAsset",e[e.TemplateDescriptor=5]="TemplateDescriptor",e[e.TemplateAsset=6]="TemplateAsset",e))(f||{}),g=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.Misc=2]="Misc",e))(g||{});const st={[g.Server]:[z(),G()],[g.Client]:[z(),G(),ee(),We({vue:"EcVue"})],[g.Misc]:[G(),ee()]},Q={"process.env":{NODE_ENV:"production"}},E={[f.Server]:{pluginType:g.Server,define:Q,ssr:!0,ssrOptions:{noExternal:!0},outDir:e=>`./${r}/${e}/js/main/server`,externalOption:[...q,...q.map(e=>`node:${e}`)],entryFileNames:"[name].js"},[f.Client]:{pluginType:g.Client,define:Q,ssr:!1,outDir:e=>`./${r}/${e}/js/main/client`,entryFileNames:"[name].js",chunkFileNames:"[name].js",assetFileNames:"assets/[name].[ext]"},[f.SectionSetting]:{pluginType:g.Misc,ssr:!1,outDir:e=>`./${r}/${e}/js/settings`,entryFileNames:"[name].mjs"},[f.SectionShowcase]:{pluginType:g.Misc,ssr:!1,outDir:e=>`./${r}/${e}/js/showcases`,entryFileNames:"[name].mjs"},[f.SectionAsset]:{pluginType:g.Misc,ssr:!1,outDir:e=>`./${r}/${e}/assets`,assetFileNames:"[name].[ext]"},[f.TemplateDescriptor]:{pluginType:g.Misc,ssr:!1,outDir:()=>`./${v}/js`,entryFileNames:`[name]${O}.mjs`},[f.TemplateAsset]:{pluginType:g.Misc,ssr:!1,outDir:()=>`./${v}/assets`,assetFileNames:"[name].[ext]"}};function nt(e){switch(typeof e){case"string":return[l(process.cwd(),e)];case"object":return e.map(t=>l(process.cwd(),t));default:return[]}}function ee(){const e=process.env.npm_lifecycle_event;return Ve({typescript:!0,vueTsc:!1,eslint:{lintCommand:`eslint --max-warnings=0 "./sections/**/*.{js,ts,vue}" --cache --cache-location "./build/eslintcache/${e}.json"`}})}function te(e,t,o){const s=E[o].define,n=E[o].ssrOptions,i=E[o].externalOption,a=E[o].entryFileNames,y=E[o].chunkFileNames,b=E[o].assetFileNames;return{plugins:st[E[o].pluginType],...s!=null&&{define:s},...n!=null&&{ssr:n},resolve:{alias:{"@":"/src"}},build:{ssr:E[o].ssr,outDir:E[o].outDir(e),emptyOutDir:!0,rollupOptions:{...i!=null&&{external:i},preserveEntrySignatures:"strict",input:nt(t),output:{validate:!0,...a!=null&&{entryFileNames:a},...y!=null&&{chunkFileNames:y},...b!=null&&{assetFileNames:b}}}}}}const oe="https://json-schema.org/draft/2020-12/schema",se="https://lightspeedhq.com/template.schema.json",ne="Custom Template",ie="A custom template enclosing the necessary custom and default blocks",re="object",ae={metadata:{type:"object",properties:{name:{description:"Name of the template",type:"string",minLength:2,maxLength:60},description:{description:"Short description of the template",type:"string",minLength:2,maxLength:150},test_site_id:{description:"Site ID of the demo website",type:"integer"},cover_image:{type:"object",properties:{set:{description:"Name of the image set",type:"object",patternProperties:{".*":{type:"object",properties:{url:{description:"Path to the preview image relative to the 'assets' folder for a specific resolution",type:"string"}},required:["url"],additionalProperties:!1}}}},required:["set"],additionalProperties:!1}},required:["name","description","test_site_id","cover_image"],additionalProperties:!1},sections:{description:"List of sections contained by this template",type:"array",items:{type:"object",properties:{type:{description:"Type of the section",type:"string",enum:["custom","default"]}},allOf:[{if:{properties:{type:{const:"default"}}},then:{$ref:"template-default.schema.json#/$defs/default-section"}},{if:{properties:{type:{const:"custom"}}},then:{$ref:"template-custom.schema.json#/$defs/custom-section"}}]},minItems:1,uniqueItems:!1}},ce=["metadata","sections"],it={$schema:oe,$id:se,title:ne,description:ie,type:re,properties:ae,required:ce},pe={__proto__:null,$id:se,$schema:oe,default:it,description:ie,properties:ae,required:ce,title:ne,type:re},le="https://json-schema.org/draft/2020-12/schema",de="https://lightspeedhq.com/template-default.schema.json",fe="Default Section",ue="Default section for a Custom Template",me="object",ye={"default-section":{type:"object",properties:{type:{description:"Type of the section",type:"string",enum:["custom","default"]},id:{description:"Identification of the section",type:"string",pattern:"^((header|cover|announcement_bar|slider|special_offer|customer_review|company_info|shipping_payment|location|store|footer)(_\\d{3})?)$"}},required:["type","id"],additionalProperties:!1}},rt={$schema:le,$id:de,title:fe,description:ue,type:me,$defs:ye},at={__proto__:null,$defs:ye,$id:de,$schema:le,default:rt,description:ue,title:fe,type:me},he="https://json-schema.org/draft/2020-12/schema",ge="https://lightspeedhq.com/template-custom.schema.json",$e="Custom Section",Ee="Custom section for a Custom Template",Te="object",be={"custom-section":{type:"object",properties:{type:{description:"Type of the section",type:"string",enum:["custom","default"]},id:{description:"Identification of the section",type:"string"},content:{type:"object",patternProperties:{".*":{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]}},allOf:[{if:{properties:{type:{const:"INPUTBOX"}}},then:{$ref:"template-custom-content.schema.json#/$defs/input_box"}},{if:{properties:{type:{const:"TEXTAREA"}}},then:{$ref:"template-custom-content.schema.json#/$defs/text_area"}},{if:{properties:{type:{const:"BUTTON"}}},then:{$ref:"template-custom-content.schema.json#/$defs/button"}},{if:{properties:{type:{const:"IMAGE"}}},then:{$ref:"template-custom-content.schema.json#/$defs/image"}},{if:{properties:{type:{const:"TOGGLE"}}},then:{$ref:"template-custom-content.schema.json#/$defs/toggle"}},{if:{properties:{type:{const:"SELECTBOX"}}},then:{$ref:"template-custom-content.schema.json#/$defs/select_box"}}]}},minProperties:1},design:{type:"object",patternProperties:{".*":{type:"object",properties:{type:{description:"Type of the design configuration element",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]}},allOf:[{if:{properties:{type:{const:"TEXT"}}},then:{$ref:"template-custom-design.schema.json#/$defs/text"}},{if:{properties:{type:{const:"BUTTON"}}},then:{$ref:"template-custom-design.schema.json#/$defs/button"}},{if:{properties:{type:{const:"IMAGE"}}},then:{$ref:"template-custom-design.schema.json#/$defs/image"}},{if:{properties:{type:{const:"TOGGLE"}}},then:{$ref:"template-custom-design.schema.json#/$defs/toggle"}},{if:{properties:{type:{const:"SELECTBOX"}}},then:{$ref:"template-custom-design.schema.json#/$defs/select_box"}},{if:{properties:{type:{const:"BACKGROUND"}}},then:{$ref:"template-custom-design.schema.json#/$defs/background"}}]}},minProperties:1}},required:["type","id"],additionalProperties:!1}},ct={$schema:he,$id:ge,title:$e,description:Ee,type:Te,$defs:be},pt={__proto__:null,$defs:be,$id:ge,$schema:he,default:ct,description:Ee,title:$e,type:Te},we="https://json-schema.org/draft/2020-12/schema",je="https://lightspeedhq.com/template-custom-content.schema.json",Oe="Custom Section :: Content Configuration",ve="Content tab configuration of a Custom Section for a Custom Template",Se="object",Ce={input_box:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"},placeholder:{description:"Placeholder of the content configuration element",type:"string"}},required:["type","label","placeholder"],additionalProperties:!1},text_area:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"},placeholder:{description:"Placeholder of the content configuration element",type:"string"}},required:["type","label","placeholder"],additionalProperties:!1},button:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"}},required:["type","label"],additionalProperties:!1},image:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"}},required:["type","label"],additionalProperties:!1},toggle:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"},description:{description:"Description of the content configuration element",type:"string"}},required:["type","label"],additionalProperties:!1},select_box:{type:"object",properties:{type:{description:"Type of the content configuration element",type:"string",enum:["INPUTBOX","TEXTAREA","BUTTON","IMAGE","TOGGLE","SELECTBOX"]},label:{description:"Label of the content configuration element",type:"string"},placeholder:{description:"Placeholder of the content configuration element",type:"string"},description:{description:"Description of the content configuration element",type:"string"},options:{description:"Individual options of the content configuration element",type:"array",items:{type:"object",properties:{value:{description:"Value of the option",type:"string"},label:{description:"Label of the option",type:"string"}},required:["value","label"],additionalProperties:!1},minItems:1}},required:["type","label","placeholder","options"],additionalProperties:!1}},lt={$schema:we,$id:je,title:Oe,description:ve,type:Se,$defs:Ce},dt={__proto__:null,$defs:Ce,$id:je,$schema:we,default:lt,description:ve,title:Oe,type:Se},Ae="https://json-schema.org/draft/2020-12/schema",Le="https://lightspeedhq.com/template-custom-design.schema.json",Ne="Custom Section :: Design Configuration",De="Design tab configuration of a Custom Section for a Custom Template",Pe="object",Ie={text:{type:"object",properties:{type:{description:"Type of the text",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the text",type:"string"},colors:{description:"Color options for the text",type:"array",items:{type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"},minItems:1,uniqueItems:!0},sizes:{description:"Size options for the text",type:"array",items:{type:"integer",minimum:0,exclusiveMaximum:100},minItems:1,uniqueItems:!0},defaults:{description:"Default values for the text",type:"object",properties:{font:{description:"Default font for the text",type:"string"},size:{description:"Default size for the text",type:"integer",minimum:1,exclusiveMaximum:50},bold:{description:"Default boldness for the text",type:"boolean"},italic:{description:"Default italic style for the text",type:"boolean"},color:{description:"Default color for the text",type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{6}|[a-fA-F0-9]{3})$"},visible:{description:"Default visibility for the text",type:"boolean"}},required:["font","size","bold","italic","color","visible"],additionalProperties:!1}},required:["type","label","colors","sizes","defaults"],additionalProperties:!1},button:{type:"object",properties:{type:{description:"Type of the button",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the button",type:"string"},colors:{description:"Color options for the button",type:"array",items:{type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"},minItems:1,uniqueItems:!0},defaults:{description:"Default values for the button",type:"object",properties:{font:{description:"Default font for the button",type:"string"},size:{description:"Default size for the button",type:"string",enum:["SMALL","MEDIUM","LARGE"]},appearance:{description:"Default appearance for the button",type:"string",enum:["SOLID","OUTLINE","TEXT"]},shape:{description:"Default shape for the button",type:"string",enum:["ROUND_CORNER","RECTANGLE","PILL"]},color:{description:"Default color for the button",type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"}},required:["font","size","appearance","shape","color"],additionalProperties:!1}},required:["type","label","colors","defaults"],additionalProperties:!1},image:{type:"object",properties:{type:{description:"Type of the image",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the image",type:"string"},colors:{description:"Color options for the image",type:"array",items:{type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"},minItems:1,uniqueItems:!0},defaults:{description:"Default values for the image",type:"object",properties:{overlay:{description:"Default overlay for the image",type:"string",enum:["COLOR","GRADIENT","NONE"]},color:{description:"Default color for the image",type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"}},required:["overlay","color"],additionalProperties:!1}},required:["type","label","colors","defaults"],additionalProperties:!1},toggle:{type:"object",properties:{type:{description:"Type of the toggle",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the toggle",type:"string"},description:{description:"Description of the toggle",type:"string"},defaults:{description:"Default values for the toggle",type:"object",properties:{enabled:{description:"Default enabled status for the toggle",type:"boolean"}},required:["enabled"],additionalProperties:!1}},required:["type","label"],additionalProperties:!1},select_box:{type:"object",properties:{type:{description:"Type of the checkbox",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the checkbox",type:"string"},placeholder:{description:"Placeholder of the checkbox",type:"string"},description:{description:"Description of the checkbox",type:"string"},options:{description:"Individual options of the checkbox",type:"array",items:{type:"object",properties:{value:{description:"Value of the option",type:"string"},label:{description:"Label of the option",type:"string"}},required:["value","label"],additionalProperties:!1},minItems:1},defaults:{description:"Default values for the checkbox",type:"object",properties:{value:{description:"Default option for the checkbox",type:"string"}},required:["value"],additionalProperties:!1}},required:["type","label","placeholder","description","options","defaults"],additionalProperties:!1},background:{type:"object",properties:{type:{description:"Type of the background",type:"string",enum:["TEXT","BUTTON","IMAGE","TOGGLE","SELECTBOX","BACKGROUND"]},label:{description:"Label of the background",type:"string"},colors:{description:"Color options for the background",type:"array",items:{type:"string",pattern:"^#([a-fA-F0-9]{8}|[a-fA-F0-9]{3})$"},minItems:1,uniqueItems:!0},defaults:{description:"Default values for the background",type:"object",properties:{style:{description:"Default style for the background",type:"string",enum:["COLOR","GRADIENT"]},color:{description:"Default color style for the background",type:"string"}},required:["style","color"],additionalProperties:!1}},required:["type","label","colors","defaults"],additionalProperties:!1}},ft={$schema:Ae,$id:Le,title:Ne,description:De,type:Pe,$defs:Ie},ut={__proto__:null,$defs:Ie,$id:Le,$schema:Ae,default:ft,description:De,title:Ne,type:Pe};async function mt(){const e=await u("**/server.{js,ts}",{ignore:["node_modules/**","dist/**"]});return Promise.all(e.map(async t=>{const o=ze(t).split(Ke).pop()??"default",s=await u(`**/${o}/client.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),n=await u(`**/${o}/settings/content.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),i=await u(`**/${o}/settings/design.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),a=await u(`**/${o}/settings/translations.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),y=await u(`**/${o}/showcases/*.{js,ts}`,{ignore:["node_modules/**","dist/**",`**/${o}/showcases/translations.{js,ts}`]}),b=await u(`**/${o}/showcases/translations.{js,ts}`,{ignore:["node_modules/**","dist/**"]}),w=await u(`**/${o}/assets/*`,{ignore:["node_modules/**","dist/**"]});return{name:o,serverEntrypoint:t,clientEntrypoint:s.at(0),contentSettingsEntrypoint:n.at(0),designSettingsEntrypoint:i.at(0),settingsTranslationsEntrypoint:a.at(0),showcasesEntrypoints:y,showcasesTranslationsEntrypoint:b.at(0),assetsEntrypoints:w}}))}async function yt(){const e=await u("**/templates/**.{js,ts}",{ignore:["node_modules/**","dist/**"]}),t=await u("**/templates/assets/*",{ignore:["node_modules/**","dist/**"]});return{templates:e,assets:t}}async function B(e,t){try{const o=l(d.cwd(),t?`${e}${O}.mjs`:`${e}.mjs`);return(await import(j(o).href)).default}catch{throw new Error(`File [${e}${O}.mjs] is either invalid or undefined`)}}async function ht(){let e=new Ze({allErrors:!0,schemas:[pe,at,pt,dt,ut]});return Ye(e),e.compile(pe)}async function gt(e,t,o,s){if(e(t)&&s===void 0)new Promise(n=>{Ue(`${o}${O}.mjs`,`${o}.mjs`,function(i){i&&n(i)})});else throw new Promise(n=>{Me(`${o}${O}.mjs`,function(i){i&&n(i)})}),new Error(`Invalid file [${P(o).name}].
3
3
  Note: Errors regarding failingKeyword: "then" can sometimes be false negatives. Please focus on fixing other errors first!
4
- Errors: ${JSON.stringify([...e.errors??[],...n??[]],null,2)}`)}async function dt(e){const t=[];for(const o of e.sections){const n=e.sections.indexOf(o);if(n===0&&o.id!=="header"&&t.push({instancePath:`/sections/${n}/id`,message:"The first section must be a default `header`"}),n===e.sections.length-1&&o.id!=="footer"&&t.push({instancePath:`/sections/${n}/id`,message:"The last section must be a default `footer`"}),o.type==="custom")if(!A(`dist/sections/${o.id}`))t.push({instancePath:`/sections/${n}/id`,message:"Custom section must have a corresponding block defined"});else{if(o.content!==void 0)if(!A(`dist/sections/${o.id}/js/settings/content.mjs`))t.push({instancePath:`/sections/${n}/content`,message:"Content descriptor is overridden, please provide a default descriptor in the block's settings folder"});else{const s=await x(`dist/sections/${o.id}/js/settings/content`,!1),i=new Set(Object.keys(s));Object.keys(o.content).every(r=>i.has(r))||t.push({instancePath:`/sections/${n}/content`,message:"Content descriptor must be a subset of the default content descriptor"})}if(o.design!==void 0)if(!A(`dist/sections/${o.id}/js/settings/design.mjs`))t.push({instancePath:`/sections/${n}/design`,message:"Design descriptor is overridden, please provide a default descriptor in the block's settings folder"});else{const s=await x(`dist/sections/${o.id}/js/settings/design`,!1),i=new Set(Object.keys(s));Object.keys(o.design).every(r=>i.has(r))||t.push({instancePath:`/sections/${n}/design`,message:"Design descriptor must be a subset of the default design descriptor"})}}}return t.length===0?void 0:t}async function ft(){async function e(t,o,n){o.length!==0&&await D({configFile:!1,...I(k(t,o,n))})}try{const t=await at().then(n=>n.map(s=>({name:s.name,serverEntrypoint:s.serverEntrypoint,clientEntrypoint:[s.clientEntrypoint].filter(G).flat(),settingsEntryPoints:[s.contentSettingsEntrypoint,s.designSettingsEntrypoint,s.settingsTranslationsEntrypoint].filter(G),showcaseEntryPoints:[...s.showcasesEntrypoints??[],s.showcasesTranslationsEntrypoint].filter(G),assetEntryPoints:s.assetsEntrypoints??[]})));for(const n of t)await D({configFile:!1,...I(k(n.name,n.serverEntrypoint,u.Server))}),await e(n.name,n.clientEntrypoint,u.Client),await e(n.name,n.settingsEntryPoints,u.SectionSetting),await e(n.name,n.showcaseEntryPoints,u.SectionShowcase),await e(n.name,n.assetEntryPoints,u.SectionAsset);const o=await ct();if(o.entryPoints.length!==0){const n=await pt();await D({configFile:!1,...I(k(void 0,o.entryPoints,u.TemplateDescriptor))});for(const s of o.entryPoints){const i=`dist/template/js/${L(s).name}`,r=await x(i,!0);await lt(n,r,i,await dt(r))}}a.info("Build successful. For deploy run: npx @lightspeed/crane@latest deploy")}catch(t){a.error(`Error while building: ${t.message}`)}}function Le(e){if(e!==void 0)return e.startsWith("global.")?{type:"GLOBAL_FONT",font:e}:{type:"PRESET_FONT",font:e}}function E(e){if(e===void 0)return;if(e.startsWith("global."))return{type:"GLOBAL_COLOR",raw:e};const t=He(e);return{type:"STRUCTURED_COLOR",raw:e,hex:t.toHex8String(),hsl:t.toHsl(),rgba:t.toRgb(),auto:!1}}function ut(e){if(e!==void 0)return typeof e=="string"&&e.startsWith("global.")?{type:"GLOBAL_TEXT_SIZE",size:e}:{type:"NUMERIC_TEXT_SIZE",size:e}}const mt={COLOR:"COLOR",GRADIENT:"GRADIENT"};function yt(e){switch(e){case"COLOR":return"solid";case"GRADIENT":return"gradient";default:throw new Error(`Unknown background type: ${e}. Right options: ${Object.keys(mt)}`)}}function ht(e){const t=e.style,o=e.color,n=Array.isArray(o)?o:[o,o];return e.background={type:yt(t),solid:{color:E(n.at(0))},gradient:{fromColor:E(n.at(0)),toColor:E(n.at(1))}},e.style=void 0,e.color=void 0,e}const gt={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};function $t(e){switch(e){case"SOLID":return"solid-button";case"OUTLINE":return"outline-button";case"TEXT":return"text-link";default:throw new Error(`Unknown button appearance: ${e}. Right options: ${Object.keys(gt)}`)}}const Et={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};function Tt(e){switch(e){case"SMALL":return"small";case"MEDIUM":return"medium";case"LARGE":return"large";default:throw new Error(`Unknown button size: ${e}. Right options: ${Object.keys(Et)}`)}}const bt={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};function wt(e){switch(e){case"ROUND_CORNER":return"round-corner";case"RECTANGLE":return"rectangle";case"PILL":return"pill";default:throw new Error(`Unknown button shape: ${e}. Right options: ${Object.keys(bt)}`)}}function jt(e){const t=e.appearance;t!==void 0&&(e.appearance=$t(t));const o=e.size;o!==void 0&&(e.size=Tt(o));const n=e.shape;n!==void 0&&(e.style=wt(n),e.shape=void 0);const s=e.font;e.font=Le(s);const i=e.color;return e.color=E(i),e}const Ot={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};function vt(e){switch(e){case"COLOR":return"solid";case"GRADIENT":return"gradient";case"NONE":return"none";default:throw new Error(`Unknown image overlay type: ${e}. Right options: ${Object.keys(Ot)}`)}}function St(e){const t=e.overlay,o=e.color,n=Array.isArray(o)?o:[o,o];return e.overlay={type:vt(t),solid:{color:E(n.at(0))},gradient:{fromColor:E(n.at(0)),toColor:E(n.at(1))}},e.color=void 0,e}function Ct(e){const t=e.font;e.font=Le(t);const o=e.color;e.color=E(o);const n=e.size;return e.size=ut(n),e}function Lt(e){const t=e.color;return e.color=E(t),e}function Ae(e){Object.keys(e).forEach(t=>{const o=e[t],n=o.type;Ne(n,o.defaults)})}function At(e){Object.keys(e).forEach(t=>{const o=e[t],n=o.type;Ne(n,o)})}function Ne(e,t){switch(e){case"TEXT":{Ct(t);break}case"BUTTON":{jt(t);break}case"IMAGE":{St(t);break}case"BACKGROUND":{ht(t);break}case"COLOR_PICKER":{Lt(t);break}case"TOGGLE":case"SELECTBOX":break;default:throw new Error(`Unknown design editor type: ${e}`)}return t}var h=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.ClientAsset=2]="ClientAsset",e[e.Asset=3]="Asset",e[e.Dependency=4]="Dependency",e))(h||{});const O="dist/sections",v={[h.Server]:{type:"server_js",isSingleton:!0,toPath:e=>`${O}/${e}/js/main/server/`,fileName:"server.js"},[h.Client]:{type:"client_js",isSingleton:!1,toPath:e=>`${O}/${e}/js/main/client/`,fileName:"client.js"},[h.ClientAsset]:{type:"assets",isSingleton:!1,toPath:e=>`${O}/${e}/js/main/client/assets/`,fileName:"*"},[h.Asset]:{type:"assets",isSingleton:!1,toPath:e=>`${O}/${e}/assets/`,fileName:"*"},[h.Dependency]:{type:"dependencies",isSingleton:!0,toPath:()=>{},fileName:"package.json"}},Nt="https://blockbuster.ecwid.com",Dt="/api/v1/app/resource/upload",It="/api/v1/app/manifest";async function Pt(){const e=await M(l(d.cwd(),"crane.config.json")),t=JSON.parse(e.toString());return{appClientId:t.app_client_id,appSecretKey:btoa(t.app_secret_key)}}async function _t(){const e=l(d.cwd(),"package.json"),t=await M(e),o=JSON.parse(t.toString());if(Gt(o))return o;throw new Error(`Package file located at path: ${e} does not contain a version field`)}function Gt(e){return typeof e=="object"&&e!==null&&"version"in e&&typeof e.version=="string"}async function kt(e){const t=Je(e.version,"patch");if(t===null)throw Error("Error while incrementing app version");e.version=t,Ue(l(d.cwd(),"package.json"),`${JSON.stringify(e,null,2)}
5
- `)}async function xt(e,t){try{const o=(await import(l(d.cwd(),`dist/sections/${e}/js/settings/content.mjs`))).default;return j(o,t),o}catch{throw new Error(`Content descriptor for section [${e}] is either invalid or undefined`)}}async function Rt(e,t){try{const o=(await import(l(d.cwd(),`dist/sections/${e}/js/settings/design.mjs`))).default;return Ae(o),j(o,t),o}catch(o){const n=o;throw new Error(`Design settings is invalid or undefined. Error ${n.stack}`)}}async function Bt(e,t){try{const o=await y("*.mjs",{cwd:l(d.cwd(),`dist/sections/${e}/js/showcases/`),ignore:"**/translations.mjs"});return Promise.all(o.map(async n=>{const s=(await import(l(d.cwd(),`dist/sections/${e}/js/showcases/${n}`))).default;return At(s.design),j(s,t),s}))}catch(o){throw new Error(`Showcases is invalid or undefined. Error ${o}`)}}async function De(e){return await Ie(`dist/sections/${e}/js/settings/translations.mjs`)}async function Ut(e){return await Ie(`dist/sections/${e}/js/showcases/translations.mjs`)}async function Ie(e){const t=(await import(l(d.cwd(),e))).default;return Ft(t)}function j(e,t){if(e&&typeof e=="object"){const o=e;for(let n in o){const s=o[n];typeof s=="string"&&s.startsWith("$")&&(o[n]=Xt(t,s)),typeof s=="object"&&j(s,t)}}}function Xt(e,t){if(!t)return;const o=e[t];return o===void 0?{en:t}:o}function Ft(e){const t={};for(let o in e){const n=e[o];for(let s in n){const i=t[s],r=n[s];if(i===void 0){const m={};m[o]=r,t[s]=m}else i[o]=r}}return t}async function Mt(){const e=await y("*/",{cwd:l(d.cwd(),"dist/sections/")});return Promise.all(e.map(async t=>{const o=await De(t),n=await Ut(t),s=await xt(t,o),i=await Rt(t,o),r=await Bt(t,n);return{id:t,name:{en:t},contentEditors:s,designEditors:i,showcases:r}}))}async function qt(e){try{return(await import(l(d.cwd(),e))).default}catch{throw new Error(`Template descriptor [${e}] is either invalid or undefined`)}}async function zt(){const e=await y("dist/template/js/**.mjs",{ignore:[`dist/template/js/**${w}.mjs`]});return Promise.all(e.map(async t=>{const o=await qt(t),n=o.sections.filter(s=>s.type==="custom");for(const s of n){const i=await De(s.id);s.content!==void 0&&j(s.content,i),s.design!==void 0&&(Ae(s.design),j(s.design,i))}return{id:`${L(d.cwd()).name.replace(/[^a-zA-Z0-9]/g,"_")}_${L(t).name}`,descriptor:o}}))}function Kt(e){const t=e.pathContext,o=t.toPath(e.currentSection),n=o===void 0?U(t.fileName):U(t.fileName,{cwd:l(d.cwd(),o),ignore:t.ignore});return t.isSingleton?n.splice(0):n}function S(e){const t=Kt(e),o=e.pathContext.toPath(e.currentSection);return t.map(n=>e.config.axios.post(Dt,{file:Xe(l(d.cwd(),o!==void 0?o+n:n))},{params:{appClientId:e.config.app.crane.appClientId,type:e.pathContext.type,version:e.config.app.packageJson.version,...e.currentSection!==void 0&&{block:e.currentSection},...e.pathContext.type!=="dependencies"&&{fileName:n}},headers:{"Content-Type":"multipart/form-data",Authorization:`Bearer ${e.config.app.crane.appSecretKey}`}}).then(s=>s.data))}function Jt(e){return[...e.app.sections.flatMap(t=>[...S({config:e,currentSection:t.id,pathContext:v[h.Server]}),...S({config:e,currentSection:t.id,pathContext:v[h.Client]}),...S({config:e,currentSection:t.id,pathContext:v[h.ClientAsset]}),...S({config:e,currentSection:t.id,pathContext:v[h.Asset]})]),...S({config:e,pathContext:v[h.Dependency]})]}async function Ht(e){try{return e.axios.post(It,{version:e.app.packageJson.version,name:"Custom Block App",blocks:e.app.sections,templates:e.app.templates},{params:{appClientId:e.app.crane.appClientId},headers:{Authorization:`Bearer ${e.app.crane.appSecretKey}`}})}catch(t){a.error(`Error while deploying manifest file: ${t.message}`)}}async function Vt(e){try{if(!A(l(d.cwd(),O))){a.error("Error while deploying: dist/sections folder not found");return}const t=e??Nt;a.info(`Custom application deployment [${t}] :: Started`);const o=Ke.create({baseURL:t});a.info("Loading configuration files ...");const n=await Promise.all([Pt(),_t(),Mt(),zt()]).then(([i,r,m,T])=>({axios:o,app:{crane:i,packageJson:r,sections:m,templates:T}}));a.info("Uploading asset files ..."),await Promise.all(Jt(n)),a.info("Uploading manifest files ..."),await Ht(n);const s=n.app.sections.map(i=>i.id);a.info(`Custom application deployment [${t}] :: Successful
6
- Current app version: ${n.app.packageJson.version}
7
- Deployed sections: ${s.join(", ")}`),await kt(n.app.packageJson),n.app.templates.length>0&&a.info(`Deployed templates: ${n.app.templates.map(i=>i.id).join(", ")}`)}catch(t){a.error(`Error while deploying: ${t.message}`)}}const Wt="1.0.1",c=Pe("crane");function Zt(){c.command("init","Initialize a new resource in the form of a directory.").option("--app <name>","Creates an app folder inside your current directory.").option("--section <name>","Creates the files necessary for one custom section with the given name, this can be repeated for each section.").option("--template <name>","Creates the directory and files necessary to build a custom template inside your app folder.").action(e=>{if(e.app)return z(e.app);if(e.section)return K(e.section);if(e.template)return J(e.template);c.outputHelp()}),c.command("build","Builds your resource code").action(ft),c.command("deploy","Deploys your resource code into Ecwid"),c.on("command:*",()=>{console.error("Invalid command: %s",c.args.join(" ")),c.outputHelp(),process.exit(1)}),c.on("command:init",()=>{const e=c.options.section,t=c.options.app,o=c.options.template;B(t)?R("app",C("init --app <name>"),z):B(e)?R("section",C("init --section <name>"),K):B(o)&&R("template",C("init --template <name>"),J)}),c.on("command:deploy",()=>Vt(c.options.url)),c.help(),c.usage("<action> <resource>"),c.version(Wt),c.parse()}try{Zt()}catch{}async function R(e,t,o){const n=`You can use ${t} to directly specify the name of the ${e}.`;console.log(n);const s=await Ve({type:"text",name:"name",message:`Please specify a name for your ${e}:`});if(s.name)return o(s.name);console.log("Please provide a name for the template."),c.outputHelp()}function B(e){return e&&(typeof e!="string"||e.trim().length==0)}
4
+ Errors: ${JSON.stringify([...e.errors??[],...s??[]],null,2)}`)}async function $t(e){const t=[];for(const o of e.sections){const s=e.sections.indexOf(o);if(s===0&&o.id!=="header"&&t.push({instancePath:`/sections/${s}/id`,message:"The first section must be a default `header`"}),s===e.sections.length-1&&o.id!=="footer"&&t.push({instancePath:`/sections/${s}/id`,message:"The last section must be a default `footer`"}),o.type==="custom")if(!N(`${r}/${o.id}`))t.push({instancePath:`/sections/${s}/id`,message:"Custom section must have a corresponding block defined"});else{if(o.content!==void 0)if(!N(`${r}/${o.id}/js/settings/content.mjs`))t.push({instancePath:`/sections/${s}/content`,message:"Content descriptor is overridden, please provide a default descriptor in the block's settings folder"});else{const n=await B(`${r}/${o.id}/js/settings/content`,!1),i=new Set(Object.keys(n));Object.keys(o.content).every(a=>i.has(a))||t.push({instancePath:`/sections/${s}/content`,message:"Content descriptor must be a subset of the default content descriptor"})}if(o.design!==void 0)if(!N(`${r}/${o.id}/js/settings/design.mjs`))t.push({instancePath:`/sections/${s}/design`,message:"Design descriptor is overridden, please provide a default descriptor in the block's settings folder"});else{const n=await B(`${r}/${o.id}/js/settings/design`,!1),i=new Set(Object.keys(n));Object.keys(o.design).every(a=>i.has(a))||t.push({instancePath:`/sections/${s}/design`,message:"Design descriptor must be a subset of the default design descriptor"})}}}return t.length===0?void 0:t}function Et(e){const t=e.reduce((o,s)=>{const n=Fe(s);return n.size>V&&(o[s]=H(n.size)),o},{});if(Object.keys(t).length!==0){const o=Math.max(...Object.keys(t).map(s=>s.length));c.error(`Size of individual assets must not exceed threshold [${H(V)}]!`);for(let s in t)c.error(`File: ${s}`.padEnd(o+10)+`| ${t[s]}`);throw new Error("Invalid asset file size")}}async function Tt(){async function e(t,o,s){o.length!==0&&await F({configFile:!1,...X(te(t,o,s))})}try{const t=await mt().then(s=>s.map(n=>({name:n.name,serverEntrypoint:n.serverEntrypoint,clientEntrypoint:[n.clientEntrypoint].filter(k).flat(),settingsEntryPoints:[n.contentSettingsEntrypoint,n.designSettingsEntrypoint,n.settingsTranslationsEntrypoint].filter(k),showcaseEntryPoints:[...n.showcasesEntrypoints??[],n.showcasesTranslationsEntrypoint].filter(k),assetEntryPoints:n.assetsEntrypoints??[]})));for(const s of t)Et(s.assetEntryPoints),await F({configFile:!1,...X(te(s.name,s.serverEntrypoint,f.Server))}),await e(s.name,s.clientEntrypoint,f.Client),await e(s.name,s.settingsEntryPoints,f.SectionSetting),await e(s.name,s.showcaseEntryPoints,f.SectionShowcase),await e(s.name,s.assetEntryPoints,f.SectionAsset);const o=await yt();if(o.templates.length!==0){const s=await ht();await e(void 0,o.assets,f.TemplateAsset),await e(void 0,o.templates,f.TemplateDescriptor);for(const n of o.templates){const i=`${v}/js/${P(n).name}`,a=await B(i,!0);await gt(s,a,i,await $t(a))}}c.info("Build successful. For deploy run: npx @lightspeed/crane@latest deploy")}catch(t){c.error(`Error while building: ${t.message}`)}}function _e(e){if(e!==void 0)return e.startsWith("global.")?{type:"GLOBAL_FONT",font:e}:{type:"PRESET_FONT",font:e}}function T(e){if(e===void 0)return;if(e.startsWith("global."))return{type:"GLOBAL_COLOR",raw:e};const t=tt(e);return{type:"STRUCTURED_COLOR",raw:e,hex:t.toHex8String(),hsl:t.toHsl(),rgba:t.toRgb(),auto:!1}}function bt(e){if(e!==void 0)return typeof e=="string"&&e.startsWith("global.")?{type:"GLOBAL_TEXT_SIZE",size:e}:{type:"NUMERIC_TEXT_SIZE",size:e}}const wt={COLOR:"COLOR",GRADIENT:"GRADIENT"};function jt(e){switch(e){case"COLOR":return"solid";case"GRADIENT":return"gradient";default:throw new Error(`Unknown background type: ${e}. Right options: ${Object.keys(wt)}`)}}function Ot(e){const t=e.style,o=e.color,s=Array.isArray(o)?o:[o,o];return e.background={type:jt(t),solid:{color:T(s.at(0))},gradient:{fromColor:T(s.at(0)),toColor:T(s.at(1))}},e.style=void 0,e.color=void 0,e}const vt={SOLID:"SOLID",OUTLINE:"OUTLINE",TEXT:"TEXT"};function St(e){switch(e){case"SOLID":return"solid-button";case"OUTLINE":return"outline-button";case"TEXT":return"text-link";default:throw new Error(`Unknown button appearance: ${e}. Right options: ${Object.keys(vt)}`)}}const Ct={SMALL:"SMALL",MEDIUM:"MEDIUM",LARGE:"LARGE"};function At(e){switch(e){case"SMALL":return"small";case"MEDIUM":return"medium";case"LARGE":return"large";default:throw new Error(`Unknown button size: ${e}. Right options: ${Object.keys(Ct)}`)}}const Lt={ROUND_CORNER:"ROUND_CORNER",RECTANGLE:"RECTANGLE",PILL:"PILL"};function Nt(e){switch(e){case"ROUND_CORNER":return"round-corner";case"RECTANGLE":return"rectangle";case"PILL":return"pill";default:throw new Error(`Unknown button shape: ${e}. Right options: ${Object.keys(Lt)}`)}}function Dt(e){const t=e.appearance;t!==void 0&&(e.appearance=St(t));const o=e.size;o!==void 0&&(e.size=At(o));const s=e.shape;s!==void 0&&(e.style=Nt(s),e.shape=void 0);const n=e.font;e.font=_e(n);const i=e.color;return e.color=T(i),e}const Pt={COLOR:"COLOR",GRADIENT:"GRADIENT",NONE:"NONE"};function It(e){switch(e){case"COLOR":return"solid";case"GRADIENT":return"gradient";case"NONE":return"none";default:throw new Error(`Unknown image overlay type: ${e}. Right options: ${Object.keys(Pt)}`)}}function _t(e){const t=e.overlay,o=e.color,s=Array.isArray(o)?o:[o,o];return e.overlay={type:It(t),solid:{color:T(s.at(0))},gradient:{fromColor:T(s.at(0)),toColor:T(s.at(1))}},e.color=void 0,e}function Gt(e){const t=e.font;e.font=_e(t);const o=e.color;e.color=T(o);const s=e.size;return e.size=bt(s),e}function xt(e){const t=e.color;return e.color=T(t),e}function Ge(e){Object.keys(e).forEach(t=>{const o=e[t],s=o.type;xe(s,o.defaults)})}function kt(e){Object.keys(e).forEach(t=>{const o=e[t],s=o.type;xe(s,o)})}function xe(e,t){switch(e){case"TEXT":{Gt(t);break}case"BUTTON":{Dt(t);break}case"IMAGE":{_t(t);break}case"BACKGROUND":{Ot(t);break}case"COLOR_PICKER":{xt(t);break}case"TOGGLE":case"SELECTBOX":break;default:throw new Error(`Unknown design editor type: ${e}`)}return t}var m=(e=>(e[e.Server=0]="Server",e[e.Client=1]="Client",e[e.ClientAsset=2]="ClientAsset",e[e.Asset=3]="Asset",e[e.TemplateAsset=4]="TemplateAsset",e[e.Dependency=5]="Dependency",e))(m||{});const S={[m.Server]:{type:"server_js",isSingleton:!0,toPath:e=>`${r}/${e}/js/main/server/`,fileName:"server.js"},[m.Client]:{type:"client_js",isSingleton:!1,toPath:e=>`${r}/${e}/js/main/client/`,fileName:"client.js"},[m.ClientAsset]:{type:"assets",isSingleton:!1,toPath:e=>`${r}/${e}/js/main/client/assets/`,fileName:"*"},[m.Asset]:{type:"assets",isSingleton:!1,toPath:e=>`${r}/${e}/assets/`,fileName:"*"},[m.TemplateAsset]:{type:"template_assets",isSingleton:!1,toPath:()=>`${v}/assets/`,fileName:"*"},[m.Dependency]:{type:"dependencies",isSingleton:!0,toPath:()=>{},fileName:"package.json"}},Bt="https://blockbuster.ecwid.com",Rt="/api/v1/app/resource/upload",Ut="/api/v1/app/manifest";async function Mt(){const e=await K(l(d.cwd(),"crane.config.json")),t=JSON.parse(e.toString());return{appClientId:t.app_client_id,appSecretKey:btoa(t.app_secret_key)}}async function Ft(){const e=l(d.cwd(),"package.json"),t=await K(e),o=JSON.parse(t.toString());if(Xt(o))return o;throw new Error(`Package file located at path: ${e} does not contain a version field`)}function Xt(e){return typeof e=="object"&&e!==null&&"version"in e&&typeof e.version=="string"}async function qt(e){const t=et(e.version,"patch");if(t===null)throw Error("Error while incrementing app version");e.version=t,Xe(l(d.cwd(),"package.json"),`${JSON.stringify(e,null,2)}
5
+ `)}async function zt(e,t){try{const o=l(d.cwd(),`${r}/${e}/js/settings/content.mjs`),s=(await import(j(o).href)).default;return C(s,t),s}catch{throw new Error(`Content descriptor for section [${e}] is either invalid or undefined`)}}async function Kt(e,t){try{const o=l(d.cwd(),`${r}/${e}/js/settings/design.mjs`),s=(await import(j(o).href)).default;return Ge(s),C(s,t),s}catch(o){const s=o;throw new Error(`Design settings is invalid or undefined. Error ${s.stack}`)}}async function Jt(e,t){try{const o=await u("*.mjs",{cwd:l(d.cwd(),`${r}/${e}/js/showcases/`),ignore:"**/translations.mjs"});return Promise.all(o.map(async s=>{const n=l(d.cwd(),`${r}/${e}/js/showcases/${s}`),i=(await import(j(n).href)).default;return kt(i.design),C(i,t),i}))}catch(o){throw new Error(`Showcases is invalid or undefined. Error ${o}`)}}async function ke(e){return await Be(`${r}/${e}/js/settings/translations.mjs`)}async function Ht(e){return await Be(`${r}/${e}/js/showcases/translations.mjs`)}async function Be(e){const t=l(d.cwd(),e),o=(await import(j(t).href)).default;return Wt(o)}function C(e,t){if(e&&typeof e=="object"){const o=e;for(let s in o){const n=o[s];typeof n=="string"&&n.startsWith("$")&&(o[s]=Vt(t,n)),typeof n=="object"&&C(n,t)}}}function Vt(e,t){if(!t)return;const o=e[t];return o===void 0?{en:t}:o}function Wt(e){const t={};for(let o in e){const s=e[o];for(let n in s){const i=t[n],a=s[n];if(i===void 0){const y={};y[o]=a,t[n]=y}else i[o]=a}}return t}async function Zt(){const e=await u("*/",{cwd:l(d.cwd(),`${r}/`)});return Promise.all(e.map(async t=>{const o=await ke(t),s=await Ht(t),n=await zt(t,o),i=await Kt(t,o),a=await Jt(t,s);return{id:t,name:{en:t},contentEditors:n,designEditors:i,showcases:a}}))}async function Yt(e){try{return(await import(j(l(d.cwd(),e)).href)).default}catch{throw new Error(`Template descriptor [${e}] is either invalid or undefined`)}}async function Qt(){const e=await u(`${v}/js/**.mjs`,{ignore:[`${v}/js/**${O}.mjs`]});return Promise.all(e.map(async t=>{const o=await Yt(t),s=o.sections.filter(n=>n.type==="custom");for(const n of s){const i=await ke(n.id);n.content!==void 0&&C(n.content,i),n.design!==void 0&&(Ge(n.design),C(n.design,i))}return{id:`${P(d.cwd()).name.replace(/[^a-zA-Z0-9]/g,"_")}_${P(t).name}`,descriptor:o}}))}function eo(e){const t=e.pathContext,o=t.toPath(e.currentSection),s=o===void 0?M(t.fileName):M(t.fileName,{cwd:l(d.cwd(),o),ignore:t.ignore});return t.isSingleton?s.splice(0):s}function A(e){const t=eo(e),o=e.pathContext.toPath(e.currentSection);return t.map(s=>e.config.axios.post(Rt,{file:qe(l(d.cwd(),o!==void 0?o+s:s))},{params:{appClientId:e.config.app.crane.appClientId,type:e.pathContext.type,version:e.config.app.packageJson.version,...e.currentSection!==void 0&&{block:e.currentSection},...e.pathContext.type!=="dependencies"&&{fileName:s}},headers:{"Content-Type":"multipart/form-data",Authorization:`Bearer ${e.config.app.crane.appSecretKey}`}}).then(n=>n.data))}function to(e){return[...e.app.sections.flatMap(t=>[...A({config:e,currentSection:t.id,pathContext:S[m.Server]}),...A({config:e,currentSection:t.id,pathContext:S[m.Client]}),...A({config:e,currentSection:t.id,pathContext:S[m.ClientAsset]}),...A({config:e,currentSection:t.id,pathContext:S[m.Asset]})]),...A({config:e,pathContext:S[m.Dependency]}),...A({config:e,pathContext:S[m.TemplateAsset]})]}async function oo(e){try{return e.axios.post(Ut,{version:e.app.packageJson.version,name:"Custom Block App",blocks:e.app.sections,templates:e.app.templates},{params:{appClientId:e.app.crane.appClientId},headers:{Authorization:`Bearer ${e.app.crane.appSecretKey}`}})}catch(t){c.error(`Error while deploying manifest file: ${t.message}`)}}async function so(e){try{if(!N(l(d.cwd(),r))){c.error(`Error while deploying: ${r} folder not found`);return}const t=e??Bt;c.info(`Custom application deployment [${t}] :: Started`);const o=Qe.create({baseURL:t});c.info("Loading configuration files ...");const s=await Promise.all([Mt(),Ft(),Zt(),Qt()]).then(([i,a,y,b])=>({axios:o,app:{crane:i,packageJson:a,sections:y,templates:b}}));c.info("Uploading asset files ..."),await Promise.all(to(s)),c.info("Uploading manifest files ..."),await oo(s);const n=s.app.sections.map(i=>i.id);c.info(`Custom application deployment [${t}] :: Successful
6
+ Current app version: ${s.app.packageJson.version}
7
+ Deployed sections: ${n.join(", ")}`),await qt(s.app.packageJson),s.app.templates.length>0&&c.info(`Deployed templates: ${s.app.templates.map(i=>i.id).join(", ")}`)}catch(t){c.error(`Error while deploying: ${t.message}`)}}const no="1.0.2",p=Re("crane");function io(){p.command("init","Initialize a new resource in the form of a directory.").option("--app <name>","Creates an app folder inside your current directory.").option("--section <name>","Creates the files necessary for one custom section with the given name, this can be repeated for each section.").option("--template <name>","Creates the directory and files necessary to build a custom template inside your app folder.").action(e=>{if(e.app)return W(e.app);if(e.section)return Z(e.section);if(e.template)return Y(e.template);p.outputHelp()}),p.command("build","Builds your resource code").action(Tt),p.command("deploy","Deploys your resource code into Ecwid"),p.on("command:*",()=>{console.error("Invalid command: %s",p.args.join(" ")),p.outputHelp(),process.exit(1)}),p.on("command:init",()=>{const e=p.options.section,t=p.options.app,o=p.options.template;U(t)?R("app",I("init --app <name>"),W):U(e)?R("section",I("init --section <name>"),Z):U(o)&&R("template",I("init --template <name>"),Y)}),p.on("command:deploy",()=>so(p.options.url)),p.help(),p.usage("<action> <resource>"),p.version(no),p.parse()}try{io()}catch{}async function R(e,t,o){const s=`You can use ${t} to directly specify the name of the ${e}.`;console.log(s);const n=await ot({type:"text",name:"name",message:`Please specify a name for your ${e}:`});if(n.name)return o(n.name);console.log("Please provide a name for the template."),p.outputHelp()}function U(e){return e&&(typeof e!="string"||e.trim().length==0)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightspeed/crane",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "bin": "bin/crane.js",
6
6
  "main": "./dist/app.mjs",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@jridgewell/sourcemap-codec": "^1.4.15",
52
- "@lightspeed/eslint-config-crane": "1.0.1",
52
+ "@lightspeed/eslint-config-crane": "1.0.2",
53
53
  "@types/prompts": "^2.4.2",
54
54
  "@vitejs/plugin-vue": "^4.1.0",
55
55
  "ajv": "^8.12.0",
@@ -7,8 +7,8 @@
7
7
  "deploy": "crane build && crane deploy"
8
8
  },
9
9
  "dependencies": {
10
- "@lightspeed/crane": "1.0.1",
11
- "@lightspeed/eslint-config-crane": "1.0.1",
10
+ "@lightspeed/crane": "1.0.2",
11
+ "@lightspeed/eslint-config-crane": "1.0.2",
12
12
  "vue": "^3.4.0"
13
13
  },
14
14
  "engines": {
@@ -2,9 +2,13 @@ export default {
2
2
  metadata: {
3
3
  name: 'Example Template :: Standard Preset',
4
4
  description: 'Standard Preset for the Example template',
5
- url: {
6
- demo_website: 'https://www.example.com',
7
- cover_image: 'https://www.example.com/cover.jpg'
5
+ test_site_id: 1,
6
+ cover_image: {
7
+ set: {
8
+ ORIGINAL: {
9
+ url: 'template_cover_image.png',
10
+ },
11
+ }
8
12
  }
9
13
  },
10
14
  sections: [
package/types.d.ts CHANGED
@@ -16,7 +16,7 @@ type ButtonType =
16
16
 
17
17
  interface ButtonContentData {
18
18
  readonly title: string;
19
- readonly buttonType: ButtonType;
19
+ readonly type: ButtonType;
20
20
  readonly link?: string;
21
21
  readonly email?: string;
22
22
  readonly phone?: string;