pejay-ui 1.0.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Prayas Jadli
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 ADDED
File without changes
package/bin/cli.js ADDED
@@ -0,0 +1,379 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { Command } from "commander";
4
+ import fs from "fs-extra";
5
+ import path from "path";
6
+ import babel from "@babel/core";
7
+ import { execSync } from "child_process";
8
+ import { fileURLToPath } from "url";
9
+
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+ const packageRoot = path.resolve(__dirname, "..");
13
+
14
+ const program = new Command();
15
+
16
+ /* -----------------------------
17
+ INQUIRER DYNAMIC IMPORT
18
+ ------------------------------*/
19
+ const prompt = async (questions) => {
20
+ const inquirer = await import("inquirer");
21
+ return inquirer.default.prompt(questions);
22
+ };
23
+
24
+ program
25
+ .name("pejay-ui")
26
+ .description("CLI to initialize, add, and remove React UI components")
27
+ .version("1.0.0");
28
+
29
+ /* =============================
30
+ INIT COMMAND
31
+ ============================= */
32
+ program
33
+ .command("init")
34
+ .description("Initialize pejay-ui configuration in your project")
35
+ .action(async () => {
36
+ console.log("Initializing pejay-ui...");
37
+
38
+ const baseDir = "src/pejay-ui";
39
+
40
+ // Save project configuration
41
+ const configPath = path.join(process.cwd(), "pejay-ui.json");
42
+ const config = {
43
+ baseDir,
44
+ installed: {}
45
+ };
46
+
47
+ await fs.writeJSON(configPath, config, { spaces: 2 });
48
+
49
+ console.log(`\nSuccess!`);
50
+ console.log(`- Created configuration at pejay-ui.json`);
51
+ console.log(`\nYou can now add components using: npx pejay-ui add <component-name>`);
52
+ });
53
+
54
+ /* =============================
55
+ ADD COMMAND
56
+ ============================= */
57
+ program
58
+ .command("add <component>")
59
+ .description("Add a component to your project")
60
+ .action(async (component) => {
61
+ try {
62
+ const cwd = process.cwd();
63
+ const configPath = path.join(cwd, "pejay-ui.json");
64
+
65
+ if (!await fs.pathExists(configPath)) {
66
+ console.error("Error: pejay-ui.json not found. Please run 'npx pejay-ui init' first.");
67
+ process.exit(1);
68
+ }
69
+
70
+ const config = await fs.readJSON(configPath);
71
+ const registryPath = path.join(packageRoot, "registry.json");
72
+
73
+ if (!await fs.pathExists(registryPath)) {
74
+ console.error("Error: Registry configuration not found in the package.");
75
+ process.exit(1);
76
+ }
77
+
78
+ const registry = await fs.readJSON(registryPath);
79
+ const isTsProject = await fs.pathExists(path.join(cwd, "tsconfig.json"));
80
+
81
+ // Track all components to install (including dependencies) in topological/order of dependencies
82
+ const installQueue = [];
83
+ const visited = new Set();
84
+
85
+ const resolveDependencies = (compName) => {
86
+ if (visited.has(compName)) return;
87
+ visited.add(compName);
88
+
89
+ const compData = registry[compName];
90
+ if (!compData) {
91
+ console.error(`Error: Component '${compName}' not found in registry.`);
92
+ console.log(`Available components: ${Object.keys(registry).join(", ")}`);
93
+ process.exit(1);
94
+ }
95
+
96
+ // Resolve dependencies first
97
+ if (compData.dependencies && compData.dependencies.length > 0) {
98
+ for (const dep of compData.dependencies) {
99
+ resolveDependencies(dep);
100
+ }
101
+ }
102
+
103
+ installQueue.push(compName);
104
+ };
105
+
106
+ resolveDependencies(component);
107
+
108
+ console.log("\nšŸš€ Starting installation...\n");
109
+
110
+ for (const compToInstall of installQueue) {
111
+ // Skip if already marked as installed in config (unless it is the main component requested)
112
+ if (config.installed?.[compToInstall] && compToInstall !== component) {
113
+ console.log(`Component '${compToInstall}' is already installed. Skipping dependency installation.`);
114
+ continue;
115
+ }
116
+
117
+ const componentData = registry[compToInstall];
118
+ console.log(`Installing component: ${componentData.name}...`);
119
+
120
+ // 1. Check target project package.json for peerDependencies
121
+ const targetPackageJsonPath = path.join(cwd, "package.json");
122
+ let missingDependencies = [];
123
+
124
+ if (componentData.peerDependencies && componentData.peerDependencies.length > 0) {
125
+ let targetDeps = {};
126
+ if (await fs.pathExists(targetPackageJsonPath)) {
127
+ try {
128
+ const targetPkg = await fs.readJSON(targetPackageJsonPath);
129
+ targetDeps = {
130
+ ...(targetPkg.dependencies || {}),
131
+ ...(targetPkg.devDependencies || {})
132
+ };
133
+ } catch (e) {}
134
+ }
135
+
136
+ missingDependencies = componentData.peerDependencies.filter(
137
+ (dep) => !targetDeps[dep]
138
+ );
139
+ }
140
+
141
+ if (missingDependencies.length > 0) {
142
+ console.error(`Error: Missing required package dependencies to use '${compToInstall}':`);
143
+ console.log(`Please run the following command to install them first:`);
144
+ console.log(`\n npm install ${missingDependencies.join(" ")}\n`);
145
+ process.exit(1);
146
+ }
147
+
148
+ // 2. Process & Copy Utility dependencies
149
+ const targetUtilsDir = path.join(cwd, config.baseDir, "utils");
150
+ const utilsList = componentData.utils || [];
151
+ const installedUtils = [];
152
+
153
+ for (const utilFile of utilsList) {
154
+ const sourceUtilPath = path.join(packageRoot, "utils", utilFile);
155
+
156
+ if (await fs.pathExists(sourceUtilPath)) {
157
+ let utilCode = await fs.readFile(sourceUtilPath, "utf-8");
158
+ const utilExt = isTsProject ? "ts" : "js";
159
+ const targetUtilFile = utilFile.replace(/\.ts$/, `.${utilExt}`);
160
+ const targetUtilPath = path.join(targetUtilsDir, targetUtilFile);
161
+
162
+ if (!await fs.pathExists(targetUtilPath)) {
163
+ console.log(`Initializing utility: utils/${targetUtilFile}...`);
164
+
165
+ if (!isTsProject) {
166
+ const transformed = babel.transformSync(utilCode, {
167
+ presets: ["@babel/preset-typescript"],
168
+ filename: utilFile,
169
+ });
170
+ utilCode = transformed?.code || utilCode;
171
+ }
172
+
173
+ await fs.ensureDir(targetUtilsDir);
174
+ await fs.writeFile(targetUtilPath, utilCode, "utf-8");
175
+ }
176
+ installedUtils.push(targetUtilFile);
177
+ }
178
+ }
179
+
180
+ // 3. Process & Copy Component Files
181
+ const targetDir = path.join(cwd, config.baseDir, "components", componentData.category);
182
+ const outputExt = isTsProject ? "tsx" : "jsx";
183
+
184
+ // Determine list of files to copy
185
+ const sourceFiles = componentData.files || (componentData.path ? [componentData.path] : []);
186
+ const installedFiles = [];
187
+
188
+ for (const srcFilePath of sourceFiles) {
189
+ const templateSrc = path.join(packageRoot, srcFilePath);
190
+ if (!await fs.pathExists(templateSrc)) {
191
+ console.error(`Error: Template file does not exist at ${templateSrc}`);
192
+ process.exit(1);
193
+ }
194
+
195
+ const filename = path.basename(srcFilePath).replace(/\.(tsx|ts)$/, (match) => {
196
+ return match === ".tsx" ? `.${outputExt}` : `.${isTsProject ? "ts" : "js"}`;
197
+ });
198
+ const targetFile = path.join(targetDir, filename);
199
+
200
+ let componentCode = await fs.readFile(templateSrc, "utf-8");
201
+
202
+ // Replace `@/utils/cn` with relative path to the local utils/cn folder
203
+ const cnImportPath = isTsProject ? "../../utils/cn" : "../../utils/cn.js";
204
+ componentCode = componentCode.replace(/@\/utils\/cn/g, cnImportPath);
205
+
206
+ if (!isTsProject) {
207
+ const transformed = babel.transformSync(componentCode, {
208
+ presets: ["@babel/preset-typescript"],
209
+ filename: path.basename(srcFilePath),
210
+ });
211
+ componentCode = transformed?.code || componentCode;
212
+ }
213
+
214
+ await fs.ensureDir(targetDir);
215
+ await fs.writeFile(targetFile, componentCode, "utf-8");
216
+ console.log(`āœ… Created components/${componentData.category}/${filename}`);
217
+ installedFiles.push(path.join("components", componentData.category, filename));
218
+ }
219
+
220
+ // 4. Update State tracking in config
221
+ config.installed = config.installed || {};
222
+ config.installed[compToInstall] = {
223
+ files: installedFiles,
224
+ utils: utilsList
225
+ };
226
+
227
+ await fs.writeJSON(configPath, config, { spaces: 2 });
228
+ console.log(`šŸŽ‰ ${componentData.name} installed successfully\n`);
229
+ }
230
+
231
+ } catch (err) {
232
+ console.error("\nāŒ Add failed\n", err);
233
+ }
234
+ });
235
+
236
+ /* =============================
237
+ REMOVE COMMAND
238
+ ============================= */
239
+ program
240
+ .command("remove <component>")
241
+ .description("Remove a component safely from your project")
242
+ .action(async (component) => {
243
+ try {
244
+ const cwd = process.cwd();
245
+ const configPath = path.join(cwd, "pejay-ui.json");
246
+
247
+ if (!await fs.pathExists(configPath)) {
248
+ console.error("Error: pejay-ui.json not found.");
249
+ process.exit(1);
250
+ }
251
+
252
+ const config = await fs.readJSON(configPath);
253
+ const registryPath = path.join(packageRoot, "registry.json");
254
+
255
+ if (!await fs.pathExists(registryPath)) {
256
+ console.error("Error: Registry configuration not found.");
257
+ process.exit(1);
258
+ }
259
+
260
+ const registry = await fs.readJSON(registryPath);
261
+ const componentData = registry[component];
262
+
263
+ if (!componentData) {
264
+ console.log(`āŒ "${component}" not found in registry`);
265
+ return;
266
+ }
267
+
268
+ const installedData = config.installed?.[component];
269
+ if (!installedData) {
270
+ console.log(`āŒ "${component}" is not marked as installed in pejay-ui.json`);
271
+ return;
272
+ }
273
+
274
+ console.log("\n🧹 Starting removal...\n");
275
+
276
+ // 1. Delete Component Files
277
+ for (const relFile of installedData.files || []) {
278
+ const fullPath = path.join(cwd, config.baseDir, relFile);
279
+ if (await fs.pathExists(fullPath)) {
280
+ await fs.remove(fullPath);
281
+ console.log(`šŸ—‘ļø Removed ${relFile}`);
282
+ }
283
+ }
284
+
285
+ // 2. Build Utility Usage Map
286
+ const utilityUsage = {};
287
+ for (const [compName, compInfo] of Object.entries(config.installed)) {
288
+ if (compName === component) continue; // Skip the one we are deleting
289
+ for (const util of compInfo.utils || []) {
290
+ utilityUsage[util] = (utilityUsage[util] || 0) + 1;
291
+ }
292
+ }
293
+
294
+ // 3. Remove Unused Utilities
295
+ const isTsProject = await fs.pathExists(path.join(cwd, "tsconfig.json"));
296
+ const utilsToRemove = [];
297
+
298
+ for (const utilFile of installedData.utils || []) {
299
+ const usage = utilityUsage[utilFile] || 0;
300
+ const utilExt = isTsProject ? "ts" : "js";
301
+ const targetUtilFile = utilFile.replace(/\.ts$/, `.${utilExt}`);
302
+
303
+ if (usage > 0) {
304
+ console.log(`ā›” Skipping utils/${targetUtilFile} (used by other components)`);
305
+ continue;
306
+ }
307
+
308
+ const { confirm } = await prompt([
309
+ {
310
+ type: "confirm",
311
+ name: "confirm",
312
+ message: `Remove utility "${targetUtilFile}"?`,
313
+ default: false,
314
+ },
315
+ ]);
316
+
317
+ if (confirm) {
318
+ const fullUtilPath = path.join(cwd, config.baseDir, "utils", targetUtilFile);
319
+ if (await fs.pathExists(fullUtilPath)) {
320
+ await fs.remove(fullUtilPath);
321
+ console.log(`šŸ—‘ļø Removed utils/${targetUtilFile}`);
322
+ utilsToRemove.push(utilFile);
323
+ }
324
+ }
325
+ }
326
+
327
+ // 4. Uninstall Unused Packages
328
+ const packageUsage = {};
329
+ for (const [compName, compInfo] of Object.entries(config.installed)) {
330
+ if (compName === component) continue;
331
+ const regData = registry[compName];
332
+ if (regData?.peerDependencies) {
333
+ for (const pkg of regData.peerDependencies) {
334
+ packageUsage[pkg] = (packageUsage[pkg] || 0) + 1;
335
+ }
336
+ }
337
+ }
338
+
339
+ const pkgsToUninstall = [];
340
+ if (componentData.peerDependencies) {
341
+ for (const pkg of componentData.peerDependencies) {
342
+ const usage = packageUsage[pkg] || 0;
343
+ if (usage === 0) {
344
+ pkgsToUninstall.push(pkg);
345
+ }
346
+ }
347
+ }
348
+
349
+ if (pkgsToUninstall.length > 0) {
350
+ const { ok } = await prompt([
351
+ {
352
+ type: "confirm",
353
+ name: "ok",
354
+ message: `Uninstall unused packages: ${pkgsToUninstall.join(", ")}?`,
355
+ default: false,
356
+ },
357
+ ]);
358
+
359
+ if (ok) {
360
+ console.log(`Uninstalling packages...`);
361
+ execSync(`npm uninstall ${pkgsToUninstall.join(" ")}`, {
362
+ cwd,
363
+ stdio: "inherit",
364
+ });
365
+ }
366
+ }
367
+
368
+ // 5. Clean up config state
369
+ delete config.installed[component];
370
+ await fs.writeJSON(configPath, config, { spaces: 2 });
371
+
372
+ console.log(`\nšŸŽ‰ ${component} removed successfully\n`);
373
+
374
+ } catch (err) {
375
+ console.error("\nāŒ Remove failed\n", err);
376
+ }
377
+ });
378
+
379
+ program.parse();
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "pejay-ui",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "react ui components",
6
+ "bin": {
7
+ "pejay-ui": "./bin/cli.js"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "templates/",
12
+ "utils/",
13
+ "registry.json"
14
+ ],
15
+ "keywords": [
16
+ "react",
17
+ "components",
18
+ "ui",
19
+ "cli"
20
+ ],
21
+ "license": "MIT",
22
+ "dependencies": {
23
+ "@babel/core": "^7.24.0",
24
+ "@babel/preset-typescript": "^7.24.0",
25
+ "commander": "^12.0.0",
26
+ "fs-extra": "^11.0.0",
27
+ "inquirer": "^9.0.0"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/pejaybro/pejay-ui.git"
32
+ },
33
+ "author": "Prayas Jadli",
34
+ "email": "[EMAIL_ADDRESS]",
35
+ "bugs": {
36
+ "url": "https://github.com/pejaybro/pejay-ui/issues"
37
+ },
38
+ "homepage": "https://github.com/pejaybro/pejay-ui#readme",
39
+ "devDependencies": {
40
+ "@floating-ui/react": "^0.27.19",
41
+ "@types/react": "^19.2.15",
42
+ "@types/react-dom": "^19.2.3",
43
+ "clsx": "^2.1.1",
44
+ "dayjs": "^1.11.21",
45
+ "lucide-react": "^1.17.0",
46
+ "react": "^19.2.6",
47
+ "react-dom": "^19.2.6",
48
+ "tailwind-merge": "^3.6.0",
49
+ "tailwindcss": "^4.3.0",
50
+ "typescript": "^6.0.3"
51
+ }
52
+ }