Skip to content

Commit

Permalink
feat: deno install in Rust (denoland/deno#3806)
Browse files Browse the repository at this point in the history
//installer couldn't be removed due to bug, but it's now deprecated.
  • Loading branch information
bartlomieju authored and caspervonb committed Jan 24, 2021
1 parent 6458cea commit 9d87efc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 105 deletions.
8 changes: 4 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ deno https://deno.land/std/examples/echo_server.ts --allow-net
Or

```shell
deno install echo_server https://deno.land/std/examples/echo_server.ts --allow-net
deno install --allow-net echo_server https://deno.land/std/examples/echo_server.ts
```

### cat - print file to standard output

```shell
deno install deno_cat https://deno.land/std/examples/cat.ts --allow-read
deno install --allow-read deno_cat https://deno.land/std/examples/cat.ts
deno_cat file.txt
```

Expand All @@ -31,7 +31,7 @@ deno_cat file.txt
A very useful command by Soheil Rashidi ported to Deno.

```shell
deno install catj https://deno.land/std/examples/catj.ts --allow-read
deno install --allow-read catj https://deno.land/std/examples/catj.ts
catj example.json
catj file1.json file2.json
echo example.json | catj -
Expand All @@ -47,7 +47,7 @@ deno --allow-net=deno.land https://deno.land/std/examples/curl.ts -- https://den

```
export GIST_TOKEN=ABC # Generate at https://github.com/settings/tokens
deno install gist https://deno.land/std/examples/gist.ts --allow-net --allow-env
deno install --allow-net --allow-env gist https://deno.land/std/examples/gist.ts
gist --title "Example gist 1" script.ts
gist --t "Example gist 2" script2.ts
```
2 changes: 1 addition & 1 deletion examples/catj.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

// Install using `deno install`
// $ deno install catj https://deno.land/std/examples/catj.ts --allow-read
// $ deno install --allow-read catj https://deno.land/std/examples/catj.ts

/* eslint-disable @typescript-eslint/no-use-before-define */
import { parse } from "../flags/mod.ts";
Expand Down
2 changes: 1 addition & 1 deletion http/file_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (serverArgs.h || serverArgs.help) {
Serves a local directory in HTTP.
INSTALL:
deno install file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read
deno install --allow-net --allow-read file_server https://deno.land/std/http/file_server.ts
USAGE:
file_server [path] [options]
Expand Down
90 changes: 1 addition & 89 deletions installer/README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1 @@
# deno_installer

Install remote or local script as executables.

## Installation

`installer` can be installed using itself:

```sh
deno -A https://deno.land/std/installer/mod.ts deno_installer https://deno.land/std/installer/mod.ts -A
```

## Usage

Install script

```sh
# remote script
$ deno_installer file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read
> [1/1] Compiling https://deno.land/std/http/file_server.ts
>
> ✅ Successfully installed file_server.
> ~/.deno/bin/file_server

# local script
$ deno_installer file_server ./deno_std/http/file_server.ts --allow-net --allow-read
> [1/1] Compiling file:///dev/deno_std/http/file_server.ts
>
> ✅ Successfully installed file_server.
> ~/.deno/bin/file_server
```

Run installed script:

```sh
$ file_server
HTTP server listening on http://0.0.0.0:4500/
```

## Custom installation directory

By default installer uses `~/.deno/bin` to store installed scripts so make sure
it's in your `$PATH`.

```
echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc # change this to your shell
```

If you prefer to change installation directory use `-d` or `--dir` flag.

```
$ deno_installer --dir /usr/local/bin file_server ./deno_std/http/file_server.ts --allow-net --allow-read
> [1/1] Compiling file:///dev/deno_std/http/file_server.ts
>
> ✅ Successfully installed file_server.
> /usr/local/bin/file_server
```

## Update installed script

```sh
$ deno_installer file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read
> ⚠️ file_server is already installed, do you want to overwrite it? [yN]
> y
>
> [1/1] Compiling file:///dev/deno_std/http/file_server.ts
>
> ✅ Successfully installed file_server.
```

Show help

```sh
$ deno_installer --help
> deno installer
Install remote or local script as executables.

USAGE:
deno -A https://deno.land/std/installer/mod.ts [OPTIONS] EXE_NAME SCRIPT_URL [FLAGS...]

ARGS:
EXE_NAME Name for executable
SCRIPT_URL Local or remote URL of script to install
[FLAGS...] List of flags for script, both Deno permission and script specific
flag can be used.

OPTIONS:
-d, --dir <PATH> Installation directory path (defaults to ~/.deno/bin)
```
WARNING: This code is deprecated and std/installer will be removed soon.
20 changes: 10 additions & 10 deletions manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ await Deno.remove("request.log");
This one serves a local directory in HTTP.

```bash
deno install file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read
deno install --allow-net --allow-read file_server https://deno.land/std/http/file_server.ts
```

Run it:
Expand Down Expand Up @@ -821,24 +821,25 @@ Or you could import it into another ES module to consume:
Deno provides ability to easily install and distribute executable code via
`deno install` command.

`deno install [EXE_NAME] [URL] [FLAGS...]` will install script available at
`URL` with name `EXE_NAME`.
`deno install [FLAGS...] [EXE_NAME] [URL] [SCRIPT_ARGS...]` will install script
available at `URL` with name `EXE_NAME`.

This command is a thin wrapper that creates executable shell scripts which
invoke `deno` with specified permissions and CLI flags.

Example:

```shell
$ deno install file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read
$ deno install --allow-net --allow-read file_server https://deno.land/std/http/file_server.ts
[1/1] Compiling https://deno.land/std/http/file_server.ts

✅ Successfully installed file_server.
/Users/deno/.deno/bin/file_server
```

By default scripts are installed at `$HOME/.deno/bin` and that directory must be
added to the path manually.
By default scripts are installed at `$HOME/.deno/bin` or
`$USERPROFILE/.deno/bin` and one of that directories must be added to the path
manually.

```shell
$ echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc
Expand All @@ -847,17 +848,16 @@ $ echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc
Installation directory can be changed using `-d/--dir` flag:

```shell
$ deno install --dir /usr/local/bin file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read
$ deno install --allow-net --allow-read --dir /usr/local/bin file_server https://deno.land/std/http/file_server.ts
```

When installing a script you can specify permissions that will be used to run
the script. They are placed after the script URL and can be mixed with any
additional CLI flags you want to pass to the script.
the script.

Example:

```shell
$ deno install file_server https://deno.land/std/http/file_server.ts --allow-net --allow-read 8080
$ deno install --allow-net --allow-read file_server https://deno.land/std/http/file_server.ts 8080
```

Above command creates an executable called `file_server` that runs with write
Expand Down

0 comments on commit 9d87efc

Please sign in to comment.