@udixio/theme 1.1.0 → 1.2.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/bin/main.ts +85 -0
  3. package/dist/API.d.ts +1 -0
  4. package/dist/API.d.ts.map +1 -1
  5. package/dist/bin.cjs +64 -0
  6. package/dist/bin.js +63 -0
  7. package/dist/browser.cjs +40 -0
  8. package/dist/browser.js +40 -0
  9. package/dist/config/config.interface.d.ts.map +1 -0
  10. package/dist/config/define-config.d.ts.map +1 -0
  11. package/dist/config/index.d.ts +3 -0
  12. package/dist/config/index.d.ts.map +1 -0
  13. package/dist/config/index.node.d.ts +2 -0
  14. package/dist/config/index.node.d.ts.map +1 -0
  15. package/dist/config/resolver-config.d.ts +11 -0
  16. package/dist/config/resolver-config.d.ts.map +1 -0
  17. package/dist/define-config-BFo7Sy7c.cjs +399 -0
  18. package/dist/define-config-CGG8l3fb.js +400 -0
  19. package/dist/index.browser.d.ts +2 -0
  20. package/dist/index.browser.d.ts.map +1 -0
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.node.d.ts +4 -0
  24. package/dist/index.node.d.ts.map +1 -0
  25. package/dist/load-from-path-BvdfXUD0.cjs +78 -0
  26. package/dist/load-from-path-CFpw2P_Y.js +39 -0
  27. package/dist/loader/index.d.ts +2 -0
  28. package/dist/loader/index.d.ts.map +1 -0
  29. package/dist/loader/index.node.d.ts +3 -0
  30. package/dist/loader/index.node.d.ts.map +1 -0
  31. package/dist/loader/load-from-path.d.ts +5 -0
  32. package/dist/loader/load-from-path.d.ts.map +1 -0
  33. package/dist/loader/loader.d.ts +3 -0
  34. package/dist/loader/loader.d.ts.map +1 -0
  35. package/dist/loader/unplugin.d.ts +16 -0
  36. package/dist/loader/unplugin.d.ts.map +1 -0
  37. package/dist/{index.js → loader-C_BIrsO2.js} +58 -557
  38. package/dist/{index.cjs → loader-TksB6_mM.cjs} +32 -572
  39. package/dist/node.cjs +192 -0
  40. package/dist/node.js +171 -0
  41. package/dist/plugin/plugin.api.d.ts +1 -1
  42. package/dist/plugin/plugin.api.d.ts.map +1 -1
  43. package/package.json +27 -10
  44. package/src/API.ts +4 -0
  45. package/src/config/index.node.ts +1 -0
  46. package/src/{adapter → config}/index.ts +0 -1
  47. package/src/config/resolver-config.ts +49 -0
  48. package/src/index.browser.ts +1 -0
  49. package/src/index.node.ts +3 -0
  50. package/src/index.ts +2 -2
  51. package/src/loader/index.node.ts +2 -0
  52. package/src/loader/index.ts +1 -0
  53. package/src/loader/load-from-path.ts +9 -0
  54. package/src/{adapter/adapter.abstract.ts → loader/loader.ts} +27 -28
  55. package/src/loader/unplugin.ts +158 -0
  56. package/src/plugin/plugin.api.ts +4 -4
  57. package/vite.config.ts +18 -4
  58. package/dist/adapter/adapter.abstract.d.ts +0 -10
  59. package/dist/adapter/adapter.abstract.d.ts.map +0 -1
  60. package/dist/adapter/config.interface.d.ts.map +0 -1
  61. package/dist/adapter/define-config.d.ts.map +0 -1
  62. package/dist/adapter/file-adapter.mixin.d.ts +0 -18
  63. package/dist/adapter/file-adapter.mixin.d.ts.map +0 -1
  64. package/dist/adapter/index.d.ts +0 -4
  65. package/dist/adapter/index.d.ts.map +0 -1
  66. package/dist/adapters/index.d.ts +0 -3
  67. package/dist/adapters/index.d.ts.map +0 -1
  68. package/dist/adapters/node.adapter.d.ts +0 -7
  69. package/dist/adapters/node.adapter.d.ts.map +0 -1
  70. package/dist/adapters/vite.adapter.d.ts +0 -3
  71. package/dist/adapters/vite.adapter.d.ts.map +0 -1
  72. package/src/adapter/file-adapter.mixin.ts +0 -72
  73. package/src/adapters/index.ts +0 -2
  74. package/src/adapters/node.adapter.ts +0 -57
  75. package/src/adapters/vite.adapter.ts +0 -79
  76. /package/dist/{adapter → config}/config.interface.d.ts +0 -0
  77. /package/dist/{adapter → config}/define-config.d.ts +0 -0
  78. /package/src/{adapter → config}/config.interface.ts +0 -0
  79. /package/src/{adapter → config}/define-config.ts +0 -0
@@ -0,0 +1,158 @@
1
+ import { loadFromPath } from './load-from-path';
2
+
3
+ export interface UdixioThemeOptions {
4
+ configPath?: string;
5
+ verbose?: boolean;
6
+ }
7
+
8
+ // Instance lazy-loadée
9
+ let unpluginInstance: any = null;
10
+
11
+ const createUnpluginTheme = async () => {
12
+ if (unpluginInstance) {
13
+ return unpluginInstance;
14
+ }
15
+
16
+ const { createUnplugin } = await import('unplugin');
17
+
18
+ unpluginInstance = createUnplugin<UdixioThemeOptions>((options = {}) => {
19
+ const { configPath = './theme.config', verbose = false } = options;
20
+
21
+ let resolvedConfigPath: string;
22
+
23
+ // Skip pendant la génération du graph NX
24
+ if (global.NX_GRAPH_CREATION) {
25
+ return {
26
+ name: 'udixio-theme',
27
+ };
28
+ }
29
+
30
+ const loadTheme = async (): Promise<void> => {
31
+ try {
32
+ if (verbose) {
33
+ console.log(`🎨 Loading theme from: ${configPath}`);
34
+ }
35
+ const result = await loadFromPath(configPath);
36
+ if (!resolvedConfigPath && result?.filePath) {
37
+ resolvedConfigPath = result.filePath;
38
+ }
39
+ if (verbose) {
40
+ console.log(`✅ Theme loaded successfully!`);
41
+ }
42
+ } catch (error) {
43
+ console.error(`❌ Theme loading failed:`, error);
44
+ throw error;
45
+ }
46
+ };
47
+
48
+ return {
49
+ name: 'udixio-theme',
50
+
51
+ // Hook appelé au début du build (tous les bundlers)
52
+ buildStart: async () => {
53
+ await loadTheme();
54
+ },
55
+
56
+ // Hook appelé pendant la génération (Rollup/Vite)
57
+ generateBundle: async () => {
58
+ await loadTheme();
59
+ },
60
+
61
+ // Support spécifique Vite pour HMR
62
+ vite: {
63
+ handleHotUpdate: async ({ server, file, modules }) => {
64
+ if (!resolvedConfigPath) {
65
+ const result = await loadFromPath(configPath);
66
+ resolvedConfigPath = result?.filePath || '';
67
+ }
68
+
69
+ if (resolvedConfigPath === file) {
70
+ if (verbose) {
71
+ console.log(`🔄 Theme config changed: ${file}`);
72
+ }
73
+ await loadTheme();
74
+ server.ws.send({ type: 'full-reload', path: '*' });
75
+ return modules;
76
+ }
77
+ return;
78
+ },
79
+ },
80
+
81
+ // Support spécifique Webpack pour HMR
82
+ webpack: (compiler) => {
83
+ if (compiler.options.mode === 'development') {
84
+ compiler.hooks.watchRun.tapAsync(
85
+ 'udixio-theme',
86
+ async (compilation, callback) => {
87
+ const changedFiles = compilation.modifiedFiles || new Set();
88
+
89
+ if (!resolvedConfigPath) {
90
+ const result = await loadFromPath(configPath);
91
+ resolvedConfigPath = result?.filePath || '';
92
+ }
93
+
94
+ if (changedFiles.has(resolvedConfigPath)) {
95
+ if (verbose) {
96
+ console.log(`🔄 Theme config changed: ${resolvedConfigPath}`);
97
+ }
98
+ await loadTheme();
99
+ }
100
+ callback();
101
+ },
102
+ );
103
+ }
104
+ },
105
+
106
+ // Support spécifique Rollup
107
+ rollup: {
108
+ watchChange: async (id) => {
109
+ if (!resolvedConfigPath) {
110
+ const result = await loadFromPath(configPath);
111
+ resolvedConfigPath = result?.filePath || '';
112
+ }
113
+
114
+ if (resolvedConfigPath === id) {
115
+ if (verbose) {
116
+ console.log(`🔄 Theme config changed: ${id}`);
117
+ }
118
+ await loadTheme();
119
+ }
120
+ },
121
+ },
122
+ };
123
+ });
124
+
125
+ return unpluginInstance;
126
+ };
127
+
128
+ // Exports avec lazy loading
129
+ export const vitePlugin = async (options?: UdixioThemeOptions) => {
130
+ const plugin = await createUnpluginTheme();
131
+ return plugin.vite(options);
132
+ };
133
+
134
+ export const webpackPlugin = async (options?: UdixioThemeOptions) => {
135
+ const plugin = await createUnpluginTheme();
136
+ return plugin.webpack(options);
137
+ };
138
+
139
+ export const rollupPlugin = async (options?: UdixioThemeOptions) => {
140
+ const plugin = await createUnpluginTheme();
141
+ return plugin.rollup(options);
142
+ };
143
+
144
+ export const esbuildPlugin = async (options?: UdixioThemeOptions) => {
145
+ const plugin = await createUnpluginTheme();
146
+ return plugin.esbuild(options);
147
+ };
148
+
149
+ // Export principal avec lazy loading
150
+ export const unpluginUdixioTheme = {
151
+ vite: vitePlugin,
152
+ webpack: webpackPlugin,
153
+ rollup: rollupPlugin,
154
+ esbuild: esbuildPlugin,
155
+ };
156
+
157
+ // Export par défaut
158
+ export default unpluginUdixioTheme;
@@ -35,10 +35,10 @@ export class PluginApi {
35
35
  );
36
36
  }
37
37
 
38
- public loadPlugins() {
39
- this.plugins.forEach((plugin) => {
40
- plugin.getInstance().onLoad?.();
41
- });
38
+ public async loadPlugins() {
39
+ for (const plugin of this.plugins.values()) {
40
+ await plugin.getInstance().onLoad?.();
41
+ }
42
42
  }
43
43
 
44
44
  public getPlugin<T extends PluginAbstract<any, any>>(
package/vite.config.ts CHANGED
@@ -2,15 +2,23 @@
2
2
  import { defineConfig } from 'vite';
3
3
  import dts from 'vite-plugin-dts';
4
4
  import * as path from 'path';
5
+ import { visualizer } from 'rollup-plugin-visualizer';
5
6
 
6
7
  export default defineConfig(() => ({
7
8
  root: __dirname,
8
9
  cacheDir: '../../node_modules/.vite/packages/theme',
10
+
9
11
  plugins: [
10
12
  dts({
11
13
  entryRoot: 'src',
12
14
  tsconfigPath: path.join(__dirname, 'tsconfig.lib.json'),
13
15
  }),
16
+ visualizer({
17
+ filename: '../../stats/theme.html',
18
+ open: false,
19
+ gzipSize: true,
20
+ brotliSize: true,
21
+ }),
14
22
  ],
15
23
  // Uncomment this if you are using workers.
16
24
  // worker: {
@@ -19,25 +27,31 @@ export default defineConfig(() => ({
19
27
  // Configuration for building your library.
20
28
  // See: https://vitejs.dev/guide/build.html#library-mode
21
29
  build: {
30
+ ssr: true,
22
31
  outDir: './dist',
23
32
  emptyOutDir: true,
24
33
  reportCompressedSize: true,
25
- ssr: true,
26
34
  commonjsOptions: {
27
35
  transformMixedEsModules: true,
28
36
  },
29
37
  lib: {
30
38
  // Could also be a dictionary or array of multiple entry points.
31
- entry: 'src/index.ts',
39
+ entry: {
40
+ node: 'src/index.node.ts',
41
+ bin: 'bin/main.ts',
42
+ browser: 'src/index.browser.ts',
43
+ },
44
+
32
45
  name: '@udixio/theme',
33
- fileName: 'index',
46
+ fileName: (format, entryName) =>
47
+ `${entryName}.${format === 'es' ? 'js' : 'cjs'}`,
34
48
  // Change this to the formats you want to support.
35
49
  // Don't forget to update your package.json as well.
36
50
  formats: ['es' as const, 'cjs' as const],
37
51
  },
38
52
  rollupOptions: {
39
53
  // External packages that should not be bundled into your library.
40
- external: ['pathe'],
54
+ external: ['pathe', 'jiti', 'commander', 'unplugin', 'chokidar'],
41
55
  },
42
56
  },
43
57
  test: {
@@ -1,10 +0,0 @@
1
- import { ConfigInterface } from './config.interface';
2
- import { API } from '../API';
3
- export declare abstract class AdapterAbstract {
4
- api: API;
5
- protected constructor();
6
- abstract getConfig(): Promise<ConfigInterface>;
7
- init(): Promise<void>;
8
- load(): void;
9
- }
10
- //# sourceMappingURL=adapter.abstract.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter.abstract.d.ts","sourceRoot":"","sources":["../../src/adapter/adapter.abstract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAI7B,8BAAsB,eAAe;IAC5B,GAAG,EAAE,GAAG,CAAC;IAEhB,SAAS;IAOT,QAAQ,CAAC,SAAS,IAAI,OAAO,CAAC,eAAe,CAAC;IAEjC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAwC3B,IAAI;CAGZ"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.interface.d.ts","sourceRoot":"","sources":["../../src/adapter/config.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CAAC;IAC/C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;CACtC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"define-config.d.ts","sourceRoot":"","sources":["../../src/adapter/define-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,wBAAgB,YAAY,CAAC,YAAY,EAAE,eAAe,GAAG,eAAe,CAQ3E"}
@@ -1,18 +0,0 @@
1
- import { AdapterAbstract } from './adapter.abstract';
2
- import { ConfigInterface } from './config.interface';
3
- import { Constructor } from 'type-fest';
4
- export declare function FileAdapterMixin<TBase extends Constructor<AdapterAbstract> & Constructor<{
5
- getConfig: () => Promise<ConfigInterface>;
6
- }>>(Base: TBase): {
7
- new (...args: any[]): {
8
- ensureOutDir(dirPath: string): Promise<void>;
9
- writeFile(filePath: string, content: string): Promise<void>;
10
- readFile(filePath: string): Promise<string>;
11
- deleteFile(filePath: string): Promise<void>;
12
- api: import('..').API;
13
- getConfig: (() => Promise<ConfigInterface>) & (() => Promise<ConfigInterface>);
14
- init(): Promise<void>;
15
- load(): void;
16
- };
17
- } & TBase;
18
- //# sourceMappingURL=file-adapter.mixin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"file-adapter.mixin.d.ts","sourceRoot":"","sources":["../../src/adapter/file-adapter.mixin.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,wBAAgB,gBAAgB,CAC9B,KAAK,SAAS,WAAW,CAAC,eAAe,CAAC,GACxC,WAAW,CAAC;IACV,SAAS,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;CAC3C,CAAC,EACJ,IAAI,EAAE,KAAK;kBAEY,GAAG,EAAE;8BAIE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;4BAaxB,MAAM,WAAW,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;2BAexC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;6BAatB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;;6DAjD9B,OAAO,CAAC,eAAe,CAAC;;;;UA8D9C"}
@@ -1,4 +0,0 @@
1
- export * from './config.interface';
2
- export * from './adapter.abstract';
3
- export * from './define-config';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from './node.adapter';
2
- export * from './vite.adapter';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC"}
@@ -1,7 +0,0 @@
1
- import { AdapterAbstract, ConfigInterface } from '../adapter';
2
- export declare class NodeAdapter extends AdapterAbstract {
3
- configPath: string;
4
- constructor(configPath?: string);
5
- getConfig(): Promise<ConfigInterface>;
6
- }
7
- //# sourceMappingURL=node.adapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"node.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/node.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI9D,qBAAa,WAAY,SAAQ,eAAe;IAC3B,UAAU;gBAAV,UAAU,SAAmB;IAI1C,SAAS;CA+ChB"}
@@ -1,3 +0,0 @@
1
- import { Plugin } from 'vite';
2
- export declare const udixioVite: (configPath?: string) => Promise<Plugin | undefined>;
3
- //# sourceMappingURL=vite.adapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vite.adapter.d.ts","sourceRoot":"","sources":["../../src/adapters/vite.adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,MAAM,EAAE,MAAM,MAAM,CAAC;AAKlD,eAAO,MAAM,UAAU,GACrB,mBAA6B,KAC5B,OAAO,CAAC,MAAM,GAAG,SAAS,CAuE5B,CAAC"}
@@ -1,72 +0,0 @@
1
- import * as fs from 'fs/promises';
2
- import * as path from 'path';
3
- import { AdapterAbstract } from './adapter.abstract';
4
- import { ConfigInterface } from './config.interface';
5
- import { Constructor } from 'type-fest';
6
-
7
- export function FileAdapterMixin<
8
- TBase extends Constructor<AdapterAbstract> &
9
- Constructor<{
10
- getConfig: () => Promise<ConfigInterface>;
11
- }>,
12
- >(Base: TBase) {
13
- return class extends Base {
14
- constructor(...args: any[]) {
15
- super(...args); // Appel du constructeur de la classe Base avec les arguments transmis
16
- }
17
-
18
- async ensureOutDir(dirPath: string): Promise<void> {
19
- try {
20
- await fs.mkdir(dirPath, { recursive: true });
21
- console.log(`Répertoire vérifié/créé avec succès : ${dirPath}`);
22
- } catch (error) {
23
- console.error(
24
- `Erreur lors de la création du répertoire : ${dirPath}`,
25
- error,
26
- );
27
- throw error;
28
- }
29
- }
30
-
31
- async writeFile(filePath: string, content: string): Promise<void> {
32
- try {
33
- const dirPath = path.dirname(filePath); // Extraction du répertoire cible
34
- await this.ensureOutDir(dirPath); // S'assurer que le répertoire existe
35
- await fs.writeFile(filePath, content, 'utf-8');
36
- console.log(`Fichier écrit avec succès : ${filePath}`);
37
- } catch (error) {
38
- console.error(
39
- `Erreur lors de l'écriture du fichier : ${filePath}`,
40
- error,
41
- );
42
- throw error;
43
- }
44
- }
45
-
46
- async readFile(filePath: string): Promise<string> {
47
- try {
48
- const data = await fs.readFile(filePath, 'utf-8');
49
- return data;
50
- } catch (error) {
51
- console.error(
52
- `Erreur lors de la lecture du fichier : ${filePath}`,
53
- error,
54
- );
55
- throw error;
56
- }
57
- }
58
-
59
- async deleteFile(filePath: string): Promise<void> {
60
- try {
61
- await fs.unlink(filePath);
62
- console.log(`Fichier supprimé avec succès : ${filePath}`);
63
- } catch (error) {
64
- console.error(
65
- `Erreur lors de la suppression du fichier : ${filePath}`,
66
- error,
67
- );
68
- throw error;
69
- }
70
- }
71
- };
72
- }
@@ -1,2 +0,0 @@
1
- export * from './node.adapter';
2
- export * from './vite.adapter';
@@ -1,57 +0,0 @@
1
- import { AdapterAbstract, ConfigInterface } from '../adapter';
2
- import { resolve } from 'pathe';
3
- import { createJiti } from 'jiti';
4
-
5
- export class NodeAdapter extends AdapterAbstract {
6
- constructor(public configPath = './theme.config') {
7
- super();
8
- }
9
-
10
- async getConfig() {
11
- if (
12
- typeof process !== 'undefined' &&
13
- process.release &&
14
- process.release.name === 'node'
15
- ) {
16
- const fs = (await import('fs')).default;
17
-
18
- // Créer une instance jiti pour importer des fichiers TypeScript
19
- const jiti = createJiti(import.meta.url, {
20
- // Options optionnelles
21
- debug: process.env.NODE_ENV === 'development',
22
- cache: true, // Cache les transpilations
23
- interopDefault: true, // Gère automatiquement les exports par défaut
24
- });
25
-
26
- const base = resolve(this.configPath);
27
- const extensions = ['.ts', '.js', '.mjs', '.cjs']; // .ts en premier
28
- let config: ConfigInterface | null = null;
29
-
30
- for (const ext of extensions) {
31
- const configFilePath = base + ext;
32
- if (fs.existsSync(configFilePath)) {
33
- try {
34
- // jiti peut importer directement des fichiers .ts
35
- config = await jiti.import(configFilePath, { default: true });
36
- break;
37
- } catch (error) {
38
- console.warn(`Failed to load ${configFilePath}:`, error);
39
- continue;
40
- }
41
- }
42
- }
43
-
44
- if (!config) {
45
- throw new Error(
46
- `Configuration file not found, looked for: ${base} with extensions: ${extensions.join(', ')}`,
47
- );
48
- }
49
-
50
- return config as ConfigInterface;
51
- } else {
52
- throw new Error(
53
- 'You must provide configuration object when using this library in a browser.',
54
- );
55
- }
56
- }
57
- }
@@ -1,79 +0,0 @@
1
- import { loadConfigFromFile, Plugin } from 'vite';
2
- import { AdapterAbstract, ConfigInterface } from '../adapter';
3
- import * as path from 'node:path';
4
- import * as fs from 'node:fs';
5
-
6
- export const udixioVite = async (
7
- configPath = './theme.config',
8
- ): Promise<Plugin | undefined> => {
9
- // @ts-expect-error - NX_GRAPH_CREATION is a global variable set by Nx
10
- if (global.NX_GRAPH_CREATION) {
11
- return;
12
- }
13
-
14
- class ViteAdapter extends AdapterAbstract {
15
- public configExtension?: string;
16
-
17
- constructor(public configPath: string) {
18
- super();
19
- }
20
-
21
- getConfigPath() {
22
- if (!this.configExtension) {
23
- throw new Error('config extension not found');
24
- }
25
- return path.resolve(this.configPath + this.configExtension);
26
- }
27
-
28
- async getConfig() {
29
- const resolvedPath = path.resolve(this.configPath);
30
-
31
- const result = await loadConfigFromFile(
32
- { command: 'serve', mode: 'development' }, // ou 'build'
33
- resolvedPath,
34
- );
35
- if (!result?.config) {
36
- throw new Error('config not found');
37
- }
38
- if (!this.configExtension) {
39
- this.configExtension = path.extname(result.dependencies[0]);
40
- }
41
- return result.config as unknown as ConfigInterface;
42
- }
43
- }
44
-
45
- const adapter = new ViteAdapter(configPath);
46
-
47
- await adapter.init();
48
-
49
- configPath = adapter.getConfigPath();
50
- return {
51
- name: 'vite:udixio-theme',
52
- async buildStart() {
53
- if (fs.existsSync(configPath)) {
54
- this.addWatchFile(configPath);
55
- }
56
- adapter.load();
57
- },
58
-
59
- async generateBundle() {
60
- adapter.load();
61
- },
62
-
63
- // Handles Hot Module Replacement in dev server
64
- async handleHotUpdate({ server, file, modules }) {
65
- // Vérifie si le fichier modifié correspond au chemin du fichier de config
66
- if (configPath === file) {
67
- const adapter = new ViteAdapter(configPath);
68
- await adapter.init();
69
- adapter.load();
70
-
71
- server.ws.send({ type: 'full-reload', path: '*' });
72
-
73
- return modules;
74
- }
75
-
76
- return;
77
- },
78
- };
79
- };
File without changes
File without changes
File without changes
File without changes