build: Add logs to sync-algolia script

This commit is contained in:
Cole Bemis 2018-05-18 17:41:39 -07:00
parent 01698dea84
commit b424fa779d

View File

@ -18,32 +18,32 @@ function syncAlgolia() {
// ALGOLIA_ADMIN_KEY must be added as an environment variable in Travis CI // ALGOLIA_ADMIN_KEY must be added as an environment variable in Travis CI
const client = algolia(ALGOLIA_APP_ID, process.env.ALGOLIA_ADMIN_KEY); const client = algolia(ALGOLIA_APP_ID, process.env.ALGOLIA_ADMIN_KEY);
// Initialize the target and temporary indexes console.log('Initializing target and temporary indexes...');
const index = client.initIndex('icons'); const index = client.initIndex('icons');
const indexTmp = client.initIndex('icons_tmp'); const indexTmp = client.initIndex('icons_tmp');
// Copy the settings, synonyms and rules (but not the records) console.log('Copying target index into temporary index...');
// of the target index into the temporary index client.copyIndex(
client.copyIndex(index.indexName, indexTmp.indexName, [ index.indexName,
'settings', indexTmp.indexName,
'synonyms', ['settings', 'synonyms', 'rules'],
'rules', err => {
]); if (err) throw err;
},
);
// Push data to the temporary index
const records = Object.keys(icons).map(name => ({ const records = Object.keys(icons).map(name => ({
name, name,
tags: tags[name] || [], tags: tags[name] || [],
})); }));
indexTmp.addObjects(records, (err, content) => { console.log('Pushing data to the temporary index...');
indexTmp.addObjects(records, err => {
if (err) throw err; if (err) throw err;
console.log(content);
}); });
// Move the temporary index to the target index console.log('Moving temporary index to target index...');
client.moveIndex(indexTmp.indexName, index.indexName, (err, content) => { client.moveIndex(indexTmp.indexName, index.indexName, err => {
if (err) throw err; if (err) throw err;
console.log(content);
}); });
} }