Skip to content

Commit f76977d

Browse files
authored
Merge pull request #2 from ReeceM/feature/test-mcb
Add Microbundle and also update the api methods to handle errors and return Slice/Type types (wip)
2 parents 822e40f + e2c4b55 commit f76977d

15 files changed

Lines changed: 3803 additions & 80 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
.vscode
12
node_modules
3+
4+
# Builds
25
dist
6+
7+
# Environment stuff
38
env.json
9+

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.github
12
node_modules
23
env.json
34
src
5+
.editorconfig
6+
pnpm-lock.yml
7+
package-lock.json

README.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,56 @@ I have intentionally only implemented mainly support for node as I don't see the
1010

1111
The readme is a WIP and the code could probably have some error handling added.
1212

13-
## Example
13+
## Usage
1414

1515
Below is an example of how to use this to interact with the API for the custom types, it gets a type and writes the result to ta json file.
1616

17+
### If using commonJS:
18+
1719
```js
18-
const Api = require('./dist/index').default;
20+
const Api = require('@reecem/custom-type-api');
1921
const credentials = require('./env.json');
2022
const fs = require('fs');
2123
const path = require('path')
2224

23-
2425
const api = new Api('slicemachine-startup', credentials.token)
2526

2627
async function test() {
27-
await api.login()
28+
await api.init()
29+
30+
try {
31+
const type = await api.types().getOne('page');
32+
33+
console.log(type)
34+
35+
fs.writeFileSync(path.join(__dirname, 'page.json'), JSON.stringify(type, null, 2))
36+
} catch (ex) {
37+
console.error(ex)
38+
}
39+
}
40+
41+
test()
42+
```
43+
44+
45+
### If using modules:
46+
47+
```js
48+
import Api from '@reecem/custom-type-api'
49+
50+
import { createRequire } from "module"; // Bring in the ability to create the 'require' method
51+
const require = createRequire(import.meta.url); // construct the require method
52+
const credentials = require('../env.json');
53+
54+
async function test() {
55+
const api = new Api('slicemachine-startup', credentials.token)
56+
57+
await api.init()
2858

2959
try {
30-
const response = await api.types().getOne('page');
31-
const res = await response.json();
32-
console.log(res)
33-
fs.writeFileSync(path.join(__dirname, 'page.json'), JSON.stringify(res, null, 2))
60+
let slice = await api.slices().getOne('form_slice');
61+
console.log(slice)
62+
fs.writeFileSync(path.join(__dirname, 'form_slice.json'), JSON.stringify(slice, null, 2))
3463
} catch (ex) {
3564
console.error(ex)
3665
}

package.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
11
{
22
"name": "@reecem/custom-type-api",
3-
"version": "0.1.1",
3+
"version": "0.2.0-alpha.3",
44
"description": "API interface for the Prismic.io Custom Type API (beta)",
5-
"main": "dist/index.js",
5+
"type": "module",
6+
"source": "src/index.ts",
7+
"main": "./dist/index.cjs",
8+
"module": "./dist/index.mjs",
9+
"types": "./dist/index.d.ts",
610
"scripts": {
711
"test": "echo \"Error: no test specified\" && exit 1",
8-
"build": "tsc --build tsconfig.json"
12+
"build": "microbundle",
13+
"dev": "microbundle watch",
14+
"tsc-build": "tsc --build tsconfig.json"
915
},
1016
"keywords": [
1117
"prismic.io",
12-
"custom-type"
18+
"custom-types",
19+
"slices",
20+
"api",
21+
"slicemachine"
1322
],
14-
"author": "ReeceM",
23+
"author": "@ReeceM",
1524
"license": "ISC",
1625
"devDependencies": {
1726
"@types/node-fetch": "^2.5.10",
27+
"microbundle": "^0.13.3",
1828
"typescript": "^4.2.4"
1929
},
30+
"engines": {
31+
"node": ">=12.0"
32+
},
2033
"dependencies": {
2134
"node-fetch": "^2.6.1"
2235
}

0 commit comments

Comments
 (0)