@infinityfx/fluid
Version:
React UI library, using zero-runtime CSS-in-JS.
3 lines (2 loc) • 2.85 kB
JavaScript
import o from"fs";import{readFile as e}from"fs/promises";import t from"readline";import{glob as n}from"glob";import{mergeRecursive as s}from"../core/utils.js";import{GLOBAL_CONTEXT as i}from"../core/shared.js";function r(o){t.cursorTo(process.stdout,0),process.stdout.write(`${(100*o).toFixed(1)}% `+new Array(Math.round(40*o)).fill("=").join(""))}const c=o=>({index:0,entries:o,start:performance.now(),compiled:0,files:[]});function a(o){console.log("\n"),console.log(`Compiled [1m${o.compiled}[0m components in [1m${((performance.now()-o.start)/1e3).toFixed(2)}[0m sec.`),console.log(),console.log("[4mFile[0m [4mSize[0m"),o.files.forEach((({name:o,size:e})=>console.log(`${o.padEnd(41," ")}${(e/1024).toFixed(1)}kb`))),console.log("")}function l(o,e,t="{}"){let n=1;for(;n>0;)o.charAt(e)==t.charAt(0)&&n++,o.charAt(e)==t.charAt(1)&&n--,n>0&&e++;return e}function m(o,e,t,n){return o.slice(0,e)+n+o.slice(t)}function p(o){return["core(\\/|\\\\)style\\.js","(\\/|\\\\)fluid(\\/|\\\\)css","styles(\\/|\\\\).+?"].map((o=>new RegExp(`import[^;]*?${o}("|');?`,"g"))).forEach((e=>o=o.replace(e,""))),o}const d=o=>o.replace(/^\s+|\s+(as\s+.+)?$/g,"").replace(/\.\w+$/,"").replace(/([a-z])([A-Z])/,"$1-$2").toLowerCase();function f(o,e){return Array.from(o.matchAll(new RegExp(`import\\s*(?:\\{([^\\}]+)\\}|\\*\\s+as.*|\\w+)\\s*from\\s*(?:'|")@infinityfx\\/${e}(?:'|")`,"g"))).map((([o,e])=>e?e.split(",").map(d):null)).flat()}let u;async function g(t){if(!u){const[t]=await n("./fluid.config.{js,mjs}");try{const[r,c,a]=await Promise.all([t&&import(`file://${process.cwd()}/${t}?nonce=${Math.random()}`),t&&e(process.cwd()+`/${t}`,{encoding:"ascii"}),n(["./node_modules/@infinityfx/fluid/package.json","./package.json"])]);r&&c&&(u=r.default,i.theme=s(u.theme,i.theme),i.components=u.components||{},i.paths=u.paths||i.paths,i.cssOutput=u.cssOutput||i.cssOutput,i.icons=u.icons||{},i.rawConfig=c);const l=a.length>1?a.find((o=>o.startsWith("node_modules"))):a[0],{name:m,version:p}=JSON.parse(o.readFileSync(l,{encoding:"ascii"}));i.name=m,i.version=p,i.isInternal=a.length<2}catch{console.log(),console.log(`Your ${t} could not be loaded.`),u={}}}return void 0!==t&&(i.isDev=t),i}function h(e,t=!1){const n=t&&/@infinityfx\/fluid\/$/.test(e)?"./":e;return o.existsSync(n)?{root:n,parent:e.match(/.+\/(.+)\/$/)?.[1]||"",timestamp:Date.now(),module:async o=>(await import(`file://${process.cwd()}/${n}dist/${o}?nonce=${Math.random()}`)).default,source:e=>o.readFileSync(n+"dist/"+e,{encoding:"ascii"}),output(e,t){o.writeFileSync(n+"compiled/"+e,t)},override(e,t){o.writeFileSync(n+"dist/"+e,t)}}:null}export{c as emptyStats,f as extractImports,g as getContext,h as getIOHelper,d as keyFromImport,l as matchBrackets,r as printProgress,a as printStats,m as replace,p as stripImports};
//# sourceMappingURL=utils.js.map