centoui-cli 1.0.0-alpha.27 → 1.0.0-alpha.29
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/dist/index.mjs +73 -18
- package/package.json +5 -3
package/dist/index.mjs
CHANGED
|
@@ -4,11 +4,11 @@ import { cancel, confirm, group, intro, isCancel, log, note, outro, tasks, text
|
|
|
4
4
|
import { dirname, join } from "pathe";
|
|
5
5
|
import fsExtra from "fs-extra";
|
|
6
6
|
import { addDependency, removeDependency } from "nypm";
|
|
7
|
-
import {
|
|
7
|
+
import { loadConfig } from "c12";
|
|
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.
|
|
11
|
+
const VERSION = "1.0.0-alpha.29";
|
|
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
|
*/
|
|
@@ -185,10 +190,7 @@ async function confirmOverwriteIfExists(label, path) {
|
|
|
185
190
|
//#endregion
|
|
186
191
|
//#region src/utils/config-utils.ts
|
|
187
192
|
/**
|
|
188
|
-
* Loads and returns the user's CentoUI configuration from `centoui.config.ts
|
|
189
|
-
*
|
|
190
|
-
* Uses a dynamic `import()` via a `file://` URL so that TypeScript config files
|
|
191
|
-
* compiled by the user's build tooling are resolved correctly at runtime.
|
|
193
|
+
* Loads and returns the user's CentoUI configuration from `centoui.config.ts` using c12.
|
|
192
194
|
*
|
|
193
195
|
* @param cwd - Absolute path to the project root.
|
|
194
196
|
* @returns The default export of `centoui.config.ts` cast as {@link CentoUIConfig}.
|
|
@@ -196,13 +198,58 @@ async function confirmOverwriteIfExists(label, path) {
|
|
|
196
198
|
* @throws If the file exists but cannot be imported or does not export a default value.
|
|
197
199
|
*/
|
|
198
200
|
async function loadCentoUIConfig(cwd) {
|
|
199
|
-
const
|
|
201
|
+
const { config, configFile } = await loadConfig({
|
|
202
|
+
name: "centoui",
|
|
203
|
+
cwd
|
|
204
|
+
});
|
|
205
|
+
if (!configFile) throw new Error(`[loadCentoUIConfig] "${CONFIG_FILE_NAME}" not found in "${cwd}". Run \`centoui init\` first.`);
|
|
206
|
+
return config;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Fetches the raw content of the default CentoUI config file from GitHub.
|
|
210
|
+
*
|
|
211
|
+
* This file contains the default icon mappings and other shared defaults
|
|
212
|
+
* that are merged into the user's generated config.
|
|
213
|
+
*
|
|
214
|
+
* @returns Raw UTF-8 content of the default config file.
|
|
215
|
+
* @throws If the network request fails or the server returns a non-2xx status.
|
|
216
|
+
*/
|
|
217
|
+
async function fetchDefaultConfig() {
|
|
218
|
+
let response;
|
|
200
219
|
try {
|
|
201
|
-
|
|
202
|
-
return (await import(pathToFileURL(configFilePath).href)).default;
|
|
220
|
+
response = await fetch(CONFIG_DEFAULTS_URL, { headers: GITHUB_RAW_FETCH_HEADERS });
|
|
203
221
|
} catch (error) {
|
|
204
|
-
throw new Error(`[
|
|
222
|
+
throw new Error(`[fetchDefaultConfigContent] Network request for default config failed: ${error}`);
|
|
205
223
|
}
|
|
224
|
+
if (!response.ok) throw new Error(`[fetchDefaultConfigContent] Server returned ${response.status} ${response.statusText} (URL: ${CONFIG_DEFAULTS_URL})`);
|
|
225
|
+
return response.text();
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Extracts the inner config object from the default config file content.
|
|
229
|
+
*
|
|
230
|
+
* Strips the `export default`, `satisfies` clause, and outer braces,
|
|
231
|
+
* returning just the inner properties as a raw string.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* // Input:
|
|
235
|
+
* // export default {
|
|
236
|
+
* // icons: { check: 'lucide:check' },
|
|
237
|
+
* // } satisfies Pick<CentoUIConfig, 'icons'>
|
|
238
|
+
* // Output:
|
|
239
|
+
* // " icons: { check: 'lucide:check' },"
|
|
240
|
+
*
|
|
241
|
+
* @param fileContent - The full source of the default config file.
|
|
242
|
+
* @returns The inner config body, or an empty string if no object is found.
|
|
243
|
+
*/
|
|
244
|
+
function extractInnerConfigContent(fileContent) {
|
|
245
|
+
let cleanedConfigContent = fileContent.replace(/^import\s+.*$/gm, "");
|
|
246
|
+
cleanedConfigContent = cleanedConfigContent.replace(/^\s*export\s+default\s+/, "");
|
|
247
|
+
cleanedConfigContent = cleanedConfigContent.replace(/\s+satisfies\s+[^}]*$/, "");
|
|
248
|
+
cleanedConfigContent = cleanedConfigContent.trim();
|
|
249
|
+
const firstBrace = cleanedConfigContent.indexOf("{");
|
|
250
|
+
const lastBrace = cleanedConfigContent.lastIndexOf("}");
|
|
251
|
+
if (firstBrace === -1 || lastBrace === -1 || lastBrace <= firstBrace) return "";
|
|
252
|
+
return cleanedConfigContent.slice(firstBrace + 1, lastBrace).replace(/^\n/, "").replace(/\n\s*$/, "");
|
|
206
253
|
}
|
|
207
254
|
/**
|
|
208
255
|
* Generates the content of a default `centoui.config.ts` file.
|
|
@@ -215,17 +262,24 @@ async function loadCentoUIConfig(cwd) {
|
|
|
215
262
|
* @param componentsDir - Relative path (from project root) where components will be installed.
|
|
216
263
|
* @returns A string containing the complete TypeScript source for the config file.
|
|
217
264
|
*/
|
|
218
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Generates the content of a user's default `centoui.config.ts` file.
|
|
267
|
+
*
|
|
268
|
+
* Fetches the default config from GitHub to get the latest default config values (icon mappings, etc.),
|
|
269
|
+
* then merges them with the user-provided paths. The generated file uses
|
|
270
|
+
* `defineConfig` so IDEs can provide type-checking and autocompletion.
|
|
271
|
+
*
|
|
272
|
+
* @param themeFilePath - Relative path (from project root) where the CSS theme file lives.
|
|
273
|
+
* @param componentsDir - Relative path (from project root) where components will be installed.
|
|
274
|
+
* @returns A string containing the complete TypeScript source for the config file.
|
|
275
|
+
*/
|
|
276
|
+
async function buildUserDefaultConfigFileContent(themeFilePath, componentsDir) {
|
|
219
277
|
return `import { defineConfig } from 'centoui'
|
|
220
278
|
|
|
221
279
|
export default defineConfig({
|
|
222
280
|
componentsDir: '${componentsDir}',
|
|
223
281
|
themeFilePath: '${themeFilePath}',
|
|
224
|
-
|
|
225
|
-
check: 'lucide:check',
|
|
226
|
-
close: 'lucide:x',
|
|
227
|
-
menu: 'lucide:menu',
|
|
228
|
-
},
|
|
282
|
+
${extractInnerConfigContent(await fetchDefaultConfig())}
|
|
229
283
|
})
|
|
230
284
|
`;
|
|
231
285
|
}
|
|
@@ -370,10 +424,11 @@ function init() {
|
|
|
370
424
|
let registry;
|
|
371
425
|
await tasks([
|
|
372
426
|
{
|
|
373
|
-
title:
|
|
427
|
+
title: "Fetching config defaults",
|
|
374
428
|
task: async () => {
|
|
375
429
|
if (!shouldWriteConfig) return `Skipped — "${CONFIG_FILE_NAME}" already exists`;
|
|
376
|
-
await
|
|
430
|
+
const userConfigContent = await buildUserDefaultConfigFileContent(directories.themeFilePath, directories.componentDir);
|
|
431
|
+
await fsExtra.outputFile(configPath, userConfigContent, "utf-8");
|
|
377
432
|
return `${CONFIG_FILE_NAME} written`;
|
|
378
433
|
}
|
|
379
434
|
},
|
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.
|
|
4
|
+
"version": "1.0.0-alpha.29",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Official CLI for CentoUI.",
|
|
7
7
|
"author": "Favour Emeka <favorodera@gmail.com>",
|
|
@@ -30,20 +30,22 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/fs-extra": "^11.0.4",
|
|
33
|
+
"@vitest/ui": "^4.1.5",
|
|
33
34
|
"tsdown": "^0.21.7",
|
|
34
35
|
"type-fest": "^5.6.0",
|
|
35
|
-
"@vitest/ui": "^4.1.5",
|
|
36
36
|
"vitest": "^4.1.2"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@clack/prompts": "^1.2.0",
|
|
40
|
+
"c12": "4.0.0-beta.5",
|
|
40
41
|
"citty": "^0.2.2",
|
|
41
42
|
"fs-extra": "^11.3.4",
|
|
42
43
|
"nypm": "^0.6.6",
|
|
43
44
|
"pathe": "^2.0.3"
|
|
44
45
|
},
|
|
45
46
|
"engines": {
|
|
46
|
-
"node": ">=22.0.0"
|
|
47
|
+
"node": ">=22.0.0",
|
|
48
|
+
"pnpm": ">=11.0.0"
|
|
47
49
|
},
|
|
48
50
|
"scripts": {
|
|
49
51
|
"build": "tsdown",
|