@udixio/tailwind 1.0.0 → 1.1.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 CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.1.0 (2025-08-21)
2
+
3
+ ### 🚀 Features
4
+
5
+ - **doc:** integrate Udixio ecosystem into Astro project ([ca6b750](https://github.com/Udixio/UI/commit/ca6b750))
6
+
7
+ ### ❤️ Thank You
8
+
9
+ - Joël VIGREUX
10
+
1
11
  # 1.0.0 (2025-08-04)
2
12
 
3
13
  ### 🚀 Features
package/dist/file.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export declare const createOrUpdateFile: (filePath: string, content: string) => void;
2
2
  export declare const getFileContent: (filePath: string, searchPattern?: RegExp | string) => string | false | null;
3
3
  export declare const replaceFileContent: (filePath: string, searchPattern: RegExp | string, replacement: string) => void;
4
- export declare const findTailwindCssFile: (startDir: string, searchPattern: string) => string | null;
4
+ export declare const findTailwindCssFile: (startDir: string, searchPattern: RegExp | string) => string | never;
5
+ export declare function findProjectRoot(startPath: any): any;
5
6
  //# sourceMappingURL=file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,KAAG,IAmBtE,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,gBAAgB,MAAM,GAAG,MAAM,KAC9B,MAAM,GAAG,KAAK,GAAG,IA4CnB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,EAChB,eAAe,MAAM,GAAG,MAAM,EAC9B,aAAa,MAAM,KAClB,IAkBF,CAAC;AACF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,EAChB,eAAe,MAAM,KACpB,MAAM,GAAG,IAyBX,CAAC"}
1
+ {"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,EAAE,SAAS,MAAM,KAAG,IAmBtE,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,UAAU,MAAM,EAChB,gBAAgB,MAAM,GAAG,MAAM,KAC9B,MAAM,GAAG,KAAK,GAAG,IA4CnB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,MAAM,EAChB,eAAe,MAAM,GAAG,MAAM,EAC9B,aAAa,MAAM,KAClB,IAkBF,CAAC;AACF,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,EAChB,eAAe,MAAM,GAAG,MAAM,KAC7B,MAAM,GAAG,KA8CX,CAAC;AAEF,wBAAgB,eAAe,CAAC,SAAS,KAAA,OAaxC"}
package/dist/index.cjs CHANGED
@@ -7,6 +7,7 @@ const plugin = require("tailwindcss/plugin");
7
7
  const fs = require("fs");
8
8
  const path = require("path");
9
9
  const replaceInFile = require("replace-in-file");
10
+ const console = require("node:console");
10
11
  const theme = require("@udixio/theme");
11
12
  function _interopNamespaceDefault(e) {
12
13
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -26,6 +27,7 @@ function _interopNamespaceDefault(e) {
26
27
  }
27
28
  const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
28
29
  const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
30
+ const console__namespace = /* @__PURE__ */ _interopNamespaceDefault(console);
29
31
  const defaultConfig = {
30
32
  statePrefix: "state",
31
33
  disabledStyles: {
@@ -166,46 +168,46 @@ const createOrUpdateFile = (filePath, content) => {
166
168
  fs__namespace.mkdirSync(dirPath, { recursive: true });
167
169
  }
168
170
  fs__namespace.writeFileSync(filePath, content);
169
- console.log(`✅ File successfully created: ${filePath}`);
171
+ console__namespace.log(`✅ File successfully created: ${filePath}`);
170
172
  } else {
171
- console.log(`⚠️ File already exists: ${filePath}`);
173
+ console__namespace.log(`⚠️ File already exists: ${filePath}`);
172
174
  replaceFileContent(filePath, /[\s\S]*/, content);
173
175
  }
174
176
  } catch (error) {
175
- console.error("❌ Error while creating the file:", error);
177
+ console__namespace.error("❌ Error while creating the file:", error);
176
178
  }
177
179
  };
178
180
  const getFileContent = (filePath, searchPattern) => {
179
181
  try {
180
182
  if (!fs__namespace.existsSync(filePath)) {
181
- console.error(`❌ The specified file does not exist: ${filePath}`);
183
+ console__namespace.error(`❌ The specified file does not exist: ${filePath}`);
182
184
  return null;
183
185
  }
184
186
  const fileContent = fs__namespace.readFileSync(filePath, "utf8");
185
187
  if (searchPattern) {
186
188
  if (typeof searchPattern === "string") {
187
189
  const found = fileContent.includes(searchPattern) ? searchPattern : false;
188
- console.log(
190
+ console__namespace.log(
189
191
  found ? `✅ The file contains the specified string: "${searchPattern}"` : `⚠️ The file does NOT contain the specified string: "${searchPattern}"`
190
192
  );
191
193
  return found;
192
194
  } else {
193
195
  const match = fileContent.match(searchPattern);
194
196
  if (match) {
195
- console.log(`✅ Found match: "${match[0]}"`);
197
+ console__namespace.log(`✅ Found match: "${match[0]}"`);
196
198
  return match[0];
197
199
  } else {
198
- console.log(
200
+ console__namespace.log(
199
201
  `⚠️ No match found for the pattern: "${searchPattern.toString()}"`
200
202
  );
201
203
  return false;
202
204
  }
203
205
  }
204
206
  }
205
- console.log(`✅ File content successfully retrieved.`);
207
+ console__namespace.log(`✅ File content successfully retrieved.`);
206
208
  return fileContent;
207
209
  } catch (error) {
208
- console.error("❌ An error occurred while processing the file:", error);
210
+ console__namespace.error("❌ An error occurred while processing the file:", error);
209
211
  return null;
210
212
  }
211
213
  };
@@ -217,36 +219,64 @@ const replaceFileContent = (filePath, searchPattern, replacement) => {
217
219
  to: replacement
218
220
  });
219
221
  if (results.length > 0 && results[0].hasChanged) {
220
- console.log(`✅ Content successfully replaced in the file: ${filePath}`);
222
+ console__namespace.log(`✅ Content successfully replaced in the file: ${filePath}`);
221
223
  } else {
222
- console.log(
224
+ console__namespace.log(
223
225
  `⚠️ No replacement made. Here are some possible reasons:
224
226
  - The pattern ${searchPattern} was not found.
225
227
  - The file might already contain the expected content.`
226
228
  );
227
229
  }
228
230
  } catch (error) {
229
- console.error("❌ Error while replacing the file content:", error);
231
+ console__namespace.error("❌ Error while replacing the file content:", error);
230
232
  }
231
233
  };
232
234
  const findTailwindCssFile = (startDir, searchPattern) => {
233
- const files = fs__namespace.readdirSync(startDir);
234
- for (const file of files) {
235
- const filePath = path__namespace.join(startDir, file);
236
- const stats = fs__namespace.statSync(filePath);
237
- if (stats.isDirectory()) {
238
- const result = findTailwindCssFile(filePath, searchPattern);
239
- if (result) return result;
240
- } else if (file.endsWith(".css") || file.endsWith(".scss") || file.endsWith(".sass")) {
241
- const content = fs__namespace.readFileSync(filePath, "utf8");
242
- if (content.includes(searchPattern)) {
243
- console.log("File found:\n", filePath);
244
- return filePath;
235
+ console__namespace.log("Recherche du fichier contenant le motif...", startDir);
236
+ const stack = [startDir];
237
+ while (stack.length > 0) {
238
+ const currentDir = stack.pop();
239
+ const files = fs__namespace.readdirSync(currentDir);
240
+ for (const file of files) {
241
+ const filePath = path__namespace.join(currentDir, file);
242
+ let stats;
243
+ try {
244
+ stats = fs__namespace.statSync(filePath);
245
+ } catch (error) {
246
+ console__namespace.error(`Erreur lors de l'accès à ${filePath}:`, error);
247
+ continue;
248
+ }
249
+ if (stats.isDirectory()) {
250
+ if (file !== "node_modules") stack.push(filePath);
251
+ } else if (stats.isFile() && (file.endsWith(".css") || file.endsWith(".scss") || file.endsWith(".sass"))) {
252
+ try {
253
+ console__namespace.log(`Analyse du fichier : ${filePath}`);
254
+ const content = fs__namespace.readFileSync(filePath, "utf8");
255
+ if (content.match(searchPattern)) {
256
+ console__namespace.log("Fichier trouvé :", filePath);
257
+ return filePath;
258
+ }
259
+ } catch (readError) {
260
+ console__namespace.error(`Erreur lors de la lecture de ${filePath}:`, readError);
261
+ }
245
262
  }
246
263
  }
247
264
  }
248
- return null;
265
+ throw new Error(
266
+ `Impossible de trouver un fichier contenant "${searchPattern}" dans "${startDir}".`
267
+ );
249
268
  };
269
+ function findProjectRoot(startPath) {
270
+ let currentPath = startPath;
271
+ while (!fs__namespace.existsSync(path__namespace.join(currentPath, "package.json"))) {
272
+ const parentPath = path__namespace.dirname(currentPath);
273
+ if (currentPath === parentPath) {
274
+ throw new Error("Impossible de localiser la racine du projet.");
275
+ }
276
+ currentPath = parentPath;
277
+ }
278
+ return currentPath;
279
+ }
250
280
  class TailwindPlugin extends theme.PluginAbstract {
251
281
  constructor() {
252
282
  super(...arguments);
@@ -263,18 +293,19 @@ class TailwindImplPlugin extends theme.PluginImplAbstract {
263
293
  });
264
294
  }
265
295
  onLoad() {
266
- const searchKeyword = "@import 'tailwindcss';";
267
- const tailwindCssPath = this.options.styleFilePath ?? findTailwindCssFile(process.cwd(), searchKeyword);
268
- if (!tailwindCssPath) {
269
- throw new Error("The style file containing tailwind was not found.");
270
- }
271
- const searchPattern = /@import ["']tailwindcss["'];/;
272
- const replacement = `@import 'tailwindcss';
296
+ let udixioCssPath = this.options.styleFilePath;
297
+ const projectRoot = findProjectRoot(path.resolve());
298
+ if (!udixioCssPath) {
299
+ const searchPattern = /@import ["']tailwindcss["'];/;
300
+ const replacement = `@import 'tailwindcss';
273
301
  @import "./udixio.css";`;
274
- if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
275
- replaceFileContent(tailwindCssPath, searchPattern, replacement);
302
+ const tailwindCssPath = findTailwindCssFile(projectRoot, searchPattern);
303
+ udixioCssPath = path.join(tailwindCssPath, "../udixio.css");
304
+ console__namespace.log("rrgfgt", tailwindCssPath, udixioCssPath);
305
+ if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
306
+ replaceFileContent(tailwindCssPath, searchPattern, replacement);
307
+ }
276
308
  }
277
- const cssFilePath = path.dirname(tailwindCssPath);
278
309
  const colors = {};
279
310
  for (const isDark of [false, true]) {
280
311
  this.api.themes.update({ isDark });
@@ -297,7 +328,7 @@ class TailwindImplPlugin extends theme.PluginImplAbstract {
297
328
  ).map(([key, value]) => `${key} ${value}`).join(", ")
298
329
  };
299
330
  createOrUpdateFile(
300
- path.join(cssFilePath, "udixio.css"),
331
+ udixioCssPath,
301
332
  `
302
333
  @plugin "@udixio/tailwind" {
303
334
  colorKeys: ${configCss.colorKeys};
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ import * as fs from "fs";
6
6
  import * as path from "path";
7
7
  import path__default from "path";
8
8
  import { replaceInFileSync } from "replace-in-file";
9
+ import * as console from "node:console";
9
10
  import { PluginAbstract, FontPlugin, PluginImplAbstract } from "@udixio/theme";
10
11
  const defaultConfig = {
11
12
  statePrefix: "state",
@@ -211,23 +212,51 @@ const replaceFileContent = (filePath, searchPattern, replacement) => {
211
212
  }
212
213
  };
213
214
  const findTailwindCssFile = (startDir, searchPattern) => {
214
- const files = fs.readdirSync(startDir);
215
- for (const file of files) {
216
- const filePath = path.join(startDir, file);
217
- const stats = fs.statSync(filePath);
218
- if (stats.isDirectory()) {
219
- const result = findTailwindCssFile(filePath, searchPattern);
220
- if (result) return result;
221
- } else if (file.endsWith(".css") || file.endsWith(".scss") || file.endsWith(".sass")) {
222
- const content = fs.readFileSync(filePath, "utf8");
223
- if (content.includes(searchPattern)) {
224
- console.log("File found:\n", filePath);
225
- return filePath;
215
+ console.log("Recherche du fichier contenant le motif...", startDir);
216
+ const stack = [startDir];
217
+ while (stack.length > 0) {
218
+ const currentDir = stack.pop();
219
+ const files = fs.readdirSync(currentDir);
220
+ for (const file of files) {
221
+ const filePath = path.join(currentDir, file);
222
+ let stats;
223
+ try {
224
+ stats = fs.statSync(filePath);
225
+ } catch (error) {
226
+ console.error(`Erreur lors de l'accès à ${filePath}:`, error);
227
+ continue;
228
+ }
229
+ if (stats.isDirectory()) {
230
+ if (file !== "node_modules") stack.push(filePath);
231
+ } else if (stats.isFile() && (file.endsWith(".css") || file.endsWith(".scss") || file.endsWith(".sass"))) {
232
+ try {
233
+ console.log(`Analyse du fichier : ${filePath}`);
234
+ const content = fs.readFileSync(filePath, "utf8");
235
+ if (content.match(searchPattern)) {
236
+ console.log("Fichier trouvé :", filePath);
237
+ return filePath;
238
+ }
239
+ } catch (readError) {
240
+ console.error(`Erreur lors de la lecture de ${filePath}:`, readError);
241
+ }
226
242
  }
227
243
  }
228
244
  }
229
- return null;
245
+ throw new Error(
246
+ `Impossible de trouver un fichier contenant "${searchPattern}" dans "${startDir}".`
247
+ );
230
248
  };
249
+ function findProjectRoot(startPath) {
250
+ let currentPath = startPath;
251
+ while (!fs.existsSync(path.join(currentPath, "package.json"))) {
252
+ const parentPath = path.dirname(currentPath);
253
+ if (currentPath === parentPath) {
254
+ throw new Error("Impossible de localiser la racine du projet.");
255
+ }
256
+ currentPath = parentPath;
257
+ }
258
+ return currentPath;
259
+ }
231
260
  class TailwindPlugin extends PluginAbstract {
232
261
  constructor() {
233
262
  super(...arguments);
@@ -244,18 +273,19 @@ class TailwindImplPlugin extends PluginImplAbstract {
244
273
  });
245
274
  }
246
275
  onLoad() {
247
- const searchKeyword = "@import 'tailwindcss';";
248
- const tailwindCssPath = this.options.styleFilePath ?? findTailwindCssFile(process.cwd(), searchKeyword);
249
- if (!tailwindCssPath) {
250
- throw new Error("The style file containing tailwind was not found.");
251
- }
252
- const searchPattern = /@import ["']tailwindcss["'];/;
253
- const replacement = `@import 'tailwindcss';
276
+ let udixioCssPath = this.options.styleFilePath;
277
+ const projectRoot = findProjectRoot(path__default.resolve());
278
+ if (!udixioCssPath) {
279
+ const searchPattern = /@import ["']tailwindcss["'];/;
280
+ const replacement = `@import 'tailwindcss';
254
281
  @import "./udixio.css";`;
255
- if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
256
- replaceFileContent(tailwindCssPath, searchPattern, replacement);
282
+ const tailwindCssPath = findTailwindCssFile(projectRoot, searchPattern);
283
+ udixioCssPath = path__default.join(tailwindCssPath, "../udixio.css");
284
+ console.log("rrgfgt", tailwindCssPath, udixioCssPath);
285
+ if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
286
+ replaceFileContent(tailwindCssPath, searchPattern, replacement);
287
+ }
257
288
  }
258
- const cssFilePath = path__default.dirname(tailwindCssPath);
259
289
  const colors = {};
260
290
  for (const isDark of [false, true]) {
261
291
  this.api.themes.update({ isDark });
@@ -278,7 +308,7 @@ class TailwindImplPlugin extends PluginImplAbstract {
278
308
  ).map(([key, value]) => `${key} ${value}`).join(", ")
279
309
  };
280
310
  createOrUpdateFile(
281
- path__default.join(cssFilePath, "udixio.css"),
311
+ udixioCssPath,
282
312
  `
283
313
  @plugin "@udixio/tailwind" {
284
314
  colorKeys: ${configCss.colorKeys};
@@ -1 +1 @@
1
- {"version":3,"file":"tailwind.plugin.d.ts","sourceRoot":"","sources":["../src/tailwind.plugin.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAG/E,UAAU,qBAAqB;IAE7B,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;CAExB;AAED,qBAAa,cAAe,SAAQ,cAAc,CAChD,kBAAkB,EAClB,qBAAqB,CACtB;IACQ,YAAY,wBAAgB;IAC5B,IAAI,SAAc;IACzB,WAAW,4BAAsB;CAClC;AAED,cAAM,kBAAmB,SAAQ,kBAAkB,CAAC,qBAAqB,CAAC;IACxE,MAAM;IAMN,MAAM;CAgGP"}
1
+ {"version":3,"file":"tailwind.plugin.d.ts","sourceRoot":"","sources":["../src/tailwind.plugin.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAI/E,UAAU,qBAAqB;IAE7B,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/C,aAAa,CAAC,EAAE,MAAM,CAAC;CAExB;AAED,qBAAa,cAAe,SAAQ,cAAc,CAChD,kBAAkB,EAClB,qBAAqB,CACtB;IACQ,YAAY,wBAAgB;IAC5B,IAAI,SAAc;IACzB,WAAW,4BAAsB;CAClC;AAED,cAAM,kBAAmB,SAAQ,kBAAkB,CAAC,qBAAqB,CAAC;IACxE,MAAM;IAMN,MAAM;CAiGP"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@udixio/tailwind",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
package/src/file.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { replaceInFileSync } from 'replace-in-file';
4
+ import * as console from 'node:console';
4
5
 
5
6
  export const createOrUpdateFile = (filePath: string, content: string): void => {
6
7
  try {
@@ -97,30 +98,66 @@ export const replaceFileContent = (
97
98
  };
98
99
  export const findTailwindCssFile = (
99
100
  startDir: string,
100
- searchPattern: string,
101
- ): string | null => {
102
- const files = fs.readdirSync(startDir);
103
-
104
- for (const file of files) {
105
- const filePath = path.join(startDir, file);
106
- const stats = fs.statSync(filePath);
107
-
108
- if (stats.isDirectory()) {
109
- // Appeler récursivement si c'est un dossier
110
- const result = findTailwindCssFile(filePath, searchPattern);
111
- if (result) return result;
112
- } else if (
113
- file.endsWith('.css') ||
114
- file.endsWith('.scss') ||
115
- file.endsWith('.sass')
116
- ) {
117
- const content = fs.readFileSync(filePath, 'utf8');
118
- if (content.includes(searchPattern)) {
119
- console.log('File found:\n', filePath);
120
- return filePath;
101
+ searchPattern: RegExp | string,
102
+ ): string | never => {
103
+ console.log('Recherche du fichier contenant le motif...', startDir);
104
+
105
+ const stack = [startDir]; // Pile pour éviter une récursion implicite.
106
+
107
+ while (stack.length > 0) {
108
+ const currentDir = stack.pop()!; // Récupérer un répertoire de la pile.
109
+ const files = fs.readdirSync(currentDir);
110
+
111
+ for (const file of files) {
112
+ const filePath = path.join(currentDir, file);
113
+
114
+ let stats: fs.Stats;
115
+ try {
116
+ stats = fs.statSync(filePath);
117
+ } catch (error) {
118
+ console.error(`Erreur lors de l'accès à ${filePath}:`, error);
119
+ continue; // Ignorer toute erreur d'accès.
120
+ }
121
+
122
+ // Ignorer le dossier `node_modules` et autres fichiers inutiles.
123
+ if (stats.isDirectory()) {
124
+ if (file !== 'node_modules') stack.push(filePath); // Empiler seulement les dossiers valides.
125
+ } else if (
126
+ stats.isFile() &&
127
+ (file.endsWith('.css') ||
128
+ file.endsWith('.scss') ||
129
+ file.endsWith('.sass'))
130
+ ) {
131
+ try {
132
+ console.log(`Analyse du fichier : ${filePath}`);
133
+ const content = fs.readFileSync(filePath, 'utf8');
134
+ if (content.match(searchPattern)) {
135
+ console.log('Fichier trouvé :', filePath);
136
+ return filePath; // Retour dès qu'un fichier valide est identifié.
137
+ }
138
+ } catch (readError) {
139
+ console.error(`Erreur lors de la lecture de ${filePath}:`, readError);
140
+ }
121
141
  }
122
142
  }
123
143
  }
124
144
 
125
- return null;
145
+ throw new Error(
146
+ `Impossible de trouver un fichier contenant "${searchPattern}" dans "${startDir}".`,
147
+ );
126
148
  };
149
+
150
+ export function findProjectRoot(startPath) {
151
+ let currentPath = startPath;
152
+
153
+ // Boucle jusqu'à trouver un package.json ou jusqu'à arriver à la racine du système
154
+ while (!fs.existsSync(path.join(currentPath, 'package.json'))) {
155
+ const parentPath = path.dirname(currentPath);
156
+ if (currentPath === parentPath) {
157
+ throw new Error('Impossible de localiser la racine du projet.');
158
+ }
159
+ currentPath = parentPath;
160
+ }
161
+
162
+ return currentPath;
163
+ }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  createOrUpdateFile,
3
+ findProjectRoot,
3
4
  findTailwindCssFile,
4
5
  getFileContent,
5
6
  replaceFileContent,
@@ -7,6 +8,7 @@ import {
7
8
  import path from 'path';
8
9
  import { FontPlugin, PluginAbstract, PluginImplAbstract } from '@udixio/theme';
9
10
  import { ConfigCss } from './main';
11
+ import * as console from 'node:console';
10
12
 
11
13
  interface TailwindPluginOptions {
12
14
  // darkMode?: 'class' | 'media';
@@ -32,22 +34,23 @@ class TailwindImplPlugin extends PluginImplAbstract<TailwindPluginOptions> {
32
34
  }
33
35
 
34
36
  onLoad() {
35
- const searchKeyword = "@import 'tailwindcss';";
37
+ let udixioCssPath = this.options.styleFilePath;
36
38
 
37
- const tailwindCssPath =
38
- this.options.styleFilePath ??
39
- findTailwindCssFile(process.cwd(), searchKeyword);
40
- if (!tailwindCssPath) {
41
- throw new Error('The style file containing tailwind was not found.');
42
- }
43
- const searchPattern = /@import ["']tailwindcss["'];/;
44
- const replacement = `@import 'tailwindcss';\n@import "./udixio.css";`;
39
+ const projectRoot = findProjectRoot(path.resolve());
45
40
 
46
- if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
47
- replaceFileContent(tailwindCssPath, searchPattern, replacement);
48
- }
41
+ if (!udixioCssPath) {
42
+ const searchPattern = /@import ["']tailwindcss["'];/;
43
+ const replacement = `@import 'tailwindcss';\n@import "./udixio.css";`;
44
+
45
+ const tailwindCssPath = findTailwindCssFile(projectRoot, searchPattern);
46
+ udixioCssPath = path.join(tailwindCssPath, '../udixio.css');
49
47
 
50
- const cssFilePath = path.dirname(tailwindCssPath);
48
+ console.log('rrgfgt', tailwindCssPath, udixioCssPath);
49
+
50
+ if (!getFileContent(tailwindCssPath, /@import\s+"\.\/udixio\.css";/)) {
51
+ replaceFileContent(tailwindCssPath, searchPattern, replacement);
52
+ }
53
+ }
51
54
 
52
55
  const colors: Record<
53
56
  string,
@@ -95,7 +98,7 @@ class TailwindImplPlugin extends PluginImplAbstract<TailwindPluginOptions> {
95
98
  };
96
99
 
97
100
  createOrUpdateFile(
98
- path.join(cssFilePath, 'udixio.css'),
101
+ udixioCssPath,
99
102
  `
100
103
  @plugin "@udixio/tailwind" {
101
104
  colorKeys: ${configCss.colorKeys};