chore: add scripts to register plugins in nushell

This commit is contained in:
Jesús Pérez 2025-09-20 20:13:14 +01:00
parent cf594da20b
commit 187a69575c
6 changed files with 394 additions and 6 deletions

View File

@ -7,8 +7,14 @@ alias h := help
# Build alias for quick compilation
alias b := build
# install plugins locally
alias i := install-local
# Build alias to collect targets
alias c := collect
# Verify plugins
alias v := verify-plugins
# Status alias for quick status check
alias s := status

View File

@ -24,7 +24,9 @@ help AREA="":
echo " just h <area> - Short alias for help"
echo " just b - Build all plugins (alias for build)"
echo " just c - Collect all plugins targets (alias for collect)"
echo " just i - Install plugin (alias for install)"
echo " just s - Show plugin status (alias for status)"
echo " just v - Verify plugins (alias for verify-plugins)"
echo " just validate-nushell - Check version consistency (START HERE)"
echo " just dev-flow - Complete development workflow"
echo ""

View File

@ -41,12 +41,75 @@ make-plugin PLUGIN_NAME:
@echo "🆕 Creating new plugin: {{PLUGIN_NAME}}"
@{{justfile_directory()}}/scripts/run.sh make_plugin.nu {{PLUGIN_NAME}}
# Install specific plugin locally
# Install specific plugin locally (build + register)
[no-cd]
install-plugin PLUGIN:
@echo "📥 Installing {{PLUGIN}} locally..."
@cd {{PLUGIN}} && cargo build --release
@echo "To add to nushell: plugin add ./{{PLUGIN}}/target/release/{{PLUGIN}}"
@{{justfile_directory()}}/scripts/run.sh install_plugin.nu {{PLUGIN}} --verify
# Register specific plugin with nushell
[no-cd]
register-plugin PLUGIN:
@{{justfile_directory()}}/scripts/run.sh register_plugins.nu register ./{{PLUGIN}}/target/release/{{PLUGIN}} --verify
# Register all built plugins with nushell
[no-cd]
register-all-plugins:
@{{justfile_directory()}}/scripts/run.sh register_plugins.nu register-all --verify
# Verify plugin registration status
[no-cd]
verify-plugins:
@{{justfile_directory()}}/scripts/run.sh register_plugins.nu verify
# Install plugins locally from distribution
[no-cd]
install-local:
#!/usr/bin/env bash
if [ ! -d "distribution" ]; then
echo "❌ Distribution directory not found"
echo "💡 Run 'just collect' first to create distribution"
exit 1
fi
if [ ! -f "distribution/install_nu_plugins.nu" ]; then
echo "❌ Installation script not found in distribution"
echo "💡 Run 'just collect' to regenerate distribution"
exit 1
fi
echo "📦 Installing plugins locally from distribution..."
echo "💡 Using register-only mode (no sudo required)"
cd distribution && nu install_nu_plugins.nu --register-only --verify
echo ""
echo "✅ Local installation completed!"
echo "💡 Plugins are now registered with nushell from current location"
echo " Run 'plugin list' in nushell to see installed plugins"
# Install plugins to system from distribution (requires sudo)
[no-cd]
install-system:
#!/usr/bin/env bash
if [ ! -d "distribution" ]; then
echo "❌ Distribution directory not found"
echo "💡 Run 'just collect' first to create distribution"
exit 1
fi
if [ ! -f "distribution/install_nu_plugins.nu" ]; then
echo "❌ Installation script not found in distribution"
echo "💡 Run 'just collect' to regenerate distribution"
exit 1
fi
echo "📦 Installing plugins to system from distribution..."
echo "💡 This will copy binaries to /usr/local/bin (requires sudo)"
cd distribution && nu install_nu_plugins.nu --verify
echo ""
echo "✅ System installation completed!"
echo "💡 Plugins are installed in /usr/local/bin and registered with nushell"
echo " Run 'plugin list' in nushell to see installed plugins"
# Remove plugin from workspace
[no-cd]
@ -338,7 +401,12 @@ tools-help:
@echo ""
@echo "PLUGIN MANAGEMENT:"
@echo " make-plugin NAME - Create new plugin from template"
@echo " install-plugin PLUGIN - Install plugin locally"
@echo " install-plugin PLUGIN - Build and register plugin (alias: i)"
@echo " register-plugin PLUGIN - Register plugin with nushell"
@echo " register-all-plugins - Register all built plugins with nushell"
@echo " verify-plugins - Verify plugin registration status"
@echo " install-local - Install plugins from distribution locally (no sudo)"
@echo " install-system - Install plugins to system from distribution (sudo)"
@echo " remove-plugin PLUGIN - Remove plugin from workspace"
@echo " list-plugins - List all plugins"
@echo " plugin-info PLUGIN - Show plugin information"

View File

@ -18,5 +18,5 @@ sysinfo = "0.37"
[dependencies.nu-protocol]
features = ["plugin"]
version = "0.107.0"
version = "0.107.1"
path = "../nushell/crates/nu-protocol"

98
scripts/install_plugin.nu Normal file
View File

@ -0,0 +1,98 @@
#!/usr/bin/env nu
# Plugin Installation Script
# Builds and registers nushell plugins
# Build and register a single plugin
def install_single_plugin [
plugin_name: string
--verify (-v) # Verify registration after installation
] {
print $"📥 Installing ($plugin_name) locally..."
# Check if plugin directory exists
if not ($plugin_name | path exists) {
print $"❌ Plugin directory not found: ($plugin_name)"
return {success: false, error: "directory_not_found"}
}
# Build the plugin
print $"🔨 Building ($plugin_name)..."
try {
nu -c $"cd ($plugin_name); cargo build --release"
} catch {|err|
print $"❌ Build failed for ($plugin_name): ($err.msg)"
return {success: false, error: "build_failed"}
}
# Check if binary was created
let binary_path = $"($plugin_name)/target/release/($plugin_name)"
if not ($binary_path | path exists) {
print $"❌ Plugin binary not found after build: ($binary_path)"
return {success: false, error: "binary_not_found"}
}
# Register the plugin using our registration script
print "🔌 Registering with nushell..."
if $verify {
let register_result = (nu $"./scripts/register_plugins.nu" register $binary_path --verify)
} else {
let register_result = (nu $"./scripts/register_plugins.nu" register $binary_path)
}
print $"✅ ($plugin_name) installation completed"
return {success: true, binary_path: $binary_path}
}
# Main command interface
def main [
plugin_name?: string # Plugin name to install
--verify (-v) # Verify registration after installation
--all (-a) # Install all plugins
] {
if $all {
print "📥 Installing all plugins..."
let plugin_dirs = (glob "nu_plugin_*" | where ($it | path type) == "dir")
if ($plugin_dirs | is-empty) {
print "❓ No plugin directories found"
return
}
mut installed = 0
mut failed = 0
for plugin in $plugin_dirs {
let result = (install_single_plugin $plugin --verify=$verify)
if $result.success {
$installed = $installed + 1
} else {
$failed = $failed + 1
}
}
print ""
print "📊 Installation summary:"
print $" ✅ Installed: ($installed) plugins"
if $failed > 0 {
print $" ❌ Failed: ($failed) plugins"
}
} else if not ($plugin_name | is-empty) {
install_single_plugin $plugin_name --verify=$verify
} else {
print "🔧 Plugin Installation Script"
print "============================="
print ""
print "Usage:"
print " nu install_plugin.nu <plugin_name> [--verify]"
print " nu install_plugin.nu --all [--verify]"
print ""
print "Options:"
print " --verify (-v) - Verify registration after installation"
print " --all (-a) - Install all plugins"
print ""
print "Examples:"
print " nu install_plugin.nu nu_plugin_clipboard --verify"
print " nu install_plugin.nu --all --verify"
}
}

214
scripts/register_plugins.nu Normal file
View File

@ -0,0 +1,214 @@
#!/usr/bin/env nu
# Plugin Registration Script with Verification
# Handles registration of nushell plugins with automatic verification
# Register a single plugin
def register_single_plugin [
plugin_path: string
--verify (-v) # Verify registration after plugin add
] {
let plugin_name = ($plugin_path | path basename)
let display_name = ($plugin_name | str replace "nu_plugin_" "")
print $"🔌 Registering ($plugin_name)..."
if not ($plugin_path | path exists) {
print $"❌ Plugin binary not found: ($plugin_path)"
return {success: false, error: "binary_not_found"}
}
# Register the plugin
try {
nu -c $"plugin add ($plugin_path)"
print $" ✅ Registered ($plugin_name)"
# Verify if requested
if $verify {
print $" 🔍 Verifying registration..."
let found = (nu -c $"plugin list | where name =~ ($display_name) | length" | into int)
if $found > 0 {
print $" ✅ Verified ($plugin_name)"
return {success: true, verified: true}
} else {
print $" ⚠️ Could not verify ($plugin_name)"
return {success: true, verified: false}
}
} else {
return {success: true, verified: null}
}
} catch {|err|
print $" ❌ Failed to register ($plugin_name): ($err.msg)"
return {success: false, error: $err.msg}
}
}
# Register multiple plugins
def register_multiple_plugins [
plugin_paths: list<string>
--verify (-v) # Verify registration after each plugin add
] {
mut results = []
mut registered = 0
mut failed = 0
mut verified = 0
for plugin_path in $plugin_paths {
let result = (register_single_plugin $plugin_path --verify=$verify)
$results = ($results | append $result)
if $result.success {
$registered = $registered + 1
if $verify and $result.verified {
$verified = $verified + 1
}
} else {
$failed = $failed + 1
}
}
print ""
print "📊 Registration summary:"
print $" ✅ Registered: ($registered) plugins"
if $verify {
print $" 🔍 Verified: ($verified) plugins"
}
if $failed > 0 {
print $" ❌ Failed: ($failed) plugins"
}
{
total: ($plugin_paths | length),
registered: $registered,
failed: $failed,
verified: $verified,
results: $results
}
}
# Verify plugin registration status
def verify_plugin_registration [
plugin_paths: list<string>
] {
print "🔍 Verifying plugin registration status..."
print ""
mut registered_plugins = 0
mut total_plugins = ($plugin_paths | length)
for plugin_path in $plugin_paths {
let plugin_name = ($plugin_path | path basename)
let display_name = ($plugin_name | str replace "nu_plugin_" "")
if ($plugin_path | path exists) {
let found = (nu -c $"plugin list | where name =~ ($display_name) | length" | into int)
if $found > 0 {
print $" ✅ ($plugin_name) \(registered\)"
$registered_plugins = $registered_plugins + 1
} else {
print $" ❌ ($plugin_name) \(not registered\)"
print $" 💡 Register with: nu register_plugins.nu register ($plugin_path)"
}
} else {
print $" ⚠️ ($plugin_name) \(binary not found\)"
}
}
print ""
print "📊 Verification summary:"
print $" 📦 Total plugins: ($total_plugins)"
print $" ✅ Registered: ($registered_plugins)"
print $" ❌ Not registered: ($total_plugins - $registered_plugins)"
if $registered_plugins == $total_plugins and $total_plugins > 0 {
print ""
print "🎉 All plugins are properly registered!"
} else if $total_plugins == 0 {
print ""
print "💡 No plugins found."
} else {
print ""
print "💡 Some plugins need registration"
}
{
total: $total_plugins,
registered: $registered_plugins,
missing: ($total_plugins - $registered_plugins)
}
}
# Find all built plugins in the workspace
def find_built_plugins [] {
glob "nu_plugin_*/target/release/nu_plugin_*"
| where ($it | path type) == "file"
| where not ($it | str ends-with ".d")
}
# Main command interface
def main [
command?: string # Command: register, verify, register-all
plugin_path?: string # Plugin path for single registration
--verify (-v) # Verify registration
--paths (-p): list<string> = [] # Multiple plugin paths
] {
match $command {
"register" => {
if ($plugin_path | is-empty) {
print "❌ Plugin path required for register command"
print "Usage: nu register_plugins.nu register <plugin_path> [--verify]"
return
}
register_single_plugin $plugin_path --verify=$verify
}
"register-multiple" => {
if ($paths | is-empty) {
print "❌ Plugin paths required for register-multiple command"
print "Usage: nu register_plugins.nu register-multiple --paths [path1, path2, ...]"
return
}
register_multiple_plugins $paths --verify=$verify
}
"register-all" => {
let built_plugins = (find_built_plugins)
if ($built_plugins | is-empty) {
print "❓ No built plugins found"
print "💡 Run 'cargo build --release' in plugin directories first"
return
}
print $"🔌 Registering all built plugins... \(found ($built_plugins | length)\)"
register_multiple_plugins $built_plugins --verify=$verify
}
"verify" => {
if not ($plugin_path | is-empty) {
verify_plugin_registration [$plugin_path]
} else if not ($paths | is-empty) {
verify_plugin_registration $paths
} else {
let built_plugins = (find_built_plugins)
verify_plugin_registration $built_plugins
}
}
_ => {
print "🔌 Plugin Registration Script"
print "=============================="
print ""
print "Commands:"
print " register <path> - Register single plugin"
print " register-multiple - Register multiple plugins (use --paths)"
print " register-all - Register all built plugins"
print " verify [path] - Verify plugin registration"
print ""
print "Options:"
print " --verify (-v) - Verify registration after plugin add"
print " --paths (-p) [...] - Specify multiple plugin paths"
print ""
print "Examples:"
print " nu register_plugins.nu register ./nu_plugin_clipboard/target/release/nu_plugin_clipboard --verify"
print " nu register_plugins.nu register-all --verify"
print " nu register_plugins.nu verify"
}
}
}