Browse Source

Rename to fnm (#2)

remotes/origin/add-simple-redirecting-site
Gal Schlezinger 6 years ago committed by GitHub
parent
commit
159282532e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      .ci/create-static-binary.sh
  2. 2
      .ci/esy-build-steps.yml
  3. 3
      .gitignore
  4. 42
      README.md
  5. 14
      azure-pipelines.yml
  6. 1
      docs/fnm.svg
  7. BIN
      docs/nsw.gif
  8. 19
      docs/record_screen.sh
  9. 33
      docs/recorded_screen_script.sh
  10. 2
      dune-project
  11. 8
      esy.lock/index.json
  12. 2
      executable/Env.re
  13. 24
      executable/FnmApp.re
  14. 4
      executable/Install.re
  15. 2
      executable/ListInstallations.re
  16. 2
      executable/ListLocal.re
  17. 2
      executable/ListRemote.re
  18. 2
      executable/Use.re
  19. 10
      executable/dune
  20. 10
      feature_tests/basic/run.sh
  21. 2
      feature_tests/nvmrc/.nvmrc
  22. 8
      feature_tests/nvmrc/run.sh
  23. 12
      feature_tests/run.sh
  24. 0
      fnm.opam
  25. 6
      library/Directories.re
  26. 6
      library/dune
  27. 22
      package.json
  28. 0
      test/TestFnm.re
  29. 8
      test/TestFramework.re
  30. 10
      test/dune

6
.ci/create-static-binary.sh

@ -2,8 +2,8 @@ @@ -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
.ci/esy-build-steps.yml

@ -14,7 +14,7 @@ steps: @@ -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

3
.gitignore vendored

@ -6,7 +6,8 @@ node_modules/ @@ -6,7 +6,8 @@ node_modules/
_build
_release
_esy/
nsw.install
fnm.install
.DS_Store
*.install
.tmp
docs/screen_recording

42
README.md

@ -1,58 +1,64 @@ @@ -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

14
azure-pipelines.yml

@ -18,15 +18,15 @@ jobs: @@ -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
@ -41,14 +41,14 @@ jobs: @@ -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

1
docs/fnm.svg

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 32 KiB

BIN
docs/nsw.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

19
docs/record_screen.sh

@ -0,0 +1,19 @@ @@ -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
docs/recorded_screen_script.sh

@ -0,0 +1,33 @@ @@ -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
dune-project

@ -1,2 +1,2 @@ @@ -1,2 +1,2 @@
(lang dune 1.6)
(name nsw)
(name fnm)

8
esy.lock/index.json

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
{
"checksum": "bc7707f147bdaf3b3f87430bb4b3f0cd",
"root": "nsw@link:./package.json",
"root": "fnm@link:./package.json",
"node": {
"refmterr@3.1.10@d41d8cd9": {
"id": "refmterr@3.1.10@d41d8cd9",
@ -47,9 +47,9 @@ @@ -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": [],

2
executable/Env.re

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
open Nsw;
open Fnm;
let run = () => {
Console.log(

24
executable/NswApp.re → executable/FnmApp.re

@ -12,12 +12,22 @@ open Cmdliner; @@ -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 = {
@ -90,10 +100,18 @@ let defaultCmd = { @@ -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
executable/Install.re

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
open Nsw;
open Fnm;
let mkDownloadsDir = () => {
let exists = Lwt_unix.file_exists(Directories.downloads);
@ -98,4 +98,4 @@ let run = (~version) => @@ -98,4 +98,4 @@ let run = (~version) =>
</Pastel>,
)
|> Lwt.return
};
};

2
executable/ListInstallations.re

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
open Nsw;
open Fnm;
let colorizeVersions = (~current, ~versions) => {
let strings =

2
executable/ListLocal.re

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
open Nsw;
open Fnm;
let run = () =>
Versions.Local.(

2
executable/ListRemote.re

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
open Nsw;
open Fnm;
let run = () => {
Console.log("Looking for some node versions upstream...");

2
executable/Use.re

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
open Nsw;
open Fnm;
let lwtIgnore = lwt => Lwt.catch(() => lwt, _ => Lwt.return());

10
executable/dune

@ -1,12 +1,12 @@ @@ -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
feature_tests/basic/run.sh

@ -1,8 +1,10 @@ @@ -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
feature_tests/nvmrc/.nvmrc

@ -1 +1 @@ @@ -1 +1 @@
10.9.0
10.9.0

8
feature_tests/nvmrc/run.sh

@ -1,10 +1,10 @@ @@ -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

12
feature_tests/run.sh

@ -6,27 +6,27 @@ DIRECTORY=`dirname $0` @@ -6,27 +6,27 @@ DIRECTORY=`dirname $0`
BINARY=$1
TEMP_DIR_BASE=$(pwd)/$DIRECTORY/.tmp
TEMP_BINARY_PATH=$TEMP_DIR_BASE/bin
TEMP_NSW_DIR=$TEMP_DIR_BASE/.nsw
TEMP_FNM_DIR=$TEMP_DIR_BASE/.fnm
if [ "$BINARY" == "" ]; then
echo "No binary supplied!"
exit 1
fi
echo "using nvm=$BINARY"
echo "using fnm=$BINARY"
rm -rf $TEMP_DIR_BASE
mkdir $TEMP_DIR_BASE $TEMP_BINARY_PATH
cp $BINARY $TEMP_BINARY_PATH/nsw
cp $BINARY $TEMP_BINARY_PATH/fnm
for test_file in $DIRECTORY/*/run.sh; do
rm -rf $TEMP_NSW_DIR
rm -rf $TEMP_FNM_DIR
echo "Running test in $test_file"
echo "Running test in $test_file" | sed "s/./-/g"
(cd $(dirname $test_file) && NSW_DIR=$TEMP_NSW_DIR PATH=$TEMP_BINARY_PATH:$PATH bash $(basename $test_file))
(cd $(dirname $test_file) && FNM_DIR=$TEMP_FNM_DIR PATH=$TEMP_BINARY_PATH:$PATH bash $(basename $test_file))
echo ""
echo " -> Finished!"
rm -rf $TEMP_NSW_DIR
rm -rf $TEMP_FNM_DIR
done

0
nsw.opam → fnm.opam

6
library/Directories.re

@ -1,13 +1,13 @@ @@ -1,13 +1,13 @@
let sfwRoot =
Opt.(
Sys.getenv_opt("NSW_DIR")
Sys.getenv_opt("FNM_DIR")
or {
let home =
Sys.getenv_opt("HOME")
|> Opt.orThrow("There isn't $HOME environment variable set.");
Filename.concat(home, ".nsw");
Filename.concat(home, ".fnm");
}
);
let nodeVersions = Filename.concat(sfwRoot, "node-versions");
let currentVersion = Filename.concat(sfwRoot, "current");
let downloads = Filename.concat(sfwRoot, "downloads");
let downloads = Filename.concat(sfwRoot, "downloads");

6
library/dune

@ -1,12 +1,12 @@ @@ -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
(library
; The namespace that other packages/libraries will access this library through
(name Nsw)
(name Fnm)
; Other libraries list this name in their package.json 'require' field to use this library.
(public_name nsw.lib)
(public_name fnm.lib)
(libraries str core lwt lwt.unix lambdasoup semver )
(preprocess ( pps lwt_ppx ppx_let )) ; From package.json preprocess field
)

22
package.json

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
{
"name": "nsw",
"name": "fnm",
"version": "0.0.0",
"description": "My Project",
"esy": {
@ -7,33 +7,33 @@ @@ -7,33 +7,33 @@
"buildsInSource": "_build",
"release": {
"releasedBinaries": [
"nsw.exe"
"fnm.exe"
]
}
},
"buildDirs": {
"test": {
"require": ["nsw.lib", "rely.lib"],
"main": "TestNsw",
"name": "TestNsw.exe",
"require": ["fnm.lib", "rely.lib"],
"main": "TestFnm",
"name": "TestFnm.exe",
"ocamloptFlags": ["-linkall", "-g"]
},
"library": {
"preprocess": ["pps", "lwt_ppx", "ppx_let"],
"require": ["str", "core", "lwt", "lwt.unix", "lambdasoup", "semver"],
"name": "nsw.lib",
"namespace": "Nsw"
"name": "fnm.lib",
"namespace": "Fnm"
},
"executable": {
"preprocess": ["pps", "lwt_ppx", "ppx_let"],
"require": ["core", "cmdliner", "lwt", "lwt.unix", "lambdasoup", "console.lib", "pastel.lib", "nsw.lib"],
"main": "NswApp",
"name": "nsw.exe"
"require": ["core", "cmdliner", "lwt", "lwt.unix", "lambdasoup", "console.lib", "pastel.lib", "fnm.lib"],
"main": "FnmApp",
"name": "fnm.exe"
}
},
"scripts": {
"pesy": "bash -c 'env PESY_MODE=update pesy'",
"test": "esy x TestNsw.exe",
"test": "esy x TestFnm.exe",
"fmt": "bash -c 'refmt --in-place {library,executable,test}/*.re'"
},
"dependencies": {

0
test/TestNsw.re → test/TestFnm.re

8
test/TestFramework.re

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
let projectDir = Sys.getcwd();
let tmpDir = Filename.concat(projectDir, ".nswTmp");
let tmpDir = Filename.concat(projectDir, ".fnmTmp");
include Rely.Make({
let config =
@ -15,8 +15,8 @@ include Rely.Make({ @@ -15,8 +15,8 @@ include Rely.Make({
let run = args => {
let arguments =
args |> Array.append([|"./_build/default/executable/NswApp.exe"|]);
let env = Unix.environment() |> Array.append([|"NSW_DIR=" ++ tmpDir|]);
args |> Array.append([|"./_build/default/executable/FnmApp.exe"|]);
let env = Unix.environment() |> Array.append([|"FNM_DIR=" ++ tmpDir|]);
let result =
Lwt_process.pread_chars(~env, ("", arguments)) |> Lwt_stream.to_string;
Lwt_main.run(result);
@ -28,4 +28,4 @@ let clearTmpDir = () => { @@ -28,4 +28,4 @@ let clearTmpDir = () => {
};
let redactSfwRoot =
Str.global_replace(Str.regexp_string(tmpDir), "<sfwRoot>");
Str.global_replace(Str.regexp_string(tmpDir), "<sfwRoot>");

10
test/dune

@ -1,12 +1,12 @@ @@ -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 TestNsw) ; From package.json main field
; The name of the executable (runnable via esy x TestNsw.exe)
(public_name TestNsw.exe) ; From package.json name field
(libraries nsw.lib rely.lib ) ; From package.json require field (array of strings)
(name TestFnm) ; From package.json main field
; The name of the executable (runnable via esy x TestFnm.exe)
(public_name TestFnm.exe) ; From package.json name field
(libraries fnm.lib rely.lib ) ; From package.json require field (array of strings)
(ocamlopt_flags ( -linkall -g )) ; From package.json ocamloptFlags field
)
Loading…
Cancel
Save