Skip to content

Commit

Permalink
Rename to fnm (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz authored Jan 23, 2019
1 parent 7ff0a6a commit 1592825
Show file tree
Hide file tree
Showing 30 changed files with 171 additions and 91 deletions.
6 changes: 3 additions & 3 deletions .ci/create-static-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

echo "Building binary in docker"

docker build . -t schlez/nsw-static-binary
docker build . -t schlez/fnm-static-binary

echo "Copying to ./nsw-linux"
echo "Copying to ./fnm-linux"

docker run --rm -v $(pwd):$(pwd) --workdir $(pwd) schlez/nsw-static-binary cp /app/_build/default/executable/NswApp.exe ./nsw-linux
docker run --rm -v $(pwd):$(pwd) --workdir $(pwd) schlez/fnm-static-binary cp /app/_build/default/executable/FnmApp.exe ./fnm-linux
2 changes: 1 addition & 1 deletion .ci/esy-build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ steps:
displayName: 'esy build'
- script: esy test
displayName: 'esy test'
- script: esy x nsw.exe
- script: esy x fnm.exe
displayName: 'Run the main binary'
- script: esy ls-libs
continueOnError: true
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ node_modules/
_build
_release
_esy/
nsw.install
fnm.install
.DS_Store
*.install
.tmp
docs/screen_recording
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
<h1 align="center">
Node Switcher (<code>nsw</code>) <a href="https://dev.azure.com/galstar0385/nsw/_build/latest?definitionId=1?branchName=master"><img alt="Build Status" src="https://dev.azure.com/galstar0385/nsw/_apis/build/status/Schniz.nsw?branchName=master" /></a>
Fast Node Manager (<code>fnm</code>) <a href="https://dev.azure.com/galstar0385/fnm/_build/latest?definitionId=1?branchName=master"><img alt="Build Status" src="https://dev.azure.com/galstar0385/fnm/_apis/build/status/Schniz.nsw?branchName=master" /></a>
</h1>

> A blazing fast and simple `nvm` replacement, built in native ReasonML. :rocket:
> :rocket: Fast and simple Node.js version manager, built in ReasonML
<div align="center">
<img src="./docs/nsw.gif" alt="Blazing fast!">
<img src="./docs/fnm.svg" alt="Blazing fast!">
</div>

## Features
- Single file, easy installation :sparkles:
- Fast fast fast fast :rocket:
- Install multiple node versions without a hassle! :clap:
- [Project-specific `.nvmrc` file support](./features_tests/nvmrc)
:sparkles: Single file, easy installation

:rocket: Built with speed in mind

:thinking: Works with `.nvmrc` files

## Installation

* Download the [latest release binary](https://github.com/Schniz/nsw/releases) for your system
* Download the [latest release binary](https://github.com/Schniz/fnm/releases) for your system
* Make it available globally on `$PATH`
* Add the following line to your `.bashrc`/`.zshrc` file:

```bash
eval `nsw env`
eval `fnm env`
```

## TODO
## Future Plans
- [ ] Add a simpler way of installing it (`curl | bash`?)
- [ ] Feature: make versions complete the latest: `10` would infer the latest minor and patch versions of node 10. `10.1` would infer the latest patch version of node 10.1
- [ ] Feature: `nsw use --install`, `nsw use --quiet`
- [ ] Feature: `nsw install lts`?
- [ ] Feature: `nsw alias`?
- [ ] Feature: `fnm use --install`, `fnm use --quiet`
- [ ] Feature: `fnm install lts`?
- [ ] Feature: `fnm alias`?
- [ ] Feature: Consider nvm-like per-shell usage with symlinks on `/tmp` directory
- [ ] OSX: Add to homebrew?
- [ ] Windows Support?
- [ ] Linux: Replace `curl` usage with `cohttp`/`ocurl` or something else which is statically-linkable
- [ ] Linux: Replace `tar` with a statically linked library too (for ungzip + untar)

## Developing:
## Contributing

PRs welcome :tada:

### Developing:

```
npm install -g esy
git clone https://github.com/Schniz/nsw.git
git clone https://github.com/Schniz/fnm.git
esy install
esy build
```

## Running Binary:
### Running Binary:

After building the project, you can run the main binary that is produced.

```
esy x nsw.exe
esy x fnm.exe
```

## Running Tests:
### Running Tests:

```
# Runs some smoke-unity test
Expand Down
14 changes: 7 additions & 7 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ jobs:
# TODO: Uncomment both this and 'publish-build-cache' below to enable build caching for Linux.
# - template: .ci/restore-build-cache.yml
- script: .ci/create-static-binary.sh
- script: ./feature_tests/run.sh $(pwd)/nsw-linux
- script: ./feature_tests/run.sh $(pwd)/fnm-linux
# - script: bash .ci/prepare-static-build.sh
# - template: .ci/esy-build-steps.yml
# - template: .ci/publish-build-cache.yml
- task: PublishBuildArtifacts@1
displayName: 'Save artifact'
inputs:
PathtoPublish: 'nsw-linux'
ArtifactName: nsw-linux
PathtoPublish: 'fnm-linux'
ArtifactName: fnm-linux

- job: MacOS
timeoutInMinutes: 0
Expand All @@ -41,14 +41,14 @@ jobs:
# TODO: Uncomment both this and 'publish-build-cache' below to enable build caching for Mac.
# - template: .ci/restore-build-cache.yml
- template: .ci/esy-build-steps.yml
- script: cp _build/default/executable/NswApp.exe _build/nsw
- script: ./feature_tests/run.sh $(pwd)/_build/nsw
- script: cp _build/default/executable/FnmApp.exe _build/fnm
- script: ./feature_tests/run.sh $(pwd)/_build/fnm
# - template: .ci/publish-build-cache.yml
- task: PublishBuildArtifacts@1
displayName: 'Save artifact'
inputs:
PathtoPublish: '_build/nsw'
ArtifactName: nsw-macos
PathtoPublish: '_build/fnm'
ArtifactName: fnm-macos

# - job: Windows
# timeoutInMinutes: 0
Expand Down
1 change: 1 addition & 0 deletions docs/fnm.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/nsw.gif
Binary file not shown.
19 changes: 19 additions & 0 deletions docs/record_screen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

DIRECTORY=`dirname $0`

function setup_binary() {
export TEMP_DIR=$(mktemp -d -t fnm)
cp _build/default/executable/FnmApp.exe $TEMP_DIR/fnm
export PATH=$TEMP_DIR:$PATH
export FNM_DIR=$TEMP_DIR/.fnm
}

setup_binary

RECORDING_PATH=$DIRECTORY/screen_recording

(rm -rf $RECORDING_PATH &> /dev/null || true)

asciinema rec -c $DIRECTORY/recorded_screen_script.sh $RECORDING_PATH
cat $RECORDING_PATH | sed "s@$TEMP_DIR@~@g" | svg-term --window --out $DIRECTORY/fnm.svg --height=17 --width=70
33 changes: 33 additions & 0 deletions docs/recorded_screen_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/zsh

set -e

GAL_PROMPT_PREFIX='\e[34m✡ \e[0m'

function type() {
printf $GAL_PROMPT_PREFIX
echo $* | pv -qL $[10+(-2 + RANDOM%5)]
}

cd ./feature_tests/nvmrc

type 'eval `fnm env`'
eval `fnm env`

type 'fnm --version'
fnm --version

type 'cat .nvmrc'
cat .nvmrc

type 'fnm install'
fnm install

type 'fnm use'
fnm use

type 'node -v'
node -v

sleep 2
echo ""
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(lang dune 1.6)
(name nsw)
(name fnm)
8 changes: 4 additions & 4 deletions esy.lock/index.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"checksum": "bc7707f147bdaf3b3f87430bb4b3f0cd",
"root": "nsw@link:./package.json",
"root": "fnm@link:./package.json",
"node": {
"[email protected]@d41d8cd9": {
"id": "[email protected]@d41d8cd9",
Expand Down Expand Up @@ -47,9 +47,9 @@
"dependencies": [],
"devDependencies": []
},
"nsw@link:./package.json": {
"id": "nsw@link:./package.json",
"name": "nsw",
"fnm@link:./package.json": {
"id": "fnm@link:./package.json",
"name": "fnm",
"version": "link:./package.json",
"source": { "type": "link", "path": ".", "manifest": "package.json" },
"overrides": [],
Expand Down
2 changes: 1 addition & 1 deletion executable/Env.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Nsw;
open Fnm;

let run = () => {
Console.log(
Expand Down
24 changes: 21 additions & 3 deletions executable/NswApp.re → executable/FnmApp.re
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@ open Cmdliner;

let help_secs = [
`S(Manpage.s_common_options),
`S(Manpage.s_environment),
`P("These options are common to all commands."),
`S("MORE HELP"),
`P("Use `$(mname) $(i,COMMAND) --help' for help on a single command."),
`Noblank,
`S(Manpage.s_bugs),
`P("File bug reports at https://github.com/Schniz/nsw"),
`P("File bug reports at https://github.com/Schniz/fnm"),
];

let envs = [
Term.env_info(
~doc=
"The root directory of fnm installations. Defaults to: "
++ Fnm.Directories.sfwRoot,
"FNM_DIR",
),
];

let install = {
Expand Down Expand Up @@ -90,10 +100,18 @@ let defaultCmd = {
let man = help_secs;
(
Term.(ret(const(_ => `Help((`Pager, None))) $ const())),
Term.info("nsw", ~version, ~doc, ~exits=Term.default_exits, ~man, ~sdocs),
Term.info(
"fnm",
~envs,
~version,
~doc,
~exits=Term.default_exits,
~man,
~sdocs,
),
);
};

let _ =
Term.eval_choice(defaultCmd, [install, use, listLocal, listRemote, env])
|> Term.exit;
|> Term.exit;
4 changes: 2 additions & 2 deletions executable/Install.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Nsw;
open Fnm;

let mkDownloadsDir = () => {
let exists = Lwt_unix.file_exists(Directories.downloads);
Expand Down Expand Up @@ -98,4 +98,4 @@ let run = (~version) =>
</Pastel>,
)
|> Lwt.return
};
};
2 changes: 1 addition & 1 deletion executable/ListInstallations.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Nsw;
open Fnm;

let colorizeVersions = (~current, ~versions) => {
let strings =
Expand Down
2 changes: 1 addition & 1 deletion executable/ListLocal.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Nsw;
open Fnm;

let run = () =>
Versions.Local.(
Expand Down
2 changes: 1 addition & 1 deletion executable/ListRemote.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Nsw;
open Fnm;

let run = () => {
Console.log("Looking for some node versions upstream...");
Expand Down
2 changes: 1 addition & 1 deletion executable/Use.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
open Nsw;
open Fnm;

let lwtIgnore = lwt => Lwt.catch(() => lwt, _ => Lwt.return());

Expand Down
10 changes: 5 additions & 5 deletions executable/dune
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

; !!!! This dune file is generated from the package.json file by pesy. If you modify it by hand
; !!!! your changes will be undone! Instead, edit the package.json and then rerun 'esy pesy' at the project root.
; !!!! If you want to stop using pesy and manage this file by hand, change pacakge.json's 'esy.build' command to: refmterr dune build -p nsw
; !!!! If you want to stop using pesy and manage this file by hand, change pacakge.json's 'esy.build' command to: refmterr dune build -p fnm
(executable
; The entrypoint module
(name NswApp) ; From package.json main field
; The name of the executable (runnable via esy x nsw.exe)
(public_name nsw.exe) ; From package.json name field
(libraries core cmdliner lwt lwt.unix lambdasoup console.lib pastel.lib nsw.lib ) ; From package.json require field (array of strings)
(name FnmApp) ; From package.json main field
; The name of the executable (runnable via esy x fnm.exe)
(public_name fnm.exe) ; From package.json name field
(libraries core cmdliner lwt lwt.unix lambdasoup console.lib pastel.lib fnm.lib ) ; From package.json require field (array of strings)
(preprocess ( pps lwt_ppx ppx_let )) ; From package.json preprocess field
)
10 changes: 6 additions & 4 deletions feature_tests/basic/run.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
eval $(nsw env)
nsw install v8.11.3
nsw use v8.11.3
#!/bin/bash

eval $(fnm env)
fnm install v8.11.3
fnm use v8.11.3

if [ "$(node --version)" != "v8.11.3" ]; then
echo "Node version is not v8.11.3!"
exit 1
fi
fi
2 changes: 1 addition & 1 deletion feature_tests/nvmrc/.nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.9.0
10.9.0
8 changes: 4 additions & 4 deletions feature_tests/nvmrc/run.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

eval $(nsw env)
nsw install
nsw use
eval $(fnm env)
fnm install
fnm use

if [ "$(node --version)" != "v10.9.0" ]; then
echo "Node version is not v10.9.0!"
exit 1
fi
fi
Loading

0 comments on commit 1592825

Please sign in to comment.