Skip to content

Commit 4457d5d

Browse files
committed
Prepare for v2.0.0 release.
- update project dependencies - [breaking]: remove `createNetlifyTypes` and `createNetlifyTypesAsync` named imports - [breaking]: export `createNetlifyTypes` as default. - update README documentation
1 parent 1e6d227 commit 4457d5d

File tree

7 files changed

+1310
-1382
lines changed

7 files changed

+1310
-1382
lines changed

README.md

+35-41
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Netlify Type Generator
1+
# Netlify CMS Type Generator
22

33
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fjsaari97%2Fnetlify-ts%2Fbadge%3Fref%3Dmaster&style=flat)](https://actions-badge.atrox.dev/jsaari97/netlify-ts/goto?ref=master)
44
![Supported Node versions](https://img.shields.io/node/v/netlify-ts)
55
[![Code coverage](https://img.shields.io/codecov/c/gh/jsaari97/netlify-ts)](https://app.codecov.io/gh/jsaari97/netlify-ts/)
66
![Project license](https://img.shields.io/npm/l/netlify-ts)
77

8-
**Turn your Netlify CMS collections into TypeScript typings!**
8+
**Turn your Netlify CMS collections into TypeScript types!**
99

1010
<br />
1111

@@ -23,80 +23,74 @@ This package generates a [TypeScript](https://www.typescriptlang.org/) schema of
2323

2424
# Installation
2525

26-
The package can be installed globally or as a `devDependency` using NPM or Yarn.
27-
28-
**NPM:**
29-
3026
```bash
31-
npm install -g netlify-ts
32-
33-
# or
34-
3527
npm install -D netlify-ts
3628
```
3729

38-
**Yarn:**
39-
40-
```bash
41-
yarn global add netlify-ts
42-
43-
# or
44-
45-
yarn add -D netlify-ts
46-
```
47-
4830
# Usage
4931

50-
## Method 1: CLI
32+
## CLI
5133

52-
The main method of usage is through the command-line. Having installed the package either globally or in project's `devDependencies`, simply call `netlify-ts` with a parameter pointing to your Netlify CMS admin `config.yml` file.
34+
The main method of usage is through the command-line. Having installed the package either globally or in project's `devDependencies`, simply call `netlify-ts` with a parameter pointing to your Netlify CMS `config.yml` file.
5335

5436
```bash
55-
netlify-ts public/admin/config.yml
37+
npx netlify-ts path/to/config.yml
5638
```
5739

58-
This generates by default a `netlify-types.ts` file in the project root containing types for your netlify content types.
40+
This generates a `netlify-types.ts` file in the project root containing types for your Netlify CMS collections.
5941

6042
### Custom output location
6143

6244
You can also specify a custom output location by providing a second optional parameter. Omitting the filename outputs a file in the given directory with the default filename (`netlify-types.ts`).
6345

6446
```bash
65-
netlify-ts public/admin/config.yml src/my-types.ts
47+
npx netlify-ts config.yml src/my-types.ts
6648
```
6749

68-
## Method 2: Programmatically
50+
## Programmatically
6951

70-
In case the CLI doesn't suit your project workflow or you need to invoke the type generation inside your code, the project exposes both a `createNetlifyTypes` and `createNetlifyTypesAsync` function that returns the generated type file as a string.
52+
In case the CLI doesn't suit your workflow or you need to invoke the type generation inside your code, the project exposes a function that returns the generated types as a string.
7153

7254
### Config file
7355

7456
```javascript
7557
const fs = require("fs");
76-
const { createNetlifyTypes } = require("netlify-ts");
58+
const createNetlifyTypes = require("netlify-ts");
7759

78-
function main() {
79-
const types = createNetlifyTypes("public/admin/config.yml");
80-
fs.writeFileSync("my-types.ts", types);
81-
}
82-
83-
main();
60+
const types = createNetlifyTypes("config.yml");
61+
fs.writeFileSync("cms-types.ts", types);
8462
```
8563

8664
### Config object
8765

8866
```javascript
8967
const fs = require("fs");
90-
const { createNetlifyTypes } = require("netlify-ts");
68+
const createNetlifyTypes = require("netlify-ts");
69+
70+
const cmsConfig = { collections: [ ... ] };
71+
72+
const types = createNetlifyTypes(cmsConfig);
73+
fs.writeFileSync("cms-types.ts", types);
74+
```
75+
76+
# Options
9177

92-
const cmsConfig = require("./config");
78+
| Option | Default | Description |
79+
| ---------- | ------- | -------------------------------------------- |
80+
| label | `true` | Use 'label_singular' or 'label' as type name |
81+
| capitalize | `false` | Capitalize type names |
82+
| delimiter | `_` | Type name delimiter, e.g. 'Posts_Author' |
9383

94-
function main() {
95-
const types = createNetlifyTypes(cmsConfig);
96-
fs.writeFileSync("my-types.ts", types);
97-
}
84+
## CLI example
9885

99-
main();
86+
```bash
87+
npx netlify-ts config.yml --capitalize
88+
```
89+
90+
### Code example
91+
92+
```javascript
93+
createNetlifyTypes("config.yml", { capitalize: true });
10094
```
10195

10296
# License

jest.config.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
12
module.exports = {
2-
preset: "ts-jest",
3-
testEnvironment: "node",
4-
globals: {
5-
"ts-jest": {
6-
tsconfig: "tsconfig.test.json",
7-
},
8-
},
9-
};
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

0 commit comments

Comments
 (0)