Skip to content

Commit da29502

Browse files
authored
feat: Present the user with the defaultPath provided by the registry when prompting for a path (#713)
1 parent 518cbd3 commit da29502

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

.changeset/curvy-planets-lead.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"jsrepo": patch
3+
---
4+
5+
feat: Present the user with the defaultPath provided by the registry when prompting for a path
6+

packages/jsrepo/src/commands/update.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export async function runUpdate(
185185
name: item.item.name,
186186
type: item.item.type,
187187
files: item.item.files,
188+
registry: item.registry,
188189
})),
189190
config,
190191
options: {

packages/jsrepo/src/utils/add.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,12 @@ export async function fetchAllResolvedItems(
406406
* @returns
407407
*/
408408
export async function getItemLocation(
409-
item: { name: string; type: RegistryItemType; files: { path: string; target?: string }[] },
409+
item: {
410+
name: string;
411+
type: RegistryItemType;
412+
files: { path: string; target?: string }[];
413+
registry: ResolvedRegistry;
414+
},
410415
{
411416
paths,
412417
nonInteractive,
@@ -427,26 +432,28 @@ export async function getItemLocation(
427432
});
428433
}
429434

430-
const defaultPath = paths['*'];
435+
const catchAllPath = paths['*'];
431436
const type = normalizeItemTypeForPath(item.type);
432437
const path = paths[type];
433438
if (!path) {
434-
if (defaultPath) {
439+
if (catchAllPath) {
435440
return ok({
436-
path: defaultPath,
441+
path: catchAllPath,
437442
// already resolved
438-
resolvedPath: defaultPath,
443+
resolvedPath: catchAllPath,
439444
});
440445
}
441446

442447
// we just error in non-interactive mode
443448
if (nonInteractive) return err(new NoPathProvidedError({ item: item.name, type }));
444449

450+
const defaultPath = item.registry.manifest.defaultPaths?.[type] ?? `./src/${type}`;
451+
445452
const blocksPath = await text({
446453
message: `Where would you like to add ${pc.cyan(type)}?`,
447-
placeholder: `./src/${type}`,
448-
initialValue: `./src/${type}`,
449-
defaultValue: `./src/${type}`,
454+
placeholder: defaultPath,
455+
initialValue: defaultPath,
456+
defaultValue: defaultPath,
450457
validate(value) {
451458
if (!value || value.trim() === '') return 'Please provide a value';
452459
},
@@ -664,6 +671,7 @@ export async function getPathsForItems({
664671
name: string;
665672
type: RegistryItemType;
666673
files: { path: ItemRelativePath; type: RegistryItemType; target?: string }[];
674+
registry: ResolvedRegistry;
667675
}[];
668676
config: Config | undefined;
669677
options: { cwd: AbsolutePath; yes: boolean };

packages/jsrepo/src/utils/config/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export type RegistryItemFile = {
251251
export type RegistryItemFolderFile = Prettify<
252252
Omit<RegistryItemFile, 'target' | 'type' | 'path'> & {
253253
/**
254-
* Path to the file relative to the parent folder.
254+
* Path to the file/folder relative to the parent folder.
255255
*/
256256
path: string;
257257
}

0 commit comments

Comments
 (0)