Coder Social home page Coder Social logo

numtostr / snm Goto Github PK

View Code? Open in Web Editor NEW
107.0 2.0 3.0 315 KB

๐Ÿค Smol and simple node version manager written in rust ๐Ÿฆ€

License: GNU General Public License v3.0

Rust 88.92% Shell 9.63% Makefile 1.45%
rust cargo node nodejs npm version-manager javascript nvm package shell

snm's Introduction

๐Ÿค Smol Node Manager

build crates.io arch-aur

snm

Terminal: kitty | Prompt: starship

โœจ Features

  • It's fast as it is written in Rust.
  • Cross Platfrom (Linux/macOS/Windows)
  • Supports .nvmrc, .node-version and package.json
  • Supports multiple shells
  • Tons of commands and options

๐Ÿš€ Installation

From package managers

  • Using cargo (Linux/macOS/Windows)
cargo install snm
  • Using yay or pamac (Arch Linux)

Why snm is available for Arch? Because I love Arch Linux

# Using `yay`
yay -S snm

# Using `pamac`
pamac build snm

From binaries

Check out the Release page for prebuild binaries for snm, available for different operating systems.

From script (Linux/macOS/Windows)

curl -fsSL https://git.io/JLFnA | bash

Available Params

  • --install-dir : Set a custom directory for binary installation. Defaults to $HOME/.snm
  • --skip-shell : Skip appending shell specific loader to the $SHELL config file.

NOTE: snm uses symlinks underneath to manage aliases. So, If you are using Windows make sure you have enabled Developer Mode or your user has permission to create symlinks. You can read more here


๐Ÿ”ง Setup

  • Bash

Add the following line to your ~/.bashrc

eval "$(snm env bash)"
  • Zsh

Add the following line to your ~/.zshrc

eval "$(snm env zsh)"
  • Fish

Add the following line to your ~/.config/fish/config.fish

snm env fish | source
  • PowerShell

Add the following line to your ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1

snm env pwsh | Out-String | Invoke-Expression

You can find more about the powershell profile here

๐Ÿคž Usage

Global Options/Flags

Options Env Variable Description
--snm-dir SNM_DIR Directory where the all files and aliases are saved
--node-dist-mirror SNM_NODE_DIST_MIRROR Nodejs download mirror

Example:

snm [--snm-dir="~/.something/else"] [--node-dist-mirror="https://myrelease.com"]
Flags Description
--no-use Only download the release
--version Prints the version
--help Prints the help doc

Commands

  • snm install <version|alias> : Install Nodejs with the provided version or lts codename
# Following command will downloads and installs the most recent 14.x.x release
snm install 14

# Following command will download the most recent lts/fermium release
snm install lts/fermium
# or snm install lts-fermium
# or snm i lts-fermium
  • snm uninstall [version|alias] : Removes the installed Nodejs

If given an alias like ten or lts-fermium then it will remove the version which the alias is pointing at and all the aliases which are pointing to the same version. Also, uninstalling a version will throw an error, if multiple installation is found in the same semver range or if the provided version/alias is active, add --force flag to override this behavior.

# Following command will remove 14.x.x installation
snm uninstall 14

# Following command will remove the lts/fermium release
snm uninstall lts/fermium
# or snm uninstall lts-fermium
# or snm rm lts-fermium

# Add --force flag to forcefully remove the active version
snm uninstall --force 16
  • snm use [version] : Change Nodejs version, Supports .nvmrc and .node-version
# Following command will use a downloaded version matching 10.x.x
snm use 10

# Searches for `.nvmrc` or `.node-version`, if <version> is not provided
snm use
  • snm lts : Installs the recent lts release

  • snm latest : Installs the recent current release

  • snm ls : List all the local downloaded versions with their aliases

  • snm ls-remote [version] : List remote Node.js versions

# Following command list 20 results with version matching 14.x.x
snm ls-remote 14

# This will show all the results
snm ls-remote 14 --all

# Following command will show 25 results
snm ls-remote 14 --count 25
  • snm alias <version> <name> : Alias a version to a common name
# Following command will alias the version 10 to ten
# 10 can refer to any semver release ie 10.15.0
snm alias 10 ten
  • snm unalias [name] : Removes aliases
# Following command will removes alias `ten`
snm unalias ten

# Removes all the aliases
snm unalias --all
  • snm exec <version> : Executes a command within snm context with the modified PATH
# Following command will output the Nodejs version
snm exec 10 -- node -v

# Following command will run yarn with Nodejs v10.x.x
snm exec 10 -- yarn start
  • snm purge : Remove all the installed versions and aliases. Except the active version.
# Doesn't remove the active version
snm purge

# Will remove everything including the active version
snm purge --all
  • snm which <version> : Prints path for the downloaded Nodejs version

  • snm help <subcommand> or snm <subcommand> --help : Help doc for the subcommand

NOTE: This is a small part of help doc. Please make sure to read the inbuilt help

Completions

snm binary has inbuilt completions supports. Please follow the instruction to generate completions according to your shell.

  • For Zsh
snm completions zsh
  • For Bash
snm completions bash
  • For Fish
snm completions fish
  • For PowerShell
snm completions pwsh

After generating the completions, please follow your shell instructions on how to load and use them.

๐Ÿค Contributing

PRs are always welcome. You can help me by adding more tests :).

First, You need to install rust toolchain via rustup.

Minimum Supported Rust Version (MSRV): 1.54.0

  • Setup
git clone https://github.com/numtostr/snm

cd ./snm
  • Build
# For debug build
cargo build


# For release build
cargo build --release
  • Running
# Same as running `snm --help`
cargo run -- --help

# Same as running `snm lsr 14`
cargo run -- lsr 14

๐Ÿ’ Credits

This project would not be possible without these awesome projects.

  • n for cli design
  • fnm for giving me a base project and some code :)

snm's People

Contributors

dependabot[bot] avatar mateossh avatar numtostr avatar scottlnorvell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

snm's Issues

Tests

Write some damn tests.

lts/* pattern in `snm unalias`

Currently snm unalias <name> only works when name is an exact match to an alias.

snm alias lts-carbon // works
snm alias lts/carbon // doesn't work

No support proxy

i am behine the proxy, when i set system proxy with cli, and try to fetch node via snm, it throws connection timeout issue.

Interactivity?

Maybe add some interactive version selection and installations.

snm exec refuse more than 1 argument

Reproduce

Make a sh script, run.sh for example. And make it executable.

#!/bin/sh
printf "%s %s" "$1" "$2"

snm exec 10 -- ./run.sh 1 2 would fails with:

error: Found argument '2' which wasn't expected, or isn't valid in this context

If you tried to supply `2` as a PATTERN use `-- 2`

USAGE:
    snm exec [FLAGS] [OPTIONS] <version> <binary> [args]

For more information try --help

Why would I need this?

snm exec 10 -- npm run dev

Bubble up the errors

Currently, errors are not properly bubbled up to the main. I want to catch all the errors in the main, where I want to print the error to stderr.

Add `tj/n` style version help in `snm --help`

Example:

Versions:

  Numeric version numbers can be complete or incomplete, with an optional leading 'v'.
  Versions can also be specified by label, or codename,
  and other downloadable releases by <remote-folder>/<version>

    4.9.1, 8, v6.1    Numeric versions
    lts               Newest Long Term Support official release
    latest, current   Newest official release
    auto              Read version from file: .n-node-version, .node-version, .nvmrc, or package.json
    engine            Read version from package.json
    boron, carbon     Codenames for release streams
    lts_latest        node support aliases

    and nightly, rc/10 et al

Publish to Homebrew

Would it be possible to publish to Homebrew for easy installation on MacOS?

Allow alias and lts* in `snm uninstall`

If semver, first find all the aliases pointing to that semver, then delete all the matches. After that, delete the semver installation.

If alias/lts*, find the semver which the alias/lts* is pointing to, then delete the semver. After that delete the alias.

Note: lts* is also an alias.

snm unalias

snm unalias <name>

and make rma alias for unalias

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.