Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit 407029b

Browse files
authored
Merge pull request #23 from netlify/release-prep
Release prep
2 parents a083ee3 + b56c3c0 commit 407029b

File tree

5 files changed

+70
-36
lines changed

5 files changed

+70
-36
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# netlify Change Log
2+
All notable changes to this project will be documented in this file.
3+
This project adheres to [Semantic Versioning](http://semver.org/).
4+
5+
## 2.0.1 - 2018-09-25
6+
* A whole new Netlify Node.js API client! 🎉
7+
* Client code was extracted from our forthcoming [2.0.0 CLI](https://www.netlify.com/blog/2018/09/10/netlify-cli-2.0-now-in-beta-/) release.
8+
* A completely new API. Treat the 2.x.x and forward as a completely separate codebase and API.
9+
* API calls are now derived from the [open-api](https://github.com/netlify/open-api) specification. See the [swagger-ui](https://open-api.netlify.com/#/default) and know that there is a matching API method for every operationID (the name on the right). See the README for full API docs.
10+
* Includes a method for creating content based deploys.

CONTRIBUTING.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,52 @@
11
# CONTRIBUTING
22

3-
Contributions are always welcome, no matter how large or small. Before contributing,
4-
please read the [code of conduct](CODE_OF_CONDUCT.md).
3+
Contributions are always welcome, no matter how large or small. Before contributing, please read the [code of conduct](CODE_OF_CONDUCT.md).
54

65
## Setup
76

8-
> Install NPM on your system: https://docs.npmjs.com/getting-started/installing-node
7+
> Install Node.js + npm on your system: https://nodejs.org/en/download/
98
109
```sh
1110
$ git clone https://github.com/netlify/js-client netlify-js-client
1211
$ cd netlify-js-client
1312
$ npm install
13+
$ npm test
1414
```
1515

16+
You can also use yarn.
17+
1618
## Testing
1719

18-
```sh
19-
$ jasmine-node spec
20-
```
20+
This repo uses [ava](https://github.com/avajs/ava) for testing. Any files in the `src` directory that have a `.test.js` file extension are automatically detected and run as tests.
21+
22+
We also test for a few other things:
23+
24+
- Dependencies (used an unused)
25+
- Linting
26+
- Test coverage
27+
- Must work with Windows + Unix environments.
2128

22-
## Pull Requests
29+
## Architecture
2330

24-
We actively welcome your pull requests.
31+
We target Node.js LTS and stable environments, and aim for basic modern browser support when possible. In order to facilitate simple contributions, we avoided any kind of build steps.
2532

26-
1. Fork the repo and create your branch from `master`.
27-
2. If you've added code that should be tested, add tests.
28-
3. If you've changed APIs, update the documentation.
29-
4. Ensure the test suite passes.
30-
5. Make sure your code lints.
33+
If you need to add new API routes, please add them to the [open-api](https://github.com/netlify/open-api) repo. This client will automatically inherent the new routes from that module.
34+
35+
Projects that depend heavily on this client that should be taken into consideration when making changes:
36+
37+
- [netlify/cli](https://github.com/netlify/cli)
38+
39+
## Releasing
40+
41+
```console
42+
# Make changes
43+
# Update README docs if they have changed.
44+
# Update the changelog
45+
$ npm version [major|minor|patch]
46+
$ git push && git push --tags
47+
# Create a github release with the changelog contents
48+
$ npm publish
49+
```
3150

3251
## License
3352

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,32 @@ Create a new instance of the Netlify API client with the provided `accessToken`.
2828
scheme: 'https',
2929
host: 'api.netlify.com',
3030
pathPrefix: '/api/v1',
31-
globalParams: {} // parameters you want available for every request
31+
globalParams: {} // parameters you want available for every request.
32+
// Global params are only sent of the open-api spec specifies the provided params.
3233
}
3334
```
3435

3536
### `client.accessToken`
3637

37-
A setter/getter that returns the `accessToken` that the client is configured to use. You can set this after the class is instantiated, and all subsequent calls will use the newly set `accessToken`.
38+
A setter/getter that returns the `accessToken` that the client is configured to use. You can set this after the class is instantiated, and all subsequent calls will use the newly set `accessToken`.
3839

3940
### `client.basePath`
4041

4142
A getter that returns the formatted base URL of the endpoint the client is configured to use.
4243

4344
### Open API Client methods
4445

45-
The client is dynamically generated from the [open-api](https://github.com/netlify/open-api) definition file. Each method is is named after the `operationId` name of each endpoint action. **To see list of available operations see the [open-api website](https://open-api.netlify.com/)**.
46+
The client is dynamically generated from the [open-api](https://github.com/netlify/open-api) definition file. Each method is is named after the `operationId` name of each endpoint action. **To see list of available operations see the [open-api website](https://open-api.netlify.com/)**.
4647

4748
Every open-api method has the following signature:
4849

4950
#### `promise(response) = client.operationId([params], [opts])`
5051

51-
Perform a call to the given endpoint corresponding with the `operationId`. Returns promise that will resolve with the body of the response, or reject with an error with details about the request attached. Rejects if the `status` > 400. Successful response objects have `status` and `statusText` properties on their prototype.
52+
Perform a call to the given endpoint corresponding with the `operationId`. Returns promise that will resolve with the body of the response, or reject with an error with details about the request attached. Rejects if the `status` > 400. Successful response objects have `status` and `statusText` properties on their prototype.
5253

53-
`params` is an object that includes any of the required or optional endpoint parameters. `params.body` should be an object which gets serialized to JSON automatically. If the endpoint accepts `binary`, `params.body` can be a Node.js readable stream.
54+
- `params` is an object that includes any of the required or optional endpoint parameters.
55+
- `params.body` should be an object which gets serialized to JSON automatically.
56+
- If the endpoint accepts `binary`, `params.body` can be a Node.js readable stream.
5457

5558
```js
5659
// example params
@@ -63,7 +66,7 @@ Perform a call to the given endpoint corresponding with the `operationId`. Retu
6366
}
6467
```
6568

66-
Optional `opts` can include any property you want passed to `node-fetch`. The `headers` property is merged with some `defaultHeaders`.
69+
Optional `opts` can include any property you want passed to `node-fetch`. The `headers` property is merged with some `defaultHeaders`.
6770

6871
```js
6972
// example opts
@@ -82,23 +85,25 @@ All methods are conveniently consumed with async/await:
8285
async function getSomeData () {
8386
// Calls may fail!
8487
try {
85-
const resposnse = await client.getSites()
86-
return response
88+
return await client.getSiteDeploy({
89+
siteId: '1234abcd',
90+
deploy_id: '4567'
91+
})
8792
} catch (e) {
8893
// handle error
8994
}
9095
}
9196
```
9297

93-
If the request response includes `json` in the `contentType` header, fetch will deserialize the JSON body. Otherwise the `text` of the response is returned.
98+
If the request response includes `json` in the `contentType` header, fetch will deserialize the JSON body. Otherwise the `text` of the response is returned.
9499

95-
### Convenience Methods
100+
### API Flow Methods
96101

97102
Some methods have been added in addition to the open API methods that make certain actions simpler to perform.
98103

99104
#### `promise(accessToken) = client.getAccessToken(ticket, [opts])`
100105

101-
Pass in a [`ticket`](https://open-api.netlify.com/#model-ticket) and get back an `accessToken`. Call this with the response from a `client.createTicket({ client_id })` call. Automatically sets the `accessToken` to `this.accessToken` and returns `accessToken` for the consumer to save for later.
106+
Pass in a [`ticket`](https://open-api.netlify.com/#model-ticket) and get back an `accessToken`. Call this with the response from a `client.createTicket({ client_id })` call. Automatically sets the `accessToken` to `this.accessToken` and returns `accessToken` for the consumer to save for later.
102107

103108
Optional `opts` include:
104109

@@ -121,34 +126,34 @@ async function login () {
121126
await openBrowser(`https://app.netlify.com/authorize?response_type=ticket&ticket=${ticket.id}`)
122127
const accessToken = await api.getAccessToken(ticket)
123128
// API is also set up to use the returned access token as a side effect
124-
return accessToken
129+
return accessToken // Save this for later so you can quickly set up an authenticated client
125130
}
126131
```
127132

128133
#### `promise(deploy) = client.deploy(siteId, buildDir, [opts])`
129134

130135
**Node.js Only**: Pass in a `siteId`, a `buildDir` (the folder you want to deploy) and an options object to deploy the contents of that folder.
131-
Sometimes need to write to a `tmpDir`.
136+
Sometimes this method needs to write to a `tmpDir`. By default `tmpDir` is the default system default.
132137

133138
The following paths can be passed in the options:
134139

135-
- `tomlPath` (a `netlify.toml` file that includes redirect rules for the deploy)
140+
- `configPath` (path to a `netlify.toml` file that includes redirect rules for the deploy, etc.)
136141
- `functionsDir` (a folder with lambda functions to deploy)
137142

138143
Optional `opts` include:
139144

140145
```js
141146
{
142147
functionsDir: null, // path to a folder of functions to deploy
143-
tomlPath: null, // path to a netlify.toml file to include in the deploy (e.g. redirect support for manual deploys)
148+
configPath: null, // path to a netlify.toml file to include in the deploy (e.g. redirect support for manual deploys)
144149
draft: false, // draft deploy or production deploy
145150
message: undefined, // a short message to associate with the deploy
146151
deployTimeout: 1.2e6, // 20 mins
147152
parallelHash: 100, // number of parallel hashing calls
148-
parallelUpload: 4, // number of files to upload in parallel
153+
parallelUpload: 15, // number of files to upload in parallel
149154
maxRetry: 5, // number of times to try on failed file uploads
150-
filter: filename => { /* return false to filter a file from the deploy */ },
151-
tmpDir: tempy.directory(), // a temporary directory to zip loose files into
155+
filter: filepath => { /* return false to filter a file from the deploy */ },
156+
tmpDir: tempy.directory(), // a temporary directory to zip functions into
152157
statusCb: statusObj => {
153158
// a callback function to receive status events
154159
/* statusObj: {

src/deploy/hash-files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const pump = promisify(require('pump'))
44
const { hasherCtor, manifestCollectorCtor, fileFilterCtor, fileNormalizerCtor } = require('./hasher-segments')
55

66
module.exports = hashFiles
7-
async function hashFiles(dir, tomlPath, opts) {
7+
async function hashFiles(dir, configPath, opts) {
88
opts = Object.assign(
99
{
1010
concurrentHash: 100,
@@ -15,7 +15,7 @@ async function hashFiles(dir, tomlPath, opts) {
1515
)
1616

1717
if (!opts.filter) throw new Error('Missing filter function option')
18-
const fileStream = walker([tomlPath, dir], { filter: opts.filter })
18+
const fileStream = walker([configPath, dir], { filter: opts.filter })
1919
const filter = fileFilterCtor()
2020
const hasher = hasherCtor(opts)
2121
const fileNormalizer = fileNormalizerCtor(opts)

src/deploy/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = async (api, siteId, dir, opts) => {
1111
opts = Object.assign(
1212
{
1313
fnDir: null,
14-
tomlPath: null,
14+
configPath: null,
1515
draft: false,
1616
message: undefined, // API calls this the 'title'
1717
tmpDir: tempy.directory(),
@@ -34,7 +34,7 @@ module.exports = async (api, siteId, dir, opts) => {
3434
opts
3535
)
3636

37-
const { fnDir, tomlPath, statusCb, message: title } = opts
37+
const { fnDir, configPath, statusCb, message: title } = opts
3838

3939
statusCb({
4040
type: 'hashing',
@@ -43,7 +43,7 @@ module.exports = async (api, siteId, dir, opts) => {
4343
})
4444

4545
const [{ files, filesShaMap }, { functions, fnShaMap }] = await Promise.all([
46-
hashFiles(dir, tomlPath, opts),
46+
hashFiles(dir, configPath, opts),
4747
hashFns(fnDir, opts)
4848
])
4949

0 commit comments

Comments
 (0)