Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

feat(npm-installer): install current version, not latest #419

Merged
merged 3 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 61 additions & 15 deletions npm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

![Banner](/banner.png)

[![crates.io](https://meritbadge.herokuapp.com/wrangler)](https://crates.io/crates/wrangler)
[![crates.io](https://meritbadge.herokuapp.com/wrangler)](https://crates.io/crates/wrangler)  
[![Build Status](https://dev.azure.com/ashleygwilliams/wrangler/_apis/build/status/cloudflare.wrangler?branchName=master)](https://dev.azure.com/ashleygwilliams/wrangler/_build/latest?definitionId=1&branchName=master)

Get started with Cloudflare Workers and Wrangler by reading the [documentation](https://workers.cloudflare.com/).
`wrangler` is a CLI tool designed for folks who are interested in using [Cloudflare Workers](https://workers.cloudflare.com/).

## Installation

Expand All @@ -25,11 +25,9 @@ cargo install wrangler

## 🎙️ Commands

`wrangler` is a CLI tool designed for folks who are interested in using Cloudflare workers.

- ### 👯 `generate`
- ### 👯 `generate`
Scaffold a project, including boilerplate for a Rust library and a Cloudflare Worker.
You can pass a name and template to this command optionally.
You can pass a name and template to this command optionally.

```
wrangler generate <name> <template> --type=["webpack", "javascript", "rust"]
Expand Down Expand Up @@ -63,7 +61,7 @@ cargo install wrangler
By default, `publish` will make your worker available at `<project-name>.<subdomain>.workers.dev`.
To disable publishing to your workers.dev subdomain, set `private = true` in your `wrangler.toml`.
This setting prevents the `publish` command from making your worker publicly available. To
explicitly enable deployment to `<project-name>.<subdomain>.workers.dev`, you can set `private = false`.
explicitly enable deployment to `<project-name>.<subdomain>.workers.dev`, you can set `private = false`.

To use this command, you'll need to have the following keys in your `wrangler.toml`:

Expand Down Expand Up @@ -111,8 +109,7 @@ There are two types of configuration that `wrangler` uses: global user and per p

To set up `wrangler` to work with your Cloudflare user, use the following commands:

- 🔧 `config`: an interactive command that asks you to pass your `email` and `api` key. Alternatively,
you can use the flags `--email` and `--api-key` to the command to skip the interactive part.
- 🔧 `config`: a command that prompts you to enter your `email` and `api` key.
- 🕵️‍♀️ `whoami`: run this command to confirm that your configuration is appropriately set up.
When successful, this command will print out your user information, including the type of plan you
are currently on.
Expand All @@ -134,7 +131,7 @@ There are two types of configuration that `wrangler` uses: global user and per p
- `javascript`: This project contains a single JavaScript file, defined in `package.json`'s `main` key.
- `rust`: This project contains a Rust crate that uses `wasm-bindgen`. It will be built with `wasm-pack`.
- `webpack`: This project contains any number of JavaScript files or Rust/C/C++ files that compile to
WebAssembly. Rust files will be built with `wasm-pack`. `C/C++` files will be build with `emscripten`.
WebAssembly. Rust files will be built with `wasm-pack`.
This project type uses webpack and webpack plugins in the background to build your worker.
- `zone_id`: This is the ID of the "zone" or domain you want to run your script on. This is optional if you
are using a workers.dev subdomain and is only reuqired for `publish --release`.
Expand All @@ -144,12 +141,42 @@ There are two types of configuration that `wrangler` uses: global user and per p
- `*example.com/*`
- `http://example.com/hello`
This key is optional if you are using a workers.dev subdomain and is only required for `publish --release`.
- `webpack_config`: This is the path to the webpack configuration file for your worker. This is optional and
defaults to `webpack.config.js`
- `[[kv-namespaces]]`: These specify any [Workers KV](https://workers.cloudflare.com/docs/reference/storage/) namespaces you want to access from
inside your Worker. Each namespace you include should have an entry in your wrangler.toml that includes:

- `binding`: the name you want to bind to in your script
- `id`: the namespace_id assigned to your kv namespace upon creation.
e.g. (per namespace):
``` toml
[[kv-namespaces]]
binding = "FOO"
id = "0f2ac74b498b48028cb68387c421e279"
```
Note: Creating your KV Namespaces should be handled either via the [api](https://workers.cloudflare.com/docs/reference/storage/writing-data/) or via your Cloudflare dashboard.

## ⚓ Installation

Wrangler can be installed both through [npm](https://www.npmjs.com/get-npm) and through Rust's package manager, [Cargo](https://github.com/rust-lang/cargo).

### Using `npm`:

1. If you don't already have npm on your machine, install it using [npm's recommended method](https://www.npmjs.com/get-npm), a node.js version manager.

If you have already installed npm with a package manager, it is possible you will run into an `EACCES` error while installing wrangler. This is related to how many system packagers install npm. You can either uninstall npm and reinstall using the npm recommended install method (a version manager), or use one of our other install methods.

1. Install Wrangler by running:

```
npm i @cloudflare/wrangler -g
```

### Using `cargo`:

1. Install `cargo`:

Wrangler is installed through [Cargo](https://github.com/rust-lang/cargo#compiling-from-source), a Rust package manager. Rustup, a tool for installing Rust, will also install Cargo. On Linux and macOS systems, `rustup` can be installed as follows:
Rustup, a tool for installing Rust, will also install Cargo. On Linux and macOS systems, `rustup` can be installed as follows:

```
curl https://sh.rustup.rs -sSf | sh
Expand All @@ -163,14 +190,33 @@ There are two types of configuration that `wrangler` uses: global user and per p
cargo install wrangler
```

1. Troubleshooting OpenSSL errors

If you are on a Mac, you might encounter an OpenSSL error when attempting to generate a project. You can resolve that issue by installing OpenSSL v1.1 through Homebrew (need to install Homebrew? Instructions available [here](https://brew.sh/)).
Installing wrangler on linux requires some [OpenSSL-related packages](https://docs.rs/openssl/0.10.24/openssl/#automatic) to be installed. If you don't want to deal with this, you can use vendored OpenSSL.

```
$ brew install openssl@1.1
cargo install wrangler --features vendored-openssl
```

### Manual Install:

1. Download the binary tarball for your platform from our [releases page](https://github.com/cloudflare/wrangler/releases). You don't need to download wranglerjs, wrangler will install that for you.

2. Unpack the tarball and place the binary `wrangler` somewhere on your `PATH`, preferably `/usr/local/bin` for linux/macOS or `Program Files` for windows.


## Updating `wrangler`:

To get the latest version of Wrangler, using Cargo, run:

```
cargo install wrangler --force
```

To get the latest version of Wrangler, using NPM, run:

```
npm install @cloudflare/wrangler
```

## ⚡ Quick Start

1. Generate a new project:
Expand Down
10 changes: 4 additions & 6 deletions npm/install-wrangler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const { homedir } = require('os');

const cwd = join(homedir(), ".wrangler");

function getLatestRelease() {
return get("https://api.github.com/repos/cloudflare/wrangler/releases/latest")
function getReleaseByTag(tag) {
return get(`https://api.github.com/repos/cloudflare/wrangler/releases/tags/v${tag}`)
.then(res => get(res.data.assets_url))
.then(res => res.data);
}
Expand Down Expand Up @@ -60,7 +60,7 @@ if (!existsSync(cwd)) {
mkdirSync(cwd);
}

getLatestRelease()
getReleaseByTag("1.1.1")
.then(assets => {
const [compatibleAssets] = assets.filter(asset =>
asset.name.endsWith(getPlatform() + ".tar.gz")
Expand All @@ -75,6 +75,4 @@ getLatestRelease()
.then(() => {
console.log("Wrangler has been installed!");
})
.catch(err => {
throw err;
});
.catch(e => { console.error("Error fetching release", e.message); });