Skip to content

Commit

Permalink
Nsw
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz committed Jan 22, 2019
1 parent 45800d0 commit f9de4c1
Show file tree
Hide file tree
Showing 47 changed files with 1,508 additions and 186 deletions.
9 changes: 9 additions & 0 deletions .ci/create-static-binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

echo "Building binary in docker"

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

echo "Copying to ./nsw-linux"

docker run --rm -v $(pwd):$(pwd) --workdir $(pwd) schlez/nsw-static-binary cp /app/_build/default/executable/NswApp.exe ./nsw-linux
6 changes: 3 additions & 3 deletions .ci/esy-build-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ steps:
- task: NodeTool@0
inputs:
versionSpec: '8.9'
- script: npm install -g esy@0.4.3
displayName: 'npm install -g esy@0.4.3'
- script: npm install -g esy@latest
displayName: 'npm install -g esy@latest'
- script: esy install
displayName: 'esy install'
- script: esy pesy
Expand All @@ -14,7 +14,7 @@ steps:
displayName: 'esy build'
- script: esy test
displayName: 'esy test'
- script: esy x NswApp.exe
- script: esy x nsw.exe
displayName: 'Run the main binary'
- script: esy ls-libs
continueOnError: true
Expand Down
1 change: 1 addition & 0 deletions .ci/prepare-static-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sed -i 's@"flags": \[\]@"flags": ["-ccopt", "-static"]@' package.json
3 changes: 3 additions & 0 deletions .ci/shasum
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
shift 2
sha1sum $@
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_build
_esy
node_modules
Dockerfile
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ _esy/
nsw.install
.DS_Store
*.install
.tmp
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM frolvlad/alpine-glibc

RUN apk add --no-cache nodejs bash npm curl g++ make m4 patch gmp-dev perl git jq
ADD .ci/shasum /usr/bin/shasum

USER root

RUN npm -g config set user root
RUN npm i -g esy@latest

WORKDIR /app
ADD . /app

RUN jq '. | .buildDirs.executable.flags |= . + ["-ccopt", "-static"]' package.json > package.json.new && mv package.json.new package.json
RUN npx esy i
RUN npx esy pesy
RUN npx esy b
RUN npx esy test
61 changes: 37 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
# nsw
<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>
</h1>

> A simple and fast `nvm` replacement, built in native ReasonML.
[![CircleCI](https://circleci.com/gh/yourgithubhandle/nsw/tree/master.svg?style=svg)](https://circleci.com/gh/yourgithubhandle/nsw/tree/master)
:rocket: Single executable :rocket: Blazing fast :rocket:

![Blazing fast](./docs/nvm_comparison.png)

**Contains the following libraries and executables:**
## 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)

```
[email protected]
├─test/
│ name: TestNsw.exe
│ main: TestNsw
│ require: nsw.lib
├─library/
│ library name: nsw.lib
│ namespace: Nsw
│ require:
└─executable/
name: NswApp.exe
main: NswApp
require: nsw.lib
```
## Installation

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

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

## TODO
- [ ] 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: 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:

```
npm install -g esy
git clone <this-repo>
git clone https://github.com/Schniz/nsw.git
esy install
esy build
```
Expand All @@ -39,12 +49,15 @@ esy build
After building the project, you can run the main binary that is produced.

```
esy x NswApp.exe
esy x nsw.exe
```

## Running Tests:

```
# Runs the "test" command in `package.json`.
# Runs some smoke-unity test
esy test
# Runs the feature tests
feature_tests/run.sh
```
41 changes: 28 additions & 13 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ jobs:
steps:
# TODO: Uncomment both this and 'publish-build-cache' below to enable build caching for Linux.
# - template: .ci/restore-build-cache.yml
- template: .ci/esy-build-steps.yml
- script: .ci/create-static-binary.sh
- script: ./feature_tests/run.sh $(pwd)/nsw-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

- job: MacOS
timeoutInMinutes: 0
Expand All @@ -33,29 +41,36 @@ 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
# - template: .ci/publish-build-cache.yml
- task: PublishBuildArtifacts@1
displayName: 'Save artifact'
inputs:
PathtoPublish: '_build/nsw'
ArtifactName: nsw-macos

- job: Windows
timeoutInMinutes: 0
pool:
vmImage: 'vs2017-win2016'
# - job: Windows
# timeoutInMinutes: 0
# pool:
# vmImage: 'vs2017-win2016'

variables:
ESY__CACHE_INSTALL_PATH: C:\Users\VssAdministrator\.esy\3_\i
ESY__CACHE_SOURCE_TARBALL_PATH: C:\Users\VssAdministrator\.esy\source\i
# variables:
# ESY__CACHE_INSTALL_PATH: C:\Users\VssAdministrator\.esy\3_\i
# ESY__CACHE_SOURCE_TARBALL_PATH: C:\Users\VssAdministrator\.esy\source\i

steps:
- template: .ci/restore-build-cache.yml
- template: .ci/esy-build-steps.yml
- template: .ci/publish-build-cache.yml
# steps:
# - template: .ci/restore-build-cache.yml
# - template: .ci/esy-build-steps.yml
# - template: .ci/publish-build-cache.yml

- job: Release
timeoutInMinutes: 0
displayName: Release
dependsOn:
- Linux
- MacOS
- Windows
# - Windows
condition: succeeded()
pool:
vmImage: ubuntu-16.04
Expand Down
Binary file added docs/nvm_comparison.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f9de4c1

Please sign in to comment.