bernova 1.3.0 → 1.3.2
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 -0
- package/dist/bin/bernova.js +1 -1
- package/dist/bin/buildstyle.js +1 -1
- package/dist/src/app.js +1 -1
- package/dist/src/lib/copyLocalFonts/copyLocalFonts.utils.js +1 -1
- package/dist/src/lib/generateCss/generateCSS.utils.js +1 -1
- package/dist/src/lib/generateProvider/template/providerTemplate.js +164 -1
- package/dist/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +1 -1
- package/dist/src/lib/writeDoc/writeDoc.utils.js +1 -1
- package/dist/types/lib/handlerForeignThemes/handlerForeignThemes.utils.d.ts +1 -2
- package/package.json +1 -1
- package/src/app.js +4 -8
- package/src/lib/copyLocalFonts/copyLocalFonts.utils.js +0 -4
- package/src/lib/generateCss/generateCSS.utils.js +0 -5
- package/src/lib/generateProvider/template/providerTemplate.js +2 -1
- package/src/lib/handlerForeignThemes/handlerForeignThemes.utils.js +3 -11
- package/src/lib/writeDoc/writeDoc.utils.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +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
|
+
## [1.3.2] - 2926-01-28
|
|
9
|
+
|
|
10
|
+
### Patch
|
|
11
|
+
|
|
12
|
+
- **Fixed js modules compability**: Fixed the compability when the js modules are transpiled with ts-node
|
|
13
|
+
- **Deleted multiple ora instances**: Delete the multiple ora instances to prevent failures
|
|
14
|
+
|
|
15
|
+
## [1.3.1] - 2026-01-21
|
|
16
|
+
|
|
17
|
+
### Patch
|
|
18
|
+
|
|
19
|
+
- **prevent minify provider**: Prevent minify providerTemplate.js file
|
|
20
|
+
|
|
8
21
|
## [1.3.0] - 2026-01-21
|
|
9
22
|
|
|
10
23
|
### New Features
|
package/dist/bin/bernova.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const{bernovaStyles:e}=require("../src/app.js"),{compilerTypeValid:r}=require("../src/constants/compilerType.js");(async()=>{
|
|
2
|
+
const{bernovaStyles:e}=require("../src/app.js"),{compilerTypeValid:r}=require("../src/constants/compilerType.js");(async()=>{try{const s=(process.argv.find(e=>e===`--${r.full}`||e===`--${r.foundationOnly}`||e===`--${r.componentOnly}`)||`--${r.full}`).replace("--","");await e(s)}catch(e){console.error("Error details:",e.message),process.exit(1)}})();
|
package/dist/bin/buildstyle.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const e=require("fs").promises,s=require("path"),t=require("@babel/core"),{minify:n}=require("terser"),{extractDocFragment:r,writeDoc:a,fileExists:o,readConfigData:i
|
|
2
|
+
const e=require("fs").promises,s=require("path"),t=require("@babel/core"),{minify:n}=require("terser"),{extractDocFragment:r,writeDoc:a,fileExists:o,readConfigData:i}=require("../src/lib");async function c({baseOutPath:t,jsFile:n,rootDir:i,customOutDirs:c,dir:l,minifyJS:m,preventMoveJS:u,provider:h,type:v="",embedCss:y,cssFiles:b}){const g=n.name.endsWith(".d.ts"),D=s.resolve(l,n.path,n.name);if(!o(l,D))return void console.error(`File not found: ${D}`);let j=await e.readFile(D,"utf8");const C=!!c?.css||y&&b.length>0;if("stats.js"===n.name&&C){const t=r({section:"CssThemes",doc:j}),n=t.replace(/export const cssThemes\s*=\s*/,""),a=new Function(`return (${n})`)();if(c?.css){const e=f({cssThemes:a,cssOutPath:c.css});j=j.replace(t,`export const cssThemes = {\n${e}};\n`)}else if(y&&b.length>0){const n={},r=await b.reduce(async(t,{name:r,path:a,parent:i})=>{const c=s.resolve(l,a,r);if(o(l,c)){const s=await e.readFile(c,"utf8");if(i)i.forEach(e=>{const{name:t,position:r}=e;t in n||(n[t]={before:"",after:""}),n[t][r]+=s.replace(/\s+/g,"")});else{const e=r.replace(".css","").replace(".min","");e in t||(t[e]=""),t[e]+=s.replace(/\s+/g,"")}}return t},{}),a=`export const cssThemes = {\n${Object.entries(r).reduce((e,[s,t])=>{const r=n[s]||{before:"",after:""};return e+`'${s}': { css: \`${r.before+t+r.after}\` },\n`},"")}};\n`;j=j.replace(t,a)}}if(n.name===`${h.name.toLocaleLowerCase()}.js`&&C){const t="\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 ",n="../src/lib/generateProvider/template/providerTemplate.js";let a=await e.readFile(s.resolve(__dirname,n),"utf8");a=a.replace(/\$_Provider_\$/g,h.name);const o=r({section:"Bernova provider methods",doc:a});j=a.replace(o,t.trim())}if(n.name===`${h.name.toLocaleLowerCase()}.d.ts`&&C){const t="\n #linkBuilder(css: string, id: string): void;\n #handlerThemes(data: { css: string }): void;\n #cleanUpLinks(): void;\n ",n="../src/lib/generateProvider/template/providerTemplate.d.ts";let a=await e.readFile(s.resolve(__dirname,n),"utf8");a=a.replace(/\$_Provider_\$/g,h.name);const o=r({section:"Bernova provider methods",doc:a});j=a.replace(o,t.trim())}"cjs"!==v||g||(j=await p(j,D,!0)),"esm"!==v||g||(j=await p(j,D)),m&&!g&&(j=await d(j));const O=s.relative(i||"",n.path),$=u?D:s.resolve(t,O,n.name);await a($,j,n.name)}async function l({baseOutPath:t,cssFiles:n,rootDir:r,customOutDirs:i,dir:c}){for(const l of n){const n=(()=>r&&!i?.css?s.relative(r,l.path):i?.css?i.css:l.path)(),m=s.resolve(c,l.path,l.name);if(o(c,m)){const r=await e.readFile(m,"utf8"),o=l.name.replace(".min","");await a(s.resolve(t,n,o),r,o)}}}function m({baseOutDir:e,type:t="-"}){const n=(()=>{switch(t){case"cjs":return"cjs";case"esm":return"esm";default:return""}})();return s.join(e,n)}async function p(e,s,n=!1){const r=!!n&&"commonjs";return(await t.transformAsync(e,{filename:s,presets:[["@babel/preset-env",{modules:r,targets:{node:"current"}}]]})).code}async function d(e){return(await n(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 u({themes:e,minifyCss:t}){return e&&Array.isArray(e)&&e.length>0?e.reduce((e,n)=>{const{name:r,stylesPath:a,foreignThemes:o}=n;return r&&a&&v(e,{name:t?`${r}.min.css`:`${r}.css`,path:a}),o&&Array.isArray(o)&&o.length>0&&o.forEach(t=>{const n=s.basename(t.path),a=t.path.replace(n,"").trim(),o=e.findIndex(e=>e.name===n&&e.path===a);o>=0?e[o].parent.push({name:r,position:t.position}):e.push({name:n,path:a,parent:[{name:r,position:t.position}]})}),e},[]):[]}function h({provider:e,themes:s,preventMoveDTS:t=!1}){const n=s&&s.bvTools?s.reduce((e,{bvTools:s})=>{const{path:n,declarationHelp:r,cssVariables:a,cssClassNames:o,cssMediaQueries:i,cssGlobalStyles:c,availableComponents:l}=s,m=r&&!t;return a&&(v(e,{name:"cssVars.js",path:n}),m&&v(e,{name:"cssVars.d.ts",path:n})),o&&(v(e,{name:"cssClasses.js",path:n}),m&&v(e,{name:"cssClasses.d.ts",path:n})),i&&(v(e,{name:"cssMediaQueries.js",path:n}),m&&v(e,{name:"cssMediaQueries.d.ts",path:n})),c&&(v(e,{name:"cssGlobalStyles.js",path:n}),m&&v(e,{name:"cssGlobalStyles.d.ts",path:n})),l&&(v(e,{name:"cssAvailableComponents.js",path:n}),m&&v(e,{name:"cssAvailableComponents.d.js",path:n})),e},[]):[];return e&&(v(n,{name:`${e.name.toLocaleLowerCase()}.js`,path:e.path}),v(n,{name:"stats.js",path:`${e.path}/stats`}),e.declarationHelp&&!t&&(v(n,{name:`${e.name.toLocaleLowerCase()}.d.ts`,path:e.path}),v(n,{name:"stats.d.ts",path:`${e.path}/stats`}))),n}function f({cssThemes:e,cssOutPath:t}){return Object.entries(e).reduce((e,[n,{foreign:r}])=>{const{before:a,after:o}=r,i=a&&Array.isArray(a)&&a.length>0?a.reduce((e,n,r)=>{const a=s.basename(n);return r>0&&(e+=", "),e+`'${t}/${a}'`},""):"",c=o&&Array.isArray(o)&&o.length>0?o.reduce((e,n,r)=>{const a=s.basename(n);return r>0&&(e+=", "),e+`'${t}/${a}'`},""):"";return e+`'${n}': { css: '${t}/${n}.css', foreign: { before: [${i}], after: [${c}] } },\n`},"")}function v(e,s){e.some(e=>e.name===s.name&&e.path===s.path)||e.push(s)}function y(){const e=["--base-out-dir","--root-dir","--prevent-process-js","--prevent-move-js","--prevent-move-dts","--types","--css","--tools","--provider","--embed-css"],s={};for(let t=0;t<process.argv.length;t++)if(e.includes(process.argv[t])){const n=process.argv[t].replace("--","").replace(/-([a-z])/g,(e,s)=>s.toUpperCase()),r=process.argv[t+1];s[n]=(()=>!(r&&!e.includes(r))||("none"===r.toLocaleLowerCase()?"":r))()}return s}function b({jsonCustomOutDirs:e,cliCustomOutDirs:s}){let t={};return e&&(t={...e}),s&&(t={...t,...s}),Object.keys(t).length>0?t:void 0}(async()=>{const e=process.cwd(),t=await i(s.resolve(e,"bernova.config.json")),{compilerOptions:n,provider:r,themes:a}=t;n&&r&&a||(console.error("Invalid configuration: Missing compilerOptions, themes or provider"),process.exit(1));const{baseOutDir:o,rootDir:p,minifyCss:d,minifyJS:f,preventMoveJS:v,preventMoveDTS:g,types:D,embedCss:j,customOutDirs:C}=n,{baseOutDir:O,rootDir:$,types:w,preventMoveJs:T,preventMoveDts:F,preventProcessJs:_=!1,embedCss:M,...S}=y(),A=O??o??"",E=$??p??void 0,L=T??v??!1,P=F??g??!1,k=w??D??void 0,J=M??j??!1,x=b({jsonCustomOutDirs:C,cliCustomOutDirs:S}),B=u({themes:a,minifyCss:d}),I=_?[]:h({provider:r,themes:a,preventMoveDTS:P}),q=m({baseOutDir:A});if(B&&B.length>0&&!J&&await l({baseOutPath:q,cssFiles:B,rootDir:E,customOutDirs:x,dir:e}),I&&I.length>0)if(k&&Array.isArray(k)&&k.length>0)for(const s of k){const t=m({baseOutDir:A,type:s});for(const n of I)await c({baseOutPath:t,jsFile:n,rootDir:E,customOutDirs:x,dir:e,minifyJS:f,preventMoveJS:L,provider:r,type:s,embedCss:J,cssFiles:B})}else for(const s of I)await c({baseOutPath:q,jsFile:s,rootDir:E,customOutDirs:x,dir:e,minifyJS:f,preventMoveJS:L,provider:r,embedCss:J,cssFiles:B})})();
|
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
|
|
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:f,processCssWithPostcss:m}=require("./lib/generateCss/helpers"),{compilerTypeValid:g}=require("./constants"),{generateTypesTools:p}=require("./lib/generateTypesTools/generateTypesTools.utils"),{generateTools:u}=require("./lib/generateTools/generateTools.utils");async function y(y){const h=process.cwd(),T={},{default:v}=await import("ora"),C=v("Starting BernovaStyled process...").start(),{themes:D,provider:w}=await r({dir:h});for(const r of D){const{themeCss:a,fonts:v,resetCss:D,bvTools:b,name:$,stylesPath:P,typesTools:S,foreignThemes:q,prefix:x}=o({themeConfig:r,dir:h}),B=await s({fonts:v,resetCss:D,stylesPath:P}),{theme:E,media:F=[],...N}=a,V=(()=>{switch(y){case g.foundationOnly:return N;case g.componentOnly:return{theme:E,media:F};default:return a}})(),{stylesCss:j,foundationsCss:H,stylesDocs:M,rootDocs:O,globalDocs:R}=await t({source:V,baseCss:B,compilerType:y,prefix:x}),W=P?e.resolve(h,P):e.resolve(h,"styles"),{cssDir:A,cssMinifiedDir:G,oldData:k}=await f({stylesDir:W,compilerType:y,name:$}),z=c({compilerType:y,stylesCss:j,foundationsCss:H,oldData:k}),I=await m(z,!1,null),J=await m(z,!0,null);C.start(`Writing CSS to file for theme: ${$}...`),await i(A,I,"css"),await i(G,J,"css minified"),C.succeed(`CSS written to file for theme: ${$}.`),C.start(`Compiling register for theme: ${$}...`),C.succeed(`Register compiled for theme: ${$}.`),C.start("Verifying types tools..."),S?(C.succeed(`Types tools verified for theme: ${$}.`),await p({dir:h,typesTools:S,mediaConfig:F,stylesDocs:M})):C.succeed(`No types tools found for theme: ${$}.`);const K=F?l({mediaConfig:F}):null;if(C.start(`Processing bvTools for theme: ${$}...`),b?(C.succeed(`bvTools found for theme: ${$}.`),await u({bvTools:b,compilerType:y,name:$,dir:h,stylesDir:W,stylesDocs:M,rootDocs:O,globalDocs:R,mediaDocs:K})):C.succeed(`No bvTools found for theme: ${$}.`),w){C.start(`Generating theme register for theme: ${$}...`);const s=P?e.join(P,`${$}.css`):e.join("./styles",`${$}.css`),{themeByPosition:o,variablesExtracted:t,classesExtracted:r}=await d({dir:h,foreignThemes:q});T[$]=n({cssPath:s,rootDocs:O,stylesDocs:M,globalDocs:R,mediaDocs:K,foreignStyles:r,foreignVars:t,foreignBeforeFiles:o.before,foreignAfterFiles:o.after}),C.succeed(`Theme register generated for provider for theme: ${$}`)}}w&&(C.start("Provider configuration found, generating tools..."),await a({dir:e.resolve(h,w.path),providerDocs:T,declarationHelp:w.declarationHelp,providerName:w.name,compilerType:y}),C.succeed("Provider tools generated successfully."))}module.exports={bernovaStyles:y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const o=require("path"),e=require("fs").promises,s=async(s,
|
|
1
|
+
const o=require("path"),e=require("fs").promises,s=async(s,r)=>{if(s&&0!==s.length)try{for(const l of s)for(const s in l.files){const c=o.resolve(l.files[s]),t=o.resolve(r,"fonts"),i=o.resolve(t,o.basename(l.files[s]));await e.mkdir(t,{recursive:!0}),await e.copyFile(c,i)}}catch(o){console.error(o)}else console.log("No local fonts to copy.")};module.exports={copyLocalFonts:s};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const{filterGenerateCss:s}=require("./helpers/filterGenerateCss.utils"),e=async({source:e,prefix:o,baseCss:r="",compilerType:t})=>{
|
|
1
|
+
const{filterGenerateCss:s}=require("./helpers/filterGenerateCss.utils"),e=async({source:e,prefix:o,baseCss:r="",compilerType:t})=>{try{const{stylesCss:c,foundationsCss:l,stylesDocs:n,rootDocs:a,globalDocs:i}=s({source:e,compilerType:t,baseCss:r,prefix:o});return{stylesCss:c,foundationsCss:l,stylesDocs:n,rootDocs:a,globalDocs:i}}catch(s){throw console.error(s),s}};module.exports={generateCSS:e};
|
|
@@ -1 +1,164 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
cssThemes,
|
|
3
|
+
cssClasses,
|
|
4
|
+
cssVars,
|
|
5
|
+
cssAvailableComponents,
|
|
6
|
+
cssGlobalStyles,
|
|
7
|
+
cssMediaQueries,
|
|
8
|
+
} from './stats/stats';
|
|
9
|
+
|
|
10
|
+
export class $_Provider_$ {
|
|
11
|
+
#currentTheme;
|
|
12
|
+
#themes;
|
|
13
|
+
#themesVariables;
|
|
14
|
+
#themesClassNames;
|
|
15
|
+
#themesComponents;
|
|
16
|
+
#themesGlobalStyles;
|
|
17
|
+
#themesMediaQueries;
|
|
18
|
+
#linkId;
|
|
19
|
+
#jsInCss;
|
|
20
|
+
/* Bernova provider methods */
|
|
21
|
+
#linkBuilder = (url, id) => {
|
|
22
|
+
if (typeof document === 'undefined') return;
|
|
23
|
+
let linkElement = document.getElementById(id);
|
|
24
|
+
if (!linkElement) {
|
|
25
|
+
linkElement = document.createElement('link');
|
|
26
|
+
linkElement.id = id;
|
|
27
|
+
linkElement.rel = 'stylesheet';
|
|
28
|
+
document.head.appendChild(linkElement);
|
|
29
|
+
}
|
|
30
|
+
const baseUrl = document.location.origin;
|
|
31
|
+
const href = new URL(url, baseUrl).href;
|
|
32
|
+
linkElement.href = href;
|
|
33
|
+
};
|
|
34
|
+
#handlerThemes = (data) => {
|
|
35
|
+
const { css, foreign } = data;
|
|
36
|
+
const beforeFiles = foreign?.before || [];
|
|
37
|
+
const afterFiles = foreign?.after || [];
|
|
38
|
+
//* set the lower priority foreign themes
|
|
39
|
+
beforeFiles.forEach((url, idx) => {
|
|
40
|
+
const id = `${this.#linkId}-foreign-before-${idx + 1}`;
|
|
41
|
+
this.#linkBuilder(url, id);
|
|
42
|
+
});
|
|
43
|
+
//* set main theme
|
|
44
|
+
this.#linkBuilder(css, this.#linkId);
|
|
45
|
+
//* set the higher priority foreign themes
|
|
46
|
+
afterFiles.forEach((url, idx) => {
|
|
47
|
+
const id = `${this.#linkId}-foreign-after-${idx + 1}`;
|
|
48
|
+
this.#linkBuilder(url, id);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
#cleanUpLinks = () => {
|
|
52
|
+
if (typeof document === 'undefined') return;
|
|
53
|
+
const links = document.querySelectorAll(`link[id^="${this.#linkId}"]`);
|
|
54
|
+
links.forEach((link) => link.remove());
|
|
55
|
+
};
|
|
56
|
+
/* Bernova provider methods */
|
|
57
|
+
|
|
58
|
+
constructor({ linkId, jsInCss } = {}) {
|
|
59
|
+
this.#themes = cssThemes;
|
|
60
|
+
this.#themesVariables = cssVars;
|
|
61
|
+
this.#themesClassNames = cssClasses;
|
|
62
|
+
this.#themesComponents = cssAvailableComponents;
|
|
63
|
+
this.#themesGlobalStyles = cssGlobalStyles;
|
|
64
|
+
this.#themesMediaQueries = cssMediaQueries;
|
|
65
|
+
this.#linkId = linkId || 'kb-styled-link';
|
|
66
|
+
this.#currentTheme = Object.keys(cssThemes)[0];
|
|
67
|
+
this.#jsInCss = !!jsInCss;
|
|
68
|
+
this.getComponentStyles = this.getComponentStyles.bind(this);
|
|
69
|
+
|
|
70
|
+
if (
|
|
71
|
+
typeof window !== 'undefined' &&
|
|
72
|
+
typeof document !== 'undefined' &&
|
|
73
|
+
this.#jsInCss
|
|
74
|
+
) {
|
|
75
|
+
this.#cleanUpLinks();
|
|
76
|
+
this.#handlerThemes(this.#themes[this.#currentTheme]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ? getters and setters
|
|
80
|
+
//* theme selected
|
|
81
|
+
get themeSelected() {
|
|
82
|
+
return this.#currentTheme;
|
|
83
|
+
}
|
|
84
|
+
set themeSelected(themeName) {
|
|
85
|
+
if (themeName in this.#themes) {
|
|
86
|
+
if (this.#jsInCss) {
|
|
87
|
+
this.#cleanUpLinks();
|
|
88
|
+
this.#handlerThemes(this.#themes[themeName]);
|
|
89
|
+
}
|
|
90
|
+
this.#currentTheme = themeName;
|
|
91
|
+
} else {
|
|
92
|
+
throw new Error(`${themeName} is not exists`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//* themes
|
|
96
|
+
get allThemesNames() {
|
|
97
|
+
return Object.keys(this.#themes);
|
|
98
|
+
}
|
|
99
|
+
get allThemes() {
|
|
100
|
+
return this.#themes;
|
|
101
|
+
}
|
|
102
|
+
//* variables
|
|
103
|
+
get variables() {
|
|
104
|
+
return this.#themesVariables[this.#currentTheme];
|
|
105
|
+
}
|
|
106
|
+
//* classNames
|
|
107
|
+
get classNames() {
|
|
108
|
+
return this.#themesClassNames[this.#currentTheme];
|
|
109
|
+
}
|
|
110
|
+
//* components
|
|
111
|
+
get components() {
|
|
112
|
+
return this.#themesComponents[this.#currentTheme];
|
|
113
|
+
}
|
|
114
|
+
//* global styles
|
|
115
|
+
get globalStyles() {
|
|
116
|
+
return this.#themesGlobalStyles[this.#currentTheme];
|
|
117
|
+
}
|
|
118
|
+
//* media queries
|
|
119
|
+
get mediaQueries() {
|
|
120
|
+
return this.#themesMediaQueries[this.#currentTheme];
|
|
121
|
+
}
|
|
122
|
+
//? methods
|
|
123
|
+
getComponentStyles({ variant, component, additionalClassNames }) {
|
|
124
|
+
const THEME = this.#themesClassNames[this.#currentTheme];
|
|
125
|
+
const upperComponent = component.toLocaleUpperCase();
|
|
126
|
+
const COMPONENT = THEME[upperComponent];
|
|
127
|
+
|
|
128
|
+
if (!COMPONENT) return {};
|
|
129
|
+
|
|
130
|
+
const structure = {};
|
|
131
|
+
const startV = '$_';
|
|
132
|
+
const componentVariant = (() => {
|
|
133
|
+
if (!!variant) {
|
|
134
|
+
const lowerVariant = variant.toLocaleLowerCase().replace(/-/g, '_');
|
|
135
|
+
return `${startV}${lowerVariant}`;
|
|
136
|
+
} else {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
})();
|
|
140
|
+
if (componentVariant && componentVariant in COMPONENT) {
|
|
141
|
+
const variantFragment = COMPONENT[componentVariant];
|
|
142
|
+
Object.entries(variantFragment).forEach(([key, value]) => {
|
|
143
|
+
if (!(key in structure)) {
|
|
144
|
+
structure[key] = value;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
Object.entries(COMPONENT).forEach(([key, value]) => {
|
|
149
|
+
if (key.startsWith(startV)) return;
|
|
150
|
+
if (!(key in structure)) {
|
|
151
|
+
structure[key] = value;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
if (!!additionalClassNames && Object.keys(additionalClassNames).length) {
|
|
155
|
+
Object.entries(additionalClassNames).forEach(([key, value]) => {
|
|
156
|
+
if (!(key in structure)) {
|
|
157
|
+
structure[key] = '';
|
|
158
|
+
}
|
|
159
|
+
structure[key] += ` ${value}`;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return structure;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("fs").promises,
|
|
1
|
+
const e=require("fs").promises,r=require("path"),{fileExists:t}=require("../fileExists/fileExists.utils"),{simplifyName:s}=require("../simplifyName/simplifyName.utils"),i=async({dir:i,foreignThemes:a})=>{const n={after:"",before:""},o={doc:"",declare:""},c={doc:"",declare:""},l=new Set;if(a&&a.length>0)for(const{path:d,position:f,name:m}of a){if(!t(i,d))continue;const a=s(m).toLocaleUpperCase(),$=r.resolve(i,d),h=await e.readFile($,"utf-8");n[f]+=0===n[f].length?`'${d}'`:`, '${d}'`;const p=h.match(/--[a-zA-Z0-9-_]+:\s*[^;]+;/g);p&&[...new Set(p)].forEach(e=>{const[r]=e.split(":").map(e=>e.trim()),t=s(r);l.has(t)||(l.add(t),c.doc+=` ${t}: 'var(${r})',\n`,c.declare+=` ${t}: string; \n`)});const u=h.match(/\.[a-zA-Z0-9_-]+/g);if(u){const{doc:e,declare:r}=[...new Set(u)].reduce((e,r)=>{const t=r.slice(1),i=s(t);return e.doc+=` ${i}: '${t}',\n`,e.declare+=` ${i}: string; \n`,e},{doc:"",declare:""});o.doc+=` ${a}: {\n${e} },\n`,o.declare+=` ${a}: {\n${r} },\n`}}return{themeByPosition:{after:`[${n.after}]`,before:`[${n.before}]`},variablesExtracted:c,classesExtracted:o}};module.exports={handlerForeignThemes:i};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const e=require("path"),r=require("fs/promises"),i=async(i,o,s)=>{try{await r.mkdir(e.dirname(i),{recursive:!0});const s=await Promise.resolve(o);await r.writeFile(i,s)}catch(e){console.error(e)}};module.exports={writeDoc:i};
|
|
@@ -3,11 +3,10 @@
|
|
|
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
|
|
7
6
|
* @param {Array} foreignThemes - Array of foreign theme configurations
|
|
8
7
|
* @param {string} foreignThemes[].path - Relative path to the theme CSS file
|
|
9
8
|
* @param {string} foreignThemes[].position - Where to include ('before' or 'after')
|
|
10
9
|
* @param {string} foreignThemes[].name - Theme identifier name
|
|
11
10
|
* @returns {Object} Processed theme data with variables, classes, and file paths
|
|
12
11
|
*/
|
|
13
|
-
export function handlerForeignThemes({ dir,
|
|
12
|
+
export function handlerForeignThemes({ dir, foreignThemes }: string): any;
|
package/package.json
CHANGED
package/src/app.js
CHANGED
|
@@ -10,7 +10,6 @@ const {
|
|
|
10
10
|
generateThemeRegister,
|
|
11
11
|
generateCssDoc,
|
|
12
12
|
handlerForeignThemes,
|
|
13
|
-
buildRelativePath,
|
|
14
13
|
} = require('./lib');
|
|
15
14
|
const {
|
|
16
15
|
validatePreviouslyExists,
|
|
@@ -146,14 +145,11 @@ async function bernovaStyles(compilerType) {
|
|
|
146
145
|
|
|
147
146
|
if (provider) {
|
|
148
147
|
spinner.start(`Generating theme register for theme: ${name}...`);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
from: providerDir,
|
|
153
|
-
to: path.join(stylesDir, `${name}.css`),
|
|
154
|
-
})
|
|
148
|
+
const cssPath = stylesPath
|
|
149
|
+
? path.join(stylesPath, `${name}.css`)
|
|
150
|
+
: path.join('./styles', `${name}.css`);
|
|
155
151
|
const { themeByPosition, variablesExtracted, classesExtracted } =
|
|
156
|
-
await handlerForeignThemes({ dir,
|
|
152
|
+
await handlerForeignThemes({ dir, foreignThemes });
|
|
157
153
|
|
|
158
154
|
themeRegister[name] = generateThemeRegister({
|
|
159
155
|
cssPath,
|
|
@@ -12,8 +12,6 @@ const copyLocalFonts = async (localFonts, outputDir) => {
|
|
|
12
12
|
console.log('No local fonts to copy.');
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
const { default: ora } = await import('ora');
|
|
16
|
-
const spinner = ora('Copying local fonts...').start();
|
|
17
15
|
|
|
18
16
|
try {
|
|
19
17
|
for (const font of localFonts) {
|
|
@@ -30,11 +28,9 @@ const copyLocalFonts = async (localFonts, outputDir) => {
|
|
|
30
28
|
|
|
31
29
|
// Copy the font file
|
|
32
30
|
await fs.copyFile(srcPath, destPath);
|
|
33
|
-
spinner.succeed(`Copied ${srcPath} to ${destPath}`);
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
} catch (error) {
|
|
37
|
-
spinner.fail('Failed to copy local fonts.');
|
|
38
34
|
console.error(error);
|
|
39
35
|
}
|
|
40
36
|
};
|
|
@@ -12,9 +12,6 @@ const { filterGenerateCss } = require('./helpers/filterGenerateCss.utils');
|
|
|
12
12
|
* @returns {Promise<Object>} - A promise that resolves to an object containing the generated CSS and minified CSS.
|
|
13
13
|
*/
|
|
14
14
|
const generateCSS = async ({ source, prefix, baseCss = '', compilerType }) => {
|
|
15
|
-
const { default: ora } = await import('ora');
|
|
16
|
-
const spinner = ora('Generating CSS...').start();
|
|
17
|
-
|
|
18
15
|
try {
|
|
19
16
|
const { stylesCss, foundationsCss, stylesDocs, rootDocs, globalDocs } =
|
|
20
17
|
filterGenerateCss({
|
|
@@ -24,7 +21,6 @@ const generateCSS = async ({ source, prefix, baseCss = '', compilerType }) => {
|
|
|
24
21
|
prefix,
|
|
25
22
|
});
|
|
26
23
|
|
|
27
|
-
spinner.succeed('CSS generation completed successfully.');
|
|
28
24
|
return {
|
|
29
25
|
stylesCss,
|
|
30
26
|
foundationsCss,
|
|
@@ -33,7 +29,6 @@ const generateCSS = async ({ source, prefix, baseCss = '', compilerType }) => {
|
|
|
33
29
|
globalDocs,
|
|
34
30
|
};
|
|
35
31
|
} catch (error) {
|
|
36
|
-
spinner.fail('Error generating CSS.');
|
|
37
32
|
console.error(error);
|
|
38
33
|
throw error; // Re-throw the error after logging it
|
|
39
34
|
}
|
|
@@ -27,7 +27,8 @@ export class $_Provider_$ {
|
|
|
27
27
|
linkElement.rel = 'stylesheet';
|
|
28
28
|
document.head.appendChild(linkElement);
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const baseUrl = document.location.origin;
|
|
31
|
+
const href = new URL(url, baseUrl).href;
|
|
31
32
|
linkElement.href = href;
|
|
32
33
|
};
|
|
33
34
|
#handlerThemes = (data) => {
|
|
@@ -10,21 +10,19 @@ 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');
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Processes and integrates foreign CSS theme files into Bernova compilation
|
|
17
16
|
* Extracts CSS variables and class names from external stylesheets
|
|
18
17
|
*
|
|
19
18
|
* @param {string} dir - Base directory for resolving theme file paths
|
|
20
|
-
* @param {string} providerDir - Directory of the provider for relative path calculation
|
|
21
19
|
* @param {Array} foreignThemes - Array of foreign theme configurations
|
|
22
20
|
* @param {string} foreignThemes[].path - Relative path to the theme CSS file
|
|
23
21
|
* @param {string} foreignThemes[].position - Where to include ('before' or 'after')
|
|
24
22
|
* @param {string} foreignThemes[].name - Theme identifier name
|
|
25
23
|
* @returns {Object} Processed theme data with variables, classes, and file paths
|
|
26
24
|
*/
|
|
27
|
-
const handlerForeignThemes = async ({ dir,
|
|
25
|
+
const handlerForeignThemes = async ({ dir, foreignThemes }) => {
|
|
28
26
|
// Initialize data structures for organizing theme content
|
|
29
27
|
const themeByPosition = { after: '', before: '' }; // File paths by position
|
|
30
28
|
const classesExtracted = { doc: '', declare: '' }; // CSS class documentation
|
|
@@ -41,12 +39,6 @@ const handlerForeignThemes = async ({ dir, providerDir, foreignThemes }) => {
|
|
|
41
39
|
|
|
42
40
|
// Build absolute path to the theme CSS file
|
|
43
41
|
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
|
-
});
|
|
50
42
|
|
|
51
43
|
// Read and parse theme CSS content
|
|
52
44
|
const data = await fs.readFile(themePathAbsolute, 'utf-8');
|
|
@@ -55,8 +47,8 @@ const handlerForeignThemes = async ({ dir, providerDir, foreignThemes }) => {
|
|
|
55
47
|
// idx === 0 ? `'${themeRoute}'` : `, '${themeRoute}'`;
|
|
56
48
|
themeByPosition[position] +=
|
|
57
49
|
themeByPosition[position].length === 0
|
|
58
|
-
? `'${
|
|
59
|
-
: `, '${
|
|
50
|
+
? `'${themePath}'`
|
|
51
|
+
: `, '${themePath}'`;
|
|
60
52
|
//* get the css variables
|
|
61
53
|
const variableMatches = data.match(/--[a-zA-Z0-9-_]+:\s*[^;]+;/g);
|
|
62
54
|
if (variableMatches) {
|
|
@@ -9,8 +9,6 @@ const fs = require('fs/promises');
|
|
|
9
9
|
* @param {string | Promise<string>} source - The CSS content to write.
|
|
10
10
|
*/
|
|
11
11
|
const writeDoc = async (dir, source, docName) => {
|
|
12
|
-
const { default: ora } = await import('ora');
|
|
13
|
-
const spinner = ora(`Writing ${docName} to ${dir}...`).start();
|
|
14
12
|
try {
|
|
15
13
|
// Ensure the directory exists
|
|
16
14
|
await fs.mkdir(path.dirname(dir), { recursive: true });
|
|
@@ -20,9 +18,7 @@ const writeDoc = async (dir, source, docName) => {
|
|
|
20
18
|
|
|
21
19
|
// Write the CSS content to the file
|
|
22
20
|
await fs.writeFile(dir, cssContent);
|
|
23
|
-
spinner.succeed(`${docName} successfully written to ${dir}`);
|
|
24
21
|
} catch (err) {
|
|
25
|
-
spinner.fail(`Error writing ${docName} to ${dir}`);
|
|
26
22
|
console.error(err);
|
|
27
23
|
}
|
|
28
24
|
};
|