@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 +10 -0
- package/dist/file.d.ts +2 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/index.cjs +67 -36
- package/dist/index.js +54 -24
- package/dist/tailwind.plugin.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/file.ts +59 -22
- package/src/tailwind.plugin.ts +17 -14
package/CHANGELOG.md
CHANGED
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 |
|
|
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
|
package/dist/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../src/file.ts"],"names":[],"mappings":"
|
|
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
|
-
|
|
171
|
+
console__namespace.log(`✅ File successfully created: ${filePath}`);
|
|
170
172
|
} else {
|
|
171
|
-
|
|
173
|
+
console__namespace.log(`⚠️ File already exists: ${filePath}`);
|
|
172
174
|
replaceFileContent(filePath, /[\s\S]*/, content);
|
|
173
175
|
}
|
|
174
176
|
} catch (error) {
|
|
175
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
197
|
+
console__namespace.log(`✅ Found match: "${match[0]}"`);
|
|
196
198
|
return match[0];
|
|
197
199
|
} else {
|
|
198
|
-
|
|
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
|
-
|
|
207
|
+
console__namespace.log(`✅ File content successfully retrieved.`);
|
|
206
208
|
return fileContent;
|
|
207
209
|
} catch (error) {
|
|
208
|
-
|
|
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
|
-
|
|
222
|
+
console__namespace.log(`✅ Content successfully replaced in the file: ${filePath}`);
|
|
221
223
|
} else {
|
|
222
|
-
|
|
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
|
-
|
|
231
|
+
console__namespace.error("❌ Error while replacing the file content:", error);
|
|
230
232
|
}
|
|
231
233
|
};
|
|
232
234
|
const findTailwindCssFile = (startDir, searchPattern) => {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
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
|
-
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
269
|
-
|
|
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
|
-
|
|
275
|
-
|
|
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
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
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
|
-
|
|
248
|
-
const
|
|
249
|
-
if (!
|
|
250
|
-
|
|
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
|
-
|
|
256
|
-
|
|
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
|
-
|
|
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":"
|
|
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
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 |
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
+
}
|
package/src/tailwind.plugin.ts
CHANGED
|
@@ -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
|
-
|
|
37
|
+
let udixioCssPath = this.options.styleFilePath;
|
|
36
38
|
|
|
37
|
-
const
|
|
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 (!
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
101
|
+
udixioCssPath,
|
|
99
102
|
`
|
|
100
103
|
@plugin "@udixio/tailwind" {
|
|
101
104
|
colorKeys: ${configCss.colorKeys};
|