Skip to content

Commit 95a9ba8

Browse files
author
Sébastien Van Eyck
committed
feat(sync data|INS-499): Allow Frontify patterns synchronization
1 parent c26176a commit 95a9ba8

6 files changed

Lines changed: 38 additions & 5 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Dedicated project files
2+
tmp-frontify
3+
14
!*.keep
25

36
# Created by https://www.gitignore.io/api/osx,linux,windows,sublimetext,sass,less,sublimetext,jetbrains,maven,node,bower,grunt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="test-pattern"></div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.test-pattern {
2+
color: black;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="test-pattern"></div>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.test-pattern {
2+
color: black;
3+
}

src/main.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ var Files = require('./files.service');
1111
var Logger = require('./logger.service');
1212

1313
function init(patternsFolder) {
14-
generatePatterns(patternsFolder);
14+
try {
15+
generatePatterns(patternsFolder);
16+
}
17+
catch(err) {
18+
Logger.error(err);
19+
return;
20+
}
21+
synchronizePatterns();
1522
}
1623

1724

@@ -22,9 +29,7 @@ function generatePatterns(patternsFolder) {
2229
walk(patternsFolder);
2330
var patternsList = Patterns.getList();
2431
if (!patternsList.length) {
25-
var error = "Error: no patterns found";
26-
Logger.error(error);
27-
return;
32+
throw "Error: no patterns found";
2833
}
2934

3035
// Create temp folder
@@ -38,7 +43,7 @@ function generatePatterns(patternsFolder) {
3843
fs.writeFileSync(tmpFolder + '/' + pattern.name + '.json', patternAsString, 'utf8');
3944
});
4045

41-
Logger.success('Created/updated ' + patternsList.length + ' patterns');
46+
Logger.info('Created/updated ' + patternsList.length + ' patterns');
4247
}
4348

4449
/**
@@ -78,6 +83,23 @@ function walk(dir, currentPattern, startPattern) {
7883
});
7984
}
8085

86+
/**
87+
* Synchronize remote Frontify project
88+
*/
89+
function synchronizePatterns() {
90+
var access = {
91+
access_token: "frontify_access_token",
92+
project: "frontify_project_id"
93+
};
94+
frontifyApi.syncPatterns(access, ['tmp-frontify/**/*.json'])
95+
.then(function(data) {
96+
Logger.success('Success: Patterns have been synchronized to Frontify');
97+
})
98+
.catch(function(err) {
99+
Logger.error(err);
100+
});
101+
}
102+
81103
module.exports = {
82104
init: init
83105
};

0 commit comments

Comments
 (0)