Skip to content

Commit b82e9c5

Browse files
author
Helehelehele
committed
Add publishing-screens example
1 parent 5a680f5 commit b82e9c5

File tree

6 files changed

+289
-0
lines changed

6 files changed

+289
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Check out the [API documentation](https://docs.zeplin.dev/reference) for complet
7070

7171
- [Command-line app using personal access token](./examples/cli-with-personal-access-token)
7272
- [Simple OAuth application](./examples/oauth-app)
73+
- [Publishing screens and screen versions](./examples/publishing-screens)
7374

7475
## License
7576

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# dependencies
2+
/node_modules
3+
4+
# misc
5+
.DS_Store
6+
7+
# debug
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
45.3 KB
Loading
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const fetch = require("node-fetch");
4+
const { ZeplinApi, Configuration } = require("@zeplin/sdk");
5+
6+
const accessToken = process.env.ZEPLIN_ACCESS_TOKEN;
7+
const projectId = process.env.ZEPLIN_PROJECT_ID;
8+
9+
const configuration = new Configuration({ accessToken });
10+
11+
const zeplinApi = new ZeplinApi(configuration);
12+
13+
const imagePath = path.resolve("image.png");
14+
15+
// Create a screen by publishing a local image file to the Zeplin project.
16+
zeplinApi.screens.createScreen(projectId, {
17+
name: "My Screen",
18+
image: {
19+
file: fs.createReadStream(imagePath),
20+
type: "png"
21+
},
22+
commitMessage: "Initial commit"
23+
}).then(response => {
24+
const { data: { id } } = response;
25+
26+
return id;
27+
}).then(screenId => {
28+
console.log(`Created screen with id: ${screenId}`);
29+
30+
return fetch("https://placekitten.com/400/320")
31+
.then(resp => resp.buffer())
32+
.then(buffer => {
33+
// Create a new version for the screen we just created.
34+
return zeplinApi.screens.createScreenVersion(projectId, screenId, {
35+
image: {
36+
file: buffer,
37+
type: "png"
38+
},
39+
commitMessage: "Secondary commit"
40+
});
41+
});
42+
}).then(response => {
43+
const { data: { id } } = response;
44+
45+
return id;
46+
}).then(versionId =>
47+
console.log(`Created screen version with id: ${versionId}`)
48+
).catch(err => console.log(err));

examples/publishing-screens/package-lock.json

Lines changed: 215 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "publishing-screens",
3+
"private": true,
4+
"version": "0.0.0",
5+
"description": "Example for publish screens to Zeplin",
6+
"main": "index.js",
7+
"scripts": {
8+
"start": "node index.js"
9+
},
10+
"license": "MIT",
11+
"dependencies": {
12+
"@zeplin/sdk": "latest",
13+
"node-fetch": "^2.6.1"
14+
}
15+
}

0 commit comments

Comments
 (0)