bernova 0.2.1 → 1.0.0
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/CHANGELOG.md +13 -1
- package/README.md +56 -4
- package/dist/bin/buildstyle.js +1 -1
- package/dist/src/app.js +1 -1
- package/dist/src/lib/buildRelativePath/buildRelativePath.utils.js +1 -0
- package/dist/src/lib/extractDocFragment/extractDocFragment.utils.js +1 -1
- package/dist/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +1 -1
- package/dist/src/lib/generateCssDoc/generateCssDoc.util.js +1 -1
- package/dist/src/lib/generateProvider/template/providerTemplate.js +1 -1
- package/dist/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +1 -1
- package/dist/src/lib/index.js +1 -1
- package/dist/src/lib/readFile/readFile.utils.js +1 -1
- package/dist/types/lib/buildRelativePath/buildRelativePath.utils.d.ts +12 -0
- package/dist/types/lib/extractDocFragment/extractDocFragment.utils.d.ts +5 -3
- package/dist/types/lib/handlerForeignThemes/handlerForeignThemes.utils.d.ts +2 -1
- package/dist/types/lib/index.d.ts +2 -1
- package/package.json +6 -2
- package/src/app.js +27 -16
- package/src/lib/buildRelativePath/buildRelativePath.utils.js +30 -0
- package/src/lib/extractDocFragment/extractDocFragment.utils.js +8 -6
- package/src/lib/generateCss/helpers/utils/validatePreviouslyExists.utils.js +7 -3
- package/src/lib/generateCssDoc/generateCssDoc.util.js +2 -2
- package/src/lib/generateProvider/template/providerTemplate.js +2 -1
- package/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +13 -5
- package/src/lib/index.js +2 -0
- package/src/lib/readFile/readFile.utils.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,19 @@ All notable changes to Bernova will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [0.
|
|
8
|
+
## [1.0.0] - 2026-01-08
|
|
9
|
+
|
|
10
|
+
### New Features
|
|
11
|
+
|
|
12
|
+
- **Improve library styles and tools build/dist**: Complete the buildStyle.js cli function.
|
|
13
|
+
- **Improve provider router hanler**: Improve the Bernova provider for handler relative doc routes.
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- **Fixed the doc routes**: Change the absolute routes for relative routes into provides's stats.
|
|
18
|
+
- **Fixed Error in partial transpilation**: Fixed the function for the flags --foundationsOnly and --componentsOnly.
|
|
19
|
+
|
|
20
|
+
## [0.3.0] - 2026-01-01
|
|
9
21
|
|
|
10
22
|
### ✨ New Features
|
|
11
23
|
|
package/README.md
CHANGED
|
@@ -645,7 +645,7 @@ const BUTTON = {
|
|
|
645
645
|
},
|
|
646
646
|
hover: {
|
|
647
647
|
background_color: '#e94141',
|
|
648
|
-
}
|
|
648
|
+
},
|
|
649
649
|
focus: {
|
|
650
650
|
border_color: '#0000ff',
|
|
651
651
|
}
|
|
@@ -1485,7 +1485,10 @@ The tools generated by the library are in JavaScript format, but they have decla
|
|
|
1485
1485
|
{
|
|
1486
1486
|
//... rest of the config
|
|
1487
1487
|
"typesTools": {
|
|
1488
|
-
"stylesTypes": {
|
|
1488
|
+
"stylesTypes": {
|
|
1489
|
+
"name": "stylesTypes",
|
|
1490
|
+
"path": "./src/styles/types"
|
|
1491
|
+
},
|
|
1489
1492
|
"componentsTypes": {
|
|
1490
1493
|
"name": "componentsTypes",
|
|
1491
1494
|
"path": "./src/styles/default/tools"
|
|
@@ -1746,12 +1749,12 @@ You probably already have CSS documents with highly customized rules and want to
|
|
|
1746
1749
|
"name": "theme-1",
|
|
1747
1750
|
"foreignThemes": [
|
|
1748
1751
|
{
|
|
1749
|
-
"
|
|
1752
|
+
"position": "before",
|
|
1750
1753
|
"name": "teams",
|
|
1751
1754
|
"path": "./fixture/teams.css"
|
|
1752
1755
|
},
|
|
1753
1756
|
{
|
|
1754
|
-
"
|
|
1757
|
+
"position": "after",
|
|
1755
1758
|
"name": "reset",
|
|
1756
1759
|
"path": "./fixture/reset.css"
|
|
1757
1760
|
}
|
|
@@ -1785,3 +1788,52 @@ export const LOGIN_BUTTON = {
|
|
|
1785
1788
|
background_color: ThemeProvider.variables.color_teams_primary, // <-- This is from ':root' into teams.css document
|
|
1786
1789
|
};
|
|
1787
1790
|
```
|
|
1791
|
+
|
|
1792
|
+
## Compiler Options
|
|
1793
|
+
|
|
1794
|
+
When publishing our projects, depending of the packager configuration, it is necessary to move static files or other types of documents not originalle included. Bernova manages the files necessary for proper operation in production.
|
|
1795
|
+
|
|
1796
|
+
```json
|
|
1797
|
+
{
|
|
1798
|
+
// ...rest of the config
|
|
1799
|
+
"compilerOptions": {
|
|
1800
|
+
"baseOutDir": "./dist",
|
|
1801
|
+
"rootDir": "./src",
|
|
1802
|
+
"minifyCss": true,
|
|
1803
|
+
"minifyJS": true,
|
|
1804
|
+
"preventMoveJS": false,
|
|
1805
|
+
"preventMoveDTS": false,
|
|
1806
|
+
"types": ["cjs", "esm"],
|
|
1807
|
+
"customOutDirs": {
|
|
1808
|
+
"css": "./custom/outdir/css",
|
|
1809
|
+
"provider": "./custom/outdir/provider",
|
|
1810
|
+
"tools": "./custom/outdir/tools"
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
// ...rest of the config
|
|
1814
|
+
}
|
|
1815
|
+
```
|
|
1816
|
+
|
|
1817
|
+
### Compiler Options Properties
|
|
1818
|
+
|
|
1819
|
+
- **baseOutDir**: Specifies the base output directory where all compiled files will be placed. This is the root folder for your distribution files.
|
|
1820
|
+
|
|
1821
|
+
- **rootDir**: Defines the root directory of your source code. Used as a reference point to maintain the relative structure of the files when copying them to the output directory.
|
|
1822
|
+
|
|
1823
|
+
- **minifyCss**: When set to `true`, CSS files will be minified to reduce file size. The minified files will have the `.min.css` extension.
|
|
1824
|
+
|
|
1825
|
+
- **minifyJS**: When set to `true`, JavaScript files will be minified using Terser. This reduces file size by compressing the code, removing dead code, and dropping debbuger statements.
|
|
1826
|
+
|
|
1827
|
+
- **preventMoveJS**: When set to `true`, JavaScript file will remain in their original location instead of being copied to the output directory. Useful if you want to manage JS file separately.
|
|
1828
|
+
|
|
1829
|
+
- **preventMoveDTS**: When set to `true`, TypeScript declaration files (.d.ts) will not be copied to the output directory. Set this to `true` if you're handling type definitions through another process.
|
|
1830
|
+
|
|
1831
|
+
- **types**: An array that specifies the module formats to generate. Accepts `"cjs"` (Commonjs) and/or `"esm"` (ES Modules). For each type specified, Bernova will create a separate folder and transpile the code accordingly.
|
|
1832
|
+
|
|
1833
|
+
- `"cjs"`: Generate CommonJS modules for node.js compability.
|
|
1834
|
+
- `"esm"`: Generate ES Modules for modern JavaScript environments
|
|
1835
|
+
|
|
1836
|
+
- **customOutDirs**: An optional object that allows you to specify custom output directories for different file types, overriding the default structure:
|
|
1837
|
+
- `"css"`: Custom output path for CSS files
|
|
1838
|
+
- `"provider"`: Custom output path for provider file
|
|
1839
|
+
- `"tools"`: Custom output path for tools files (cssVars, cssClasses, etc)
|
package/dist/bin/buildstyle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const e=require("
|
|
2
|
+
const e=require("fs").promises,s=require("path"),t=require("@babel/core"),{minify:a}=require("terser"),{extractDocFragment:r,writeDoc:n,fileExists:o,readConfigData:i,buildRelativePath:c}=require("../src/lib");async function m({baseOutPath:t,jsFile:a,rootDir:i,customOutDirs:m,dir:l,minifyJS:p,preventMoveJS:f,provider:d,type:y=""}){const b=s.resolve(l,a.path,a.name);if(!o(l,b))return void console.error(`File not found: ${b}`);let D=await e.readFile(b,"utf8");if("stats.js"===a.name&&m?.css){const e=r({section:"CssThemes",doc:D}),t=e.replace(/export const cssThemes\s*=\s*/,""),a=new Function(`return (${t})`)(),n=s.relative(i||"",d.path),o=v({cssThemes:a,cssOutPath:c({from:s.resolve(n),to:s.resolve(l,m.css)})});D=D.replace(e,`export const cssThemes = {\n${o}};\n`)}"cjs"===y&&(D=await u(D,b,!0)),"esm"===y&&(D=await u(D,b)),p&&(D=await h(D));const O=s.relative(i||"",a.path),g=f?b:s.resolve(t,O,a.name);await n(g,D,a.name)}async function l({baseOutPath:t,cssFiles:a,rootDir:r,customOutDirs:i,dir:c}){for(const m of a){const a=(()=>r&&i?.css?s.relative(r,m.path):i?.css?i.css:m.path)(),l=s.resolve(c,m.path,m.name);if(o(c,l)){const r=await e.readFile(l,"utf8");await n(s.resolve(t,a,m.name),r,m.name)}}}function p({baseOutDir:e,type:t="-"}){const a=(()=>{switch(t){case"cjs":return"cjs";case"esm":return"esm";default:return""}})();return s.join(e,a)}async function u(e,s,a=!1){const r=!!a&&"commonjs";return(await t.transformAsync(e,{filename:s,presets:[["@babel/preset-env",{modules:r,target:{node:"current"}}]]})).code}async function h(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 f({themes:e,minifyCss:t}){return e&&Array.isArray(e)&&e.length>0?e.reduce((e,a)=>{const{name:r,stylesPath:n,foreignThemes:o}=a;r&&n&&y(e,{name:t?`${r}.min.css`:`${r}.css`,path:n}),o&&Array.isArray(o)&&o.length>0&&o.forEach(t=>{const a=s.basename(t),r=t.replace(a,"").trim();y(e,{name:a,path:r})})},[]):[]}function d({provider:e,themes:s,preventMoveDTS:t=!1}){const a=s&&s.bvTools?s.reduce((e,{bvTools:s})=>{const{path:a,declarationHelp:r,cssVariables:n,cssClassNames:o,cssMediaQueries:i,cssGlobalStyles:c,availableComponents:m}=s,l=r&&!t;return n&&(y(e,{name:"cssVars.js",path:a}),l&&y(e,{name:"cssVars.d.ts",path:a})),o&&(y(e,{name:"cssClasses.js",path:a}),l&&y(e,{name:"cssClasses.d.ts",path:a})),i&&(y(e,{name:"cssMediaQueries.js",path:a}),l&&y(e,{name:"cssMediaQueries.d.ts",path:a})),c&&(y(e,{name:"cssGlobalStyles.js",path:a}),l&&y(e,{name:"cssGlobalStyles.d.ts",path:a})),m&&(y(e,{name:"cssAvailableComponents.js",path:a}),l&&y(e,{name:"cssAvailableComponents.d.js",path:a})),e},[]):[];return e&&(y(a,{name:`${e.name.toLocaleLowerCase()}.js`,path:e.path}),y(a,{name:"stats.js",path:`${e.path}/stats`}),e.declarationHelp&&!t&&(y(a,{name:`${e.name.toLocaleLowerCase()}.d.ts`,path:e.path}),y(a,{name:"stats.d.ts",path:`${e.path}/stats`}))),a}function v({cssThemes:e,cssOutPath:t}){return Object.entries(e).reduce((e,[a,{foreign:r}])=>{const{before:n,after:o}=r;n&&Array.isArray(n)&&n.length>0&&n.reduce((e,a,r)=>{const n=s.basename(a);return r>0&&(e+=", "),e+`'${t}${n}'`},""),o&&Array.isArray(o)&&o.length>0&&o.reduce((e,a,r)=>{const n=s.basename(a);return r>0&&(e+=", "),e+`'${t}${n}'`},"")},"")}function y(e,s){e.some(e=>e.name===s.name&&e.path===s.path)||e.push(s)}(async()=>{const e=process.cwd(),t=await i(s.resolve(e,"bernova.config.json")),{compilerOptions:a,provider:r,themes:n}=t;a&&r&&n||(console.error("Invalid configuration: Missing compilerOptions, themes or provider"),process.exit(1));const{baseOutDir:o,rootDir:c,minifyCss:u,minifyJS:h,preventMoveJS:v,preventMoveDTS:y,types:b,customOutDirs:D}=a,O=f({themes:n,minifyCss:u}),g=d({provider:r,themes:n,preventMoveDTS:y});if(b&&Array.isArray(b)&&b.length>0)for(const s of b){const t=p({baseOutDir:o,type:s});if(O&&O.length>0&&await l({baseOutPath:t,cssFiles:O,rootDir:c,customOutDirs:D,dir:e}),g&&g.length>0)for(const a of g)await m({baseOutPath:t,jsFile:a,rootDir:c,customOutDirs:D,dir:e,minifyJS:h,preventMoveJS:v,provider:r,type:s})}else{const s=p({baseOutDir:o});if(O&&O.length>0&&await l({baseOutPath:s,cssFiles:O,rootDir:c,customOutDirs:D,dir:e}),g&&g.length>0)for(const t of g)await m({baseOutPath:s,jsFile:t,rootDir:c,customOutDirs:D,dir:e,minifyJS:h,preventMoveJS:v,provider:r})}})();
|
package/dist/src/app.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("path"),{generateBaseCss:s,compileThemes:o,generateCSS:t,compileConfig:r,writeDoc:i,generateProvider:a,processMediaConfig:l,generateThemeRegister:n,generateCssDoc:c,handlerForeignThemes:d}=require("./lib"),{validatePreviouslyExists:
|
|
1
|
+
const e=require("path"),{generateBaseCss:s,compileThemes:o,generateCSS:t,compileConfig:r,writeDoc:i,generateProvider:a,processMediaConfig:l,generateThemeRegister:n,generateCssDoc:c,handlerForeignThemes:d,buildRelativePath:f}=require("./lib"),{validatePreviouslyExists:m,processCssWithPostcss:p}=require("./lib/generateCss/helpers"),{compilerTypeValid:g}=require("./constants"),{generateTypesTools:u}=require("./lib/generateTypesTools/generateTypesTools.utils"),{generateTools:h}=require("./lib/generateTools/generateTools.utils");async function y(y){const T=process.cwd(),v={},{default:D}=await import("ora"),C=D("Starting BernovaStyled process...").start(),{themes:b,provider:w}=await r({dir:T});for(const r of b){const{themeCss:a,fonts:D,resetCss:b,bvTools:$,name:P,stylesPath:S,typesTools:q,foreignThemes:x,prefix:B}=o({themeConfig:r,dir:T}),E=await s({fonts:D,resetCss:b,stylesPath:S}),{theme:F,media:N=[],...R}=a,V=(()=>{switch(y){case g.foundationOnly:return R;case g.componentOnly:return{theme:F,media:N};default:return a}})(),{stylesCss:H,foundationsCss:M,stylesDocs:O,rootDocs:W,globalDocs:j}=await t({source:V,baseCss:E,compilerType:y,prefix:B}),A=S?e.resolve(T,S):e.resolve(T,"styles"),{cssDir:G,cssMinifiedDir:k,oldData:z}=await m({stylesDir:A,compilerType:y,name:P}),I=c({compilerType:y,stylesCss:H,foundationsCss:M,oldData:z}),J=await p(I,!1,null),K=await p(I,!0,null);C.start(`Writing CSS to file for theme: ${P}...`),await i(G,J,"css"),await i(k,K,"css minified"),C.succeed(`CSS written to file for theme: ${P}.`),C.start(`Compiling register for theme: ${P}...`),C.succeed(`Register compiled for theme: ${P}.`),C.start("Verifying types tools..."),q?(C.succeed(`Types tools verified for theme: ${P}.`),await u({dir:T,typesTools:q,mediaConfig:N,stylesDocs:O})):C.succeed(`No types tools found for theme: ${P}.`);const L=N?l({mediaConfig:N}):null;if(C.start(`Processing bvTools for theme: ${P}...`),$?(C.succeed(`bvTools found for theme: ${P}.`),await h({bvTools:$,compilerType:y,name:P,dir:T,stylesDir:A,stylesDocs:O,rootDocs:W,globalDocs:j,mediaDocs:L})):C.succeed(`No bvTools found for theme: ${P}.`),w){C.start(`Generating theme register for theme: ${P}...`);const s=e.resolve(w.path),o=f({from:s,to:e.join(A,`${P}.css`)}),{themeByPosition:t,variablesExtracted:r,classesExtracted:i}=await d({dir:T,providerDir:s,foreignThemes:x});v[P]=n({cssPath:o,rootDocs:W,stylesDocs:O,globalDocs:j,mediaDocs:L,foreignStyles:i,foreignVars:r,foreignBeforeFiles:t.before,foreignAfterFiles:t.after}),C.succeed(`Theme register generated for provider for theme: ${P}`)}}w&&(C.start("Provider configuration found, generating tools..."),await a({dir:e.resolve(T,w.path),providerDocs:v,declarationHelp:w.declarationHelp,providerName:w.name,compilerType:y}),C.succeed("Provider tools generated successfully."))}module.exports={bernovaStyles:y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("path"),n=({from:n,to:i})=>{const a=e.basename(n),l=e.basename(i),r=a.includes(".")&&n.includes(a)?e.dirname(n):e.normalize(n),s=l.includes(".")&&i.includes(l)?e.dirname(i):e.normalize(i),d=e.relative(r,s),o=l.includes(".")?l:"";return e.join(d,o)};module.exports={buildRelativePath:n};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=({section:t,doc:e})=>{const
|
|
1
|
+
const t=({section:t,doc:e,endSection:c})=>{const n=new RegExp(`/\\* ${t} \\*/([\\s\\S]*?)/\\* ${c||t} \\*/`),o=e.match(n);return o?o[1].trim():""};module.exports={extractDocFragment:t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("fs").promises,r=require("path"),{compilerTypeValid:t}=require("../../../../constants"),{extractDocFragment:s}=require("../../../extractDocFragment/extractDocFragment.utils"),
|
|
1
|
+
const e=require("fs").promises,r=require("path"),{compilerTypeValid:t}=require("../../../../constants"),{extractDocFragment:s}=require("../../../extractDocFragment/extractDocFragment.utils"),c=async({stylesDir:c,compilerType:a,name:i})=>{const n={cssDir:r.resolve(c,`${i}.css`),cssMinifiedDir:r.resolve(c,`${i}.min.css`),oldData:""};try{await e.access(c);try{if(await e.access(n.cssDir),!a||a===t.full)return n;const r=await e.readFile(n.cssDir,"utf8"),c=(()=>{switch(a){case t.foundationOnly:return"COMPONENTS";case t.componentOnly:return"FOUNDATIONS";default:return""}})();n.oldData=s({section:`=== BERNOVA ${c} ===`,endSection:`=== END ${c} ===`,doc:r})}catch{return n}}catch{return await e.mkdir(c,{recursive:!0}),n}return n};module.exports={validatePreviouslyExists:c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const{compilerTypeValid:n}=require("../../constants"),o=({compilerType:o,stylesCss:e,foundationsCss:s,oldData:N=""})=>`${o!==n.componentOnly?`/* === BERNOVA FOUNDATIONS === */\n${s}
|
|
1
|
+
const{compilerTypeValid:n}=require("../../constants"),o=({compilerType:o,stylesCss:e,foundationsCss:s,oldData:N=""})=>`${o!==n.componentOnly?`/* === BERNOVA FOUNDATIONS === */\n${s}/* === END FOUNDATIONS === */\n\n`:N}${o!==n.foundationOnly?`/* === BERNOVA COMPONENTS === */\n${e}/* === END COMPONENTS === */\n`:N}`;module.exports={generateCssDoc:o};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cssThemes as e,cssClasses as t,cssVars as s,cssAvailableComponents as i,cssGlobalStyles as n,cssMediaQueries as h}from"./stats/stats";export class $_Provider_${#e;#t;#s;#i;#n;#h;#r;#l;#m;#o=(e,t)=>{if("undefined"==typeof document)return;let s=document.getElementById(t);s||(s=document.createElement("link"),s.id=t,s.rel="stylesheet",document.head.appendChild(s)),s.href=
|
|
1
|
+
import{cssThemes as e,cssClasses as t,cssVars as s,cssAvailableComponents as i,cssGlobalStyles as n,cssMediaQueries as h}from"./stats/stats";export class $_Provider_${#e;#t;#s;#i;#n;#h;#r;#l;#m;#o=(e,t)=>{if("undefined"==typeof document)return;let s=document.getElementById(t);s||(s=document.createElement("link"),s.id=t,s.rel="stylesheet",document.head.appendChild(s));const i=new URL(e,import.meta.url).href;s.href=i};#a=e=>{const{css:t,foreign:s}=e,i=s?.before||[],n=s?.after||[];i.forEach((e,t)=>{const s=`${this.#l}-foreign-before-${t+1}`;this.#o(e,s)}),this.#o(t,this.#l),n.forEach((e,t)=>{const s=`${this.#l}-foreign-after-${t+1}`;this.#o(e,s)})};#c=()=>{"undefined"!=typeof document&&document.querySelectorAll(`link[id^="${this.#l}"]`).forEach(e=>e.remove())};constructor({linkId:r,jsInCss:l}={}){this.#t=e,this.#s=s,this.#i=t,this.#n=i,this.#h=n,this.#r=h,this.#l=r||"kb-styled-link",this.#e=Object.keys(e)[0],this.#m=!!l,this.getComponentStyles=this.getComponentStyles.bind(this),"undefined"!=typeof window&&"undefined"!=typeof document&&this.#m&&(this.#c(),this.#a(this.#t[this.#e]))}get themeSelected(){return this.#e}set themeSelected(e){if(!(e in this.#t))throw new Error(`${e} is not exists`);this.#m&&(this.#c(),this.#a(this.#t[e])),this.#e=e}get allThemesNames(){return Object.keys(this.#t)}get allThemes(){return this.#t}get variables(){return this.#s[this.#e]}get classNames(){return this.#i[this.#e]}get components(){return this.#n[this.#e]}get globalStyles(){return this.#h[this.#e]}get mediaQueries(){return this.#r[this.#e]}getComponentStyles({variant:e,component:t,additionalClassNames:s}){const i=this.#i[this.#e][t.toLocaleUpperCase()];if(!i)return{};const n={},h=!!e&&`$_${e.toLocaleLowerCase().replace(/-/g,"_")}`;if(h&&h in i){const e=i[h];Object.entries(e).forEach(([e,t])=>{e in n||(n[e]=t)})}return Object.entries(i).forEach(([e,t])=>{e.startsWith("$_")||e in n||(n[e]=t)}),s&&Object.keys(s).length&&Object.entries(s).forEach(([e,t])=>{e in n||(n[e]=""),n[e]+=` ${t}`}),n}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("fs").promises,
|
|
1
|
+
const e=require("fs").promises,t=require("path"),{fileExists:r}=require("../fileExists/fileExists.utils"),{simplifyName:i}=require("../simplifyName/simplifyName.utils"),{buildRelativePath:a}=require("../buildRelativePath/buildRelativePath.utils"),s=async({dir:s,providerDir:o,foreignThemes:n})=>{const c={after:"",before:""},l={doc:"",declare:""},d={doc:"",declare:""},f=new Set;if(n&&n.length>0)for(const{path:m,position:u,name:h}of n){if(!r(s,m))continue;const n=i(h).toLocaleUpperCase(),$=t.resolve(s,m),p=a({from:o,to:$}),g=await e.readFile($,"utf-8");c[u]+=0===c[u].length?`'${p}'`:`, '${p}'`;const b=g.match(/--[a-zA-Z0-9-_]+:\s*[^;]+;/g);b&&[...new Set(b)].forEach(e=>{const[t]=e.split(":").map(e=>e.trim()),r=i(t);f.has(r)||(f.add(r),d.doc+=` ${r}: 'var(${t})',\n`,d.declare+=` ${r}: string; \n`)});const v=g.match(/\.[a-zA-Z0-9_-]+/g);if(v){const{doc:e,declare:t}=[...new Set(v)].reduce((e,t)=>{const r=t.slice(1),a=i(r);return e.doc+=` ${a}: '${r}',\n`,e.declare+=` ${a}: string; \n`,e},{doc:"",declare:""});l.doc+=` ${n}: {\n${e} },\n`,l.declare+=` ${n}: {\n${t} },\n`}}return{themeByPosition:{after:`[${c.after}]`,before:`[${c.before}]`},variablesExtracted:d,classesExtracted:l}};module.exports={handlerForeignThemes:s};
|
package/dist/src/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const{generateCSS:e}=require("./generateCss/generateCSS.utils.js"),{readConfigData:r,readThemeData:s}=require("./readFile/readFile.utils.js"),{writeDoc:i}=require("./writeDoc/writeDoc.utils.js"),{generateBaseCss:t}=require("./generateBaseCss/generateBaseCss.utils.js"),{copyLocalFonts:a}=require("./copyLocalFonts/copyLocalFonts.utils.js"),{generateCssFonts:o}=require("./copyLocalFonts/generateCssFonts.utils.js"),{generateProvider:n}=require("./generateProvider/generateProvider.utils.js"),{compileThemes:
|
|
1
|
+
const{generateCSS:e}=require("./generateCss/generateCSS.utils.js"),{readConfigData:r,readThemeData:s}=require("./readFile/readFile.utils.js"),{writeDoc:i}=require("./writeDoc/writeDoc.utils.js"),{generateBaseCss:t}=require("./generateBaseCss/generateBaseCss.utils.js"),{copyLocalFonts:a}=require("./copyLocalFonts/copyLocalFonts.utils.js"),{generateCssFonts:o}=require("./copyLocalFonts/generateCssFonts.utils.js"),{generateProvider:n}=require("./generateProvider/generateProvider.utils.js"),{compileThemes:l}=require("./compileThemes.js"),{compileConfig:g}=require("./compileConfig.js"),{typingStyles:u}=require("./typingStyles"),{extractDocFragment:c}=require("./extractDocFragment/extractDocFragment.utils.js"),{fileExists:m}=require("./fileExists/fileExists.utils.js"),{handlerForeignThemes:C}=require("./handlerForeignThemes/handlerForeignThemes.utils.js"),{simplifyName:d}=require("./simplifyName/simplifyName.utils.js"),{processMediaConfig:p}=require("./processMediaConfig/processMediaConfig.util.js"),{buildRelativePath:h}=require("./buildRelativePath/buildRelativePath.utils.js"),{generateThemeRegister:q}=require("./generateThemeRegister/generateThemeRegister.utils.js"),{generateCssDoc:F}=require("./generateCssDoc/generateCssDoc.util.js");module.exports={generateCSS:e,readConfigData:r,readThemeData:s,writeDoc:i,generateBaseCss:t,copyLocalFonts:a,generateCssFonts:o,generateProvider:n,compileThemes:l,compileConfig:g,typingStyles:u,extractDocFragment:c,handlerForeignThemes:C,fileExists:m,simplifyName:d,processMediaConfig:p,buildRelativePath:h,generateThemeRegister:q,generateCssDoc:F};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("fs").promises,
|
|
1
|
+
const e=require("fs").promises,o=require("path"),{register:r}=require("ts-node");r({compilerOptions:{module:"commonjs",target:"es6",moduleResolution:"node",esModuleInterop:!0,allowJs:!0,skipLibCheck:!0,allowSyntheticDefaultImports:!0,checkJs:!1}});const t=async o=>{try{const r=await e.readFile(o,"utf8"),t=JSON.parse(r);if(!t||"object"!=typeof t)throw new Error("Configuration file must contain a valid JSON object");return t}catch(e){if("ENOENT"===e.code)throw new Error(`Configuration file not found: ${o}`);if(e instanceof SyntaxError)throw new Error(`Invalid JSON in configuration file: ${e.message}`);throw console.error(`Error reading config file at ${o}:`,e.message),e}},n=e=>{const r={};return Object.entries(e).forEach(([e,t])=>{try{const{path:n,name:a}=t;if(!n||!a)throw new Error(`Invalid configuration for ${e}: missing path or name`);const i=o.resolve(n);delete require.cache[i];const module=require(i);if(!(a in module))throw new Error(`Export "${a}" not found in module ${n}`);r[e]=module[a]}catch(o){throw console.error(`Failed to load theme data for ${e}:`,o.message),new Error(`Cannot load theme data for "${e}": ${o.message}`)}}),r};module.exports={readConfigData:t,readThemeData:n};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds a relative path from one location to another, handling both file paths and/or directory paths
|
|
3
|
+
*
|
|
4
|
+
* @param {object} params
|
|
5
|
+
* @param {string} params.from - The origin path (can be a file path or directory path)
|
|
6
|
+
* @param {string} params.to - The destination path (can be a file path or directory path)
|
|
7
|
+
* @returns {string} - The relative path from 'from' to 'to', including the filename if 'to' is a file path
|
|
8
|
+
*/
|
|
9
|
+
export function buildRelativePath({ from, to }: {
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
}): string;
|
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
* Extracts a specific section from CSS documentation using regex matching
|
|
9
9
|
* Looks for content between matching comment markers
|
|
10
10
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {string}
|
|
11
|
+
* @param {object}
|
|
12
|
+
* @param {string} param.section - Name of the section to extract
|
|
13
|
+
* @param {string} param.doc - CSS document content to search in
|
|
14
|
+
* @param {string} param.endSection - Optional different end section name
|
|
13
15
|
* @returns {string} Extracted section content (trimmed) or empty string if not found
|
|
14
16
|
*/
|
|
15
|
-
export function extractDocFragment({ section, doc }:
|
|
17
|
+
export function extractDocFragment({ section, doc, endSection }: object): string;
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* Extracts CSS variables and class names from external stylesheets
|
|
4
4
|
*
|
|
5
5
|
* @param {string} dir - Base directory for resolving theme file paths
|
|
6
|
+
* @param {string} providerDir - Directory of the provider for relative path calculation
|
|
6
7
|
* @param {Array} foreignThemes - Array of foreign theme configurations
|
|
7
8
|
* @param {string} foreignThemes[].path - Relative path to the theme CSS file
|
|
8
9
|
* @param {string} foreignThemes[].position - Where to include ('before' or 'after')
|
|
9
10
|
* @param {string} foreignThemes[].name - Theme identifier name
|
|
10
11
|
* @returns {Object} Processed theme data with variables, classes, and file paths
|
|
11
12
|
*/
|
|
12
|
-
export function handlerForeignThemes({ dir, foreignThemes }: string): any;
|
|
13
|
+
export function handlerForeignThemes({ dir, providerDir, foreignThemes }: string): any;
|
|
@@ -13,6 +13,7 @@ import { handlerForeignThemes } from './handlerForeignThemes/handlerForeignTheme
|
|
|
13
13
|
import { fileExists } from './fileExists/fileExists.utils.js';
|
|
14
14
|
import { simplifyName } from './simplifyName/simplifyName.utils.js';
|
|
15
15
|
import { processMediaConfig } from './processMediaConfig/processMediaConfig.util.js';
|
|
16
|
+
import { buildRelativePath } from './buildRelativePath/buildRelativePath.utils.js';
|
|
16
17
|
import { generateThemeRegister } from './generateThemeRegister/generateThemeRegister.utils.js';
|
|
17
18
|
import { generateCssDoc } from './generateCssDoc/generateCssDoc.util.js';
|
|
18
|
-
export { generateCSS, readConfigData, readThemeData, writeDoc, generateBaseCss, copyLocalFonts, generateCssFonts, generateProvider, compileThemes, compileConfig, typingStyles, extractDocFragment, handlerForeignThemes, fileExists, simplifyName, processMediaConfig, generateThemeRegister, generateCssDoc };
|
|
19
|
+
export { generateCSS, readConfigData, readThemeData, writeDoc, generateBaseCss, copyLocalFonts, generateCssFonts, generateProvider, compileThemes, compileConfig, typingStyles, extractDocFragment, handlerForeignThemes, fileExists, simplifyName, processMediaConfig, buildRelativePath, generateThemeRegister, generateCssDoc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bernova",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "The best way to write CSS with Javascript syntax",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -78,7 +78,11 @@
|
|
|
78
78
|
"postcss-font-magician": "^4.0.0",
|
|
79
79
|
"postcss-preset-env": "^10.4.0",
|
|
80
80
|
"ts-node": "^10.9.2",
|
|
81
|
-
"typescript": "*"
|
|
81
|
+
"typescript": "*",
|
|
82
|
+
"terser": "^5.44.1",
|
|
83
|
+
"tsconfig-paths": "^4.2.0",
|
|
84
|
+
"@babel/core": "^7.28.5",
|
|
85
|
+
"@babel/preset-env": "^7.28.5"
|
|
82
86
|
},
|
|
83
87
|
"devDependencies": {
|
|
84
88
|
"@babel/cli": "^7.28.3",
|
package/src/app.js
CHANGED
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
generateThemeRegister,
|
|
11
11
|
generateCssDoc,
|
|
12
12
|
handlerForeignThemes,
|
|
13
|
+
buildRelativePath,
|
|
13
14
|
} = require('./lib');
|
|
14
15
|
const {
|
|
15
16
|
validatePreviouslyExists,
|
|
@@ -59,7 +60,7 @@ async function bernovaStyles(compilerType) {
|
|
|
59
60
|
|
|
60
61
|
const baseCss = await generateBaseCss({ fonts, resetCss, stylesPath });
|
|
61
62
|
|
|
62
|
-
const { theme, media, ...withoutTheme } = themeCss;
|
|
63
|
+
const { theme, media = [], ...withoutTheme } = themeCss;
|
|
63
64
|
const source = (() => {
|
|
64
65
|
switch (compilerType) {
|
|
65
66
|
case compilerTypeValid.foundationOnly:
|
|
@@ -122,7 +123,7 @@ async function bernovaStyles(compilerType) {
|
|
|
122
123
|
spinner.succeed(`No types tools found for theme: ${name}.`);
|
|
123
124
|
}
|
|
124
125
|
|
|
125
|
-
const mediaDocs = processMediaConfig({ mediaConfig: media });
|
|
126
|
+
const mediaDocs = media ? processMediaConfig({ mediaConfig: media }) : null;
|
|
126
127
|
|
|
127
128
|
// Generate development tools if configured (bvTools)
|
|
128
129
|
spinner.start(`Processing bvTools for theme: ${name}...`);
|
|
@@ -143,20 +144,30 @@ async function bernovaStyles(compilerType) {
|
|
|
143
144
|
spinner.succeed(`No bvTools found for theme: ${name}.`);
|
|
144
145
|
}
|
|
145
146
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
cssPath
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
147
|
+
if (provider) {
|
|
148
|
+
spinner.start(`Generating theme register for theme: ${name}...`);
|
|
149
|
+
// build a relative path to CSS file from provider
|
|
150
|
+
const providerDir = path.resolve(provider.path);
|
|
151
|
+
const cssPath = buildRelativePath({
|
|
152
|
+
from: providerDir,
|
|
153
|
+
to: path.join(stylesDir, `${name}.css`),
|
|
154
|
+
})
|
|
155
|
+
const { themeByPosition, variablesExtracted, classesExtracted } =
|
|
156
|
+
await handlerForeignThemes({ dir, providerDir, foreignThemes });
|
|
157
|
+
|
|
158
|
+
themeRegister[name] = generateThemeRegister({
|
|
159
|
+
cssPath,
|
|
160
|
+
rootDocs,
|
|
161
|
+
stylesDocs,
|
|
162
|
+
globalDocs,
|
|
163
|
+
mediaDocs,
|
|
164
|
+
foreignStyles: classesExtracted,
|
|
165
|
+
foreignVars: variablesExtracted,
|
|
166
|
+
foreignBeforeFiles: themeByPosition.before,
|
|
167
|
+
foreignAfterFiles: themeByPosition.after,
|
|
168
|
+
});
|
|
169
|
+
spinner.succeed(`Theme register generated for provider for theme: ${name}`);
|
|
170
|
+
}
|
|
160
171
|
}
|
|
161
172
|
|
|
162
173
|
// Generate React/framework provider if configured
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
/**
|
|
3
|
+
* Builds a relative path from one location to another, handling both file paths and/or directory paths
|
|
4
|
+
*
|
|
5
|
+
* @param {object} params
|
|
6
|
+
* @param {string} params.from - The origin path (can be a file path or directory path)
|
|
7
|
+
* @param {string} params.to - The destination path (can be a file path or directory path)
|
|
8
|
+
* @returns {string} - The relative path from 'from' to 'to', including the filename if 'to' is a file path
|
|
9
|
+
*/
|
|
10
|
+
const buildRelativePath = ({ from , to }) => {
|
|
11
|
+
//* file names
|
|
12
|
+
const fromFileName = path.basename(from);
|
|
13
|
+
const toFileName = path.basename(to);
|
|
14
|
+
|
|
15
|
+
const fromDir =
|
|
16
|
+
fromFileName.includes('.') && from.includes(fromFileName)
|
|
17
|
+
? path.dirname(from)
|
|
18
|
+
: path.normalize(from);
|
|
19
|
+
const toDir =
|
|
20
|
+
toFileName.includes('.') && to.includes(toFileName)
|
|
21
|
+
? path.dirname(to)
|
|
22
|
+
: path.normalize(to);
|
|
23
|
+
|
|
24
|
+
const relativePath = path.relative(fromDir, toDir);
|
|
25
|
+
const fileName = toFileName.includes('.') ? toFileName : '';
|
|
26
|
+
|
|
27
|
+
return path.join(relativePath, fileName);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { buildRelativePath };
|
|
@@ -9,15 +9,17 @@
|
|
|
9
9
|
* Extracts a specific section from CSS documentation using regex matching
|
|
10
10
|
* Looks for content between matching comment markers
|
|
11
11
|
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {string}
|
|
12
|
+
* @param {object}
|
|
13
|
+
* @param {string} param.section - Name of the section to extract
|
|
14
|
+
* @param {string} param.doc - CSS document content to search in
|
|
15
|
+
* @param {string} param.endSection - Optional different end section name
|
|
14
16
|
* @returns {string} Extracted section content (trimmed) or empty string if not found
|
|
15
17
|
*/
|
|
16
|
-
const extractDocFragment = ({ section, doc }) => {
|
|
18
|
+
const extractDocFragment = ({ section, doc, endSection }) => {
|
|
19
|
+
const start = section;
|
|
20
|
+
const end = endSection || section;
|
|
17
21
|
// Create regex pattern to match section markers
|
|
18
|
-
const matcher = new RegExp(
|
|
19
|
-
`/\\* ${section} \\*/([\\s\\S]*?)/\\* ${section} \\*/`
|
|
20
|
-
);
|
|
22
|
+
const matcher = new RegExp(`/\\* ${start} \\*/([\\s\\S]*?)/\\* ${end} \\*/`);
|
|
21
23
|
const match = doc.match(matcher);
|
|
22
24
|
return match ? match[1].trim() : '';
|
|
23
25
|
};
|
|
@@ -39,14 +39,18 @@ const validatePreviouslyExists = async ({ stylesDir, compilerType, name }) => {
|
|
|
39
39
|
const section = (() => {
|
|
40
40
|
switch (compilerType) {
|
|
41
41
|
case compilerTypeValid.foundationOnly:
|
|
42
|
-
return '
|
|
42
|
+
return 'COMPONENTS';
|
|
43
43
|
case compilerTypeValid.componentOnly:
|
|
44
|
-
return '
|
|
44
|
+
return 'FOUNDATIONS';
|
|
45
45
|
default:
|
|
46
46
|
return '';
|
|
47
47
|
}
|
|
48
48
|
})();
|
|
49
|
-
dirs.oldData = extractDocFragment({
|
|
49
|
+
dirs.oldData = extractDocFragment({
|
|
50
|
+
section: `=== BERNOVA ${section} ===`,
|
|
51
|
+
endSection: `=== END ${section} ===`,
|
|
52
|
+
doc: oldCss
|
|
53
|
+
});
|
|
50
54
|
} catch {
|
|
51
55
|
return dirs;
|
|
52
56
|
}
|
|
@@ -31,12 +31,12 @@ const generateCssDoc = ({
|
|
|
31
31
|
|
|
32
32
|
// Generate foundations section (CSS variables, reset, base styles)
|
|
33
33
|
const foundations = createFoundations
|
|
34
|
-
? `/* === BERNOVA FOUNDATIONS === */\n${foundationsCss}
|
|
34
|
+
? `/* === BERNOVA FOUNDATIONS === */\n${foundationsCss}/* === END FOUNDATIONS === */\n\n`
|
|
35
35
|
: oldData;
|
|
36
36
|
|
|
37
37
|
// Generate components section (component styles, utilities, media queries)
|
|
38
38
|
const components = createComponents
|
|
39
|
-
? `/* === BERNOVA COMPONENTS === */\n${stylesCss}
|
|
39
|
+
? `/* === BERNOVA COMPONENTS === */\n${stylesCss}/* === END COMPONENTS === */\n`
|
|
40
40
|
: oldData;
|
|
41
41
|
|
|
42
42
|
// Combine sections into final CSS document
|
|
@@ -26,7 +26,8 @@ export class $_Provider_$ {
|
|
|
26
26
|
linkElement.rel = 'stylesheet';
|
|
27
27
|
document.head.appendChild(linkElement);
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
const href = new URL(url, import.meta.url).href;
|
|
30
|
+
linkElement.href = href;
|
|
30
31
|
};
|
|
31
32
|
#handlerThemes = (data) => {
|
|
32
33
|
const { css, foreign } = data;
|
|
@@ -10,19 +10,21 @@ const fs = require('fs').promises;
|
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const { fileExists } = require('../fileExists/fileExists.utils');
|
|
12
12
|
const { simplifyName } = require('../simplifyName/simplifyName.utils');
|
|
13
|
+
const { buildRelativePath } = require('../buildRelativePath/buildRelativePath.utils');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Processes and integrates foreign CSS theme files into Bernova compilation
|
|
16
17
|
* Extracts CSS variables and class names from external stylesheets
|
|
17
18
|
*
|
|
18
19
|
* @param {string} dir - Base directory for resolving theme file paths
|
|
20
|
+
* @param {string} providerDir - Directory of the provider for relative path calculation
|
|
19
21
|
* @param {Array} foreignThemes - Array of foreign theme configurations
|
|
20
22
|
* @param {string} foreignThemes[].path - Relative path to the theme CSS file
|
|
21
23
|
* @param {string} foreignThemes[].position - Where to include ('before' or 'after')
|
|
22
24
|
* @param {string} foreignThemes[].name - Theme identifier name
|
|
23
25
|
* @returns {Object} Processed theme data with variables, classes, and file paths
|
|
24
26
|
*/
|
|
25
|
-
const handlerForeignThemes = async ({ dir, foreignThemes }) => {
|
|
27
|
+
const handlerForeignThemes = async ({ dir, providerDir, foreignThemes }) => {
|
|
26
28
|
// Initialize data structures for organizing theme content
|
|
27
29
|
const themeByPosition = { after: '', before: '' }; // File paths by position
|
|
28
30
|
const classesExtracted = { doc: '', declare: '' }; // CSS class documentation
|
|
@@ -36,12 +38,18 @@ const handlerForeignThemes = async ({ dir, foreignThemes }) => {
|
|
|
36
38
|
|
|
37
39
|
// Generate normalized theme name
|
|
38
40
|
const themeName = simplifyName(name).toLocaleUpperCase();
|
|
39
|
-
|
|
40
|
-
//
|
|
41
|
-
const
|
|
41
|
+
|
|
42
|
+
// Build absolute path to the theme CSS file
|
|
43
|
+
const themePathAbsolute = path.resolve(dir, themePath);
|
|
44
|
+
|
|
45
|
+
// build a relative path to CSS file from provider location
|
|
46
|
+
const themeRoute = buildRelativePath({
|
|
47
|
+
from: providerDir,
|
|
48
|
+
to: themePathAbsolute
|
|
49
|
+
});
|
|
42
50
|
|
|
43
51
|
// Read and parse theme CSS content
|
|
44
|
-
const data = await fs.readFile(
|
|
52
|
+
const data = await fs.readFile(themePathAbsolute, 'utf-8');
|
|
45
53
|
//* save the route of the file read;
|
|
46
54
|
// themeByPosition[position] +=
|
|
47
55
|
// idx === 0 ? `'${themeRoute}'` : `, '${themeRoute}'`;
|
package/src/lib/index.js
CHANGED
|
@@ -32,6 +32,7 @@ const { simplifyName } = require('./simplifyName/simplifyName.utils.js');
|
|
|
32
32
|
const {
|
|
33
33
|
processMediaConfig,
|
|
34
34
|
} = require('./processMediaConfig/processMediaConfig.util.js');
|
|
35
|
+
const { buildRelativePath } = require('./buildRelativePath/buildRelativePath.utils.js');
|
|
35
36
|
//* register
|
|
36
37
|
const {
|
|
37
38
|
generateThemeRegister,
|
|
@@ -56,6 +57,7 @@ module.exports = {
|
|
|
56
57
|
fileExists,
|
|
57
58
|
simplifyName,
|
|
58
59
|
processMediaConfig,
|
|
60
|
+
buildRelativePath,
|
|
59
61
|
generateThemeRegister,
|
|
60
62
|
generateCssDoc,
|
|
61
63
|
};
|