centoui-cli 1.0.0-alpha.27 → 1.0.0-alpha.28

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 (2) hide show
  1. package/dist/index.mjs +68 -9
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ import { pathToFileURL } from "node:url";
8
8
  //#endregion
9
9
  //#region src/constants.ts
10
10
  /** CentoUI current package version, sourced directly from package.json. */
11
- const VERSION = "1.0.0-alpha.27";
11
+ const VERSION = "1.0.0-alpha.28";
12
12
  /** File name for the user-side CentoUI config (created by `centoui init`). */
13
13
  const CONFIG_FILE_NAME = "centoui.config.ts";
14
14
  /**
@@ -27,6 +27,11 @@ const REGISTRY_INDEX_URL = `${`${CORE_SRC_BASE_URL}/registry`}/index.json`;
27
27
  */
28
28
  const THEME_CSS_URL = `${CORE_SRC_BASE_URL}/defaults/centoui.css`;
29
29
  /**
30
+ * Full URL to the default values file for the CentoUI config.
31
+ * The contents of this file are written to the user's project during `centoui init`.
32
+ */
33
+ const CONFIG_DEFAULTS_URL = `${CORE_SRC_BASE_URL}/defaults/config.ts`;
34
+ /**
30
35
  * HTTP headers required when fetching raw content from the GitHub API.
31
36
  * These ensure we get the raw file bytes, not GitHub's HTML wrapper.
32
37
  */
@@ -205,6 +210,52 @@ async function loadCentoUIConfig(cwd) {
205
210
  }
206
211
  }
207
212
  /**
213
+ * Fetches the raw content of the default CentoUI config file from GitHub.
214
+ *
215
+ * This file contains the default icon mappings and other shared defaults
216
+ * that are merged into the user's generated config.
217
+ *
218
+ * @returns Raw UTF-8 content of the default config file.
219
+ * @throws If the network request fails or the server returns a non-2xx status.
220
+ */
221
+ async function fetchDefaultConfig() {
222
+ let response;
223
+ try {
224
+ response = await fetch(CONFIG_DEFAULTS_URL, { headers: GITHUB_RAW_FETCH_HEADERS });
225
+ } catch (error) {
226
+ throw new Error(`[fetchDefaultConfigContent] Network request for default config failed: ${error}`);
227
+ }
228
+ if (!response.ok) throw new Error(`[fetchDefaultConfigContent] Server returned ${response.status} ${response.statusText} (URL: ${CONFIG_DEFAULTS_URL})`);
229
+ return response.text();
230
+ }
231
+ /**
232
+ * Extracts the inner config object from the default config file content.
233
+ *
234
+ * Strips the `export default`, `satisfies` clause, and outer braces,
235
+ * returning just the inner properties as a raw string.
236
+ *
237
+ * @example
238
+ * // Input:
239
+ * // export default {
240
+ * // icons: { check: 'lucide:check' },
241
+ * // } satisfies Pick<CentoUIConfig, 'icons'>
242
+ * // Output:
243
+ * // " icons: { check: 'lucide:check' },"
244
+ *
245
+ * @param fileContent - The full source of the default config file.
246
+ * @returns The inner config body, or an empty string if no object is found.
247
+ */
248
+ function extractInnerConfigContent(fileContent) {
249
+ let cleanedConfigContent = fileContent.replace(/^import\s+.*$/gm, "");
250
+ cleanedConfigContent = cleanedConfigContent.replace(/^\s*export\s+default\s+/, "");
251
+ cleanedConfigContent = cleanedConfigContent.replace(/\s+satisfies\s+[^}]*$/, "");
252
+ cleanedConfigContent = cleanedConfigContent.trim();
253
+ const firstBrace = cleanedConfigContent.indexOf("{");
254
+ const lastBrace = cleanedConfigContent.lastIndexOf("}");
255
+ if (firstBrace === -1 || lastBrace === -1 || lastBrace <= firstBrace) return "";
256
+ return cleanedConfigContent.slice(firstBrace + 1, lastBrace).replace(/^\n/, "").replace(/\n\s*$/, "");
257
+ }
258
+ /**
208
259
  * Generates the content of a default `centoui.config.ts` file.
209
260
  *
210
261
  * The generated file uses `defineConfig` so IDEs can provide type-checking
@@ -215,17 +266,24 @@ async function loadCentoUIConfig(cwd) {
215
266
  * @param componentsDir - Relative path (from project root) where components will be installed.
216
267
  * @returns A string containing the complete TypeScript source for the config file.
217
268
  */
218
- function buildDefaultConfigFileContent(themeFilePath, componentsDir) {
269
+ /**
270
+ * Generates the content of a user's default `centoui.config.ts` file.
271
+ *
272
+ * Fetches the default config from GitHub to get the latest default config values (icon mappings, etc.),
273
+ * then merges them with the user-provided paths. The generated file uses
274
+ * `defineConfig` so IDEs can provide type-checking and autocompletion.
275
+ *
276
+ * @param themeFilePath - Relative path (from project root) where the CSS theme file lives.
277
+ * @param componentsDir - Relative path (from project root) where components will be installed.
278
+ * @returns A string containing the complete TypeScript source for the config file.
279
+ */
280
+ async function buildUserDefaultConfigFileContent(themeFilePath, componentsDir) {
219
281
  return `import { defineConfig } from 'centoui'
220
282
 
221
283
  export default defineConfig({
222
284
  componentsDir: '${componentsDir}',
223
285
  themeFilePath: '${themeFilePath}',
224
- icons: {
225
- check: 'lucide:check',
226
- close: 'lucide:x',
227
- menu: 'lucide:menu',
228
- },
286
+ ${extractInnerConfigContent(await fetchDefaultConfig())}
229
287
  })
230
288
  `;
231
289
  }
@@ -370,10 +428,11 @@ function init() {
370
428
  let registry;
371
429
  await tasks([
372
430
  {
373
- title: `Writing ${CONFIG_FILE_NAME}`,
431
+ title: "Fetching config defaults",
374
432
  task: async () => {
375
433
  if (!shouldWriteConfig) return `Skipped — "${CONFIG_FILE_NAME}" already exists`;
376
- await fsExtra.outputFile(configPath, buildDefaultConfigFileContent(directories.themeFilePath, directories.componentDir), "utf-8");
434
+ const userConfigContent = await buildUserDefaultConfigFileContent(directories.themeFilePath, directories.componentDir);
435
+ await fsExtra.outputFile(configPath, userConfigContent, "utf-8");
377
436
  return `${CONFIG_FILE_NAME} written`;
378
437
  }
379
438
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "centoui-cli",
3
3
  "type": "module",
4
- "version": "1.0.0-alpha.27",
4
+ "version": "1.0.0-alpha.28",
5
5
  "private": false,
6
6
  "description": "Official CLI for CentoUI.",
7
7
  "author": "Favour Emeka <favorodera@gmail.com>",