@devup-ui/next-plugin
Version:
Zero Config, Zero FOUC, Zero Runtime, CSS in JS Preprocessor
2 lines (1 loc) • 1.35 kB
JavaScript
import{existsSync as K,readFileSync as N}from"node:fs";import{writeFile as q}from"node:fs/promises";import{basename as y,dirname as u,join as $,relative as B}from"node:path";import{codeExtract as S,exportClassMap as w,exportFileMap as M,exportSheet as n,getCss as h,importClassMap as E,importFileMap as I,importSheet as L,registerTheme as U}from"@devup-ui/wasm";var j={watch:!1,build:!1},m=function(z){let{watch:A,package:P,cssDir:O,sheetFile:Q,classMapFile:R,fileMapFile:V,themeFile:W,singleCss:T,theme:k,defaultClassMap:g,defaultFileMap:v,defaultSheet:b}=this.getOptions(),G=[],X=A?"watch":"build";if(!j[X])if(j[X]=!0,A){if(K(Q))L(JSON.parse(N(Q,"utf-8")));if(K(R))E(JSON.parse(N(R,"utf-8")));if(K(V))I(JSON.parse(N(V,"utf-8")));if(K(W))U(JSON.parse(N(W,"utf-8"))?.theme??{})}else I(v),E(g),L(b),U(k);let Y=this.async();try{let H=this.resourcePath,J=B(u(H),O).replaceAll("\\","/"),D=B(process.cwd(),H);if(!J.startsWith("./"))J=`./${J}`;let{code:x,map:Z,cssFile:_,updatedBaseStyle:f}=S(D,z.toString(),P,J,T,!1,!0),C=Z?JSON.parse(Z):null;if(f&&A)G.push(q($(O,"devup-ui.css"),h(null,!1),"utf-8"));if(_&&A)G.push(q($(O,y(_)),`/* ${this.resourcePath} ${Date.now()} */`),q(Q,n()),q(R,w()),q(V,M()));Promise.all(G).catch(console.error).finally(()=>Y(null,x,C))}catch(H){Promise.all(G).catch(console.error).finally(()=>Y(H))}return},r=m;export{r as default};