forked from nushell/nu_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolkit.nu
64 lines (51 loc) · 1.65 KB
/
toolkit.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
# this module regroups a bunch of development tools to make the development
# process easier for anyone.
#
# the main purpose of `toolkit` is to offer an easy to use interface for the
# developer during a PR cycle.
# check that all the tests pass
export def test [
] {
print "toolkit test: not implemented!"
}
# run all the necessary checks and tests to submit a perfect PR
export def "check pr" [
] {
generate-file-list
test
}
export def main [] { help toolkit }
export def generate-file-list [ --full ] {
let start = "let files = ["
mut files = [""]
if $full {
# all the *.nu files in the repo
# exept for `before_v0.60`
print "checking all files..."
mut $files = glob **/*.nu --exclude [before_v0.60/**]
} else {
# only the *.nu files changed in comparison with origin/main
$files = (git diff --name-only origin/main | lines | filter { str ends-with '.nu'} | each { path expand })
}
let new_list = $files | str join ",\n" | append "]"
let final = "
mut exit_code = 0
for file in $files {
let diagnostics_table = nu --ide-check 10 $file | to text | ['[', $in, ']'] | str join | from json
let result = $diagnostics_table | where type == \"diagnostic\" | is-empty
if $result {
print $\"✔ ($file) is ok\"
} else {
print $\"❌ ($file) has errors:\"
print ($diagnostics_table | where type == \"diagnostic\" | reject span)
$exit_code = 1
}
}
print $\"💚 All files checked!\"
exit $exit_code
"
$start
| append $new_list
| append $final
| save "check-files.nu" --force
}