243 lines
7.6 KiB
Plaintext
243 lines
7.6 KiB
Plaintext
![]() |
#!/usr/bin/env nu
|
||
|
|
||
|
# Collect Install Script
|
||
|
# Collects built plugins and prepares them for installation/distribution
|
||
|
|
||
|
# Load environment variables from env file
|
||
|
def load_env_vars [] {
|
||
|
let env_file = "env"
|
||
|
if ($env_file | path exists) {
|
||
|
let content = open $env_file | lines
|
||
|
| where ($it | str trim | str length) > 0
|
||
|
| where not ($it | str starts-with "#")
|
||
|
| each {|line|
|
||
|
if ($line | str contains "=") {
|
||
|
let parts = $line | split column "=" key value
|
||
|
let key = $parts | get 0 | str replace "export " "" | str trim
|
||
|
let value = $parts | get 1 | str trim
|
||
|
{$key: $value}
|
||
|
} else {
|
||
|
{}
|
||
|
}
|
||
|
}
|
||
|
| reduce -f {} {|item, acc| $acc | merge $item}
|
||
|
|
||
|
$content
|
||
|
} else {
|
||
|
{
|
||
|
TARGET_PATH: "distribution",
|
||
|
INSTALL_BIN_PATH: "/usr/local/bin",
|
||
|
ARCHIVE_DIR_PATH: "/tmp",
|
||
|
BIN_ARCHIVES_DIR_PATH: "bin_archives"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Get all built plugin binaries
|
||
|
def get_built_plugins [] {
|
||
|
glob "nu_plugin_*/target/release/nu_plugin_*"
|
||
|
| where ($it | path type) == "file"
|
||
|
| where ($it | path exists)
|
||
|
| each {|path|
|
||
|
let plugin_name = $path | path basename
|
||
|
let plugin_dir = $path | path dirname | path dirname | path dirname
|
||
|
{
|
||
|
name: $plugin_name,
|
||
|
path: $path,
|
||
|
source_dir: $plugin_dir,
|
||
|
size: (ls $path | get 0.size)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Create target directory structure
|
||
|
def create_target_structure [target_path: string] {
|
||
|
if not ($target_path | path exists) {
|
||
|
mkdir $target_path
|
||
|
print $"📁 Created target directory: ($target_path)"
|
||
|
}
|
||
|
|
||
|
# Create subdirectories if needed
|
||
|
let subdirs = ["scripts", "docs"]
|
||
|
for subdir in $subdirs {
|
||
|
let subdir_path = $"($target_path)/($subdir)"
|
||
|
if not ($subdir_path | path exists) {
|
||
|
mkdir $subdir_path
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Copy plugin binaries to target
|
||
|
def copy_plugins [plugins: list, target_path: string] {
|
||
|
print $"📦 Copying ($plugins | length) plugin binaries..."
|
||
|
|
||
|
for plugin in $plugins {
|
||
|
let dest_path = $"($target_path)/($plugin.name)"
|
||
|
cp $plugin.path $dest_path
|
||
|
|
||
|
# Make executable
|
||
|
chmod +x $dest_path
|
||
|
|
||
|
print $" ✅ ($plugin.name) (($plugin.size))"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Copy additional files
|
||
|
def copy_additional_files [target_path: string] {
|
||
|
let files_to_copy = [
|
||
|
{src: "LICENSE", dest: "LICENSE", required: false},
|
||
|
{src: "README.md", dest: "README", required: false},
|
||
|
{src: "env", dest: "env", required: false}
|
||
|
]
|
||
|
|
||
|
for file in $files_to_copy {
|
||
|
if ($file.src | path exists) {
|
||
|
cp $file.src $"($target_path)/($file.dest)"
|
||
|
print $" 📄 Copied ($file.src) → ($file.dest)"
|
||
|
} else if $file.required {
|
||
|
print $" ⚠️ Required file not found: ($file.src)"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Create installation script
|
||
|
def create_install_script [target_path: string, install_file: string] {
|
||
|
let install_script_content = $"#!/usr/bin/env nu
|
||
|
|
||
|
# Auto-generated installation script for nushell plugins
|
||
|
# Generated at: (date now)
|
||
|
|
||
|
def main [
|
||
|
--bin-path (-b): string = \"/usr/local/bin\" # Installation path
|
||
|
--plugins (-p): list<string> = [] # Specific plugins to install
|
||
|
--list (-l) # List available plugins
|
||
|
--dry-run (-d) # Show what would be done
|
||
|
] {
|
||
|
let available_plugins = ls | where type == file and name =~ \"nu_plugin_\" | get name
|
||
|
|
||
|
if \\$list {
|
||
|
print \"📦 Available plugins:\"
|
||
|
for plugin in \\$available_plugins {
|
||
|
print \\$\" - (\\$plugin)\"
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
let plugins_to_install = if (\\$plugins | length) > 0 {
|
||
|
\\$plugins | where \\$it in \\$available_plugins
|
||
|
} else {
|
||
|
\\$available_plugins
|
||
|
}
|
||
|
|
||
|
if (\\$plugins_to_install | length) == 0 {
|
||
|
print \"❓ No plugins to install\"
|
||
|
return
|
||
|
}
|
||
|
|
||
|
print \\$\"🚀 Installing (\\$plugins_to_install | length) plugins to (\\$bin_path)...\"
|
||
|
|
||
|
for plugin in \\$plugins_to_install {
|
||
|
if \\$dry_run {
|
||
|
print \\$\"Would install: (\\$plugin) → (\\$bin_path)/(\\$plugin)\"
|
||
|
} else {
|
||
|
try {
|
||
|
cp \\$plugin \\$\"(\\$bin_path)/(\\$plugin)\"
|
||
|
chmod +x \\$\"(\\$bin_path)/(\\$plugin)\"
|
||
|
print \\$\" ✅ Installed (\\$plugin)\"
|
||
|
} catch {|err|
|
||
|
print \\$\" ❌ Failed to install (\\$plugin): (\\$err.msg)\"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if not \\$dry_run {
|
||
|
print \"\\n💡 Don't forget to run 'plugin add' for each plugin in nushell!\"
|
||
|
}
|
||
|
}
|
||
|
"
|
||
|
|
||
|
$install_script_content | save $"($target_path)/($install_file)"
|
||
|
chmod +x $"($target_path)/($install_file)"
|
||
|
print $"📜 Created installation script: ($install_file)"
|
||
|
}
|
||
|
|
||
|
# Main function
|
||
|
def main [
|
||
|
--target (-t): string = "" # Override target path
|
||
|
--force (-f) # Force overwrite existing files
|
||
|
--list (-l) # List available plugins only
|
||
|
] {
|
||
|
# Ensure we're in the repository root directory
|
||
|
if not ("nu_plugin_clipboard" | path exists) {
|
||
|
error make {msg: "Please run this script from the nushell-plugins repository root directory"}
|
||
|
}
|
||
|
|
||
|
print "📦 Nushell Plugin Collection & Installation Preparation"
|
||
|
|
||
|
# Load environment variables
|
||
|
let env_vars = load_env_vars
|
||
|
let target_path = if ($target | str length) > 0 { $target } else { $env_vars.TARGET_PATH? | default "distribution" }
|
||
|
let install_file = $env_vars.INSTALL_FILE? | default "install_nu_plugins.nu"
|
||
|
|
||
|
# Get built plugins
|
||
|
let plugins = get_built_plugins
|
||
|
|
||
|
if $list {
|
||
|
if ($plugins | length) == 0 {
|
||
|
print "❓ No built plugins found"
|
||
|
print "💡 Run './scripts/sh/build-all.sh' first to build plugins"
|
||
|
} else {
|
||
|
print $"📦 Found ($plugins | length) built plugins:"
|
||
|
for plugin in $plugins {
|
||
|
print $" ✅ ($plugin.name) (($plugin.size)) from ($plugin.source_dir)"
|
||
|
}
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if ($plugins | length) == 0 {
|
||
|
print "❓ No built plugins found"
|
||
|
print "💡 Run './scripts/sh/build-all.sh' first to build plugins"
|
||
|
exit 1
|
||
|
}
|
||
|
|
||
|
print $"📦 Found ($plugins | length) built plugins to collect"
|
||
|
|
||
|
# Check if target exists and handle accordingly
|
||
|
if ($target_path | path exists) and not $force {
|
||
|
print $"⚠️ Target directory '($target_path)' already exists"
|
||
|
let confirm = input "Continue and overwrite? [y/N]: "
|
||
|
if ($confirm | str downcase) != "y" {
|
||
|
print "❌ Aborted"
|
||
|
exit 1
|
||
|
}
|
||
|
}
|
||
|
|
||
|
# Create target structure
|
||
|
create_target_structure $target_path
|
||
|
|
||
|
# Copy plugins
|
||
|
copy_plugins $plugins $target_path
|
||
|
|
||
|
# Copy additional files
|
||
|
print "📄 Copying additional files..."
|
||
|
copy_additional_files $target_path
|
||
|
|
||
|
# Create installation script
|
||
|
create_install_script $target_path $install_file
|
||
|
|
||
|
# Summary
|
||
|
print $"\n✅ Collection completed!"
|
||
|
print $"📁 Target directory: ($target_path)"
|
||
|
print $"📦 Plugins collected: ($plugins | length)"
|
||
|
print $"🚀 Installation script: ($target_path)/($install_file)"
|
||
|
|
||
|
print "\n💡 Next steps:"
|
||
|
print $" 1. Test installation: cd ($target_path) && nu ($install_file) --dry-run"
|
||
|
print $" 2. Package for distribution: ./scripts/sh/pack-dist.sh"
|
||
|
print $" 3. Install locally: cd ($target_path) && nu ($install_file)"
|
||
|
}
|
||
|
|
||
|
if ($env.NUSHELL_EXECUTION_CONTEXT? | default "" | str contains "run") {
|
||
|
main
|
||
|
}
|