UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

41 lines (38 loc) 2.16 kB
const cosmetic = require('cosmetic'), { Google } = require('../models'), { csvBuffer, extractHTMLText, getAdvertised, grGreen, uploadGoogleFeeds } = require('../helpers'), { models: { Unit_Extended } } = require('@gameroom/kit'), { google_product_categories, spinner } = require('../refs') module.exports = async ({ path }) => { if (!process.env.GOOGLE_FTP_USERNAME || !process.env.GOOGLE_FTP_PASSWORD) throw new Error('Missing Google FTP credentials') const google = `${cosmetic.xterm(27)('g')}${cosmetic.xterm(196)('o')}${cosmetic.yellow('o')}${cosmetic.xterm(27)('g')}${cosmetic.green('l')}${cosmetic.xterm(196)('e')}` spinner.info(`updating ${google} merchant feeds @ ${new Date().toLocaleString()}`) spinner.text = `getting ${grGreen('units')} for ${google} merchant feeds` const unit_extendeds = await getAdvertised() spinner.info(`got ${unit_extendeds.length} ${grGreen('units')}`) spinner.text = `generating ${google} merchant feeds` const google_products = [] const google_inventory = [] const added = {} for (const unit of unit_extendeds) { // product feed const product = Google.Product.fromUnitExtended(unit) // only one per product id if (!added[unit.product_id]) added[unit.product_id] = [] if (!added[unit.product_id].includes(product.title)) { added[unit.product_id].push(product.title) google_products.push(product) // inventory feed // only lincoln and omaha storefronts if (unit.store_id !== '505f56ba-d014-4b94-b43f-12212faa7d6a' && unit.store_id !== '1df88fbc-bd52-4a79-a14d-f896f668a228') continue const inventory = Google.Inventory.fromUnitExtended(unit) google_inventory.push(inventory) } } // upload spinner.text = `uploading ${google_products.length} products and ${google_inventory.length} inventory to ${google} merchant feeds` const products = await csvBuffer(google_products) const inventory = await csvBuffer(google_inventory) await uploadGoogleFeeds({ products, inventory }) spinner.succeed(`uploaded ${google_products.length} products and ${google_inventory.length} inventory to ${google} merchant feeds`).stop() }