Skip to content

Commit 612b7bc

Browse files
author
Dane Springmeyer
committed
more edits
1 parent 778be83 commit 612b7bc

File tree

1 file changed

+43
-51
lines changed

1 file changed

+43
-51
lines changed

README.md

+43-51
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
# node-pre-gyp
22

3-
`node-pre-gyp` is a tool that makes it easy to publish and install Node.js C++ from binaries.
3+
#### node-pre-gyp makes it easy to publish and install Node.js C++ from binaries
44

55
[![NPM](https://nodei.co/npm/node-pre-gyp.png)](https://nodei.co/npm/node-pre-gyp/)
66

77
[![Build Status](https://secure.travis-ci.org/mapbox/node-pre-gyp.png)](https://travis-ci.org/mapbox/node-pre-gyp)
88
[![Dependencies](https://david-dm.org/mapbox/node-pre-gyp.png)](https://david-dm.org/mapbox/node-pre-gyp)
99

10-
## Overview
10+
`node-pre-gyp` stands between [npm](https://github.com/npm/npm) and [node-gyp](https://github.com/Tootallnate/node-gyp) and offers a cross-platform method of binary deployment.
1111

12-
`node-pre-gyp` stands between [npm](https://github.com/npm/npm) and [node-gyp](https://github.com/Tootallnate/node-gyp). It offers two main things:
12+
### Features
1313

14-
- A command line tool called `node-pre-gyp` that can install your package from a binary or publish it.
15-
- Javascript code that can be required to dynamically find your module: `require('node-pre-gyp').find`
14+
- A command line tool called `node-pre-gyp` that can install your package's c++ module from a binary.
15+
- A variety of developer targeted commands for packaging, testing, and publishing binaries.
16+
- A Javascript module that can dynamically require your installed binary: `require('node-pre-gyp').find`
1617

17-
For a hello world example of a Node.js C++ module packaged with `node-pre-gyp` see <https://github.com/springmeyer/node-addon-example>.
18-
19-
## Modules using `node-pre-gyp`:
20-
21-
- [node-sqlite3](https://github.com/mapbox/node-sqlite3)
22-
- [node-mapnik](https://github.com/mapnik/node-mapnik)
23-
- [node-osmium](https://github.com/osmcode/node-osmium)
24-
- [node-osrm](https://github.com/DennisOSRM/node-OSRM)
25-
- [node-addon-example](https://github.com/springmeyer/node-addon-example)
26-
27-
For more examples see the [test apps](test/).
18+
For a hello world example of a module packaged with `node-pre-gyp` see <https://github.com/springmeyer/node-addon-example> and [the wiki ](https://github.com/mapbox/node-pre-gyp/wiki/Modules-using-node-pre-gyp) for real world examples.
2819

2920
## Depends
3021

@@ -38,7 +29,7 @@ For more examples see the [test apps](test/).
3829

3930
But you can also install it globally:
4031

41-
npm install node-pre-gyp -g
32+
npm install node-pre-gyp -g
4233

4334
## Usage
4435

@@ -63,15 +54,32 @@ You can also chain commands:
6354

6455
node-pre-gyp clean build unpublish publish info
6556

66-
### Configuring your module to use node-pre-gyp
57+
### Options
58+
59+
Options include:
60+
61+
- `-C/--directory`: run the command in this directory
62+
- `--build-from-source`: build from source instead of using pre-built binary
63+
- `--fallback-to-build`: fallback to building from source if pre-built binary is not available
64+
- `--target=0.10.25`: Pass the target node or node-webkit version to compile against
65+
66+
Both `--build-from-source` and `--fallback-to-build` can be passed alone or they can provide values. You can pass `--fallback-to-build=false` to override the option as declared in package.json. In addition to being able to pass `--build-from-source` you can also pass `--build-from-source=myapp` where `myapp` is the name of your module.
67+
68+
For example: `npm install --build-from-source=myapp`. This is useful if:
69+
70+
- `myapp` is referenced in the package.json of a larger app and therefore `myapp` is being installed as a dependent with `npm install`.
71+
- The larger app also depends on other modules installed with `node-pre-gyp`
72+
- You only want to trigger a source compile for `myapp` and the other modules.
73+
74+
### Configuring
6775

68-
**1) Add new entries to your `package.json`**
76+
This is guide to configuring your module to use node-pre-gyp.
6977

70-
We need to:
78+
#### 1) Add new entries to your `package.json`
7179

72-
- Add node-pre-gyp as a bundled dependency
80+
- Add `node-pre-gyp` as a bundled dependency
7381
- Add a custom `install` script
74-
- Add a `binary` object
82+
- Declare a `binary` object
7583

7684
This looks like:
7785

@@ -90,33 +98,33 @@ This looks like:
9098
}
9199
```
92100

93-
#### The `binary` object has three required properties
101+
##### The `binary` object has three required properties
94102

95-
##### module_name
103+
###### module_name
96104

97105
The name of your native node module.This must match the name passed to [the NODE_MODULE macro](http://nodejs.org/api/addons.html#addons_hello_world) and should not include the `.node` extension.
98106

99-
##### module_path
107+
###### module_path
100108

101109
The location your native module is placed after a build. This should be an empty directory without other javascript files. This is because everything in the directory will be packaged in the binary tarball and when unpack anything inside the directory will be overwritten with the contents of the tarball. **
102110

103-
##### host
111+
###### host
104112

105113
A url to the remote location where you've published tarball binaries (must be `https` not `http`)
106114

107-
#### The `binary` object has two optional properties
115+
##### The `binary` object has two optional properties
108116

109-
##### remote_path
117+
###### remote_path
110118

111119
It **is recommended** that you customize this property. This is an extra path to use for publishing and finding remote tarballs. The default value for `remote_path` is `""` meaning that if you do not provide it then all packages will be published at the base of the `host`. It is recommended to provide a value like `./{module_name}/v{version}` to help organize remote packages in the case that you choose to publish multiple node addons to the same `host`. **
112120

113-
##### package_name
121+
###### package_name
114122

115123
It is **not recommended** to override this property. This is the versioned name of the remote tarball containing the binary `.node` module and any supporting files you've placed inside the `module_path`. If you do not provide it in your `package.json` then it defaults to `{module_name}-v{version}-{node_abi}-{platform}-{arch}.tar.gz` which is a versioning string capable of supporting any remove lookup of your modules across all of its pubished versions and various node versions, platforms and architectures. But if you only wish to support windows you could could change it to `{module_name}-v{version}-{node_abi}-win32-{arch}.tar.gz`. See [Versioning](#versioning for details) about what each variable evaluates to. **
116124

117125
** Properties supporting versioning mean that they will be evaluated against known node-pre-gyp variables. See [Versioning](#versioning for details).
118126

119-
**4) Dynamically require your `.node`
127+
#### 2) Dynamically require your `.node`
120128

121129
Inside the main js file that requires your addon module you are likely currently doing:
122130

@@ -139,7 +147,7 @@ var binding_path = binary.find(path.resolve(path.join(__dirname,'./package.json'
139147
var binding = require(binding_path);
140148
```
141149

142-
**5) Build and package your app**
150+
#### 3) Build and package your app
143151

144152
Now build your module from source:
145153

@@ -149,11 +157,11 @@ The `--build-from-source` tells `node-pre-gyp` to not look for a remote package
149157

150158
Now `node-pre-gyp` should now also be installed as a local dependency so the command line tool it offers can be found at `./node_modules/.bin/node-pre-gyp`.
151159

152-
**6) Test **
160+
#### 4) Test
153161

154162
Now `npm test` should work just as it did before.
155163

156-
**7) Publish the tarball**
164+
#### 5) Publish the tarball
157165

158166
Then package your app:
159167

@@ -175,11 +183,11 @@ You can also host your binaries elsewhere. To do this requires:
175183
- You manually publish the binary created by the `package` command to an `https` endpoint
176184
- Ensure that the `host` value points to your custom `https` endpoint.
177185

178-
**8) Automating builds**
186+
#### 6) Automate builds
179187

180188
Now you need to publish builds for all the platforms and node versions you wish to support. This is best automated. See [Travis Automation](#travis-automation) for how to auto-publish builds on OS X and Linux. On windows consider using a script [like this](https://github.com/mapbox/node-sqlite3/blob/master/scripts/build.bat) to quickly create and publish binaries and check out <https://appveyor.com>.
181189

182-
**9) You're done!**
190+
#### 7) You're done!
183191

184192
Now publish your package to the npm registry. Users will now be able to install your module from a binary.
185193

@@ -322,22 +330,6 @@ Or you could automatically detect if the git branch is a tag:
322330
Remember this publishing is not the same as `npm publish`. We're just talking about the
323331
binary module here and not your entire npm package. To automate the publishing of your entire package to npm on travis see http://about.travis-ci.org/docs/user/deployment/npm/
324332

325-
### Options
326-
327-
Options include:
328-
329-
- `-C/--directory`: run the command in this directory
330-
- `--build-from-source`: build from source instead of using pre-built binary
331-
- `--fallback-to-build`: fallback to building from source if pre-built binary is not available
332-
333-
Both `--build-from-source` and `--fallback-to-build` can be passed alone or they can provide values. So, in addition to being able to pass `--build-from-source` you can also pass `--build-from-source=myapp` where `myapp` is the name of your module.
334-
335-
For example: `npm install --build-from-source=myapp`. This is useful if:
336-
337-
- `myapp` is referenced in the package.json of a larger app and therefore `myapp` is being installed as a dependent with `npm install`.
338-
- The larger app also depends on other modules installed with `node-pre-gyp`
339-
- You only want to trigger a source compile for `myapp` and the other modules.
340-
341333
# Versioning
342334

343335
The versioning template accepts these variables, which will get evaluated by `node-pre-gyp` depending on your system and any custom build flags you passed.

0 commit comments

Comments
 (0)