bernova 1.7.4 → 1.7.6

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +69 -1
  3. package/dist/bin/buildstyle.js +1 -1
  4. package/dist/bin/copyCss.js +2 -0
  5. package/dist/bin/copyProvider.js +2 -0
  6. package/dist/bin/copyTools.js +2 -0
  7. package/dist/bin/functions/getFx.js +1 -0
  8. package/dist/bin/functions/scriptFx.js +1 -0
  9. package/dist/bin/functions/utils.js +1 -0
  10. package/dist/bin/functions/writeFx.js +1 -0
  11. package/dist/bin/preBuildStyles.js +2 -0
  12. package/dist/interfaces/componentsType.ts +633 -173
  13. package/dist/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +1 -1
  14. package/dist/src/lib/generateCss/helpers/generateCssStyles.utils.js +1 -1
  15. package/dist/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +1 -1
  16. package/dist/src/lib/generateProvider/generateProvider.utils.js +1 -1
  17. package/dist/src/lib/generateProvider/template/{providerTemplate.js → providerTemplate-link.js} +11 -5
  18. package/dist/src/lib/generateProvider/template/providerTemplate-style.js +155 -0
  19. package/dist/src/lib/generateProvider/template/providerTemplate.d.ts +1 -1
  20. package/dist/src/lib/typingStyles/typingStyles.utils.js +1 -1
  21. package/dist/types/lib/generateCss/helpers/rulename/formatRuleName.utils.d.ts +2 -1
  22. package/dist/types/lib/generateProvider/template/providerTemplate-style.d.ts +18 -0
  23. package/package.json +6 -2
  24. package/src/app.js +4 -2
  25. package/src/lib/generateCss/helpers/classnames/handlerRegister.utils.js +48 -8
  26. package/src/lib/generateCss/helpers/generateCssStyles.utils.js +5 -2
  27. package/src/lib/generateCss/helpers/rulename/formatRuleName.utils.js +25 -0
  28. package/src/lib/generateProvider/generateProvider.utils.js +9 -8
  29. package/src/lib/generateProvider/template/{providerTemplate.js → providerTemplate-link.js} +11 -5
  30. package/src/lib/generateProvider/template/providerTemplate-style.js +155 -0
  31. package/src/lib/generateProvider/template/providerTemplate.d.ts +1 -1
  32. package/src/lib/typingStyles/typingStyles.utils.js +12 -6
  33. /package/dist/types/lib/generateProvider/template/{providerTemplate.d.ts → providerTemplate-link.d.ts} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Merge pull request #35 from kubit-ui/feat/new-function-named-literals
8
+
9
+ ## 1.7.5
10
+
11
+ ### Patch Changes
12
+
13
+ - Merge pull request #34 from kubit-ui/feat/new-bv-scripts-options-and-improve-stats-interfaces
14
+
3
15
  ## 1.7.4
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -45,6 +45,7 @@
45
45
  - [Complex Styles](#Complex-Styles)
46
46
  - [Foreign Feature](#Foreign-Feature)
47
47
  - [Dynamic Values Feature](#Dynamic-Values-Feature)
48
+ - [Literals Values Feature](#Literals-Values-Feature)
48
49
  - [Fonts](#setting-text-fonts)
49
50
  - [Reset CSS](#enable-reset-css)
50
51
  - [Typescript helps](#typescript-helps)
@@ -1108,6 +1109,50 @@ export const Container = ({ bgColor, borderColor, children }) => {
1108
1109
 
1109
1110
  In this case, only the styles for the header will be generated, and in the development tools, for _nav_item_ and _login_button_, the existing classes for BUTTON and LINK will be returned.
1110
1111
 
1112
+ ### Literals Values Feature
1113
+
1114
+ You might need to set a literal value in the component's styles object for Bernova. By default, it would be processed as a CSS class with its respective values. However, if that value is within the _$literals_ key, these values can be retrieved by the provider or set in the **cssClassNames** object.
1115
+
1116
+ ```js
1117
+ const BUTTON = {
1118
+ padding: '4px',
1119
+ border_radius: '8px',
1120
+ PRIMARY: {
1121
+ color: 'white',
1122
+ background: 'red',
1123
+ $literals: {
1124
+ loader_variant: 'loader-primary.json',
1125
+ },
1126
+ },
1127
+ SECONDARY: {
1128
+ color: 'black',
1129
+ background: 'gray',
1130
+ $literals: {
1131
+ loader_variant: 'loader-secondary.json',
1132
+ },
1133
+ },
1134
+ };
1135
+ ```
1136
+
1137
+ Example of implementation:
1138
+
1139
+ ```jsx
1140
+ import { useClassNames } from '@/hooks';
1141
+
1142
+ const Button = (props) => {
1143
+ const styles = useClassNames({ component: 'BUTTON', variant: 'PRIMARY' });
1144
+
1145
+ /**
1146
+ * styles = {
1147
+ * button: 'button button--primary',
1148
+ * loader_variant: 'loader-primary.json'
1149
+ * }
1150
+ */
1151
+ };
1152
+ ```
1153
+
1154
+ **Important**: Within literals, values can be of different primitive types: numbers, booleans, etc.
1155
+
1111
1156
  ## Access to classNames
1112
1157
 
1113
1158
  To use the generated CSS classes, you can use the name directly on the HTML element, as the library will return a valid CSS file.
@@ -1907,13 +1952,36 @@ npx bv-build --prevent-move-dts
1907
1952
  # unset types values from bernova.config.json
1908
1953
  npx bv-build --types none
1909
1954
 
1910
- # Prevent process the js ad dts files
1955
+ # Prevent process the js ad dts files [deprecated]
1911
1956
  npx bv-build --prevent-process-js
1912
1957
 
1913
1958
  # Embed styles
1914
1959
  npx bv-build --embed-css
1915
1960
  ```
1916
1961
 
1962
+ ### Partial Compilation
1963
+
1964
+ There may be occasions when you need to compile only part of Bernova's tools, or prepare them to be processed with other bundlers or processors. For these cases, Bernova provides scripts that allow you to perform only part of the process.
1965
+
1966
+ **IMPORTANT**: _Although all flags are available, some will not perform any action in certain individual processes._
1967
+
1968
+ ```bash
1969
+ # Available flags: --embed-css | --css
1970
+ npx bv-pre-build
1971
+ # Available flags: --base-out-dir & --css
1972
+ npx bv-copy-css
1973
+ # Available flags: --base-out-dir & --root-dir & --tools & --prevent-move-dts
1974
+ npx bv-copy-tools
1975
+ # Available flags: --base-out-dir & --root-dir & --provider & --prevent-process-js [deprecated]
1976
+ # Available flags: --prevent-move-dts & --embed-css & --css
1977
+ npx bv-copy-provider
1978
+ ```
1979
+
1980
+ - **bv-pre-build**: Prepares and updates the provider (and its stats) to production, without moving it to the final build folder.
1981
+ - **bv-copy-css**: Copies the files generated or used by Bernova to the final build folder.
1982
+ - **bv-copy-tools**: Copies the tools generated by Bernova to the final build folder.
1983
+ - **bv-copy-provider**: Copies the provider and its stats to the final build folder.
1984
+
1917
1985
  ---
1918
1986
 
1919
1987
  ## Contributing
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const e=require("fs").promises,t=require("path"),s=require("@babel/core"),{minify:a}=require("terser"),{extractDocFragment:n,writeDoc:r,fileExists:o,readConfigData:i}=require("../src/lib");async function c({baseOutPath:s,jsFile:a,rootDir:i,customOutDirs:c,dir:l,minifyJS:m,preventMoveJS:d,provider:h={name:""},type:v="",embedCss:y,cssFiles:b}){const P=a.name.endsWith(".d.ts"),j=t.resolve(l,a.path,a.name);if(!o(l,j))return void console.error(`File not found: ${j}`);let D=await e.readFile(j,"utf8");const O=!!c?.css||y&&b.length>0;if("cssTheme.js"===a.name&&O){const s=D.replace("export default","").replaceAll(";","").trim(),a=new Function(`return (${s})`)();if(c?.css)D=`export default {\n${f({cssThemes:a,cssOutPath:c.css})}};\n`;else if(y&&b.length>0){const s=Object.keys(a)[0],n=b.find(e=>e.name===`${s}.css`||e.name===`${s}.min.css`);if(n){const{name:a,path:r}=n,i=t.resolve(l,r,a),c=o(l,i)?(await e.readFile(i,"utf8")).replace(/\s+/g,""):"",m={before:"",after:""};for(const a of b){const{name:n,path:r,parent:i}=a;if(i)for(const{name:a,position:c}of i)if(a===s){const s=t.resolve(l,r,n);if(o(l,s)){const t=(await e.readFile(s,"utf8")).replace(/\s+/g,"");m[c]+=t}}}const p=m.before+c+m.after;D=`export default {'${s}':{css:\`${p}\`}};`}}}if(a.name===`${g(h.name)}.js`&&y&&b.length>0){const s="\n #linkBuilder = (css, id) => {\n if (typeof document === 'undefined') return;\n let styleElement = document.getElementById(id);\n if (!styleElement) {\n styleElement = document.createElement('style');\n styleElement.id = id;\n styleElement.type = 'text/css';\n document.head.appendChild(styleElement);\n }\n styleElement.innerHTML = css;\n };\n #handlerThemes = (data) => {\n const { css } = data;\n this.#linkBuilder(css, this.#linkId);\n };\n #cleanUpLinks = () => {\n if (typeof document === 'undefined') return;\n const style = document.getElementById(this.#linkId);\n if (style) style.remove();\n };\n ",a="../src/lib/generateProvider/template/providerTemplate.js";let r=await e.readFile(t.resolve(__dirname,a),"utf8");r=r.replace(/\$_Provider_\$/g,h.name);const o=n({section:"Bernova provider methods",doc:r});D=r.replace(o,s.trim())}if(a.name===`${g(h.name)}.d.ts`&&y&&b.length>0){const s="\n #linkBuilder(css: string, id: string): void;\n #handlerThemes(data: { css: string }): void;\n #cleanUpLinks(): void;\n ",a="../src/lib/generateProvider/template/providerTemplate.d.ts";let r=await e.readFile(t.resolve(__dirname,a),"utf8");r=r.replace(/\$_Provider_\$/g,h.name);const o=n({section:"Bernova provider methods",doc:r});D=r.replace(o,s.trim())}"cjs"!==v||P||(D=await p(D,j,!0)),"esm"!==v||P||(D=await p(D,j)),m&&!P&&(D=await u(D));const C=t.relative(i||"",a.outPath),w=d?j:t.resolve(s,C,a.name);await r(w,D,a.name)}async function l({baseOutPath:s,cssFiles:a,rootDir:n,customOutDirs:i,dir:c}){for(const l of a){const a=(()=>n&&!i?.css?t.relative(n,l.path):i?.css?i.css:l.path)(),m=t.resolve(c,l.path,l.name);if(o(c,m)){const n=await e.readFile(m,"utf8"),o=l.name.replace(".min","");await r(t.resolve(s,a,o),n,o)}}}function m({baseOutDir:e,type:s="-"}){const a=(()=>{switch(s){case"cjs":return"cjs";case"esm":return"esm";default:return""}})();return t.join(e,a)}async function p(e,t,a=!1){const n=!!a&&"commonjs";return(await s.transformAsync(e,{filename:t,presets:[["@babel/preset-env",{modules:n,targets:{node:"current"}}]]})).code}async function u(e){return(await a(e,{compress:{dead_code:!0,drop_console:!1,drop_debugger:!0,keep_classnames:!1,keep_fargs:!0,keep_fnames:!1,keep_infinity:!1},mangle:{toplevel:!1},format:{comments:!1}})).code}function d({themes:e,minifyCss:s}){return e&&Array.isArray(e)&&e.length>0?e.reduce((e,a)=>{const{name:n,stylesPath:r,foreignThemes:o}=a;return n&&r&&v(e,{name:s?`${n}.min.css`:`${n}.css`,path:r}),o&&Array.isArray(o)&&o.length>0&&o.forEach(s=>{const a=t.basename(s.path),r=s.path.replace(a,"").trim(),o=e.findIndex(e=>e.name===a&&e.path===r);o>=0?e[o].parent.push({name:n,position:s.position}):e.push({name:a,path:r,parent:[{name:n,position:s.position}]})}),e},[]):[]}async function h({dir:s,customOutDirs:a,provider:n,themes:r,preventMoveDTS:o=!1}){const i=r&&r.bvTools?r.reduce((e,{bvTools:t})=>{const{path:s,declarationHelp:n,cssVariables:r,cssClassNames:i,cssMediaQueries:c,cssGlobalStyles:l,availableComponents:m}=t,p=n&&!o,u=a?.tools?a.tools:s;return r&&(v(e,{name:"cssVars.js",path:s,outPath:u}),p&&v(e,{name:"cssVars.d.ts",path:s,outPath:u})),i&&(v(e,{name:"cssClasses.js",path:s,outPath:u}),p&&v(e,{name:"cssClasses.d.ts",path:s,outPath:u})),c&&(v(e,{name:"cssMediaQueries.js",path:s,outPath:u}),p&&v(e,{name:"cssMediaQueries.d.ts",path:s,outPath:u})),l&&(v(e,{name:"cssGlobalStyles.js",path:s,outPath:u}),p&&v(e,{name:"cssGlobalStyles.d.ts",path:s,outPath:u})),m&&(v(e,{name:"cssAvailableComponents.js",path:s,outPath:u}),p&&v(e,{name:"cssAvailableComponents.d.js",path:s,outPath:u})),e},[]):[];if(n){const r=g(n.name),c=`${r}.js`,l=a?.provider?a.provider:n.path;v(i,{name:c,path:n.path,outPath:l});const m=t.join(n.path,"stats"),p=a?.provider?t.join(a.provider,"stats"):m;v(i,{name:"stats.js",path:m,outPath:p});const u=t.resolve(s,m),d=await e.readdir(u,{withFileTypes:!0});d.forEach(e=>{if(e.isDirectory()){const s=t.join(m,e.name),a=t.join(p,e.name);v(i,{name:"cssAvailableComponents.js",path:s,outPath:a}),v(i,{name:"cssClassNames.js",path:s,outPath:a}),v(i,{name:"cssGlobalStyles.js",path:s,outPath:a}),v(i,{name:"cssMediaQueries.js",path:s,outPath:a}),v(i,{name:"cssTheme.js",path:s,outPath:a}),v(i,{name:"cssVars.js",path:s,outPath:a})}}),n.declarationHelp&&!o&&(v(i,{name:`${r}.d.ts`,path:n.path,outPath:l}),v(i,{name:"stats.d.ts",path:m,outPath:p}),d.forEach(e=>{if(e.isDirectory()){const s=t.join(m,e.name),a=t.join(p,e.name);v(i,{name:"cssAvailableComponents.d.ts",path:s,outPath:a}),v(i,{name:"cssClassNames.d.ts",path:s,outPath:a}),v(i,{name:"cssGlobalStyles.d.ts",path:s,outPath:a}),v(i,{name:"cssMediaQueries.d.ts",path:s,outPath:a}),v(i,{name:"cssTheme.d.ts",path:s,outPath:a}),v(i,{name:"cssVars.d.ts",path:s,outPath:a})}}))}return i}function f({cssThemes:e,cssOutPath:s}){return Object.entries(e).reduce((e,[a,{foreign:n}])=>{const{before:r,after:o}=n,i=r&&Array.isArray(r)&&r.length>0?r.reduce((e,a,n)=>{const r=t.basename(a);return n>0&&(e+=", "),e+`'${s}/${r}'`},""):"",c=o&&Array.isArray(o)&&o.length>0?o.reduce((e,a,n)=>{const r=t.basename(a);return n>0&&(e+=", "),e+`'${s}/${r}'`},""):"";return e+`'${a}':{css:'${s}/${a}.css',foreign:{before: [${i}],after: [${c}]}}`},"")}function v(e,t){e.some(e=>e.name===t.name&&e.path===t.path)||e.push(t)}function y(){const e=["--base-out-dir","--root-dir","--prevent-process-js","--prevent-move-js","--prevent-move-dts","--types","--css","--tools","--provider","--embed-css"],t={};for(let s=0;s<process.argv.length;s++)if(e.includes(process.argv[s])){const a=process.argv[s].replace("--","").replace(/-([a-z])/g,(e,t)=>t.toUpperCase()),n=process.argv[s+1];t[a]=(()=>!(n&&!e.includes(n))||("none"===n.toLocaleLowerCase()?"":n))()}return t}function b({jsonCustomOutDirs:e,cliCustomOutDirs:t}){let s={};return e&&(s={...e}),t&&(s={...s,...t}),Object.keys(s).length>0?s:void 0}function g(e="provider"){return e.charAt(0).toLowerCase()+e.slice(1)}(async()=>{const e=process.cwd(),s=await i(t.resolve(e,"bernova.config.json")),{compilerOptions:a,provider:n,themes:r}=s;a&&n&&r||(console.error("Invalid configuration: Missing compilerOptions, themes or provider"),process.exit(1));const{baseOutDir:o,rootDir:p,minifyCss:u,minifyJS:f,preventMoveJS:v,preventMoveDTS:g,types:P,embedCss:j,customOutDirs:D}=a,{baseOutDir:O,rootDir:C,types:w,preventMoveJs:$,preventMoveDts:F,preventProcessJs:A=!1,embedCss:T,...M}=y(),S=O??o??"",_=C??p??void 0,E=$??v??!1,k=F??g??!1,J=w??P??void 0,x=T??j??!1,B=b({jsonCustomOutDirs:D,cliCustomOutDirs:M}),I=d({themes:r,minifyCss:u}),L=A?[]:await h({dir:e,customOutDirs:B,provider:n,themes:r,preventMoveDTS:k}),q=m({baseOutDir:S});if(I&&I.length>0&&!x&&await l({baseOutPath:q,cssFiles:I,rootDir:_,customOutDirs:B,dir:e}),L&&L.length>0)if(J&&Array.isArray(J)&&J.length>0)for(const t of J){const s=m({baseOutDir:S,type:t});for(const a of L)await c({baseOutPath:s,jsFile:a,rootDir:_,customOutDirs:B,dir:e,minifyJS:f,preventMoveJS:E,provider:n,type:t,embedCss:x,cssFiles:I})}else for(const t of L)await c({baseOutPath:q,jsFile:t,rootDir:_,customOutDirs:B,dir:e,minifyJS:f,preventMoveJS:E,provider:n,embedCss:x,cssFiles:I})})();
2
+ const{bvBuildScript:s}=require("./functions/scriptFx");(async()=>{try{const c=await s();await c.fullBuild(),console.log("Styles built successfully.")}catch(s){console.error("Error building styles:",s),process.exit(1)}})();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ const{bvBuildScript:c}=require("./functions/scriptFx");(async()=>{try{const s=await c();await s.copyCss(),console.log("CSS files copied successfully.")}catch(c){console.error("Error copying CSS files:",c),process.exit(1)}})();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ const{bvBuildScript:o}=require("./functions/scriptFx");(async()=>{try{const r=await o();await r.copyProvider(),await r.copyStats(),console.log("Provider files copied successfully.")}catch(o){console.error("Error copying provider files:",o),process.exit(1)}})();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ const{bvBuildScript:o}=require("./functions/scriptFx");(async()=>{try{const s=await o();await s.copyTools(),console.log("Tools files copied successfully.")}catch(o){console.error("Error copying tools files:",o),process.exit(1)}})();
@@ -0,0 +1 @@
1
+ const s=require("fs").promises,t=require("path"),{pushUniqueFile:a,lowerCaseFirstChar:e}=require("./utils");function o(s){const t={};for(let a=0;a<process.argv.length;a++)if(s.includes(process.argv[a])){const e=process.argv[a].replace("--","").replace(/-([a-z])/g,(s,t)=>t.toUpperCase()),o=process.argv[a+1];t[e]=(()=>!(o&&!s.includes(o))||("none"===o.toLocaleLowerCase()?"":o))()}return t}async function n({dir:o,customOutDirs:n,provider:r,themes:h,preventMoveDTS:i=!1}){const c=h&&h.bvTools?h.reduce((s,{bvTools:t})=>{const{path:e,declarationHelp:o,cssVariables:r,cssClassNames:h,cssMediaQueries:c,cssGlobalStyles:p,availableComponents:u}=t,l=o&&!i,m=n?.tools?n.tools:e;return r&&(a(s,{name:"cssVars.js",path:e,outPath:m}),l&&a(s,{name:"cssVars.d.ts",path:e,outPath:m})),h&&(a(s,{name:"cssClasses.js",path:e,outPath:m}),l&&a(s,{name:"cssClasses.d.ts",path:e,outPath:m})),c&&(a(s,{name:"cssMediaQueries.js",path:e,outPath:m}),l&&a(s,{name:"cssMediaQueries.d.ts",path:e,outPath:m})),p&&(a(s,{name:"cssGlobalStyles.js",path:e,outPath:m}),l&&a(s,{name:"cssGlobalStyles.d.ts",path:e,outPath:m})),u&&(a(s,{name:"cssAvailableComponents.js",path:e,outPath:m}),l&&a(s,{name:"cssAvailableComponents.d.js",path:e,outPath:m})),s},[]):[];if(r){const h=`${e(r.name)}.js`,p=n?.provider?n.provider:r.path;a(c,{name:h,path:r.path,outPath:p});const u=t.join(r.path,"stats"),l=n?.provider?t.join(n.provider,"stats"):u;a(c,{name:"stats.js",path:u,outPath:l});const m=t.resolve(o,u),d=await s.readdir(m,{withFileTypes:!0});if(d.forEach(s=>{if(s.isDirectory()){const e=t.join(u,s.name),o=t.join(l,s.name);a(c,{name:"cssAvailableComponents.js",path:e,outPath:o}),a(c,{name:"cssClassNames.js",path:e,outPath:o}),a(c,{name:"cssGlobalStyles.js",path:e,outPath:o}),a(c,{name:"cssMediaQueries.js",path:e,outPath:o}),a(c,{name:"cssTheme.js",path:e,outPath:o}),a(c,{name:"cssVars.js",path:e,outPath:o})}}),r.declarationHelp&&!i){const s=`${e(r.name)}.d.ts`;a(c,{name:s,path:r.path,outPath:p}),a(c,{name:"stats.d.ts",path:u,outPath:l}),d.forEach(s=>{if(s.isDirectory()){const e=t.join(u,s.name),o=t.join(l,s.name);a(c,{name:"cssAvailableComponents.d.ts",path:e,outPath:o}),a(c,{name:"cssClassNames.d.ts",path:e,outPath:o}),a(c,{name:"cssGlobalStyles.d.ts",path:e,outPath:o}),a(c,{name:"cssMediaQueries.d.ts",path:e,outPath:o}),a(c,{name:"cssTheme.d.ts",path:e,outPath:o}),a(c,{name:"cssVars.d.ts",path:e,outPath:o})}})}}return c}function r({themes:s,minifyCss:e}){return s&&Array.isArray(s)&&s.length>0?s.reduce((s,o)=>{const{name:n,stylesPath:r,foreignThemes:h}=o;return n&&r&&a(s,{name:e?`${n}.min.css`:`${n}.css`,path:r}),h&&Array.isArray(h)&&h.length>0&&h.forEach(a=>{const e=t.basename(a.path),o=a.path.replace(e,"").trim(),r=s.findIndex(s=>s.name===e&&s.path===o);r>=0?s[r].parent.push({name:n,position:a.position}):s.push({name:e,path:o,parent:[{name:n,position:a.position}]})}),s},[]):[]}function h({baseOutDir:s="",type:a="-"}){const e=(()=>{switch(a){case"cjs":return"cjs";case"esm":return"esm";default:return""}})();return s?t.join(s,e):e}module.exports={getBernovaBuildArgs:o,getJsFiles:n,getCssFiles:r,getBaseOutDir:h};
@@ -0,0 +1 @@
1
+ const o=require("path"),{getBernovaBuildArgs:e,getBaseOutDir:t}=require("./getFx"),{readConfigData:s}=require("../../src/lib"),{copyCssFiles:i,embedCssForProvider:r,rewriteCssPathInStats:n,writeStatsinBuild:a,writeToolsInBuild:c,rewriteProviderTemplate:l}=require("./writeFx"),{isIterableArray:p,buildCustomOutDirs:u}=require("./utils");async function d(){console.log("Reading configuration...");const d=process.cwd(),{themes:f,provider:v,compilerOptions:y}=await s(o.resolve(d,"bernova.config.json")),{minifyCss:g,minifyJS:m,...h}=y,{css:w,tools:S,provider:C,...b}=e(["--base-out-dir","--root-dir","--prevent-process-js","--prevent-move-js","--prevent-move-dts","--types","--css","--tools","--provider","--embed-css"]),D=(()=>{const o={};return w&&(o.css=w),S&&(o.tools=S),C&&(o.provider=C),Object.keys(o).length>0?o:void 0})(),{baseOutDir:P="",rootDir:O,preventMoveJS:j,preventMoveDTS:B,preventProcessJs:T,types:J,embedCss:q,customOutDirs:M}=u({jsonConfig:h,cliConfig:{...b,customOutDirs:D}}),F=p(J)?J:[""];async function x(){const o=M?.css;if(p(f)){for(const e of f)q?await r({dir:d,theme:e,provider:v}):o&&await n({dir:d,theme:e,css:o,provider:v});await l({dir:d,embedCss:q,provider:v})}}async function I(){const e=M?.css;if(p(f))for(const t of f){const s=e??t.stylesPath??"",r=o.join(P,s);await i({dir:d,cssPath:r,theme:t})}}async function A(){let e=M?.provider??v.path??"";O&&(e=o.relative(O,e));for(const s of F){const i=t({baseOutDir:P,type:s}),r=o.join(i,e,"stats");await a({dir:d,providerPath:v.path,outPath:r,type:s,preventMoveDTS:B,minifyJS:m})}}async function k(){let e=M?.provider??v.path??"";O&&(e=o.relative(O,e));for(const s of F){const i=t({baseOutDir:P,type:s}),r=o.join(i,e);T&&await x(),await c({dir:d,toolsPath:v.path,outPath:r,preventMoveDTS:B,type:s,minifyJS:m})}}return console.log("Configuration read successfully"),{preBuildStyles:x,copyCss:I,copyStats:A,copyProvider:k,fullBuild:async function(){console.log("Copying CSS files..."),await I(),console.log("CSS files copied successfully"),j||(console.log("Copying tools files..."),await async function(){if(p(f))for(const e of f){const{bvTools:s}=e,i=s?.path;if(i){let e=M?.tools??i??"";O&&(e=o.relative(O,e));for(const s of F){const r=t({baseOutDir:P,type:s}),n=o.join(r,e);await c({dir:d,toolsPath:i,outPath:n,preventMoveDTS:B,type:s,minifyJS:m})}}}}(),console.log("Tools files copied successfully"),console.log("Copying provider and stats files..."),await k(),await A(),console.log("Provider and stats files copied successfully"))}}}module.exports={bvBuildScript:d};
@@ -0,0 +1 @@
1
+ const e=require("fs").promises,r=require("path"),t=require("@babel/core"),{minify:s}=require("terser");function o({cssThemes:e,cssOutPath:t}){return Object.entries(e).reduce((e,[s,{foreign:o}])=>{const{before:n,after:i}=o,a=n&&Array.isArray(n)&&n.length>0?n.reduce((e,s,o)=>{const n=r.basename(s);return o>0&&(e+=", "),e+`'${t}/${n}'`},""):"",u=i&&Array.isArray(i)&&i.length>0?i.reduce((e,s,o)=>{const n=r.basename(s);return o>0&&(e+=", "),e+`'${t}/${n}'`},""):"";return e+`'${s}':{css:'${t}/${s}.css',foreign:{before: [${a}],after: [${u}]}}`},"")}async function n(e,r,s=!1){const o=!!s&&"commonjs";return(await t.transformAsync(e,{filename:r,presets:[["@babel/preset-env",{modules:o,targets:{node:"current"}}]]})).code}async function i(e){return(await s(e,{compress:{dead_code:!0,drop_console:!1,drop_debugger:!0,keep_classnames:!1,keep_fargs:!0,keep_fnames:!1,keep_infinity:!1},mangle:{toplevel:!1},format:{comments:!1}})).code}function a(e,r){e.some(e=>e.name===r.name&&e.path===r.path)||e.push(r)}function u({jsonCustomOutDirs:e,cliCustomOutDirs:r}){let t={};return e&&(t={...e}),r&&(t={...t,...r}),Object.keys(t).length>0?t:void 0}function c(e="provider"){return e.charAt(0).toLowerCase()+e.slice(1)}async function m({dir:t,theme:s,foreignThemes:o}){const n=r.resolve(t,s.stylesPath,`${s.name}.min.css`),i=await e.readFile(n,"utf-8"),a={before:"",after:""};if(o)for(const s of o){const o=await e.readFile(r.resolve(t,s.path),"utf-8");a[s.position]+=o.replace(/\s+/g," ")}return a.before+i+a.after}function f({jsonConfig:e,cliConfig:r}){return{baseOutDir:r?.baseOutDir??e?.baseOutDir??"",rootDir:r?.rootDir??e?.rootDir??void 0,preventMoveJS:r?.preventMoveJs??e?.preventMoveJS??!1,preventMoveDTS:r?.preventMoveDts??e?.preventMoveDts??!1,types:r?.types??e?.types??void 0,embedCss:r?.embedCss??e?.embedCss??!1,customOutDirs:u({jsonCustomOutDirs:e?.customOutDirs,cliCustomOutDirs:r?.customOutDirs})}}function l(e){return e&&Array.isArray(e)&&e.length>0}module.exports={modifyThemesPath:o,isIterableArray:l,transpileTo:n,minifyJSFile:i,pushUniqueFile:a,overwriteCustomOutDirs:u,lowerCaseFirstChar:c,generateEmbedCssContent:m,buildCustomOutDirs:f};
@@ -0,0 +1 @@
1
+ const e=require("fs").promises,t=require("path"),{writeDoc:s,fileExists:i}=require("../../src/lib"),{modifyThemesPath:a,transpileTo:r,minifyJSFile:o,lowerCaseFirstChar:n,generateEmbedCssContent:l}=require("./utils");async function c({baseOutPath:a,cssFiles:r,rootDir:o,customOutDirs:n,dir:l}){for(const c of r){const r=(()=>o&&!n?.css?t.relative(o,c.path):n?.css?n.css:c.path)(),m=t.resolve(l,c.path,c.name);if(i(l,m)){const i=await e.readFile(m,"utf8"),o=c.name.replace(".min","");await s(t.resolve(a,r,o),i,o)}}}async function m({dir:a,cssPath:r,theme:o}){const{stylesPath:n,foreignThemes:l}=o,c=t.resolve(a,n,`${o.name}.min.css`);if(i(a,c)){const i=await e.readFile(c,"utf-8"),n=t.resolve(a,r,`${o.name}.css`);await s(n,i,`${o.name}.css`)}if(l&&Array.isArray(l)&&l.length>0)for(const o of l){const n=t.basename(o.path),l=t.resolve(a,o.path);if(i(a,l)){const i=(await e.readFile(l,"utf-8")).replace(/\s+/g," "),o=t.resolve(a,r,n);await s(o,i,n)}}}async function f({dir:e,theme:i,provider:a}){const{foreignThemes:r}=i,o=r&&Array.isArray(r)&&r.length>0?r.reduce((e,t)=>(e.push({position:t.position,path:t.path}),e),[]):void 0,n=await l({dir:e,theme:i,foreignThemes:o}),c=`export default {'${i.name}':{css:\`${n}\`}};`,m=t.resolve(e,a.path,"stats",i.name,"cssTheme.js");await s(m,c,"cssTheme.js")}async function h({dir:e,theme:i,css:r,provider:o}){const n=t.resolve(e,o.path,"stats",i.name,"cssTheme.js"),{default:l}=require(n),c=`export default {${a({cssThemes:l,cssOutPath:r})}};`;await s(n,c,"cssTheme.js")}async function p({dir:i,embedCss:a,provider:r}){const o=a?"style":"link",l=t.resolve(__dirname,`../../src/lib/generateProvider/template/providerTemplate-${o}.js`);let c=await e.readFile(l,"utf-8");c=c.replace(/\$_Provider_\$/g,r.name);const m=`${n(r.name)}.js`,f=t.resolve(i,r.path,m);await s(f,c,m)}async function d({file:i,type:a,minifyJS:n,outPath:l,currentPath:c,preventMoveDTS:m=!1}){if(i.name.endsWith(".js")){const m=t.resolve(c,i.name);let f=await e.readFile(m,"utf-8");"cjs"===a?f=await r(f,m,!0):"esm"===a&&(f=await r(f,m)),n&&(f=await o(f)),s(t.join(l,i.name),f,i.name)}if(i.name.endsWith(".d.ts")&&!m){const a=t.resolve(c,i.name),r=await e.readFile(a,"utf-8");s(t.join(l,i.name),r,i.name)}}async function u({dir:s,providerPath:i,outPath:a,minifyJS:r,preventMoveDTS:o,type:n}){const l=t.resolve(s,i,"stats"),c=await e.readdir(l,{withFileTypes:!0});for(const i of c)if(i.isDirectory()){const c=t.resolve(l,i.name),m=await e.readdir(c,{withFileTypes:!0});for(file of m)file.isFile()&&await d({file:file,type:n,minifyJS:r,outPath:t.resolve(s,a,i.name),currentPath:c,preventMoveDTS:o})}else i.isFile()&&await d({file:i,type:n,minifyJS:r,outPath:t.resolve(s,a),currentPath:l,preventMoveDTS:o})}async function v({dir:s,toolsPath:i,outPath:a,type:r,minifyJS:o,preventMoveDTS:n=!1}){const l=t.resolve(s,i),c=await e.readdir(l,{withFileTypes:!0});for(const e of c)e.isFile()&&await d({file:e,type:r,minifyJS:o,outPath:t.resolve(s,a),currentPath:l,preventMoveDTS:n})}module.exports={writeJs:d,writeCss:c,copyCssFiles:m,embedCssForProvider:f,rewriteCssPathInStats:h,rewriteProviderTemplate:p,writeStatsinBuild:u,writeToolsInBuild:v};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ const{bvBuildScript:s}=require("./functions/scriptFx");(async()=>{try{const e=await s();await e.preBuildStyles(),console.log("Pre-build styles processing completed successfully.")}catch(s){console.error("Error during pre-build styles processing:",s),process.exit(1)}})();