sync-algolia.js 817 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
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'
) {
Cole Bemis's avatar
Cole Bemis committed
11
  console.log('Syncing Algolia records...');
12
  syncAlgolia();
13
} else {
Cole Bemis's avatar
Cole Bemis committed
14
  console.log('Skipped Algolia sync.');
15 16 17 18 19 20 21 22 23 24 25 26 27 28
}

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;
29
    console.log(content);
30

31 32 33 34
    index.addObjects(records, (err, content) => {
      if (err) throw err;
      console.log(content);
    });
35 36
  });
}