Skip to content

Commit

Permalink
fix(generate): s/generate/new, name is postional
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleygwilliams committed Apr 15, 2019
1 parent 251d198 commit 88ce9b5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docs/src/SUMMARY.md
Expand Up @@ -6,7 +6,7 @@
- [npm (optional)](./prerequisites/npm.md)
- [Non-`rustup` setups](./prerequisites/non-rustup-setups.md)
- [Commands](./commands/index.md)
- [`generate`](./commands/generate.md)
- [`new`](./commands/new.md)
- [`build`](./commands/build.md)
- [`test`](./commands/test.md)
- [`pack` and `publish`](./commands/pack-and-publish.md)
Expand Down
32 changes: 0 additions & 32 deletions docs/src/commands/generate.md

This file was deleted.

9 changes: 6 additions & 3 deletions docs/src/commands/index.md
Expand Up @@ -3,11 +3,14 @@
`wasm-pack` has several commands to help you during the process of building
a Rust-generated WebAssembly project.

- `init`: This command has been deprecated in favor of `build`.
- `generate`: This command generates a new project for you using a template. [Learn more][generate]
- `new`: This command generates a new project for you using a template. [Learn more][generate]
- `build`: This command builds a `pkg` directory for you with compiled wasm and generated JS. [Learn more][build]
- `pack` and `publish`: These command will create a tarball, and optionally publish it to a registry, such as npm. [Learn more][pack-pub]


### Deprecated Commands
- `init`: This command has been deprecated in favor of `build`.

[build]: ./build.html
[generate]: ./generate.html
[new]: ./new.html
[pack-pub]: ./pack-and-publish.html
50 changes: 50 additions & 0 deletions docs/src/commands/new.md
@@ -0,0 +1,50 @@
# wasm-pack new

The `wasm-pack new` command creates a new RustWasm project for you,
using [`cargo-generate`] under the hood.

It takes 3 parameters, name, template, and mode:

```
wasm-pack new <name> --template <template> --mode <normal|noinstall|force>
```

The template will default to the `rustwasm/wasm-pack-template`.

## Name

The `wasm-pack new` command must be given a name argument, e.g.:

```
wasm-pack new myproject
```

## Template

The `wasm-pack new` command can be given an optional template argument, e.g.:

```
wasm-pack new myproject --template https://github.com/rustwasm/wasm-pack-template
```

The template can be an address to a git repo that contains a [`cargo-generate`]
template.

[`cargo-generate`]: https://github.com/ashleygwilliams/cargo-generate

## Mode

The `wasm-pack new` command can be given an optional mode argument, e.g.:

```
wasm-pack new myproject --mode noinstall
```

The mode pass can be either "normal", "noinstall", or "force". "normal is passed by
degault.

`noinstall` means that wasm-pack should not attempt to install any underlying tools.
If a necessary tool cannot be found, the command will error.

`force` means that wasm-pack should not check the local Rust version. If a local Rust
is an unacceptable Rust version, the command will error.
2 changes: 1 addition & 1 deletion docs/src/quickstart.md
Expand Up @@ -2,7 +2,7 @@

1. Install `rust` using [`rustup`].
1. [Install this tool.]
1. Run `wasm-pack generate`.
1. Run `wasm-pack new hello-wasm`.
1. `cd hello-wasm`
1. Run `wasm-pack build`.
1. This tool generates files in a `pkg` dir
Expand Down
7 changes: 3 additions & 4 deletions src/command/mod.rs
Expand Up @@ -36,19 +36,18 @@ pub enum Command {
path: Option<PathBuf>,
},

#[structopt(name = "generate")]
#[structopt(name = "new")]
/// 🐑 create a new project with a template
Generate {
/// The name of the project
name: String,
/// The URL to the template
#[structopt(
long = "template",
short = "temp",
default_value = "https://github.com/rustwasm/wasm-pack-template"
)]
template: String,
/// The name of the project
#[structopt(long = "name", short = "n")]
name: String,
#[structopt(long = "mode", short = "m", default_value = "normal")]
/// Should we install or check the presence of binary tools. [possible values: no-install, normal, force]
mode: InstallMode,
Expand Down
8 changes: 4 additions & 4 deletions tests/all/generate.rs
Expand Up @@ -3,17 +3,17 @@ use std::str;
use utils;

#[test]
fn generate_with_defaults() {
fn new_with_no_name_errors() {
let fixture = utils::fixture::not_a_crate();
let cmd = fixture.wasm_pack().arg("generate").assert().failure();
fixture.wasm_pack().arg("new").assert().failure();
}

#[test]
fn generate_with_provided_name() {
fn new_with_provided_name() {
let fixture = utils::fixture::not_a_crate();
let cmd = fixture
.wasm_pack()
.arg("generate")
.arg("new")
.arg("--name")
.arg("ferris")
.assert();
Expand Down

0 comments on commit 88ce9b5

Please sign in to comment.