const Factory = require('../factory') const Utils = require('./utils') // // Initialize the child logger for // the module // const log = require('../log').child({ module: 'custom emoji' }) module.exports = async function (context) { const collection = context.rocketchat.emojiCollection() const fileCollection = context.rocketchat.collection('custom_emoji') const cursor = collection.find() while (await cursor.hasNext()) { const result = await cursor.next() const filename = `${result.name}.${result.extension}` const dest = `${context.config.target.filesPath}/custom_emoji/${filename}` try { const srcFilename = Utils.srcPath(context.config.source.customEmojiPath, filename) if (srcFilename) { Utils.copyFile(srcFilename, dest) } else { await Utils.downloadGridFSByName(context, fileCollection, filename, dest) } log.info(`... copied ${result.name}`) } catch (err) { log.warn(`... skipping emoji "${result.name}": ${err.message}`) } } return context }