pejay-ui 1.4.0 → 1.4.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.
Files changed (2) hide show
  1. package/bin/cli.js +61 -1
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -218,6 +218,67 @@ program
218
218
  }
219
219
 
220
220
  const componentData = registry[compToInstall];
221
+
222
+ // Check if the component is already installed or if any target files already exist
223
+ const outputExt = isTsProject ? "tsx" : "jsx";
224
+ let isAlreadyPresent = !!config.installed?.[compToInstall];
225
+
226
+ if (!isAlreadyPresent) {
227
+ let targetDir;
228
+ if (componentData.category === "scaffold") {
229
+ targetDir = path.join(cwd, "src", componentData.targetDirName || compToInstall);
230
+ } else {
231
+ targetDir = path.join(cwd, config.baseDir, "components", componentData.category);
232
+ }
233
+
234
+ const sourceFiles = componentData.files || (componentData.path ? [componentData.path] : []);
235
+ for (const srcFilePath of sourceFiles) {
236
+ const templateSrc = path.join(packageRoot, srcFilePath);
237
+ if (await fs.pathExists(templateSrc)) {
238
+ const isDir = (await fs.stat(templateSrc)).isDirectory();
239
+ if (isDir) {
240
+ const allFiles = await getFilesRecursively(templateSrc);
241
+ for (const file of allFiles) {
242
+ const relativePath = path.relative(templateSrc, file);
243
+ const filename = relativePath.replace(/\.(tsx|ts)$/, (match) => {
244
+ return match === ".tsx" ? `.${outputExt}` : `.${isTsProject ? "ts" : "js"}`;
245
+ });
246
+ const targetFile = path.join(targetDir, filename);
247
+ if (await fs.pathExists(targetFile)) {
248
+ isAlreadyPresent = true;
249
+ break;
250
+ }
251
+ }
252
+ } else {
253
+ const filename = path.basename(srcFilePath).replace(/\.(tsx|ts)$/, (match) => {
254
+ return match === ".tsx" ? `.${outputExt}` : `.${isTsProject ? "ts" : "js"}`;
255
+ });
256
+ const targetFile = path.join(targetDir, filename);
257
+ if (await fs.pathExists(targetFile)) {
258
+ isAlreadyPresent = true;
259
+ }
260
+ }
261
+ }
262
+ if (isAlreadyPresent) break;
263
+ }
264
+ }
265
+
266
+ if (isAlreadyPresent) {
267
+ const { overwrite } = await prompt([
268
+ {
269
+ type: "confirm",
270
+ name: "overwrite",
271
+ message: `Component '${compToInstall}' is already present in your project. Overwriting it will discard any local changes you have made. Do you want to proceed and overwrite it?`,
272
+ default: false,
273
+ },
274
+ ]);
275
+
276
+ if (!overwrite) {
277
+ console.log(`Skipping component: ${componentData.name}.\n`);
278
+ continue;
279
+ }
280
+ }
281
+
221
282
  console.log(`Installing component: ${componentData.name}...`);
222
283
 
223
284
  // 1. Check target project package.json for peerDependencies
@@ -300,7 +361,6 @@ program
300
361
  } else {
301
362
  targetDir = path.join(cwd, config.baseDir, "components", componentData.category);
302
363
  }
303
- const outputExt = isTsProject ? "tsx" : "jsx";
304
364
 
305
365
  // Determine list of files to copy
306
366
  const sourceFiles = componentData.files || (componentData.path ? [componentData.path] : []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pejay-ui",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "description": "react ui components",
6
6
  "bin": {