vueless 1.2.1-beta.0 → 1.2.1-beta.1

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": "vueless",
3
- "version": "1.2.1-beta.0",
3
+ "version": "1.2.1-beta.1",
4
4
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
5
5
  "author": "Johnny Grid <hello@vueless.com> (https://vueless.com)",
6
6
  "homepage": "https://vueless.com",
package/plugin-vite.js CHANGED
@@ -120,21 +120,21 @@ export const Vueless = function (options = {}) {
120
120
  configResolved: async (config) => {
121
121
  if (!isNuxtModuleEnv) {
122
122
  /* auto import user configs */
123
- await autoImportUserConfigs();
123
+ await autoImportUserConfigs(basePath);
124
124
 
125
125
  /* merge and cache component configs. */
126
126
  await cacheMergedConfigs(vuelessSrcDir);
127
127
  }
128
128
 
129
- await buildWebTypes(vuelessSrcDir);
130
- await setCustomPropTypes(vuelessSrcDir);
129
+ await buildWebTypes({ vuelessSrcDir, basePath });
130
+ await setCustomPropTypes({ vuelessSrcDir, basePath });
131
131
 
132
132
  /* collect used in project colors for tailwind safelist */
133
- await createTailwindSafelist({ env, srcDir: vuelessSrcDir, targetFiles, debug });
133
+ await createTailwindSafelist({ env, srcDir: vuelessSrcDir, targetFiles, basePath, debug });
134
134
 
135
135
  /* cache vueless built-in and project icons */
136
136
  await removeIconsCache(basePath);
137
- await createIconsCache({ env, debug, targetFiles });
137
+ await createIconsCache({ env, targetFiles, basePath, debug });
138
138
 
139
139
  if (isNuxtModuleEnv) {
140
140
  await copyIconsCache(basePath);
@@ -170,7 +170,7 @@ export const Vueless = function (options = {}) {
170
170
 
171
171
  if (hasIconChanges && currentIconLines.length) {
172
172
  /* cache vueless built-in and project icons */
173
- await createIconsCache({ env, debug, targetFiles: [file] });
173
+ await createIconsCache({ env, targetFiles: [file], basePath, debug });
174
174
 
175
175
  if (isNuxtModuleEnv) {
176
176
  await copyIconsCache(basePath);
@@ -1,2 +1,2 @@
1
- export function setCustomPropTypes(srcDir: any): Promise<void>;
1
+ export function setCustomPropTypes({ vuelessSrcDir, basePath }?: {}): Promise<void>;
2
2
  export function removeCustomPropTypes(srcDir: any): Promise<void>;
@@ -3,7 +3,7 @@ import { existsSync } from "node:fs";
3
3
  import path from "node:path";
4
4
 
5
5
  import { removeFolderIfEmpty } from "./helper.js";
6
- import { vuelessConfig } from "./vuelessConfig.js";
6
+ import { getVuelessConfig } from "./vuelessConfig.js";
7
7
 
8
8
  import {
9
9
  CACHE_DIR,
@@ -25,7 +25,9 @@ const WORD_IN_QUOTE_REG_EXP = /"([^"]+)"/g;
25
25
 
26
26
  const DEFAULT_SAFE_COLORS = [PRIMARY_COLOR, GRAYSCALE_COLOR, INHERIT_COLOR, TEXT_COLOR];
27
27
 
28
- export async function setCustomPropTypes(srcDir) {
28
+ export async function setCustomPropTypes({ vuelessSrcDir, basePath } = {}) {
29
+ const vuelessConfig = await getVuelessConfig(basePath);
30
+
29
31
  for await (const [componentName, componentDir] of Object.entries(COMPONENTS)) {
30
32
  let componentGlobalConfig = vuelessConfig.components?.[componentName];
31
33
 
@@ -78,8 +80,10 @@ export async function setCustomPropTypes(srcDir) {
78
80
  const isCustomProps = componentGlobalConfig && componentGlobalConfig.props;
79
81
 
80
82
  if (isCustomProps) {
81
- await cacheComponentTypes(path.join(srcDir, componentDir));
82
- await modifyComponentTypes(path.join(srcDir, componentDir), componentGlobalConfig.props);
83
+ const cachePath = path.join(vuelessSrcDir, componentDir);
84
+
85
+ await cacheComponentTypes(cachePath);
86
+ await modifyComponentTypes(cachePath, componentGlobalConfig.props);
83
87
  }
84
88
  }
85
89
  }
@@ -1,4 +1,4 @@
1
- export function createIconsCache({ env, debug, targetFiles }?: string): Promise<void>;
1
+ export function createIconsCache({ env, debug, targetFiles, basePath }?: string): Promise<void>;
2
2
  export function removeIconsCache(basePath: string, isVuelessEnv?: boolean): Promise<void>;
3
3
  export function copyIconsCache(basePath: string, isVuelessEnv?: boolean): Promise<void>;
4
4
  export function generateIconExports(): string;
@@ -11,7 +11,7 @@ import { cwd } from "node:process";
11
11
  import { rm, cp } from "node:fs/promises";
12
12
  import { createRequire } from "module";
13
13
 
14
- import { vuelessConfig } from "./vuelessConfig.js";
14
+ import { getVuelessConfig } from "./vuelessConfig.js";
15
15
  import { getDirFiles, getMergedComponentConfig } from "./helper.js";
16
16
  import {
17
17
  ICONS_DIR,
@@ -34,8 +34,9 @@ let uIconDefaults = {};
34
34
  * @param {string} env
35
35
  * @param {boolean} debug
36
36
  * @param {Array} targetFiles
37
+ * @param {string} basePath
37
38
  */
38
- export async function createIconsCache({ env, debug = false, targetFiles = [] } = {}) {
39
+ export async function createIconsCache({ env, debug = false, targetFiles = [], basePath } = {}) {
39
40
  const isInternalEnv = env === INTERNAL_ENV;
40
41
  const isStorybookEnv = env === STORYBOOK_ENV;
41
42
 
@@ -55,6 +56,8 @@ export async function createIconsCache({ env, debug = false, targetFiles = [] }
55
56
  ...vuelessMergedConfigFiles,
56
57
  ];
57
58
 
59
+ const vuelessConfig = await getVuelessConfig(basePath);
60
+
58
61
  if (isInternalEnv) {
59
62
  const storybookFiles = [];
60
63
  const internalFiles = [];
@@ -65,13 +68,13 @@ export async function createIconsCache({ env, debug = false, targetFiles = [] }
65
68
  : internalFiles.push(file);
66
69
  }
67
70
 
68
- await findAndCopyIcons(storybookFiles, STORYBOOK_ICONS_LIBRARY, debug);
69
- await findAndCopyIcons(internalFiles, INTERNAL_ICONS_LIBRARY, debug);
71
+ await findAndCopyIcons(storybookFiles, STORYBOOK_ICONS_LIBRARY, vuelessConfig, debug);
72
+ await findAndCopyIcons(internalFiles, INTERNAL_ICONS_LIBRARY, vuelessConfig, debug);
70
73
  }
71
74
 
72
75
  if (!isInternalEnv) {
73
76
  await cachePackageIcons(isStorybookEnv);
74
- await findAndCopyIcons(files, uIconDefaults.library, debug);
77
+ await findAndCopyIcons(files, uIconDefaults.library, vuelessConfig, debug);
75
78
  }
76
79
  }
77
80
 
@@ -180,9 +183,10 @@ async function cachePackageIcons(isStorybookEnv) {
180
183
  * Scan the project for icon names and copy found icons to the cache.
181
184
  * @param {Array} files
182
185
  * @param {string} library
186
+ * @param {object} vuelessConfig
183
187
  * @param {boolean} debug
184
188
  */
185
- async function findAndCopyIcons(files, library, debug) {
189
+ async function findAndCopyIcons(files, library, vuelessConfig, debug) {
186
190
  const safelistIcons = vuelessConfig.components?.["UIcon"]?.safelistIcons;
187
191
 
188
192
  const validIconNamesRegex = /^(?!icon$|name$)[a-z0-9_-]+$/;
@@ -1,2 +1,2 @@
1
1
  export function defineConfigWithVueless(config: Object): Promise<Object>;
2
- export function getVuelessStoriesGlob(vuelessEnv: string, basePath: string): Promise<string[]>;
2
+ export function getVuelessStoriesGlob(vuelessEnv: string): Promise<string[]>;
@@ -1,5 +1,4 @@
1
1
  import { getVuelessConfig } from "./vuelessConfig.js";
2
- import { autoImportUserConfigs } from "./helper.js";
3
2
  import {
4
3
  COMPONENTS,
5
4
  DIRECTIVES,
@@ -17,10 +16,7 @@ import {
17
16
  export function defineConfigWithVueless(config) {
18
17
  return (async () => ({
19
18
  ...config,
20
- stories: [
21
- ...config.stories,
22
- ...(await getVuelessStoriesGlob(config?.vuelessEnv, config?.basePath)),
23
- ],
19
+ stories: [...config.stories, ...(await getVuelessStoriesGlob(config?.vuelessEnv))],
24
20
  addons: [
25
21
  ...new Set([
26
22
  ...(config.addons || []),
@@ -53,13 +49,9 @@ export function defineConfigWithVueless(config) {
53
49
  * Retrieves the glob pattern for Vueless stories based on the provided Vueless environment.
54
50
  *
55
51
  * @param {string} vuelessEnv - The Vueless environment.
56
- * @param {string} basePath - The Project base path.
57
52
  * @return {Promise<string[]>} A promise that resolves to an array of glob patterns for Vueless stories.
58
53
  */
59
- export async function getVuelessStoriesGlob(vuelessEnv, basePath) {
60
- /* Auto import user configs. */
61
- await autoImportUserConfigs(basePath);
62
-
54
+ export async function getVuelessStoriesGlob(vuelessEnv) {
63
55
  const vuelessSrcDir = vuelessEnv === INTERNAL_ENV ? VUELESS_LOCAL_DIR : VUELESS_PACKAGE_DIR;
64
56
  const vuelessConfig = await getVuelessConfig();
65
57
  const storiesGlob = [];
@@ -1,5 +1,5 @@
1
1
  export function clearTailwindSafelist(): Promise<void>;
2
- export function createTailwindSafelist({ env, srcDir, targetFiles }?: {
2
+ export function createTailwindSafelist({ env, srcDir, targetFiles, basePath }?: {
3
3
  env: string;
4
4
  srcDir: string;
5
5
  targetFiles?: string[] | undefined;
@@ -5,7 +5,7 @@ import { readFile, unlink, writeFile, mkdir } from "node:fs/promises";
5
5
  import { merge } from "lodash-es";
6
6
 
7
7
  import { getDefaultComponentConfig, getMergedComponentConfig, getDirFiles } from "./helper.js";
8
- import { vuelessConfig } from "./vuelessConfig.js";
8
+ import { getVuelessConfig } from "./vuelessConfig.js";
9
9
  import {
10
10
  COMPONENTS,
11
11
  INTERNAL_ENV,
@@ -50,25 +50,31 @@ export async function clearTailwindSafelist() {
50
50
  * @param {string[]} [options.targetFiles=[]] - Optional array of target file paths to include in the safelist generation.
51
51
  * @return {Promise<void>} A promise that resolves when the safelist file is successfully created and written to disk.
52
52
  */
53
- export async function createTailwindSafelist({ env, srcDir, targetFiles = [] } = {}) {
53
+ export async function createTailwindSafelist({ env, srcDir, targetFiles, basePath } = {}) {
54
54
  const isStorybookEnv = env === STORYBOOK_ENV;
55
55
  const isInternalEnv = env === INTERNAL_ENV;
56
56
 
57
+ const vuelessConfig = await getVuelessConfig(basePath);
58
+
57
59
  /* Safelist dynamic color classes in components. */
58
- const classes = await getComponentsSafelistClasses({
60
+ const classes = await getComponentsSafelistClasses(vuelessConfig, {
59
61
  env: { isStorybookEnv, isInternalEnv },
60
62
  targetFiles,
61
63
  srcDir,
62
64
  });
63
65
 
64
66
  /* Safelist all color shades to allow runtime color switching feature. */
65
- const runtimeColorCSSVariables = getRuntimeColorCSSVariables(isStorybookEnv, isInternalEnv);
67
+ const runtimeColorCSSVariables = getRuntimeColorCSSVariables(
68
+ vuelessConfig,
69
+ isStorybookEnv,
70
+ isInternalEnv,
71
+ );
66
72
 
67
73
  /* Safelist primary and neutral color variables. */
68
- let brandColorCSSVariables = getBrandColorCSSVariables(isInternalEnv);
74
+ let brandColorCSSVariables = getBrandColorCSSVariables(vuelessConfig, isInternalEnv);
69
75
 
70
76
  /* Safelist all color variables to allow runtime color switching feature. */
71
- const themeCSSVariables = getThemeCSSVariables();
77
+ const themeCSSVariables = getThemeCSSVariables(vuelessConfig);
72
78
 
73
79
  const safelist = [
74
80
  ...new Set([
@@ -91,11 +97,12 @@ export async function createTailwindSafelist({ env, srcDir, targetFiles = [] } =
91
97
  * Generates a list of runtime CSS color variables based on the environment
92
98
  * and available configuration.
93
99
  *
100
+ * @param {object} vuelessConfig - The Vueless config object.
94
101
  * @param {boolean} isStorybookEnv - Indicates if the method is executed in a Storybook environment.
95
102
  * @param {boolean} isInternalEnv - Indicates if the method is executed in an Internal environment.
96
103
  * @return {string[]} An array of strings, each representing CSS variable definitions for colors and shades.
97
104
  */
98
- function getRuntimeColorCSSVariables(isStorybookEnv, isInternalEnv) {
105
+ function getRuntimeColorCSSVariables(vuelessConfig, isStorybookEnv, isInternalEnv) {
99
106
  if (!isStorybookEnv && !isInternalEnv && !vuelessConfig.runtimeColors) return [];
100
107
 
101
108
  const colors = vuelessConfig.runtimeColors?.length
@@ -110,10 +117,11 @@ function getRuntimeColorCSSVariables(isStorybookEnv, isInternalEnv) {
110
117
  /**
111
118
  * Generates an array of CSS variable strings for `primary` and `neutral` colors based on environment settings.
112
119
  *
120
+ * @param {object} vuelessConfig - The Vueless config object.
113
121
  * @param {boolean} isInternalEnv - Indicates whether the current environment is internal.
114
122
  * @return {string[]} An array of CSS variable strings representing brand colors and their shades.
115
123
  */
116
- function getBrandColorCSSVariables(isInternalEnv) {
124
+ function getBrandColorCSSVariables(vuelessConfig, isInternalEnv) {
117
125
  if (isInternalEnv) return [];
118
126
 
119
127
  const colors = [
@@ -132,9 +140,10 @@ function getBrandColorCSSVariables(isInternalEnv) {
132
140
  * This method combines theme settings from default and custom configurations and
133
141
  * returns an array of variable values for each theme.
134
142
  *
143
+ * @param {object} vuelessConfig - The Vueless config object.
135
144
  * @return {Array} An array containing CSS variable values from the light and dark themes.
136
145
  */
137
- function getThemeCSSVariables() {
146
+ function getThemeCSSVariables(vuelessConfig) {
138
147
  const lightThemeConfig = merge({}, DEFAULT_LIGHT_THEME, vuelessConfig.lightTheme);
139
148
  const darkThemeConfig = merge({}, DEFAULT_DARK_THEME, vuelessConfig.darkTheme);
140
149
 
@@ -150,6 +159,7 @@ function getThemeCSSVariables() {
150
159
  * CSS classes based on component usage, environment conditions, and configured colors.
151
160
  *
152
161
  * @param {Object} params - The parameters for the function.
162
+ * @param {object} vuelessConfig - The Vueless config object.
153
163
  * @param {Array<string>} params.targetFiles - List of file paths to check for component usage.
154
164
  * @param {Object} params.env - Environment variables for distinguishing between different environments.
155
165
  * @param {boolean} params.env.isStorybookEnv - Indicates whether the function is running in a Storybook environment.
@@ -159,7 +169,7 @@ function getThemeCSSVariables() {
159
169
  * @return {Promise<Array<string>>} A promise that resolves to an array of safelisted CSS class names
160
170
  * for all matched components and nested components.
161
171
  */
162
- async function getComponentsSafelistClasses({ targetFiles, env, srcDir }) {
172
+ async function getComponentsSafelistClasses(vuelessConfig, { targetFiles = [], env, srcDir }) {
163
173
  const { isStorybookEnv, isInternalEnv } = env;
164
174
 
165
175
  let srcVueFiles = [];
@@ -1 +1 @@
1
- export function buildWebTypes(srcDir: any): Promise<void>;
1
+ export function buildWebTypes({ vuelessSrcDir, basePath }?: {}): Promise<void>;
@@ -1,10 +1,11 @@
1
- import { vuelessConfig } from "./vuelessConfig.js";
1
+ import { getVuelessConfig } from "./vuelessConfig.js";
2
2
 
3
- export async function buildWebTypes(srcDir) {
3
+ export async function buildWebTypes({ vuelessSrcDir, basePath } = {}) {
4
4
  try {
5
+ const vuelessConfig = await getVuelessConfig(basePath);
5
6
  const { default: build } = await import("@vueless/storybook/webTypes/index.js");
6
7
 
7
- await build(vuelessConfig, srcDir);
8
+ await build(vuelessConfig, vuelessSrcDir);
8
9
  } catch (error) {
9
10
  if (error.code !== "ERR_MODULE_NOT_FOUND") {
10
11
  // eslint-disable-next-line no-console
package/utils/theme.ts CHANGED
@@ -78,9 +78,10 @@ function toggleColorModeClass() {
78
78
  * @param {boolean} isCachedAutoMode
79
79
  * @return {string} current color mode
80
80
  */
81
- function setColorMode(mode: `${ColorMode}`, isCachedAutoMode: boolean = false): string {
81
+ function setColorMode(mode: `${ColorMode}`, isCachedAutoMode?: boolean): string {
82
82
  const colorMode = mode || getStored(COLOR_MODE_KEY) || vuelessConfig.colorMode || ColorMode.Light;
83
83
 
84
+ // TODO: This always true `!!Number(getStored(AUTO_MODE_KEY))` > `!!Number(undefined) = true`
84
85
  isCachedAutoMode = isCachedAutoMode ?? !!Number(getStored(AUTO_MODE_KEY));
85
86
 
86
87
  const isAutoMode = colorMode === ColorMode.Auto;