Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install gm version through custom package #191

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkgs/nu-git-manager/build.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use std log

def main [package_file: path] {
let pkg_root = $package_file | path dirname
let pkg = open $package_file

let module_dir = $env.NUPM_HOME | path join "modules"
log info "ensuring Nupm's module directory exists"
log debug $"making directory `($module_dir)`"
mkdir $module_dir

log info "cleaning previous installation"
log debug $"removing directory `($module_dir | path join $pkg.name)`"
rm --recursive --force ($module_dir | path join $pkg.name)

log info "installing package"
log debug $"copying `($pkg_root | path join $pkg.name)` to `($module_dir)`"
cp -r ($pkg_root | path join $pkg.name) $module_dir

log info "preparing `gm version` command"
let n = ^git -C $pkg_root describe | parse "{v}-{n}-{r}" | into record | get n? | default 0
let version_cmd = [
"# see the version of NGM that is currently installed",
"#",
"# # Examples",
"# ```nushell",
"# # get the version of NGM",
"# gm version",
"# ```",
"export def \"gm version\" []: nothing -> record<version: string, branch: string, commit: string, date: datetime> {",
" {",
$" version: \"($pkg.version)+($n)\",",
$" branch: \"(^git -C $pkg_root branch --show-current)\",",
$" commit: \"(^git -C $pkg_root rev-parse HEAD)\",",
$" date: \((date now | to nuon)\),",
" }",
"}",
]

let mod = $env.NUPM_HOME | path join "modules" $pkg.name "mod.nu"
log info $"dumping `gm version` to `($mod)`"
"\n" | save --append $mod
$version_cmd | str join "\n" | save --append $mod
}

2 changes: 1 addition & 1 deletion pkgs/nu-git-manager/nupm.nuon
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
nushell: 0.91.0
git: 2.40.1
}
type: "module"
type: "custom"
}

24 changes: 0 additions & 24 deletions toolkit.nu
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,6 @@ export def "install" []: nothing -> nothing {
null
"

let mod = $env.NUPM_HOME | path join "modules" "nu-git-manager" "mod.nu"
let v = (open pkgs/nu-git-manager/nupm.nuon).version
let n = ^git describe | parse "{v}-{n}-{r}" | into record | get n? | default 0
let version_cmd = [
"# see the version of NGM that is currently installed",
"#",
"# # Examples",
"# ```nushell",
"# # get the version of NGM",
"# gm version",
"# ```",
"export def \"gm version\" []: nothing -> record<version: string, branch: string, commit: string, date: datetime> {",
" {",
$" version: \"($v)+($n)\",",
$" branch: \"(^git branch --show-current)\",",
$" commit: \"(^git rev-parse HEAD)\",",
$" date: \((date now | to nuon)\),",
" }",
"}",
]

"\n" | save --append $mod
$version_cmd | str join "\n" | save --append $mod

null
}

Expand Down
Loading