storyblok-generator
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -1,2 +0,2 @@ | ||
"use strict";var O=Object.create;var $=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var q=(e,t)=>{for(var o in t)$(e,o,{get:t[o],enumerable:!0})},B=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of H(t))!Z.call(e,n)&&n!==o&&$(e,n,{get:()=>t[n],enumerable:!(s=W(t,n))||s.enumerable});return e};var E=(e,t,o)=>(o=e!=null?O(V(e)):{},B(t||!e||!e.__esModule?$(o,"default",{value:e,enumerable:!0}):o,e)),I=e=>B($({},"__esModule",{value:!0}),e);var ee={};q(ee,{storyblokPlugin:()=>L});module.exports=I(ee);var F=require("child_process"),a=require("fs"),j=require("fs/promises"),r=E(require("path")),p=E(require("chalk")),v=require("vite"),d=process.env.NODE_ENV==="development"?console.log:()=>{},K=process.env.NODE_ENV==="development"?console.error:()=>{},S=async e=>{try{return await a.promises.readFile(e,"utf8")}catch{return null}},z=async({inputFile:e,outputDir:t,cwd:o,typeFile:s,fileNameConvention:n,componentAs:m,debug:f})=>{let y=o??process.cwd(),b=r.default.relative(y,t),g=await S(r.default.resolve(y,e));if(!g){K(`Component file ${e} not found`);return}let i=JSON.parse(g).components;if(await(0,j.mkdir)(b,{recursive:!0}),i.length===0){d(p.default.red(`No components found in ${e}`));return}let T=(await Promise.all(i.map(async l=>{let u=l?.name,C=M(u),c=C===C.toUpperCase()?C.toLowerCase().replace(/^./,C[0]):C,w=n==="kebab-case"?c.match(/[A-Z][a-z]+/g)?.map(A=>A.toLowerCase()).join("-")??c:c,h=r.default.join(t,m==="folder"?`${w}/${w}.tsx`:`${w}.tsx`),x={name:c,originalName:l.name,fileName:w};if(await Y(h)&&f)return d(`\u26A0\uFE0F Component ${p.default.yellow(u)} already exists. Skipping...`),x;let _=l?.schema?.body,D=l?.schema?.columns,G=(0,v.normalizePath)(r.default.relative(h,s).replace("..\\","")).replace(".d.ts",""),R=await S(h),N=[`import { type SbBlokData, storyblokEditable${_||D?", StoryblokComponent":""} } from "@storyblok/react";`,`import type { ${c}Storyblok } from "${G}";`,"",`export const ${c} = ({ blok }: { blok: ${c}Storyblok }) => {`," return ("," <div {...storyblokEditable(blok as SbBlokData)} key={blok._uid}>",X(l)," </div>"," )","};","",`export default ${c}`].join(` | ||
"use strict";var O=Object.create;var $=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var q=(e,t)=>{for(var o in t)$(e,o,{get:t[o],enumerable:!0})},B=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of H(t))!Z.call(e,n)&&n!==o&&$(e,n,{get:()=>t[n],enumerable:!(s=W(t,n))||s.enumerable});return e};var E=(e,t,o)=>(o=e!=null?O(V(e)):{},B(t||!e||!e.__esModule?$(o,"default",{value:e,enumerable:!0}):o,e)),I=e=>B($({},"__esModule",{value:!0}),e);var ee={};q(ee,{storyblokPlugin:()=>L});module.exports=I(ee);var F=require("child_process"),a=require("fs"),j=require("fs/promises"),r=E(require("path")),p=E(require("chalk")),v=require("vite"),d=process.env.NODE_ENV==="development"?console.log:()=>{},K=process.env.NODE_ENV==="development"?console.error:()=>{},S=async e=>{try{return await a.promises.readFile(e,"utf8")}catch{return null}},z=async({inputFile:e,outputDir:t,cwd:o,typeFile:s,fileNameConvention:n,componentAs:m,debug:f})=>{let y=o??process.cwd(),b=r.default.relative(y,t),g=await S(r.default.resolve(y,e));if(!g){K(`Component file ${e} not found`);return}let i=JSON.parse(g).components;if(await(0,j.mkdir)(b,{recursive:!0}),i.length===0){d(p.default.red(`No components found in ${e}`));return}let T=(await Promise.all(i.map(async l=>{let u=l?.name,C=M(u),c=C===C.toUpperCase()?C.toLowerCase().replace(/^./,C[0]):C,w=n==="kebab-case"?c.match(/[A-Z][a-z]+/g)?.map(A=>A.toLowerCase()).join("-")??c:c,h=r.default.join(t,m==="folder"?`${w}/${w}.tsx`:`${w}.tsx`),x={name:c,originalName:l.name,fileName:w};if(await Y(h))return f&&d(`\u26A0\uFE0F Component ${p.default.yellow(u)} already exists. Skipping...`),x;let _=l?.schema?.body,D=l?.schema?.columns,G=(0,v.normalizePath)(r.default.relative(h,s).replace("..\\","")).replace(".d.ts",""),R=await S(h),N=[`import { type SbBlokData, storyblokEditable${_||D?", StoryblokComponent":""} } from "@storyblok/react";`,`import type { ${c}Storyblok } from "${G}";`,"",`export const ${c} = ({ blok }: { blok: ${c}Storyblok }) => {`," return ("," <div {...storyblokEditable(blok as SbBlokData)} key={blok._uid}>",X(l)," </div>"," )","};","",`export default ${c}`].join(` | ||
`);return R!==N&&(m==="folder"&&await a.promises.mkdir(r.default.dirname(h),{recursive:!0}),await a.promises.writeFile(h,N),d(p.default.green(`Component ${u} created`))),x}))).filter(Boolean),U=await S(r.default.join(t,"index.ts")),P=['import { lazy } from "react"',"","export const components = {",T.map(({fileName:l,originalName:u})=>` ${Q(u)?`"${u}"`:u}: lazy(() => import("./${m==="folder"?`${l}/${l}`:l}")),`).join(` | ||
@@ -3,0 +3,0 @@ `),"};"].join(` |
{ | ||
"name": "storyblok-generator", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Generate Storyblok components out of your components.json file and get full type-safety and bundle splitting out of the box", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
54891