|
| 1 | +set shell := ['nu', '-m', 'light', '-c'] |
| 2 | + |
| 3 | +# The export setting causes all just variables |
| 4 | +# to be exported as environment variables. |
| 5 | + |
| 6 | +set export := true |
| 7 | + |
| 8 | +JUST_FILE_PATH := justfile() |
| 9 | +NU_DIR := parent_directory(`$nu.current-exe`) |
| 10 | +[private] |
| 11 | +_inc_plugin := if os_family() == 'windows' { 'nu_plugin_inc.exe' } else { 'nu_plugin_inc' } |
| 12 | + |
| 13 | +# Just commands aliases |
| 14 | +# alias d := dev |
| 15 | +# alias b := build |
| 16 | + |
| 17 | +alias t := test |
| 18 | + |
| 19 | +# 默认显示所有可用命令 |
| 20 | +default: |
| 21 | + @just --list --list-prefix "··· " |
| 22 | + |
| 23 | +# 更新 Moonbit 依赖 |
| 24 | +i: __setup |
| 25 | + moon update |
| 26 | + |
| 27 | +# Moonbit 代码全量格式化 |
| 28 | +fmt: __setup |
| 29 | + moon info |
| 30 | + moon fmt |
| 31 | + |
| 32 | +# 代码全量扫描检查 |
| 33 | +lint: |
| 34 | + moon check --target all |
| 35 | + |
| 36 | +# Build: 以生产模式构建应用 |
| 37 | +b: __setup |
| 38 | + moon build --target all |
| 39 | + |
| 40 | +# Bench: 运行性能基准测试 |
| 41 | +bench: |
| 42 | + moon bench -p benchmarks |
| 43 | + |
| 44 | +# 运行测试 |
| 45 | +test: |
| 46 | + moon test --target all |
| 47 | + |
| 48 | +# 清理构建目录 |
| 49 | +clean: |
| 50 | + #!/usr/bin/env nu |
| 51 | + |
| 52 | + moon clean |
| 53 | + print $'(ansi pb)Directories have been cleaned !(ansi reset)' |
| 54 | + |
| 55 | +# 扫描代码中的拼写错误, 需要本机安装 `typos-cli`, 使用:`just typos` or `just typos raw` |
| 56 | +typos output=('table'): |
| 57 | + #!/usr/bin/env nu |
| 58 | + |
| 59 | + $env.config.table.mode = 'light' |
| 60 | + $env.config.color_config.leading_trailing_space_bg = { attr: n } |
| 61 | + let output = '{{ output }}' |
| 62 | + if not ((which typos | length) > 0) { |
| 63 | + print $'(ansi y)[WARN]: (ansi reset)`Typos` not installed, please install it by running `brew install typos-cli`...' |
| 64 | + exit 2 |
| 65 | + } |
| 66 | + if $output != 'table' { typos .; exit 0 } |
| 67 | + typos . --format brief |
| 68 | + | lines |
| 69 | + | split column : |
| 70 | + | rename file line column correction |
| 71 | + | sort-by correction |
| 72 | + | update line {|l| $'(ansi pb)($l.line)(ansi reset)' } |
| 73 | + | update column {|l| $'(ansi pb)($l.column)(ansi reset)' } |
| 74 | + | upsert author {|l| |
| 75 | + let line = ($l.line | ansi strip) |
| 76 | + git blame $l.file -L $'($line),($line)' --porcelain | lines | get 1 | str replace 'author ' '' |
| 77 | + } |
| 78 | + | move author --before correction |
| 79 | + |
| 80 | +# 检查过期依赖: `just outdated` 检查所有 Node 依赖, `just outdated mbt` 检查 MoonBit 依赖 |
| 81 | +outdated: |
| 82 | + #!/usr/bin/env nu |
| 83 | + |
| 84 | + cd ($env.JUST_FILE_PATH | path dirname) |
| 85 | + moon update |
| 86 | + let diff = (git diff moon.mod.json) |
| 87 | + if ($diff | is-empty) { |
| 88 | + print $'(ansi g)All MoonBit dependencies are up to date!(ansi reset)' |
| 89 | + } else { |
| 90 | + print $'(ansi y)MoonBit dependency updates available:(ansi reset)' |
| 91 | + print $diff |
| 92 | + } |
| 93 | + |
| 94 | +__setup: |
| 95 | + #!/usr/bin/env nu |
| 96 | + let version = moon version | lines | first |
| 97 | + print $'Current moon Version: (ansi g)($version)(ansi reset)' |
| 98 | + print $'(ansi p)------------------------------------->(ansi reset)(char nl)' |
| 99 | + |
| 100 | +# 从 Nu v0.61.0 开始插件只需注册一次即可 |
| 101 | +_register_plugins: |
| 102 | + #!/usr/bin/env nu |
| 103 | + let incExists = not (scope commands | where name == 'inc' | is-empty) |
| 104 | + if not $incExists { plugin add {{ join(NU_DIR, _inc_plugin) }} } |
| 105 | + |
0 commit comments