Skip to content

Commit 1d3283d

Browse files
committed
build: Add sync-algolia script
1 parent 894dcfd commit 1d3283d

4 files changed

Lines changed: 2022 additions & 1883 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ before_script:
99
- npm prune
1010
script:
1111
- npm start
12+
after_success:
13+
- npx babel-node ./bin/sync-algolia.js
1214
deploy:
1315
provider: script
1416
skip_cleanup: true

bin/sync-algolia.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import algolia from 'algoliasearch';
3+
import icons from '../dist/icons.json';
4+
import tags from '../src/tags.json';
5+
6+
const ALGOLIA_APP_ID = '5EEOG744D0';
7+
8+
if (
9+
process.env.TRAVIS_PULL_REQUEST === 'false' &&
10+
process.env.TRAVIS_BRANCH === 'master'
11+
) {
12+
syncAlgolia();
13+
}
14+
15+
function syncAlgolia() {
16+
const client = algolia(ALGOLIA_APP_ID, process.env.ALGOLIA_ADMIN_KEY);
17+
18+
const index = client.initIndex('icons');
19+
20+
const records = Object.keys(icons).map(name => ({
21+
name,
22+
tags: tags[name] || [],
23+
}));
24+
25+
index.clearIndex((err, content) => {
26+
if (err) throw err;
27+
console.log(content); // eslint-disable-line no-console
28+
});
29+
30+
index.addObjects(records, (err, content) => {
31+
if (err) throw err;
32+
console.log(content); // eslint-disable-line no-console
33+
});
34+
}

0 commit comments

Comments
 (0)