@udixio/theme 1.0.0-beta.12 → 1.0.0-beta.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@udixio/theme",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.13",
4
4
  "license": "MIT",
5
5
  "author": "vigreux-joël",
6
6
  "main": "dist/index.js",
@@ -4,6 +4,7 @@ import { resolve } from 'path';
4
4
  import { defaultColors } from '../color';
5
5
  import { VariantModel } from '../theme';
6
6
  import { AppService } from '../app.service';
7
+ import { existsSync } from 'node:fs';
7
8
 
8
9
  export function defineConfig(configObject: ConfigInterface): ConfigInterface {
9
10
  if (!configObject || typeof configObject !== 'object') {
@@ -24,7 +25,7 @@ export class ConfigService {
24
25
  this.appService = appService;
25
26
  }
26
27
 
27
- public async loadConfig(): Promise<void> {
28
+ public loadConfig(): void {
28
29
  const { themeService, colorService, pluginService } = this.appService;
29
30
  const {
30
31
  sourceColor,
@@ -35,7 +36,7 @@ export class ConfigService {
35
36
  colors,
36
37
  useDefaultColors = true,
37
38
  plugins,
38
- } = await this.getConfig();
39
+ } = this.getConfig();
39
40
  themeService.create({
40
41
  contrastLevel: contrastLevel,
41
42
  isDark: isDark,
@@ -65,9 +66,23 @@ export class ConfigService {
65
66
  }
66
67
  }
67
68
 
68
- private async getConfig(): Promise<ConfigInterface> {
69
- const path = resolve(this.configPath);
70
- const configImport = await import(path);
69
+ private getConfig(): ConfigInterface {
70
+ const base = resolve(this.configPath);
71
+ const extensions = ['.js', '.ts', '.jms', '.jcs'];
72
+ let configImport = null;
73
+
74
+ for (const ext of extensions) {
75
+ const path = base + ext;
76
+ if (existsSync(path)) {
77
+ configImport = require(path);
78
+ break;
79
+ }
80
+ }
81
+
82
+ if (!configImport) {
83
+ throw new Error('Configuration file not found');
84
+ }
85
+
71
86
  const config: unknown = configImport.default;
72
87
  return config as ConfigInterface;
73
88
  }
package/src/main.ts CHANGED
@@ -6,9 +6,9 @@ export function bootstrap(): AppService {
6
6
  return AppContainer.resolve<AppService>('appService');
7
7
  }
8
8
 
9
- export async function bootstrapFromConfig(path?: string): Promise<AppService> {
9
+ export function bootstrapFromConfig(path?: string): AppService {
10
10
  const configService = AppContainer.resolve<ConfigService>('configService');
11
11
  if (path) configService.configPath = path;
12
- await configService.loadConfig();
12
+ configService.loadConfig();
13
13
  return AppContainer.resolve<AppService>('appService');
14
14
  }
@@ -8,8 +8,8 @@ export type Theme = {
8
8
  plugins: Partial<PluginsConfig>;
9
9
  };
10
10
 
11
- export const createTheme = async (): Promise<Theme> => {
12
- const app = await bootstrapFromConfig();
11
+ export const createTheme = (): Theme => {
12
+ const app = bootstrapFromConfig();
13
13
  const plugin = app.pluginService.getPlugin(TailwindPlugin);
14
14
  if (!plugin) {
15
15
  throw new Error('Tailwind plugin not found');