|
1 | 1 | # Registry management for nupm |
2 | 2 |
|
3 | 3 | use utils/dirs.nu [nupm-home-prompt REGISTRY_FILENAME] |
4 | | -use utils/log.nu throw-error |
| 4 | +use utils/log.nu [throw-error UNIMPLEMENTED] |
| 5 | +use utils/registry.nu registry-cache |
5 | 6 |
|
6 | 7 | # Manage nupm registires |
7 | 8 | @example "List all configured registries" { nupm registry } |
@@ -30,25 +31,25 @@ export def describe [ |
30 | 31 | } |
31 | 32 |
|
32 | 33 | let registry_url = $env.NUPM_REGISTRIES | get $registry |
33 | | - let registry_cache_dir = cache-dir --ensure | path join $registry |
34 | | - let cached_registry = $registry_cache_dir | path join $REGISTRY_FILENAME |
| 34 | + let cache = registry-cache $registry |
| 35 | + let cached_registry = $cache.dir | path join $REGISTRY_FILENAME |
35 | 36 |
|
36 | 37 | # Always check cache first, only fall back to URL if cache doesn't exist |
37 | | - let registry_data = if ($cached_registry | path exists) { |
38 | | - open $cached_registry |
| 38 | + let registry_data = if ($cache.file | path exists) { |
| 39 | + open $cache.file |
39 | 40 | } else if ($registry_url | path exists) { |
40 | 41 | # Local registry file |
41 | 42 | open $registry_url |
42 | 43 | } else { |
43 | 44 | # Remote registry - fetch and cache |
44 | 45 | let data = http get $registry_url |
45 | | - mkdir $registry_cache_dir |
46 | | - $data | save $cached_registry |
| 46 | + mkdir $cache.dir |
| 47 | + $data | save $cache.file |
47 | 48 | $data |
48 | 49 | } |
49 | 50 |
|
50 | 51 | $registry_data | each {|entry| |
51 | | - let package_cache_path = $registry_cache_dir | path join $"($entry.name).nuon" |
| 52 | + let package_cache_path = $cache.dir | path join $"($entry.name).nuon" |
52 | 53 |
|
53 | 54 | # Always check cache first for package data too |
54 | 55 | let package_file_data = if ($package_cache_path | path exists) { |
@@ -91,12 +92,17 @@ export def --env add [ |
91 | 92 | throw-error $"Registry '($name)' already exists. Use 'nupm registry update' to modify it." |
92 | 93 | } |
93 | 94 | $env.NUPM_REGISTRIES = $env.NUPM_REGISTRIES | insert $name $url |
| 95 | + mut add_success_msg = $"Registry '($name)' added successfully" |
94 | 96 |
|
95 | 97 | if $save { |
96 | 98 | $env.NUPM_REGISTRIES | save --force $env.NUPM_INDEX_PATH |
| 99 | + $add_success_msg = $add_success_msg | append $" and written to ($env.NUPM_INDEX_PATH)." | str join " " |
| 100 | + |
| 101 | + } else { |
| 102 | + $add_success_msg = $add_success_msg | append $". To commit the change to disk, use the `--save` flag." | str join " " |
97 | 103 | } |
98 | 104 |
|
99 | | - print $"Registry '($name)' added successfully." |
| 105 | + print $add_success_msg |
100 | 106 | } |
101 | 107 |
|
102 | 108 | # Remove a registry |
@@ -174,5 +180,6 @@ export def init [--index] { |
174 | 180 | return |
175 | 181 | } |
176 | 182 | # TODO initialize registry index here |
| 183 | + throw-error UNIMPLEMENTED "`nupm registry --index` is not implemented." |
177 | 184 | } |
178 | 185 |
|
0 commit comments