centoui-cli 0.0.0 → 0.0.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/dist/index.mjs +232 -0
- package/package.json +7 -6
- package/dist/index.js +0 -20
- /package/dist/{index.d.ts → index.d.mts} +0 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { defineCommand, runMain } from "citty";
|
|
3
|
+
import { cancel, confirm, group, intro, isCancel, log, note, outro, tasks, text } from "@clack/prompts";
|
|
4
|
+
import { join } from "pathe";
|
|
5
|
+
import fsExtra from "fs-extra";
|
|
6
|
+
import { addDependency } from "nypm";
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/constants.ts
|
|
9
|
+
/** CentoUI current package version */
|
|
10
|
+
const VERSION = "0.0.1";
|
|
11
|
+
/** CentoUI config file name */
|
|
12
|
+
const CONFIG_FILE_NAME = "centoui.config.ts";
|
|
13
|
+
/** CentoUI registry file name */
|
|
14
|
+
const REGISTRY_FILE_NAME = "index.json";
|
|
15
|
+
/** CentoUI core base API URL */
|
|
16
|
+
const BASE_URL = `https://raw.githubusercontent.com/favorodera/centoui/refs/tags/v${VERSION}/packages/core/src`;
|
|
17
|
+
/** CentoUI registry files URL */
|
|
18
|
+
const REGISTRY_URL = `${BASE_URL}/registry`;
|
|
19
|
+
/** CentoUI theme file URL */
|
|
20
|
+
const THEME_URL = `${BASE_URL}/css/centoui.css`;
|
|
21
|
+
/** GitHub API fetch headers */
|
|
22
|
+
const FETCH_HEADERS = {
|
|
23
|
+
"Accept": "application/vnd.github.raw+json",
|
|
24
|
+
"X-GitHub-Api-Version": "2026-03-10"
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/utils/package-utils.ts
|
|
28
|
+
/**
|
|
29
|
+
* Install packages that are missing or on a different version.
|
|
30
|
+
* Reads the project's `package.json` to diff against what's already installed.
|
|
31
|
+
* nypm auto-detects the package manager from lockfiles (npm / pnpm / yarn / bun).
|
|
32
|
+
*
|
|
33
|
+
* @param packages - Map of package name → required version
|
|
34
|
+
* @param cwd - Root of the project to install into
|
|
35
|
+
* @param onProgress - Optional callback fired with a status string per package
|
|
36
|
+
* @returns A human-readable summary string (used as the task return value in clack)
|
|
37
|
+
*/
|
|
38
|
+
async function installPackages(packages, cwd, onProgress) {
|
|
39
|
+
if (Object.keys(packages).length === 0) return "No packages to install";
|
|
40
|
+
const packageJson = await fsExtra.readJson(join(cwd, "package.json")).catch(() => ({}));
|
|
41
|
+
const installedPackages = {
|
|
42
|
+
...packageJson.dependencies,
|
|
43
|
+
...packageJson.devDependencies
|
|
44
|
+
};
|
|
45
|
+
const packagesToInstall = Object.entries(packages).filter(([packageName, version]) => installedPackages[packageName] !== version).map(([packageName, version]) => `${packageName}@${version}`);
|
|
46
|
+
if (packagesToInstall.length === 0) return "All packages already up to date";
|
|
47
|
+
for (const [index, packageToInstall] of packagesToInstall.entries()) {
|
|
48
|
+
onProgress?.(`[${index + 1}/${packagesToInstall.length}] ${packageToInstall}`);
|
|
49
|
+
await addDependency(packageToInstall, {
|
|
50
|
+
cwd,
|
|
51
|
+
silent: true
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return `Installed ${packagesToInstall.length} package(s)`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Validate that the given value is a non-empty string representing a valid directory path.
|
|
58
|
+
* Returns `undefined` if valid, otherwise returns an error message.
|
|
59
|
+
*/
|
|
60
|
+
function validatePath(path) {
|
|
61
|
+
if (typeof path !== "string") return "Invalid input";
|
|
62
|
+
if (path.trim().length < 1) return "Path is required";
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/utils/file-system-utils.ts
|
|
66
|
+
/**
|
|
67
|
+
* Ask the user whether to overwrite a path that already exists.
|
|
68
|
+
* Returns `true` immediately (no prompt) if the file does not exist yet.
|
|
69
|
+
*
|
|
70
|
+
* @param label - Human-readable path shown in the prompt message
|
|
71
|
+
* @param path - The path to the file or directory to overwrite.
|
|
72
|
+
*/
|
|
73
|
+
async function promptOverwrite(label, path) {
|
|
74
|
+
if (!await fsExtra.pathExists(path)) return true;
|
|
75
|
+
const answer = await confirm({ message: `${label} already exists. Overwrite?` });
|
|
76
|
+
if (isCancel(answer)) {
|
|
77
|
+
cancel(`${label} operation cancelled.`);
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
return answer;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/utils/config-utils.ts
|
|
84
|
+
/**
|
|
85
|
+
* Generates the default user-defined CentoUI config file template.
|
|
86
|
+
* @param themeFilePath - The relative path to the user's theme CSS file.
|
|
87
|
+
* @param componentsDir - The relative path to the user's components directory.
|
|
88
|
+
* @returns The default user-defined CentoUI config file template as a string.
|
|
89
|
+
*/
|
|
90
|
+
function generateDefaultUserConfigTemplate(themeFilePath, componentsDir) {
|
|
91
|
+
return `import { defineConfig } from 'centoui'
|
|
92
|
+
|
|
93
|
+
export default defineConfig({
|
|
94
|
+
version: '${VERSION}',
|
|
95
|
+
componentsDir: '${componentsDir}',
|
|
96
|
+
themeFilePath: '${themeFilePath}',
|
|
97
|
+
icons: {
|
|
98
|
+
check: 'lucide:check',
|
|
99
|
+
close: 'lucide:x',
|
|
100
|
+
menu: 'lucide:menu',
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/utils/registry-utils.ts
|
|
107
|
+
let registryCache = null;
|
|
108
|
+
/**
|
|
109
|
+
* Fetches the complete component registry once and caches it in memory.
|
|
110
|
+
*
|
|
111
|
+
* @returns The complete registry including components and globals.
|
|
112
|
+
* @throws If the network request fails or returns a non-OK status
|
|
113
|
+
*/
|
|
114
|
+
async function fetchRegistry() {
|
|
115
|
+
if (registryCache) return registryCache;
|
|
116
|
+
const requestUrl = `${REGISTRY_URL}/${REGISTRY_FILE_NAME}`;
|
|
117
|
+
const response = await fetch(requestUrl, { headers: FETCH_HEADERS });
|
|
118
|
+
if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`);
|
|
119
|
+
const registry = await response.json();
|
|
120
|
+
registryCache = registry;
|
|
121
|
+
return registry;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Fetches the theme file from the registry.
|
|
125
|
+
*
|
|
126
|
+
* @returns The raw source code of the theme file
|
|
127
|
+
*/
|
|
128
|
+
async function fetchThemeFile() {
|
|
129
|
+
const response = await fetch(THEME_URL, { headers: FETCH_HEADERS });
|
|
130
|
+
if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`);
|
|
131
|
+
return response.text();
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/commands/init.ts
|
|
135
|
+
function init() {
|
|
136
|
+
return defineCommand({
|
|
137
|
+
meta: {
|
|
138
|
+
name: "init",
|
|
139
|
+
description: "Initialize a new CentoUI project"
|
|
140
|
+
},
|
|
141
|
+
async run() {
|
|
142
|
+
try {
|
|
143
|
+
const cwd = process.cwd();
|
|
144
|
+
intro("CentoUI — Initialize project");
|
|
145
|
+
const directories = await group({
|
|
146
|
+
componentDir: () => text({
|
|
147
|
+
message: "Directory to store components",
|
|
148
|
+
initialValue: "src/components/centoui",
|
|
149
|
+
validate: validatePath
|
|
150
|
+
}),
|
|
151
|
+
themeFilePath: () => text({
|
|
152
|
+
message: "Directory to store theme CSS file",
|
|
153
|
+
initialValue: "src/assets/css/centoui.css",
|
|
154
|
+
validate: validatePath
|
|
155
|
+
})
|
|
156
|
+
}, { onCancel: () => {
|
|
157
|
+
cancel("Initialization cancelled.");
|
|
158
|
+
process.exit(0);
|
|
159
|
+
} });
|
|
160
|
+
const configPath = join(cwd, CONFIG_FILE_NAME);
|
|
161
|
+
const themePath = join(cwd, directories.themeFilePath);
|
|
162
|
+
const componentsPath = join(cwd, directories.componentDir);
|
|
163
|
+
const shouldWriteConfig = await promptOverwrite(CONFIG_FILE_NAME, configPath);
|
|
164
|
+
const shouldWriteTheme = await promptOverwrite(directories.themeFilePath, themePath);
|
|
165
|
+
const shouldWriteComponents = await promptOverwrite(directories.componentDir, componentsPath);
|
|
166
|
+
let registry;
|
|
167
|
+
await tasks([
|
|
168
|
+
{
|
|
169
|
+
title: `Writing ${CONFIG_FILE_NAME}`,
|
|
170
|
+
task: async () => {
|
|
171
|
+
if (!shouldWriteConfig) return `Skipped writing ${CONFIG_FILE_NAME}, already exists`;
|
|
172
|
+
await fsExtra.outputFile(configPath, generateDefaultUserConfigTemplate(directories.themeFilePath, directories.componentDir), "utf-8");
|
|
173
|
+
return `${CONFIG_FILE_NAME} written`;
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
title: "Fetching theme CSS",
|
|
178
|
+
task: async () => {
|
|
179
|
+
if (!shouldWriteTheme) return "Skipped fetching theme CSS, already exists";
|
|
180
|
+
const themeFile = await fetchThemeFile();
|
|
181
|
+
await fsExtra.outputFile(themePath, themeFile, "utf-8");
|
|
182
|
+
return `${directories.themeFilePath} written`;
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
title: "Preparing components directory",
|
|
187
|
+
task: async () => {
|
|
188
|
+
if (!shouldWriteComponents) return "Skipped preparing components directory. already exists.";
|
|
189
|
+
await fsExtra.emptyDir(componentsPath);
|
|
190
|
+
return `${directories.componentDir} ready`;
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
title: "Fetching registry",
|
|
195
|
+
task: async () => {
|
|
196
|
+
registry = await fetchRegistry();
|
|
197
|
+
return "Registry index loaded";
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
title: "Installing global dependencies",
|
|
202
|
+
task: async (message) => {
|
|
203
|
+
return installPackages(registry.globals.packageDeps, cwd, message);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
]);
|
|
207
|
+
note([
|
|
208
|
+
`Config > ${configPath}`,
|
|
209
|
+
`Theme > ${themePath}`,
|
|
210
|
+
`Components > ${componentsPath}`,
|
|
211
|
+
"",
|
|
212
|
+
"Run 'centoui add button' to install your first component"
|
|
213
|
+
].join("\n"), "CentoUI initialized");
|
|
214
|
+
outro("All Set!");
|
|
215
|
+
} catch (error) {
|
|
216
|
+
log.error(`Failed to build registry: ${error}`);
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
//#endregion
|
|
223
|
+
//#region src/index.ts
|
|
224
|
+
runMain(defineCommand({
|
|
225
|
+
meta: {
|
|
226
|
+
name: "centoui",
|
|
227
|
+
version: VERSION
|
|
228
|
+
},
|
|
229
|
+
subCommands: { init }
|
|
230
|
+
}));
|
|
231
|
+
//#endregion
|
|
232
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "centoui-cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.1",
|
|
5
5
|
"description": "Official CLI for CentoUI.",
|
|
6
6
|
"author": "Favour Emeka <favorodera@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"access": "public"
|
|
18
18
|
},
|
|
19
19
|
"exports": {
|
|
20
|
-
".": "./dist/index.
|
|
20
|
+
".": "./dist/index.mjs",
|
|
21
21
|
"./package.json": "./package.json"
|
|
22
22
|
},
|
|
23
23
|
"types": "./dist/types.d.mts",
|
|
@@ -25,18 +25,19 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"bin": {
|
|
28
|
-
"centoui": "./dist/index.
|
|
28
|
+
"centoui": "./dist/index.mjs"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/fs-extra": "^11.0.4",
|
|
32
|
-
"tsdown": "^0.21.7"
|
|
32
|
+
"tsdown": "^0.21.7",
|
|
33
|
+
"type-fest": "^5.6.0"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
36
|
+
"@clack/prompts": "^1.2.0",
|
|
35
37
|
"citty": "^0.2.2",
|
|
36
38
|
"fs-extra": "^11.3.4",
|
|
37
39
|
"nypm": "^0.6.6",
|
|
38
|
-
"pathe": "^2.0.3"
|
|
39
|
-
"@clack/prompts": "^1.2.0"
|
|
40
|
+
"pathe": "^2.0.3"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
43
|
"node": ">=22.0.0"
|
package/dist/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { defineCommand, runMain } from "citty";
|
|
3
|
-
//#endregion
|
|
4
|
-
//#region src/constants.ts
|
|
5
|
-
/** CentoUI current package version */
|
|
6
|
-
const VERSION = "0.0.0";
|
|
7
|
-
/** CentoUI core base API URL */
|
|
8
|
-
const BASE_URL = `https://raw.githubusercontent.com/favorodera/centoui/refs/tags/v${VERSION}/packages/core/src`;
|
|
9
|
-
`${BASE_URL}`;
|
|
10
|
-
`${BASE_URL}`;
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/index.ts
|
|
13
|
-
runMain(defineCommand({
|
|
14
|
-
meta: {
|
|
15
|
-
name: "centoui",
|
|
16
|
-
version: VERSION
|
|
17
|
-
},
|
|
18
|
-
subCommands: {}
|
|
19
|
-
}));
|
|
20
|
-
//#endregion
|
|
File without changes
|