centoui-cli 0.0.0 → 0.1.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Favour Emeka
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Favour Emeka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -4,13 +4,13 @@
4
4
  [![npm downloads](https://img.shields.io/npm/dm/centoui-cli.svg?style=flat-square)](https://www.npmjs.com/package/centoui-cli)
5
5
  [![license](https://img.shields.io/github/license/favorodera/centoui.svg?style=flat-square)](https://github.com/favorodera/centoui/blob/main/LICENSE)
6
6
 
7
- **CentoUI CLI: Manage your components with ease.**
7
+ **CentoUI CLI: Manage your CentoUI components with ease.**
8
8
 
9
9
  `centoui-cli` is the official command-line interface for [CentoUI](https://github.com/favorodera/centoui). It allows you to initialize CentoUI in your project, add new components, and manage their versions directly from your terminal.
10
10
 
11
11
  ## Commands
12
12
 
13
- - **`init`**: Set up a new CentoUI project (generates `centoui.config.ts` and `tokens.css`).
13
+ - **`init`**: Set up a new CentoUI project (generates `centoui.config.ts` and `centoui.css`).
14
14
  - **`add [component]`**: Add specific components to your project. Peer dependencies install automatically.
15
15
  - **`remove [component]`**: Cleanly remove components and their dependencies.
16
16
 
@@ -18,10 +18,10 @@
18
18
 
19
19
  ```bash
20
20
  # Initialize CentoUI in your project
21
- npx centoui init
21
+ pnpm dlx centoui init
22
22
 
23
23
  # Add components
24
- npx centoui add button dialog input select
24
+ pnpm dlx centoui add button dialog input select
25
25
  ```
26
26
 
27
27
  ## Configuration
@@ -34,15 +34,11 @@ import { defineConfig } from "centoui"
34
34
  export default defineConfig({
35
35
  version: "1.0.0",
36
36
  componentsDir: "./src/components/centoui",
37
- themeDir: "./src/assets/css/centoui.css",
37
+ themeFilePath: "./src/assets/css/centoui.css",
38
38
  icons: {
39
39
  check: "lucide:check",
40
40
  close: "lucide:x",
41
41
  menu: "lucide:menu",
42
42
  },
43
43
  })
44
- ```
45
-
46
- ## License
47
-
48
- [MIT](../../LICENSE) © [Favour Emeka](https://github.com/favorodera)
44
+ ```
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.1.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/main/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,8 @@
1
1
  {
2
2
  "name": "centoui-cli",
3
3
  "type": "module",
4
- "version": "0.0.0",
4
+ "version": "0.1.1",
5
+ "private": false,
5
6
  "description": "Official CLI for CentoUI.",
6
7
  "author": "Favour Emeka <favorodera@gmail.com>",
7
8
  "license": "MIT",
@@ -17,7 +18,7 @@
17
18
  "access": "public"
18
19
  },
19
20
  "exports": {
20
- ".": "./dist/index.js",
21
+ ".": "./dist/index.mjs",
21
22
  "./package.json": "./package.json"
22
23
  },
23
24
  "types": "./dist/types.d.mts",
@@ -25,18 +26,19 @@
25
26
  "dist"
26
27
  ],
27
28
  "bin": {
28
- "centoui": "./dist/index.js"
29
+ "centoui": "./dist/index.mjs"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@types/fs-extra": "^11.0.4",
32
- "tsdown": "^0.21.7"
33
+ "tsdown": "^0.21.7",
34
+ "type-fest": "^5.6.0"
33
35
  },
34
36
  "dependencies": {
37
+ "@clack/prompts": "^1.2.0",
35
38
  "citty": "^0.2.2",
36
39
  "fs-extra": "^11.3.4",
37
40
  "nypm": "^0.6.6",
38
- "pathe": "^2.0.3",
39
- "@clack/prompts": "^1.2.0"
41
+ "pathe": "^2.0.3"
40
42
  },
41
43
  "engines": {
42
44
  "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