Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dherman committed Jan 7, 2024
1 parent 168540d commit 684e697
Show file tree
Hide file tree
Showing 19 changed files with 719 additions and 81 deletions.
5 changes: 5 additions & 0 deletions pkgs/create-neon/data/templates/.gitignore.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ index.node
**/node_modules
**/.DS_Store
npm-debug.log*
{{#if package.lang.isTypeScript}}
lib
{{/if}}
cargo.log
cross.log
3 changes: 3 additions & 0 deletions pkgs/create-neon/data/templates/.npmignore.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#if package.isLibrary}}
platforms
{{/if}}
73 changes: 51 additions & 22 deletions pkgs/create-neon/data/templates/README.md.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,24 @@
{{/if}}
This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon).

## Installing {{package.name}}

Installing {{package.name}} requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support).

You can install the project with npm. In the project directory, run:

```sh
$ npm install
```

This fully installs the project, including installing any dependencies and running the build.

## Building {{package.name}}

If you have already installed the project and only want to run the build, run:
Building {{package.name}} requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support).

To run the build, run:

```sh
$ npm run build
```

This command uses the [cargo-cp-artifact](https://github.com/neon-bindings/cargo-cp-artifact) utility to run the Rust build and copy the built library into `./index.node`.
This command uses the [@neon-rs/cli](https://github.com/neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`.

## Exploring {{package.name}}

After building {{package.name}}, you can explore its exports at the Node REPL:

```sh
$ npm install
$ npm run build
$ node
> require('.').hello()
"hello node"
Expand All @@ -43,27 +33,29 @@ $ node

In the project directory, you can run:

{{#unless package.isLibrary}}
### `npm install`

Installs the project, including running `npm run build`.

### `npm build`
{{/unless}}
### `npm run build`

Builds the Node addon (`index.node`) from source.
Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`.

Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm build` and `npm build-*` commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html):
Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm run build` and similar commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html):

```
npm run build -- --feature=beetle
```

#### `npm build-debug`
#### `npm run debug`

Alias for `npm build`.
Similar to `npm run build` but generates a debug build with `cargo`.

#### `npm build-release`
#### `npm run cross`

Same as [`npm build`](#npm-build) but, builds the module with the [`release`](https://doc.rust-lang.org/cargo/reference/profiles.html#release) profile. Release builds will compile slower, but run faster.
Similar to `npm run build` but uses [cross-rs](https://github.com/cross-rs/cross) to cross-compile for another platform. Use the [`CARGO_BUILD_TARGET`](https://doc.rust-lang.org/cargo/reference/config.html#buildtarget) environment variable to select the build target.

### `npm test`

Expand All @@ -77,7 +69,17 @@ The directory structure of this project is:
{{package.name}}/
├── Cargo.toml
├── README.md
{{#if package.isLibrary}}
├── lib/
{{#if package.lang.isTypeScript}}
├── ts/
| ├── index.mts
| └── index.cts
{{/if}}
├── platforms/
{{else}}
├── index.node
{{/if}}
├── package.json
├── src/
| └── lib.rs
Expand All @@ -92,12 +94,39 @@ The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.htm

This file.

{{#if package.isLibrary}}
### lib/

{{#if package.lang.isTypeScript}}
The directory containing the generated output from [tsc](https://typescriptlang.org).

### ts/

The directory containing the TypeScript source files.

### ts/index.mts

Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax.

### ts/index.cts

Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid).
{{else}}
The directory containing the JavaScript source files.

{{/if}}
### platforms/

The directory containing distributions of the binary addon backend for each platform supported by this library.

{{else}}
### index.node

The Node addon—i.e., a binary Node module—generated by building the project. This is the main module for this package, as dictated by the `"main"` key in `package.json`.

Under the hood, a [Node addon](https://nodejs.org/api/addons.html) is a [dynamically-linked shared object](https://en.wikipedia.org/wiki/Library_(computing)#Shared_libraries). The `"build"` script produces this file by copying it from within the `target/` directory, which is where the Rust build produces the shared object.

{{/if}}
### package.json

The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command.
Expand Down
Loading

0 comments on commit 684e697

Please sign in to comment.