This repository has been archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.nu
77 lines (59 loc) · 1.85 KB
/
bootstrap.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use std log
def nupm-home [] {
$env.NUPM_HOME? | default (
$env.XDG_DATA_HOME?
| default ($nu.home-path | path join ".local" "share")
| path join "nupm"
)
}
def "dump to" [file: string] {
let content = ($in | str join "\n")
let file = (nupm-home | path join $file)
if ($file | path exists) {
log info $"($file) already exists: skipping"
return
}
log info $"dumping ($content | nu-highlight) to (ansi yellow)($file)(ansi reset)"
$content | save --force $file
}
def install-nupm [directory: string] {
let destination = (nupm-home | path join $directory)
if ($destination | path exists) {
log info $"($destination) already exists: updating"
git -C $destination pull origin main
} else {
log info $"installing ($destination)"
git clone https://github.com/amtoine/nupm.git $destination
}
}
def post-bootstrap-hints [] {
print $"add the following snippet to your ('$nu.env-path' | nu-highlight)"
print ([
"export-env {"
" let-env NUPM_HOME = ..."
" let-env NU_LIB_DIRS = ($env.NU_LIB_DIRS? | default [] | append ["
" $env.NUPM_HOME"
" ])"
"}"
] | str join "\n" | nu-highlight)
print ""
print "it is also recommended to add the following to allow the use of the `--save` option on `install` and `activate`"
print ([
"let-env NUPM_CONFIG = {"
" activations: ..."
" packages: ..."
"}"
] | str join "\n" | nu-highlight)
print ""
print $"add the following snippet to your ('$nu.config-path' | nu-highlight)"
print ($"use nupm/activations (char -i 42)" | nu-highlight)
}
def main [] {
mkdir (nupm-home)
install-nupm "nupm/"
[''] | dump to "nupm/activations"
print ""
post-bootstrap-hints
}
main
exec nu