@veluai/velu 0.1.3 → 0.1.4

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/cli.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- var me=Object.defineProperty;var g=(e,t)=>()=>(e&&(t=e(e=0)),t);var j=(e,t)=>{for(var o in t)me(e,o,{get:t[o],enumerable:!0})};var R={};j(R,{initProject:()=>ye});import y from"node:fs/promises";import w from"node:path";import{fileURLToPath as ge}from"node:url";async function ye(e,t){try{if((await y.readdir(e)).length>0)throw new Error(`Directory "${t}" already exists and is not empty. Choose a different name or remove the folder first.`)}catch(i){if(i.code!=="ENOENT")throw i}await y.mkdir(e,{recursive:!0}),await y.cp(ve,e,{recursive:!0});let o=w.join(e,"velu.json"),n=JSON.parse(await y.readFile(o,"utf-8"));n.name=t,await y.writeFile(o,JSON.stringify(n,null,2)+`
3
- `,"utf-8");let r=await L(e);console.log(`[velu] created ${t}/`);for(let i of r)console.log(` ${i}`);console.log(""),console.log("Next steps:"),console.log(` cd ${t}`),console.log(" velu dev")}async function L(e,t=e,o=[]){let n=await y.readdir(e,{withFileTypes:!0});for(let r of n){let i=w.join(e,r.name);r.isDirectory()?await L(i,t,o):o.push(w.relative(t,i).split(w.sep).join("/"))}return o.sort()}var he,ve,_=g(()=>{he=w.dirname(ge(import.meta.url)),ve=w.resolve(he,"..","templates","starter")});import{visit as we}from"unist-util-visit";import{toString as xe}from"mdast-util-to-string";import be from"github-slugger";import{valueToEstree as Se}from"estree-util-value-to-estree";function E(){return e=>{let t=new be,o=[];we(e,"heading",s=>{let l=xe(s);o.push({depth:s.depth,id:t.slug(l),label:l})});let n={children:[]},r=[{node:n,depth:0}];for(let s of o){for(;r.length>1&&r[r.length-1].depth>=s.depth;)r.pop();let l={id:s.id,label:s.label},a=r[r.length-1].node;a.children||(a.children=[]),a.children.push(l),r.push({node:l,depth:s.depth})}let i=n.children;e.children.unshift({type:"mdxjsEsm",value:"",data:{estree:{type:"Program",sourceType:"module",body:[{type:"ExportNamedDeclaration",specifiers:[],declaration:{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"toc"},init:Se(i)}]}}]}}})}}var C=g(()=>{});import ke from"node:fs/promises";import I from"node:path";function N(e={},t){let o=e.colors?.primary??$e;return{name:e.name??t??"docs",colors:{primary:o,light:e.colors?.light??o,dark:e.colors?.dark??o},favicon:e.favicon??null,font:{family:e.font?.family??Pe},navigation:e.navigation??null}}async function z(e){let t=I.join(e,"velu.json"),o;try{o=await ke.readFile(t,"utf-8")}catch(r){throw r.code==="ENOENT"?new Error(`No velu.json found in ${e}. Run \`velu init <name>\` to scaffold one.`):r}let n;try{n=JSON.parse(o)}catch(r){throw new Error(`velu.json is not valid JSON: ${r.message}`)}return N(n,I.basename(e))}function V(e){let{colors:t,font:o}=e;return[":root:root {",` --accent-color: ${t.light};`,` --font-sans: "${o.family}", sans-serif;`,"}",':root:root[data-theme="dark"] {',` --accent-color: ${t.dark};`,"}"].join(`
4
- `)}var $e,Pe,B=g(()=>{$e="#dc143c",Pe="Google Sans Flex"});import Ae from"github-slugger";import Te from"iso-639-1";function Ne(e){let t=String(e).toLowerCase();return Te.getNativeName(t)||e}function P(e){return new Ae().slug(String(e??""))}function Fe(e){let t=String(e).replace(/^\/+|\/+$/g,"").split("/").filter(Boolean);return t[t.length-1]==="index"&&t.pop(),"/"+t.join("/")}function G(e){let t={kind:"root",children:b(e??{})};return D(t.children),t}function b(e){let t=Array.isArray(e.anchors)?e.anchors.map(Re):[];if(Array.isArray(e.products))return[...t,...e.products.map(Oe)];if(Array.isArray(e.versions))return[...t,...e.versions.map(Ue)];if(Array.isArray(e.languages))return[...t,...e.languages.map(je)];if(Array.isArray(e.tabs))return[...t,...e.tabs.map(Le)];let o=[...t];return Array.isArray(e.groups)&&o.push(...e.groups.map(M)),Array.isArray(e.pages)&&o.push(...e.pages.map(J)),o}function Oe(e){return{kind:"product",label:e.name??e.product,slug:P(e.product),icon:e.icon,color:e.color,default:!!e.default,children:b(e)}}function Ue(e){return{kind:"version",label:e.version,slug:P(e.version),default:!!e.default,children:b(e)}}function je(e){let t=String(e.language);return{kind:"language",code:t,label:Ne(t),slug:P(t),default:!!e.default,children:b(e)}}function Le(e){return{kind:"tab",label:e.tab,slug:P(e.tab),icon:e.icon,href:e.href,children:b(e)}}function Re(e){return{kind:"anchor",label:e.anchor,icon:e.icon,href:e.href,color:e.color}}function M(e){let t=(e.pages??[]).map(J);return e.root&&t.unshift({kind:"page",pagePath:e.root}),{kind:"group",label:e.group,icon:e.icon,expanded:!!e.expanded,root:e.root,children:t}}function J(e){return typeof e=="string"?{kind:"page",pagePath:e}:M(e)}function D(e){for(let t of Ee){let o=e.filter(n=>n.kind===t);o.length&&!o.some(n=>n.default)&&(o[0].default=!0)}for(let t of e)t.children&&D(t.children)}function q(e){let t=[],o=(n,r,i)=>{if(n.kind==="page"){t.push({pagePath:n.pagePath,url:_e(n.pagePath,r),ctx:{...r},ancestors:i,node:n});return}let s=r;n.kind==="product"?s={...r,product:n.default?null:n.slug}:n.kind==="version"?s={...r,version:n.default?null:n.slug}:n.kind==="language"&&(s={...r,language:n.default?null:n.slug});let l=n.kind==="root"?i:[...i,n];for(let a of n.children??[])o(a,s,l)};return o(e,{product:null,version:null,language:null},[]),t}function _e(e,t){let o=[t.product,t.version,t.language].filter(Boolean),n=Fe(e).split("/").filter(Boolean);return"/"+[...o,...n].join("/")}var Ee,F=g(()=>{Ee=["product","version","language"]});import Ce from"node:fs";import H from"node:path";function W(e,t){let o=[],n=[],r=new Set;for(let i of q(e)){if(r.has(i.url)){o.push(`duplicate URL "${i.url}" (page "${i.pagePath}") \u2014 keeping the first occurrence`);continue}r.add(i.url);let s=i.pagePath.replace(/^\/+|\/+$/g,""),l=H.join(t,...s.split("/"))+".mdx",a=Ce.existsSync(l);a||o.push(`page "${i.pagePath}" \u2192 ${H.relative(t,l)} not found`),n.push({pagePath:i.pagePath,url:i.url,fileAbsPath:l,exists:a})}return{pageEntries:n,warnings:o}}var Y=g(()=>{F()});import Ie from"node:fs";import K from"node:path";function Z(e){return{name:"velu-site",resolveId(t){return t===Q?X:null},load(t){return t!==X?null:ze(e)}}}function ze(e){let t={};try{t=JSON.parse(Ie.readFileSync(K.join(e,"velu.json"),"utf-8"))}catch{}let o=G(t.navigation??{}),{pageEntries:n,warnings:r}=W(o,e);for(let a of r)console.warn(`[velu] nav: ${a}`);let i=[],s=[],l=0;for(let a of n)if(a.exists){let A=JSON.stringify(a.fileAbsPath.split(K.sep).join("/")),p=`__p${l++}`;i.push(`import * as ${p} from ${A};`),s.push(` ${JSON.stringify(a.url)}: { Component: ${p}.default, frontmatter: ${p}.frontmatter, toc: ${p}.toc },`)}else s.push(` ${JSON.stringify(a.url)}: { missing: true },`);return["// AUTO-GENERATED by vite-plugin-velu-site. Do not edit.",i.join(`
2
+ var we=Object.defineProperty;var g=(e,t)=>()=>(e&&(t=e(e=0)),t);var R=(e,t)=>{for(var o in t)we(e,o,{get:t[o],enumerable:!0})};var _={};R(_,{initProject:()=>ke});import w from"node:fs/promises";import x from"node:path";import{fileURLToPath as xe}from"node:url";async function ke(e,t){try{if((await w.readdir(e)).length>0)throw new Error(`Directory "${t}" already exists and is not empty. Choose a different name or remove the folder first.`)}catch(i){if(i.code!=="ENOENT")throw i}await w.mkdir(e,{recursive:!0}),await w.cp(Se,e,{recursive:!0});let o=x.join(e,"velu.json"),r=JSON.parse(await w.readFile(o,"utf-8"));r.name=t,await w.writeFile(o,JSON.stringify(r,null,2)+`
3
+ `,"utf-8");let n=await I(e);console.log(`[velu] created ${t}/`);for(let i of n)console.log(` ${i}`);console.log(""),console.log("Next steps:"),console.log(` cd ${t}`),console.log(" velu dev")}async function I(e,t=e,o=[]){let r=await w.readdir(e,{withFileTypes:!0});for(let n of r){let i=x.join(e,n.name);n.isDirectory()?await I(i,t,o):o.push(x.relative(t,i).split(x.sep).join("/"))}return o.sort()}var be,Se,C=g(()=>{be=x.dirname(xe(import.meta.url)),Se=x.resolve(be,"..","templates","starter")});import{visit as $e}from"unist-util-visit";import{toString as Pe}from"mdast-util-to-string";import Ae from"github-slugger";import{valueToEstree as Te}from"estree-util-value-to-estree";function L(){return e=>{let t=new Ae,o=[];$e(e,"heading",s=>{let l=Pe(s);o.push({depth:s.depth,id:t.slug(l),label:l})});let r={children:[]},n=[{node:r,depth:0}];for(let s of o){for(;n.length>1&&n[n.length-1].depth>=s.depth;)n.pop();let l={id:s.id,label:s.label},a=n[n.length-1].node;a.children||(a.children=[]),a.children.push(l),n.push({node:l,depth:s.depth})}let i=r.children;e.children.unshift({type:"mdxjsEsm",value:"",data:{estree:{type:"Program",sourceType:"module",body:[{type:"ExportNamedDeclaration",specifiers:[],declaration:{type:"VariableDeclaration",kind:"const",declarations:[{type:"VariableDeclarator",id:{type:"Identifier",name:"toc"},init:Te(i)}]}}]}}})}}var V=g(()=>{});import Ee from"node:fs/promises";import z from"node:path";function O(e={},t){let o=e.colors?.primary??Fe;return{name:e.name??t??"docs",colors:{primary:o,light:e.colors?.light??o,dark:e.colors?.dark??o},favicon:e.favicon??null,font:{family:e.font?.family??Le},navigation:e.navigation??null}}async function B(e){let t=z.join(e,"velu.json"),o;try{o=await Ee.readFile(t,"utf-8")}catch(n){throw n.code==="ENOENT"?new Error(`No velu.json found in ${e}. Run \`velu init <name>\` to scaffold one.`):n}let r;try{r=JSON.parse(o)}catch(n){throw new Error(`velu.json is not valid JSON: ${n.message}`)}return O(r,z.basename(e))}function G(e){let{colors:t,font:o}=e;return[":root:root {",` --accent-color: ${t.light};`,` --font-sans: "${o.family}", sans-serif;`,"}",':root:root[data-theme="dark"] {',` --accent-color: ${t.dark};`,"}"].join(`
4
+ `)}var Fe,Le,M=g(()=>{Fe="#dc143c",Le="Google Sans Flex"});import Oe from"github-slugger";import Ne from"iso-639-1";function je(e){let t=String(e).toLowerCase();return Ne.getNativeName(t)||e}function E(e){return new Oe().slug(String(e??""))}function Re(e){let t=String(e).replace(/^\/+|\/+$/g,"").split("/").filter(Boolean);return t[t.length-1]==="index"&&t.pop(),"/"+t.join("/")}function J(e){let t={kind:"root",children:k(e??{})};return H(t.children),t}function k(e){let t=Array.isArray(e.anchors)?e.anchors.map(ze):[];if(Array.isArray(e.products))return[...t,...e.products.map(Ie)];if(Array.isArray(e.versions))return[...t,...e.versions.map(_e)];if(Array.isArray(e.languages))return[...t,...e.languages.map(Ce)];if(Array.isArray(e.tabs))return[...t,...e.tabs.map(Ve)];let o=[...t];return Array.isArray(e.groups)&&o.push(...e.groups.map(q)),Array.isArray(e.pages)&&o.push(...e.pages.map(D)),o}function Ie(e){return{kind:"product",label:e.name??e.product,slug:E(e.product),icon:e.icon,color:e.color,default:!!e.default,children:k(e)}}function _e(e){return{kind:"version",label:e.version,slug:E(e.version),default:!!e.default,children:k(e)}}function Ce(e){let t=String(e.language);return{kind:"language",code:t,label:je(t),slug:E(t),default:!!e.default,children:k(e)}}function Ve(e){return{kind:"tab",label:e.tab,slug:E(e.tab),icon:e.icon,href:e.href,children:k(e)}}function ze(e){return{kind:"anchor",label:e.anchor,icon:e.icon,href:e.href,color:e.color}}function q(e){let t=(e.pages??[]).map(D);return e.root&&t.unshift({kind:"page",pagePath:e.root}),{kind:"group",label:e.group,icon:e.icon,expanded:!!e.expanded,root:e.root,children:t}}function D(e){return typeof e=="string"?{kind:"page",pagePath:e}:q(e)}function H(e){for(let t of Ue){let o=e.filter(r=>r.kind===t);o.length&&!o.some(r=>r.default)&&(o[0].default=!0)}for(let t of e)t.children&&H(t.children)}function W(e){let t=[],o=(r,n,i)=>{if(r.kind==="page"){t.push({pagePath:r.pagePath,url:Be(r.pagePath,n),ctx:{...n},ancestors:i,node:r});return}let s=n;r.kind==="product"?s={...n,product:r.default?null:r.slug}:r.kind==="version"?s={...n,version:r.default?null:r.slug}:r.kind==="language"&&(s={...n,language:r.default?null:r.slug});let l=r.kind==="root"?i:[...i,r];for(let a of r.children??[])o(a,s,l)};return o(e,{product:null,version:null,language:null},[]),t}function Be(e,t){let o=[t.product,t.version,t.language].filter(Boolean),r=Re(e).split("/").filter(Boolean);return"/"+[...o,...r].join("/")}var Ue,N=g(()=>{Ue=["product","version","language"]});import Ge from"node:fs";import Y from"node:path";function K(e,t){let o=[],r=[],n=new Set;for(let i of W(e)){if(n.has(i.url)){o.push(`duplicate URL "${i.url}" (page "${i.pagePath}") \u2014 keeping the first occurrence`);continue}n.add(i.url);let s=i.pagePath.replace(/^\/+|\/+$/g,""),l=Y.join(t,...s.split("/"))+".mdx",a=Ge.existsSync(l);a||o.push(`page "${i.pagePath}" \u2192 ${Y.relative(t,l)} not found`),r.push({pagePath:i.pagePath,url:i.url,fileAbsPath:l,exists:a})}return{pageEntries:r,warnings:o}}var X=g(()=>{N()});import Me from"node:fs";import Q from"node:path";function te(e){return{name:"velu-site",resolveId(t){return t===ee?Z:null},load(t){return t!==Z?null:Je(e)}}}function Je(e){let t={};try{t=JSON.parse(Me.readFileSync(Q.join(e,"velu.json"),"utf-8"))}catch{}let o=J(t.navigation??{}),{pageEntries:r,warnings:n}=K(o,e);for(let a of n)console.warn(`[velu] nav: ${a}`);let i=[],s=[],l=0;for(let a of r)if(a.exists){let P=JSON.stringify(a.fileAbsPath.split(Q.sep).join("/")),v=`__p${l++}`;i.push(`import * as ${v} from ${P};`),s.push(` ${JSON.stringify(a.url)}: { Component: ${v}.default, frontmatter: ${v}.frontmatter, toc: ${v}.toc },`)}else s.push(` ${JSON.stringify(a.url)}: { missing: true },`);return["// AUTO-GENERATED by vite-plugin-velu-site. Do not edit.",i.join(`
5
5
  `),"","export const pages = {",s.join(`
6
6
  `),"};",`export const navigation = ${JSON.stringify(o)};`,""].join(`
7
- `)}var Q,X,ee=g(()=>{F();Y();Q="virtual:velu-site",X="\0"+Q});var re={};j(re,{startDevServer:()=>at});import Ve from"node:fs/promises";import te from"node:fs";import c from"node:path";import{fileURLToPath as Be}from"node:url";import{createRequire as Ge}from"node:module";import Me from"chokidar";import Je from"express";import De from"@tailwindcss/vite";import qe from"@vitejs/plugin-react";import He from"@mdx-js/rollup";import We from"remark-frontmatter";import Ye from"remark-mdx-frontmatter";import Ke from"remark-gfm";import Xe from"rehype-slug";import{createServer as Qe,searchForWorkspaceRoot as Ze}from"vite";function rt(e){return`<link rel="stylesheet" href="${`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e).replace(/%20/g,"+")}:wght@300;400;500;600;700&display=swap`}" />`}async function ne(e){try{return await z(e)}catch(t){return console.warn(`[velu] ${t.message} Using defaults.`),N({},c.basename(e))}}async function it(e,t){let o=await e.moduleGraph.getModuleByUrl(t,!0),n=new Map,r=new Set;async function i(s){if(!(!s||r.has(s.url))){if(r.add(s.url),s.id&&tt.test(s.id)){let l=s.url.includes("?")?"&":"?",a=await e.transformRequest(`${s.url}${l}direct`);a?.code&&n.set(s.url,a.code)}for(let l of s.importedModules)await i(l)}}return await i(o),[...n.values()].join(`
8
- `)}async function at(e){console.log(`[velu-cli] dev server for: ${e}`);let t=await ne(e),o=e;try{o=te.realpathSync(e)}catch{}let r=Ge(import.meta.url).resolve("@mdx-js/react"),i=c.resolve(S,"runtime","velu-ui"),s=te.existsSync(i)?i:c.resolve(S,"..","velu-ui","src"),l=[{find:"@mdx-js/react",replacement:r},{find:/^velu-ui$/,replacement:c.join(s,"index.js")},{find:/^velu-ui\//,replacement:s+"/"}],a=Number(process.env.PORT)||5173,A=a+1,p=Je(),d=await Qe({root:S,appType:"custom",plugins:[Z(e),He({remarkPlugins:[We,Ye,Ke,E],rehypePlugins:[Xe],providerImportSource:"@mdx-js/react"}),qe(),De()],cacheDir:c.resolve(e,".velu","vite-cache"),optimizeDeps:{include:["react","react-dom","react-dom/client","react-router-dom","@mdx-js/react","lucide-react","prism-react-renderer","@icons-pack/react-simple-icons","iso-639-1","github-slugger"],esbuildOptions:{loader:{".mdx":"jsx"}}},resolve:{alias:l,dedupe:["react","react-dom","@mdx-js/react"]},server:{middlewareMode:!0,fs:{allow:[Ze(S),e,o]},hmr:{port:A}}});p.use(d.middlewares),p.get(oe,async(v,u,x)=>{if(!t.favicon)return u.status(404).end();let m=c.resolve(e,t.favicon.replace(/^\//,""));u.sendFile(m,f=>{f&&u.status(404).end()})}),p.use("*",async(v,u,x)=>{let m=v.originalUrl;try{let f=await Ve.readFile(st,"utf-8");f=await d.transformIndexHtml(m,f);let k="/src/runtime/server-entry.jsx",{render:$}=await d.ssrLoadModule(k),T=await $(m),U=await it(d,k),le=U?`<style data-velu-ssr>${U}</style>`:"",ce=`<style data-velu-config>
9
- ${V(t)}
10
- </style>`,ue=ot.has(t.font.family)?"":rt(t.font.family),fe=t.favicon?`<link rel="icon" href="${oe}" />`:"",pe=[le,ce,ue,fe].filter(Boolean).join(`
11
- `),de=f.replace("<!--app-title-->",nt(t.name)).replace("<!--app-head-->",pe).replace("<!--app-html-->",T);u.status(200).set({"Content-Type":"text/html"}).end(de)}catch(f){d.ssrFixStacktrace(f),x(f)}}),Me.watch(e,{ignoreInitial:!0,ignored:/(^|[\\/])(node_modules|\.git)([\\/]|$)/,awaitWriteFinish:{stabilityThreshold:100,pollInterval:20}}).on("all",async(v,u)=>{console.log(`[velu-cli] content ${v}: ${c.relative(e,u)}`);let x=c.basename(u)==="velu.json",m=u.endsWith(".mdx"),f=x||m&&(v==="add"||v==="unlink");if(x&&(t=await ne(e)),f)d.moduleGraph.invalidateAll();else if(m){let k=u.split(c.sep).join("/"),$=d.moduleGraph.getModulesByFile(k);if($)for(let T of $)d.moduleGraph.invalidateModule(T)}d.ws.send({type:"full-reload"})}),p.listen(a,()=>{console.log(`[velu-cli] listening on http://localhost:${a}`)})}var et,tt,ot,oe,nt,S,st,ie=g(()=>{C();B();ee();et=c.dirname(Be(import.meta.url)),tt=/\.(css|less|sass|scss|styl|stylus|pcss|postcss)(\?|$)/,ot=new Set(["Google Sans Flex","Google Sans Code","Outfit"]),oe="/@velu-favicon",nt=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");S=c.resolve(et,".."),st=c.resolve(S,"src","template.html")});import se from"node:path";import h from"node:process";var[,,ae,O]=h.argv;async function lt(){switch(ae){case"init":{O||(console.error("Usage: velu init <project-name>"),h.exit(1));let e=O,t=se.resolve(h.cwd(),e),{initProject:o}=await Promise.resolve().then(()=>(_(),R));await o(t,e);break}case"dev":{let e=se.resolve(h.cwd(),O??"."),{startDevServer:t}=await Promise.resolve().then(()=>(ie(),re));await t(e);break}default:console.log("Usage:"),console.log(" velu init <project-name> scaffold a new docs project"),console.log(" velu dev [dir] start the dev preview server"),h.exit(ae?1:0)}}lt().catch(e=>{console.error(h.env.VELU_DEBUG?e:`Error: ${e.message}`),h.exit(1)});
7
+ `)}var ee,Z,oe=g(()=>{N();X();ee="virtual:velu-site",Z="\0"+ee});var se={};R(se,{startDevServer:()=>pt});import qe from"node:fs/promises";import re from"node:fs";import p from"node:path";import{fileURLToPath as De}from"node:url";import{createRequire as He}from"node:module";import We from"chokidar";import Ye from"express";import Ke from"@tailwindcss/vite";import Xe from"@vitejs/plugin-react";import Qe from"@mdx-js/rollup";import Ze from"remark-frontmatter";import et from"remark-mdx-frontmatter";import tt from"remark-gfm";import ot from"rehype-slug";import{createServer as rt,searchForWorkspaceRoot as nt}from"vite";function ct(e){return`<link rel="stylesheet" href="${`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e).replace(/%20/g,"+")}:wght@300;400;500;600;700&display=swap`}" />`}async function ie(e){try{return await B(e)}catch(t){return console.warn(`[velu] ${t.message} Using defaults.`),O({},p.basename(e))}}async function ut(e,t){let o=await e.moduleGraph.getModuleByUrl(t,!0),r=new Map,n=new Set;async function i(s){if(!(!s||n.has(s.url))){if(n.add(s.url),s.id&&st.test(s.id)){let l=s.url.includes("?")?"&":"?",a=await e.transformRequest(`${s.url}${l}direct`);a?.code&&r.set(s.url,a.code)}for(let l of s.importedModules)await i(l)}}return await i(o),[...r.values()].join(`
8
+ `)}async function pt(e){console.log(`[velu-cli] dev server for: ${e}`);let t=!!process.env.VELU_PROFILE,o=performance.now(),r=(m,c)=>t&&console.log(`[velu-profile] ${m}: ${(performance.now()-c).toFixed(0)}ms`),n=await ie(e),i=e;try{i=re.realpathSync(e)}catch{}let l=He(import.meta.url).resolve("@mdx-js/react"),a=p.resolve($,"runtime","velu-ui"),P=re.existsSync(a)?a:p.resolve($,"..","velu-ui","src"),v=[{find:"@mdx-js/react",replacement:l},{find:/^velu-ui$/,replacement:p.join(P,"index.js")},{find:/^velu-ui\//,replacement:P+"/"}],F=Number(process.env.PORT)||5173,ue=F+1,A=Ye(),d=await rt({root:$,appType:"custom",logLevel:t?"info":"warn",plugins:[te(e),Qe({remarkPlugins:[Ze,et,tt,L],rehypePlugins:[ot],providerImportSource:"@mdx-js/react"}),Xe(),Ke()],cacheDir:p.resolve(e,".velu","vite-cache"),optimizeDeps:{include:["react","react-dom","react-dom/client","react-router-dom","@mdx-js/react","lucide-react","prism-react-renderer","iso-639-1","github-slugger"],esbuildOptions:{loader:{".mdx":"jsx"}}},resolve:{alias:v,dedupe:["react","react-dom","@mdx-js/react"]},server:{middlewareMode:!0,fs:{allow:[nt($),e,i]},hmr:{port:ue}}});r("vite server created",o),A.use(d.middlewares),A.get(ne,async(m,c,b)=>{if(!n.favicon)return c.status(404).end();let u=p.resolve(e,n.favicon.replace(/^\//,""));c.sendFile(u,S=>{S&&c.status(404).end()})}),A.use("*",async(m,c,b)=>{let u=m.originalUrl,S=performance.now();try{let f=performance.now(),y=await qe.readFile(ft,"utf-8");y=await d.transformIndexHtml(u,y),r(`transformIndexHtml ${u}`,f);let T="/src/runtime/server-entry.jsx";f=performance.now();let{render:fe}=await d.ssrLoadModule(T);r(`ssrLoadModule ${u} (1st req includes dep pre-bundle)`,f),f=performance.now();let pe=await fe(u);r(`render ${u}`,f),f=performance.now();let j=await ut(d,T);r(`collectSsrCss ${u}`,f);let de=j?`<style data-velu-ssr>${j}</style>`:"",me=`<style data-velu-config>
9
+ ${G(n)}
10
+ </style>`,ge=at.has(n.font.family)?"":ct(n.font.family),he=n.favicon?`<link rel="icon" href="${ne}" />`:"",ve=[de,me,ge,he].filter(Boolean).join(`
11
+ `),ye=y.replace("<!--app-title-->",lt(n.name)).replace("<!--app-head-->",ve).replace("<!--app-html-->",pe);c.status(200).set({"Content-Type":"text/html"}).end(ye),r(`TOTAL ${u}`,S)}catch(f){d.ssrFixStacktrace(f),b(f)}}),We.watch(e,{ignoreInitial:!0,ignored:/(^|[\\/])(node_modules|\.git)([\\/]|$)/,awaitWriteFinish:{stabilityThreshold:100,pollInterval:20}}).on("all",async(m,c)=>{console.log(`[velu-cli] content ${m}: ${p.relative(e,c)}`);let b=p.basename(c)==="velu.json",u=c.endsWith(".mdx"),S=b||u&&(m==="add"||m==="unlink");if(b&&(n=await ie(e)),S)d.moduleGraph.invalidateAll();else if(u){let f=c.split(p.sep).join("/"),y=d.moduleGraph.getModulesByFile(f);if(y)for(let T of y)d.moduleGraph.invalidateModule(T)}d.ws.send({type:"full-reload"})}),A.listen(F,()=>{console.log(`[velu-cli] listening on http://localhost:${F}`)})}var it,st,at,ne,lt,$,ft,ae=g(()=>{V();M();oe();it=p.dirname(De(import.meta.url)),st=/\.(css|less|sass|scss|styl|stylus|pcss|postcss)(\?|$)/,at=new Set(["Google Sans Flex","Google Sans Code","Outfit"]),ne="/@velu-favicon",lt=e=>String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;");$=p.resolve(it,".."),ft=p.resolve($,"src","template.html")});import le from"node:path";import h from"node:process";var[,,ce,U]=h.argv;async function dt(){switch(ce){case"init":{U||(console.error("Usage: velu init <project-name>"),h.exit(1));let e=U,t=le.resolve(h.cwd(),e),{initProject:o}=await Promise.resolve().then(()=>(C(),_));await o(t,e);break}case"dev":{let e=le.resolve(h.cwd(),U??"."),{startDevServer:t}=await Promise.resolve().then(()=>(ae(),se));await t(e);break}default:console.log("Usage:"),console.log(" velu init <project-name> scaffold a new docs project"),console.log(" velu dev [dir] start the dev preview server"),h.exit(ce?1:0)}}dt().catch(e=>{console.error(h.env.VELU_DEBUG?e:`Error: ${e.message}`),h.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veluai/velu",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "bin": "./dist/cli.js",
6
6
  "publishConfig": {
@@ -1,156 +1,147 @@
1
- import React from 'react';
2
- import {
3
- SiJavascript,
4
- SiTypescript,
5
- SiReact,
6
- SiPython,
7
- SiRuby,
8
- SiGo,
9
- SiRust,
10
- SiOpenjdk,
11
- SiSharp,
12
- SiC,
13
- SiCplusplus,
14
- SiPhp,
15
- SiSwift,
16
- SiKotlin,
17
- SiScala,
18
- SiDart,
19
- SiR,
20
- SiHaskell,
21
- SiElixir,
22
- SiErlang,
23
- SiLua,
24
- SiPerl,
25
- SiJulia,
26
- SiOcaml,
27
- SiFsharp,
28
- SiNim,
29
- SiZig,
30
- SiClojure,
31
- SiCoffeescript,
32
- SiHtml5,
33
- SiCss,
34
- SiVuedotjs,
35
- SiSvelte,
36
- SiSolid,
37
- SiJson,
38
- SiYaml,
39
- SiToml,
40
- SiGraphql,
41
- SiMarkdown,
42
- SiLatex,
43
- SiAsciidoctor,
44
- SiGnubash,
45
- SiFishshell,
46
- SiNodedotjs,
47
- SiMysql,
48
- SiPostgresql,
49
- SiSqlite,
50
- SiMongodb,
51
- SiRedis,
52
- SiDocker,
53
- SiKubernetes,
54
- SiNginx,
55
- SiApache,
56
- } from '@icons-pack/react-simple-icons';
57
- import { resolveLang } from './prism-loader.js';
58
-
59
- /**
60
- * Language → icon mapping.
61
- *
62
- * Brand icons (JS / Python / Ruby / etc.) come from
63
- * @icons-pack/react-simple-icons — monochrome SVG, tree-shaken, scales to
64
- * the surrounding font size via `size="1em"`. Anything without a brand
65
- * icon falls back to a semantic lucide id (string) which `resolveIcon`
66
- * handles downstream.
67
- *
68
- * Tab's icon prop already accepts either a React node or a lucide id, so
69
- * we can mix both freely here.
70
- */
71
-
72
- // Brand icons (React components from simple-icons).
73
- const BRAND = {
74
- javascript: SiJavascript,
75
- typescript: SiTypescript,
76
- jsx: SiReact,
77
- tsx: SiReact,
78
- python: SiPython,
79
- ruby: SiRuby,
80
- go: SiGo,
81
- rust: SiRust,
82
- java: SiOpenjdk,
83
- csharp: SiSharp,
84
- c: SiC,
85
- cpp: SiCplusplus,
86
- php: SiPhp,
87
- swift: SiSwift,
88
- kotlin: SiKotlin,
89
- scala: SiScala,
90
- dart: SiDart,
91
- r: SiR,
92
- haskell: SiHaskell,
93
- elixir: SiElixir,
94
- erlang: SiErlang,
95
- lua: SiLua,
96
- perl: SiPerl,
97
- julia: SiJulia,
98
- ocaml: SiOcaml,
99
- fsharp: SiFsharp,
100
- nim: SiNim,
101
- zig: SiZig,
102
- clojure: SiClojure,
103
- coffeescript: SiCoffeescript,
104
- html: SiHtml5,
105
- css: SiCss,
106
- vue: SiVuedotjs,
107
- svelte: SiSvelte,
108
- solid: SiSolid,
109
- json: SiJson,
110
- yaml: SiYaml,
111
- toml: SiToml,
112
- graphql: SiGraphql,
113
- markdown: SiMarkdown,
114
- mdx: SiMarkdown,
115
- latex: SiLatex,
116
- asciidoc: SiAsciidoctor,
117
- bash: SiGnubash,
118
- shell: SiGnubash,
119
- sh: SiGnubash,
120
- fish: SiFishshell,
121
- nodejs: SiNodedotjs,
122
- mysql: SiMysql,
123
- postgresql: SiPostgresql,
124
- plsql: SiPostgresql,
125
- sqlite: SiSqlite,
126
- mongodb: SiMongodb,
127
- redis: SiRedis,
128
- docker: SiDocker,
129
- dockerfile: SiDocker,
130
- kubernetes: SiKubernetes,
131
- nginx: SiNginx,
132
- apacheconf: SiApache,
133
- };
134
-
135
- // Generic lucide fallback for langs without a brand icon. Returns a
136
- // lucide id string — `resolveIcon` turns it into the icon component.
137
- const LUCIDE = {
138
- sql: 'database',
139
- xml: 'code-xml',
140
- diff: 'git-compare-arrows',
141
- ini: 'braces',
142
- properties: 'braces',
143
- powershell: 'terminal',
144
- batch: 'terminal',
145
- zsh: 'terminal',
146
- text: 'file-code',
147
- plaintext: 'file-code',
148
- };
149
-
150
- export function iconForLang(lang) {
151
- if (!lang) return 'file-code';
152
- const id = resolveLang(lang) || lang;
153
- const Cmp = BRAND[id] || BRAND[lang];
154
- if (Cmp) return <Cmp size="1em" />;
155
- return LUCIDE[id] || LUCIDE[lang] || 'file-code';
156
- }
1
+ import React, { useState, useEffect } from 'react';
2
+ import { resolveLang } from './prism-loader.js';
3
+
4
+ /**
5
+ * Language → icon mapping.
6
+ *
7
+ * Brand icons (JS / Python / Ruby / etc.) come from
8
+ * @icons-pack/react-simple-icons. We load each one with an explicit
9
+ * dynamic `import()` (static specifier, so Vite code-splits one chunk per
10
+ * icon) — the browser then fetches ONLY the languages a page actually
11
+ * renders, never the full set and never the package's ~3000-icon barrel
12
+ * (importing that barrel makes Vite transform all 3000 modules on the
13
+ * first dev load, which dominated cold start).
14
+ *
15
+ * Because the import is dynamic, a brand icon isn't available during SSR;
16
+ * `BrandIcon` renders a sized placeholder until the module resolves on the
17
+ * client. The placeholder is identical on the server and the first client
18
+ * render, so hydration never mismatches. Langs without a brand icon fall
19
+ * back to a semantic lucide id (string) handled by `resolveIcon`.
20
+ */
21
+
22
+ // canonical lang → loader (() => import of that icon's module).
23
+ const BRAND_LOADERS = {
24
+ javascript: () => import('@icons-pack/react-simple-icons/icons/SiJavascript.mjs'),
25
+ typescript: () => import('@icons-pack/react-simple-icons/icons/SiTypescript.mjs'),
26
+ jsx: () => import('@icons-pack/react-simple-icons/icons/SiReact.mjs'),
27
+ tsx: () => import('@icons-pack/react-simple-icons/icons/SiReact.mjs'),
28
+ python: () => import('@icons-pack/react-simple-icons/icons/SiPython.mjs'),
29
+ ruby: () => import('@icons-pack/react-simple-icons/icons/SiRuby.mjs'),
30
+ go: () => import('@icons-pack/react-simple-icons/icons/SiGo.mjs'),
31
+ rust: () => import('@icons-pack/react-simple-icons/icons/SiRust.mjs'),
32
+ java: () => import('@icons-pack/react-simple-icons/icons/SiOpenjdk.mjs'),
33
+ csharp: () => import('@icons-pack/react-simple-icons/icons/SiSharp.mjs'),
34
+ c: () => import('@icons-pack/react-simple-icons/icons/SiC.mjs'),
35
+ cpp: () => import('@icons-pack/react-simple-icons/icons/SiCplusplus.mjs'),
36
+ php: () => import('@icons-pack/react-simple-icons/icons/SiPhp.mjs'),
37
+ swift: () => import('@icons-pack/react-simple-icons/icons/SiSwift.mjs'),
38
+ kotlin: () => import('@icons-pack/react-simple-icons/icons/SiKotlin.mjs'),
39
+ scala: () => import('@icons-pack/react-simple-icons/icons/SiScala.mjs'),
40
+ dart: () => import('@icons-pack/react-simple-icons/icons/SiDart.mjs'),
41
+ r: () => import('@icons-pack/react-simple-icons/icons/SiR.mjs'),
42
+ haskell: () => import('@icons-pack/react-simple-icons/icons/SiHaskell.mjs'),
43
+ elixir: () => import('@icons-pack/react-simple-icons/icons/SiElixir.mjs'),
44
+ erlang: () => import('@icons-pack/react-simple-icons/icons/SiErlang.mjs'),
45
+ lua: () => import('@icons-pack/react-simple-icons/icons/SiLua.mjs'),
46
+ perl: () => import('@icons-pack/react-simple-icons/icons/SiPerl.mjs'),
47
+ julia: () => import('@icons-pack/react-simple-icons/icons/SiJulia.mjs'),
48
+ ocaml: () => import('@icons-pack/react-simple-icons/icons/SiOcaml.mjs'),
49
+ fsharp: () => import('@icons-pack/react-simple-icons/icons/SiFsharp.mjs'),
50
+ nim: () => import('@icons-pack/react-simple-icons/icons/SiNim.mjs'),
51
+ zig: () => import('@icons-pack/react-simple-icons/icons/SiZig.mjs'),
52
+ clojure: () => import('@icons-pack/react-simple-icons/icons/SiClojure.mjs'),
53
+ coffeescript: () => import('@icons-pack/react-simple-icons/icons/SiCoffeescript.mjs'),
54
+ html: () => import('@icons-pack/react-simple-icons/icons/SiHtml5.mjs'),
55
+ css: () => import('@icons-pack/react-simple-icons/icons/SiCss.mjs'),
56
+ vue: () => import('@icons-pack/react-simple-icons/icons/SiVuedotjs.mjs'),
57
+ svelte: () => import('@icons-pack/react-simple-icons/icons/SiSvelte.mjs'),
58
+ solid: () => import('@icons-pack/react-simple-icons/icons/SiSolid.mjs'),
59
+ json: () => import('@icons-pack/react-simple-icons/icons/SiJson.mjs'),
60
+ yaml: () => import('@icons-pack/react-simple-icons/icons/SiYaml.mjs'),
61
+ toml: () => import('@icons-pack/react-simple-icons/icons/SiToml.mjs'),
62
+ graphql: () => import('@icons-pack/react-simple-icons/icons/SiGraphql.mjs'),
63
+ markdown: () => import('@icons-pack/react-simple-icons/icons/SiMarkdown.mjs'),
64
+ mdx: () => import('@icons-pack/react-simple-icons/icons/SiMarkdown.mjs'),
65
+ latex: () => import('@icons-pack/react-simple-icons/icons/SiLatex.mjs'),
66
+ asciidoc: () => import('@icons-pack/react-simple-icons/icons/SiAsciidoctor.mjs'),
67
+ bash: () => import('@icons-pack/react-simple-icons/icons/SiGnubash.mjs'),
68
+ shell: () => import('@icons-pack/react-simple-icons/icons/SiGnubash.mjs'),
69
+ sh: () => import('@icons-pack/react-simple-icons/icons/SiGnubash.mjs'),
70
+ fish: () => import('@icons-pack/react-simple-icons/icons/SiFishshell.mjs'),
71
+ nodejs: () => import('@icons-pack/react-simple-icons/icons/SiNodedotjs.mjs'),
72
+ mysql: () => import('@icons-pack/react-simple-icons/icons/SiMysql.mjs'),
73
+ postgresql: () => import('@icons-pack/react-simple-icons/icons/SiPostgresql.mjs'),
74
+ plsql: () => import('@icons-pack/react-simple-icons/icons/SiPostgresql.mjs'),
75
+ sqlite: () => import('@icons-pack/react-simple-icons/icons/SiSqlite.mjs'),
76
+ mongodb: () => import('@icons-pack/react-simple-icons/icons/SiMongodb.mjs'),
77
+ redis: () => import('@icons-pack/react-simple-icons/icons/SiRedis.mjs'),
78
+ docker: () => import('@icons-pack/react-simple-icons/icons/SiDocker.mjs'),
79
+ dockerfile: () => import('@icons-pack/react-simple-icons/icons/SiDocker.mjs'),
80
+ kubernetes: () => import('@icons-pack/react-simple-icons/icons/SiKubernetes.mjs'),
81
+ nginx: () => import('@icons-pack/react-simple-icons/icons/SiNginx.mjs'),
82
+ apacheconf: () => import('@icons-pack/react-simple-icons/icons/SiApache.mjs'),
83
+ };
84
+
85
+ // Generic lucide fallback for langs without a brand icon. Returns a
86
+ // lucide id string — `resolveIcon` turns it into the icon component.
87
+ const LUCIDE = {
88
+ sql: 'database',
89
+ xml: 'code-xml',
90
+ diff: 'git-compare-arrows',
91
+ ini: 'braces',
92
+ properties: 'braces',
93
+ powershell: 'terminal',
94
+ batch: 'terminal',
95
+ zsh: 'terminal',
96
+ text: 'file-code',
97
+ plaintext: 'file-code',
98
+ };
99
+
100
+ // Module-level cache so an icon that's been loaded once renders
101
+ // synchronously everywhere after (no repeat import, no flash).
102
+ const iconCache = new Map();
103
+
104
+ /**
105
+ * Renders a brand icon loaded lazily by `key`. SSR + the first client
106
+ * render emit a sized placeholder (identical → hydration-safe); after
107
+ * mount the icon's module is imported and swapped in.
108
+ */
109
+ function BrandIcon({ iconKey, ...props }) {
110
+ const [Icon, setIcon] = useState(() => iconCache.get(iconKey) || null);
111
+
112
+ useEffect(() => {
113
+ if (iconCache.has(iconKey)) {
114
+ setIcon(() => iconCache.get(iconKey));
115
+ return;
116
+ }
117
+ const load = BRAND_LOADERS[iconKey];
118
+ if (!load) return;
119
+ let alive = true;
120
+ load().then((mod) => {
121
+ iconCache.set(iconKey, mod.default);
122
+ if (alive) setIcon(() => mod.default);
123
+ });
124
+ return () => {
125
+ alive = false;
126
+ };
127
+ }, [iconKey]);
128
+
129
+ if (!Icon) {
130
+ // Reserve the icon's box so swapping it in causes no layout shift.
131
+ return (
132
+ <span
133
+ aria-hidden="true"
134
+ style={{ display: 'inline-block', width: '1em', height: '1em' }}
135
+ />
136
+ );
137
+ }
138
+ return <Icon {...props} />;
139
+ }
140
+
141
+ export function iconForLang(lang) {
142
+ if (!lang) return 'file-code';
143
+ const id = resolveLang(lang) || lang;
144
+ const key = BRAND_LOADERS[id] ? id : BRAND_LOADERS[lang] ? lang : null;
145
+ if (key) return <BrandIcon iconKey={key} size="1em" />;
146
+ return LUCIDE[id] || LUCIDE[lang] || 'file-code';
147
+ }
@@ -1,28 +1,29 @@
1
- ---
2
- title: Code blocks
3
- description: Syntax-highlighted code and groups.
4
- ---
5
-
6
- Fenced code blocks are upgraded to a rich code component with a copy
7
- button and a language label.
8
-
9
- ```js
10
- export function greet(name) {
11
- return `Hello, ${name}!`;
12
- }
13
- ```
14
-
15
- ## Code groups
16
-
17
- Show the same example in several languages with a `CodeGroup`:
18
-
19
- <CodeGroup>
20
- ```js index.js
21
- fetch('/api/hello').then((r) => r.json());
22
- ```
23
-
24
- ```py main.py
25
- import requests
26
- requests.get('/api/hello').json()
27
- ```
28
- </CodeGroup>
1
+ ---
2
+ title: Code blocks
3
+ description: Syntax-highlighted code and groups.
4
+ ---
5
+
6
+ Fenced code blocks are upgraded to a rich code component with a copy
7
+ button and a language label.
8
+
9
+ ```js
10
+ export function greet(name) {
11
+ return `Hello, ${name}!`;
12
+ }
13
+ ```
14
+
15
+ ## Code groups
16
+
17
+ Show the same example in several languages with a `CodeGroup`. Each
18
+ alternative is a `<CodeBlock>` with a `title` (the tab label) and a
19
+ `language` (drives syntax highlighting and the tab's language icon):
20
+
21
+ <CodeGroup>
22
+ <CodeBlock title="index.js" language="javascript">
23
+ {`fetch('/api/hello').then((r) => r.json());`}
24
+ </CodeBlock>
25
+ <CodeBlock title="main.py" language="python">
26
+ {`import requests
27
+ requests.get('/api/hello').json()`}
28
+ </CodeBlock>
29
+ </CodeGroup>