pejay-ui 1.4.0 → 1.4.2
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/README.md +8 -0
- package/bin/cli.js +61 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,14 @@ import { Input, Checkbox, AmountInput } from "@/pejay-ui/components";
|
|
|
46
46
|
**Component-Specific Documentation (READMEs):**
|
|
47
47
|
Certain components (like `toast`) ship with localized `README.md` guides. When you install them, the CLI automatically copies their detailed usage documentation directly into the component's folder (e.g., `src/pejay-ui/components/toast/README.md`) so you have helper docs right next to the code.
|
|
48
48
|
|
|
49
|
+
**Overwrite Protection:**
|
|
50
|
+
To prevent accidentally overwriting any custom modifications you have made to your components, the CLI checks if the component is already tracked in `pejay-ui.json` or if its files already exist in your workspace. It will ask for confirmation before overwriting:
|
|
51
|
+
```
|
|
52
|
+
? Component '<name>' is already present in your project. Overwriting it will discard any local changes you have made. Do you want to proceed and overwrite it? (y/N)
|
|
53
|
+
```
|
|
54
|
+
- Choosing **No** safely skips the installation, preserving your local changes.
|
|
55
|
+
- Choosing **Yes** overwrites the files with a fresh copy of the component template.
|
|
56
|
+
|
|
49
57
|
### 3. Remove Component
|
|
50
58
|
```bash
|
|
51
59
|
npx pejay-ui remove <component-name>
|
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] : []);
|