-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
run
executable file
·215 lines (190 loc) · 6.01 KB
/
run
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#!/usr/bin/env nu
# From: https://github.com/r3bl-org/nu_script_template
#
# nu shell docs
# - language fundamentals: https://www.nushell.sh/book/custom_commands.html#sub-commands
# - strings: https://www.nushell.sh/book/working_with_strings.html#string-interpolation
# - functions (aka commands, subcommands): https://www.nushell.sh/book/custom_commands.html
# - variables: https://www.nushell.sh/book/variables_and_subexpressions.html
# - built-in command reference: https://www.nushell.sh/commands/#command-reference
# - length: https://www.nushell.sh/commands/docs/length.html
# - ansi: https://www.nushell.sh/commands/docs/ansi.html
# - print: https://www.nushell.sh/commands/docs/print.html
# - input: https://www.nushell.sh/commands/docs/input.html
# - input list: https://www.nushell.sh/commands/docs/input_list.html
# - match: https://www.nushell.sh/commands/docs/match.html
# - mental model
# - coming from bash: https://www.nushell.sh/book/coming_from_bash.html
# - thinking in nu: https://www.nushell.sh/book/thinking_in_nu.html
let workspace_folders = [
"core", "macro", "redux", "tui", "tuify", "ansi_color", "simple_logger", "utils",
"cmdr", "analytics_schema", "terminal_async"
]
# Main entry point for the script.
def main [...args: string] {
let num_args = $args | length
if $num_args == 0 {
print-help all
return
}
let command = $args | get 0
match $command {
"all" => {all}
"all-cicd" => {all-cicd}
"build" => {build}
"build-full" => {build-full}
"clean" => {clean}
"install-cargo-tools" => {install-cargo-tools}
"test" => {test}
"docs" => {docs}
"check" => {check}
"check-watch" => {check-watch}
"clippy" => {clippy}
"clippy-watch" => {clippy-watch}
"rustfmt" => {rustfmt}
"upgrade-deps" => {upgrade-deps}
"serve-docs" => {serve-docs}
"help" => {print-help all}
"audit-deps" => {audit-deps}
_ => {print $'Unknown command: (ansi red_bold)($command)(ansi reset)'}
}
}
# Prints help for the script.
# - If "all" is passed in, prints help for all commands.
# - Otherwise, prints help for the specified command.
def print-help [command: string] {
if $command == "all" {
print $'Usage: (ansi magenta_bold)run(ansi reset) (ansi green_bold)<command>(ansi reset) (ansi blue_bold)[args](ansi reset)'
print $'(ansi green_bold)<command>(ansi reset) can be:'
print $' (ansi green)all(ansi reset)'
print $' (ansi green)all-cicd(ansi reset)'
print $' (ansi green)build(ansi reset)'
print $' (ansi green)build-full(ansi reset)'
print $' (ansi green)clean(ansi reset)'
print $' (ansi green)install-cargo-tools(ansi reset)'
print $' (ansi green)test(ansi reset)'
print $' (ansi green)docs(ansi reset)'
print $' (ansi green)check(ansi reset)'
print $' (ansi green)check-watch(ansi reset)'
print $' (ansi green)clippy(ansi reset)'
print $' (ansi green)clippy-watch(ansi reset)'
print $' (ansi green)serve-docs(ansi reset)'
print $' (ansi green)upgrade-deps(ansi reset)'
print $' (ansi green)rustfmt(ansi reset)'
print $' (ansi green)help(ansi reset)'
} else {
print $'Unknown command: (ansi red_bold)($command)(ansi reset)'
}
}
def install-cargo-tools [] {
cargo install bacon
cargo install cargo-workspaces
cargo install cargo-cache
cargo install cargo-watch
cargo install flamegraph
cargo install cargo-outdated
cargo install cargo-update
cargo install cargo-deny
cargo install cargo-unmaintained
cargo install cargo-expand
}
def all [] {
cargo install cargo-deny
cargo install cargo-unmaintained
build
test
clippy
docs
audit-deps
unmaintained
rustfmt
}
# Runs everything that all does, except for cargo-unmaintained and cargo-deny.
def all-cicd [] {
# cargo install cargo-deny
# cargo install cargo-unmaintained
build
test
clippy
docs
# audit-deps
# unmaintained
rustfmt
}
def unmaintained [] {
cargo unmaintained --color always --fail-fast --tree --verbose
}
def build [] {
cargo build
}
def build-full [] {
install-cargo-tools
cargo cache -r all
cargo clean
cargo +nightly update
cargo build
}
def clean [] {
cargo clean
}
def test [] {
for folder in ($workspace_folders) {
cd $folder
print $'(ansi magenta)≡ Running tests in ($folder) .. ≡(ansi reset)'
cargo test -q -- --test-threads=20
cd ..
}
}
def check [] {
cargo check --workspace
}
def check-watch [] {
cargo watch -x 'check --workspace'
}
def clippy [] {
for folder in ($workspace_folders) {
cd $folder
print $'(ansi magenta)≡ Running cargo clippy in ($folder) .. ≡(ansi reset)'
cargo fix --allow-dirty --allow-staged
cargo fmt --all
cd ..
}
}
def clippy-watch [] {
cargo fix --allow-dirty --allow-staged
cargo fmt --all
cargo watch -x 'clippy --fix --allow-dirty --allow-staged' -c -q
}
def docs [] {
for folder in $workspace_folders {
cd $folder
print $'(ansi magenta)≡ Running cargo doc in ($folder) .. ≡(ansi reset)'
cargo doc --no-deps --all-features
cd ..
}
}
def serve-docs [] {
npm i -g serve
serve target/doc
}
def upgrade-deps [] {
for folder in $workspace_folders {
cd $folder
print $'(ansi magenta)≡ Upgrading ($folder) .. ≡(ansi reset)'
cargo outdated --workspace --verbose
cargo upgrade --verbose
cd ..
}
}
def rustfmt [] {
for folder in $workspace_folders {
cd $folder
print $'(ansi magenta)≡ Running cargo fmt --all in ($folder) .. ≡(ansi reset)'
cargo fmt --all
cd ..
}
}
# More info: https://github.com/EmbarkStudios/cargo-deny
def audit-deps [] {
cargo deny check licenses advisories
}