feather/bin/sync-algolia.js

37 lines
817 B
JavaScript
Raw Normal View History

2018-05-18 07:51:49 +03:00
import algolia from 'algoliasearch';
import icons from '../dist/icons.json';
import tags from '../src/tags.json';
const ALGOLIA_APP_ID = '5EEOG744D0';
if (
process.env.TRAVIS_PULL_REQUEST === 'false' &&
process.env.TRAVIS_BRANCH === 'master'
) {
2018-05-18 08:42:08 +03:00
console.log('Syncing Algolia records...');
2018-05-18 07:51:49 +03:00
syncAlgolia();
} else {
2018-05-18 08:42:08 +03:00
console.log('Skipped Algolia sync.');
2018-05-18 07:51:49 +03:00
}
function syncAlgolia() {
const client = algolia(ALGOLIA_APP_ID, process.env.ALGOLIA_ADMIN_KEY);
const index = client.initIndex('icons');
const records = Object.keys(icons).map(name => ({
name,
tags: tags[name] || [],
}));
index.clearIndex((err, content) => {
if (err) throw err;
2018-05-18 08:43:41 +03:00
console.log(content);
2018-05-18 07:51:49 +03:00
index.addObjects(records, (err, content) => {
if (err) throw err;
console.log(content);
});
2018-05-18 07:51:49 +03:00
});
}