UNPKG

3.83 kBMarkdownView Raw
1# Frontify API
2
3Simplifies the creation of UI patterns within Frontify.
4Its a simple brick in your frontend build that handles creating and updating your pattern library.
5
6![Pattern Library Sync](https://cdn.frontify.com/assets/marketing/github/pattern-library-sync.png)
7
8The Frontify API package allows you to use your current project structure as your pattern library master.
9Moreover it gives you granular control over which patterns and code snippets to sync.
10
11> Note: an access token is required to use the API. Please write us an in-app message or [email](mailto:hello@frontify.com) to get one for your project.
12
13## Install
14
15```
16$ npm install --save @frontify/frontify-api
17```
18
19## Usage
20
21```
22var frontifyApi = require('@frontify/frontify-api');
23```
24
25### Scenario 1: "Bootstrap" case
26
27Simply loop over a set of pattern html files. A pattern is created for every matched html file.
28The pattern name is inferred by the name of the file.
29
30```
31frontifyApi.syncPatterns({access_token: '1234', project: 1}, ['patterns/**/*.html']).catch(function(err) {
32 console.error(err);
33});
34```
35
36### Scenario 2: Metadata JSON
37
38Loop over a set of pattern metadata json files. A pattern - and possible variants of a pattern - is created for every matched json file.
39The json file contains all pattern related data
40
41```
42frontifyApi.syncPatterns({access_token: '1234', project: 1}, ['patterns/**/*.json']).catch(function(err) {
43 console.error(err);
44});
45```
46
47#### Sample JSON Structure
48```
49{
50 "name": "Paragraph",
51 "type": "atom",
52 "stability": "stable",
53 "variations": {
54 "lead": {
55 "name": "Lead paragraph",
56 "assets": {
57 "html": [
58 "test/fixtures/patterns/atoms/paragraph/paragraph_lead.html"
59 ],
60 "css": [
61 "test/fixtures/patterns/atoms/paragraph/css/paragraph_lead.css"
62 ]
63 }
64 }
65 },
66 "assets": {
67 "html": [
68 "test/fixtures/patterns/atoms/paragraph/paragraph.html"
69 ],
70 "css": [
71 "test/fixtures/patterns/atoms/paragraph/css/paragraph.css"
72 ]
73 }
74}
75```
76
77## API
78
79### syncPatterns(options, glob-pattern)
80
81Returns a Promise
82
83#### options
84Type: object
85
86Attributes
87* `access_token` (string) - Please write us an in-app message or [email](mailto:hello@frontify.com) to get one for your project
88* `project` (number) - Your project id (we will provide it to you)
89* `dryRun` (boolean) - True = only dry-run your pattern creation to see what would be updated (default = false)
90* `baseUrl` (string) - the base url of your pattern library, e.g. http://yourbrand.frontify.com (default: http://app.frontify.com)
91
92## Advanced Usage
93### Gulp Integration
94
95Simply create a gulp task and you are ready to go.
96
97```
98gulp.task('frontify', function() {
99 frontifyApi.syncPatterns({access_token: '1234', project: 23, baseUrl: 'http://yourbrand.frontify.com'}, ['patterns/**/*.html']).catch(function(err) {
100 console.error(err);
101 });
102});
103```
104
105The Frontify API is a Promise-returning node module. This makes it easy to integrate it in your existing gulp streams by using the [vinyl-paths](https://github.com/sindresorhus/vinyl-paths/) module.
106
107```
108var vinylPaths = require('vinyl-paths');
109var frontifyApi = require('frontify-api');
110
111// sync patterns in the stream
112gulp.task('frontify', function () {
113 return gulp.src('patterns/**/*.html')
114 .pipe(vinylPaths(function(paths) {
115 return frontifyApi.syncPatterns({access_token: '1234', project: 1}, paths).catch(function(err) {
116 console.error(err);
117 });
118 }));
119});
120```
121
122Note that this results in an API call for each pattern. If you experience some performance issues, please refer to the usage above.
123
124### Grunt integration
125
126Simply [create a Grunt task](http://gruntjs.com/creating-tasks) and you are ready to go.
127
128## License
129
130MIT © [Frontify](https://frontify.com/)
\No newline at end of file