@yberagroup/kaizen-ui 0.0.3 → 0.0.5
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/README.md +15 -1
- package/bin/kaizen-ui.mjs +78 -3
- package/package.json +2 -2
- package/src/styles/globals.base.css +2 -0
package/README.md
CHANGED
|
@@ -23,6 +23,7 @@ npx @yberagroup/kaizen-ui init
|
|
|
23
23
|
O comando cria/atualiza:
|
|
24
24
|
- `tailwind.config.cjs` com preset Kaizen
|
|
25
25
|
- `postcss.config.cjs` com Tailwind + Autoprefixer
|
|
26
|
+
- se existirem `tailwind.config.js`, `tailwind.config.mjs`, `postcss.config.js` ou `postcss.config.mjs` (ex.: template Vite), eles sao **removidos** para nao competir com os `.cjs`
|
|
26
27
|
- import do tema no arquivo de entrada (`src/main.tsx`, `src/index.tsx`, `app/layout.tsx`, etc.) **ou**, no modo migracao, no seu CSS global
|
|
27
28
|
|
|
28
29
|
Temas suportados no wizard:
|
|
@@ -47,12 +48,25 @@ Com **varios** candidatos e **nenhum** importado pelo entry, o wizard lista os a
|
|
|
47
48
|
|
|
48
49
|
## Configuracao Tailwind (consumidor)
|
|
49
50
|
|
|
51
|
+
O Tailwind so gera classes que aparecem nos arquivos listados em `content`. As classes dos componentes (`text-kz-*`, `font-kz-*`, `rounded-kz-*`, etc.) ficam no **JS compilado** em `node_modules/@yberagroup/kaizen-ui/dist`. Por isso e obrigatorio incluir esse caminho; o `init` ja faz isso com `require.resolve`.
|
|
52
|
+
|
|
50
53
|
No `tailwind.config.cjs`:
|
|
51
54
|
|
|
52
55
|
```js
|
|
56
|
+
const path = require("path");
|
|
57
|
+
|
|
58
|
+
const kaizenUiRoot = path.dirname(
|
|
59
|
+
require.resolve("@yberagroup/kaizen-ui/tailwind-preset"),
|
|
60
|
+
);
|
|
61
|
+
|
|
53
62
|
module.exports = {
|
|
54
63
|
presets: [require("@yberagroup/kaizen-ui/tailwind-preset")],
|
|
55
|
-
content: [
|
|
64
|
+
content: [
|
|
65
|
+
"./index.html",
|
|
66
|
+
"./src/**/*.{js,ts,jsx,tsx}",
|
|
67
|
+
"./app/**/*.{js,ts,jsx,tsx}",
|
|
68
|
+
path.join(kaizenUiRoot, "dist", "**", "*.{js,mjs}"),
|
|
69
|
+
],
|
|
56
70
|
darkMode: "class",
|
|
57
71
|
};
|
|
58
72
|
```
|
package/bin/kaizen-ui.mjs
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
readFileSync,
|
|
4
|
+
writeFileSync,
|
|
5
|
+
existsSync,
|
|
6
|
+
copyFileSync,
|
|
7
|
+
unlinkSync,
|
|
8
|
+
} from "node:fs";
|
|
3
9
|
import { dirname, join, relative, resolve } from "node:path";
|
|
4
10
|
import process from "node:process";
|
|
5
11
|
import { createInterface } from "node:readline/promises";
|
|
@@ -91,6 +97,39 @@ function ensureLocalCssImportInEntry(entryPath, cssAbsPath) {
|
|
|
91
97
|
return true;
|
|
92
98
|
}
|
|
93
99
|
|
|
100
|
+
function escapeForRegExp(s) {
|
|
101
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Import ESM do pacote (aspas simples ou duplas). */
|
|
105
|
+
function hasPackageImportOfPath(source, importPath) {
|
|
106
|
+
const esc = escapeForRegExp(importPath);
|
|
107
|
+
return new RegExp(`import\\s+["']${esc}["']`).test(source);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** @import do tema dentro de CSS. */
|
|
111
|
+
function cssImportsKaizenTheme(cssSource, importPath) {
|
|
112
|
+
const esc = escapeForRegExp(importPath);
|
|
113
|
+
if (new RegExp(`@import\\s+["']${esc}["']`).test(cssSource)) return true;
|
|
114
|
+
return cssSource.includes(importPath);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* O tema Kaizen está acessível: import direto no entry ou @import em algum .css
|
|
119
|
+
* importado pelo entry (cadeia simples a partir do entry).
|
|
120
|
+
*/
|
|
121
|
+
function entryReachableKaizenTheme(entryPath, theme) {
|
|
122
|
+
const importPath = THEME_IMPORT[theme];
|
|
123
|
+
const entrySrc = readFileSync(entryPath, "utf-8");
|
|
124
|
+
if (hasPackageImportOfPath(entrySrc, importPath)) return true;
|
|
125
|
+
for (const abs of findCssImportsFromEntry(entryPath)) {
|
|
126
|
+
if (!existsSync(abs)) continue;
|
|
127
|
+
const css = readFileSync(abs, "utf-8");
|
|
128
|
+
if (cssImportsKaizenTheme(css, importPath)) return true;
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
94
133
|
function removeKaizenThemeImportsFromEntry(entryPath) {
|
|
95
134
|
let source = readFileSync(entryPath, "utf-8");
|
|
96
135
|
const lines = source.split("\n");
|
|
@@ -112,9 +151,9 @@ function removeKaizenThemeImportsFromEntry(entryPath) {
|
|
|
112
151
|
|
|
113
152
|
function ensureImportInEntry(entryPath, importPath) {
|
|
114
153
|
const source = readFileSync(entryPath, "utf-8");
|
|
115
|
-
|
|
116
|
-
if (source.includes(importLine)) return false;
|
|
154
|
+
if (hasPackageImportOfPath(source, importPath)) return false;
|
|
117
155
|
|
|
156
|
+
const importLine = `import "${importPath}";`;
|
|
118
157
|
const nextSource = `${importLine}\n${source}`;
|
|
119
158
|
writeFileSync(entryPath, nextSource, "utf-8");
|
|
120
159
|
return true;
|
|
@@ -123,12 +162,19 @@ function ensureImportInEntry(entryPath, importPath) {
|
|
|
123
162
|
function writeTailwindConfig(cwd) {
|
|
124
163
|
const file = join(cwd, "tailwind.config.cjs");
|
|
125
164
|
const content = `/** @type {import('tailwindcss').Config} */
|
|
165
|
+
const path = require("path");
|
|
166
|
+
|
|
167
|
+
const kaizenUiRoot = path.dirname(
|
|
168
|
+
require.resolve("@yberagroup/kaizen-ui/tailwind-preset"),
|
|
169
|
+
);
|
|
170
|
+
|
|
126
171
|
module.exports = {
|
|
127
172
|
presets: [require("@yberagroup/kaizen-ui/tailwind-preset")],
|
|
128
173
|
content: [
|
|
129
174
|
"./index.html",
|
|
130
175
|
"./src/**/*.{js,ts,jsx,tsx}",
|
|
131
176
|
"./app/**/*.{js,ts,jsx,tsx}",
|
|
177
|
+
path.join(kaizenUiRoot, "dist", "**", "*.{js,mjs}"),
|
|
132
178
|
],
|
|
133
179
|
darkMode: "class",
|
|
134
180
|
};
|
|
@@ -148,6 +194,24 @@ function writePostcssConfig(cwd) {
|
|
|
148
194
|
writeFileSync(file, content, "utf-8");
|
|
149
195
|
}
|
|
150
196
|
|
|
197
|
+
/** Remove configs legadas (.js/.mjs) para o Tailwind/PostCSS nao carregarem o arquivo errado ao lado do .cjs. */
|
|
198
|
+
function removeConflictingToolingConfigs(cwd) {
|
|
199
|
+
const names = [
|
|
200
|
+
"tailwind.config.js",
|
|
201
|
+
"tailwind.config.mjs",
|
|
202
|
+
"postcss.config.js",
|
|
203
|
+
"postcss.config.mjs",
|
|
204
|
+
];
|
|
205
|
+
for (const name of names) {
|
|
206
|
+
const abs = join(cwd, name);
|
|
207
|
+
if (!existsSync(abs)) continue;
|
|
208
|
+
unlinkSync(abs);
|
|
209
|
+
logStep(
|
|
210
|
+
`Removido ${name} (evita conflito com ${name.replace(/\.(js|mjs)$/i, ".cjs")}).`,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
151
215
|
async function runInit() {
|
|
152
216
|
const cwd = process.cwd();
|
|
153
217
|
const rl = createInterface({ input, output });
|
|
@@ -193,6 +257,8 @@ async function runInit() {
|
|
|
193
257
|
writePostcssConfig(cwd);
|
|
194
258
|
logStep("postcss.config.cjs criado/atualizado.");
|
|
195
259
|
|
|
260
|
+
removeConflictingToolingConfigs(cwd);
|
|
261
|
+
|
|
196
262
|
const themeImport = THEME_IMPORT[theme];
|
|
197
263
|
|
|
198
264
|
if (cssStrategy === "migrate") {
|
|
@@ -253,6 +319,15 @@ async function runInit() {
|
|
|
253
319
|
}
|
|
254
320
|
}
|
|
255
321
|
|
|
322
|
+
if (!entryReachableKaizenTheme(entryPath, theme)) {
|
|
323
|
+
const fixed = ensureImportInEntry(entryPath, themeImport);
|
|
324
|
+
if (fixed) {
|
|
325
|
+
logStep(
|
|
326
|
+
`Import do tema ${theme} garantido em ${relative(cwd, entryPath) || entryPath} (verificação final).`,
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
256
331
|
rl.close();
|
|
257
332
|
logStep("Concluído.");
|
|
258
333
|
output.write(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yberagroup/kaizen-ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"prepublishOnly": "npm run build && npm run lint"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@yberagroup/kaizen-tokens": "^0.0.
|
|
12
|
+
"@yberagroup/kaizen-tokens": "^0.0.5",
|
|
13
13
|
"class-variance-authority": "^0.7.1",
|
|
14
14
|
"clsx": "^2.1.1",
|
|
15
15
|
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|