UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

152 lines (145 loc) 5.53 kB
const Table = require('tabley'), { models: { Container, Unit } } = require('@gameroom/kit'), { join, resolve } = require('path'), { dateAddDays, dateLocaleString, dateString, grGreen, printTable, writeCSVFile } = require('../../helpers'), { spinner } = require('../../refs') const autoPriced = p => p.properties.auto_price === 'true' const lastProps = p => Object.keys(p.properties).filter(k => k.startsWith('last_')).length const sum = (t, p) => t += p module.exports = async ({ products, write }) => { if (write === true) write = '.' spinner.text = `generating ${grGreen('auto priced')} report` spinner.start() const repriced_products = products.filter(autoPriced) const meta = [{ system: 'Total', total_products: products.length, repriced_products: repriced_products.length, updated_prices: repriced_products.map(lastProps).reduce(sum) }] const rows = [] // ps4 const ps4 = products.filter(p => p.tags.includes('PS4')) if (ps4.length > 0) rows.push({ system: 'PS4', total_products: ps4.length, repriced_products: ps4.filter(autoPriced).length, updated_prices: ps4.filter(autoPriced).map(lastProps).reduce(sum) }) // xbox one const xbox_one = products.filter(p => p.tags.includes('Xbox One')) if (xbox_one.length > 0) rows.push({ system: 'Xbox One', total_products: xbox_one.length, repriced_products: xbox_one.filter(autoPriced).length, updated_prices: xbox_one.filter(autoPriced).map(lastProps).reduce(sum) }) // switch const switch_products = products.filter(p => p.tags.includes('Switch')) if (switch_products.length > 0) rows.push({ system: 'Switch', total_products: switch_products.length, repriced_products: switch_products.filter(autoPriced).length, updated_prices: switch_products.filter(autoPriced).map(lastProps).reduce(sum) }) // wii-u const wii_u = products.filter(p => p.tags.includes('Wii U')) if (wii_u.length > 0) rows.push({ system: 'Wii U', total_products: wii_u.length, repriced_products: wii_u.filter(autoPriced).length, updated_prices: wii_u.filter(autoPriced).map(lastProps).reduce(sum) }) // ps3 const ps3 = products.filter(p => p.tags.includes('PS3')) if (ps3.length > 0) rows.push({ system: 'PS3', total_products: ps3.length, repriced_products: ps3.filter(autoPriced).length, updated_prices: ps3.filter(autoPriced).map(lastProps).reduce(sum) }) // xbox-360 const xbox_360 = products.filter(p => p.tags.includes('Xbox 360')) if (xbox_360.length > 0) rows.push({ system: 'Xbox 360', total_products: xbox_360.length, repriced_products: xbox_360.filter(autoPriced).length, updated_prices: xbox_360.filter(autoPriced).map(lastProps).reduce(sum) }) // wii const wii = products.filter(p => p.tags.includes('Wii')) if (wii.length > 0) rows.push({ system: 'Wii', total_products: wii.length, repriced_products: wii.filter(autoPriced).length, updated_prices: wii.filter(autoPriced).map(lastProps).reduce(sum) }) // ps2 const ps2 = products.filter(p => p.tags.includes('PS2')) if (ps2.length > 0) rows.push({ system: 'PS2', total_products: ps2.length, repriced_products: ps2.filter(autoPriced).length, updated_prices: ps2.filter(autoPriced).map(lastProps).reduce(sum) }) // xbox const xbox = products.filter(p => p.tags.includes('Xbox')) if (xbox.length > 0) rows.push({ system: 'Xbox', total_products: xbox.length, repriced_products: xbox.filter(autoPriced).length, updated_prices: xbox.filter(autoPriced).map(lastProps).reduce(sum) }) // gamecube const gamecube = products.filter(p => p.tags.includes('Gamecube')) if (gamecube.length > 0) rows.push({ system: 'Gamecube', total_products: gamecube.length, repriced_products: gamecube.filter(autoPriced).length, updated_prices: gamecube.filter(autoPriced).map(lastProps).reduce(sum) }) // ps1 const ps1 = products.filter(p => p.tags.includes('PS1')) if (ps1.length > 0) rows.push({ system: 'PS1', total_products: ps1.length, repriced_products: ps1.filter(autoPriced).length, updated_prices: ps1.filter(autoPriced).map(lastProps).reduce(sum) }) // dreamcast const dreamcast = products.filter(p => p.tags.includes('Dreamcast')) if (dreamcast.length > 0) rows.push({ system: 'Dreamcast', total_products: dreamcast.length, repriced_products: dreamcast.filter(autoPriced).length, updated_prices: dreamcast.filter(autoPriced).map(lastProps).reduce(sum) }) // sega-cd const sega_cd = products.filter(p => p.tags.includes('Sega CD')) if (sega_cd.length > 0) rows.push({ system: 'Sega CD', total_products: sega_cd.length, repriced_products: sega_cd.filter(autoPriced).length, updated_prices: sega_cd.filter(autoPriced).map(lastProps).reduce(sum) }) // saturn const saturn = products.filter(p => p.tags.includes('Saturn')) if (saturn.length > 0) rows.push({ system: 'Saturn', total_products: saturn.length, repriced_products: saturn.filter(autoPriced).length, updated_prices: saturn.filter(autoPriced).map(lastProps).reduce(sum) }) const table = new Table(rows, { title: grGreen('container units report'), meta, align: 'center', margin: 4 }) if (write) await writeCSVFile(join(resolve(write), 'container-units-report.csv'), [...rows, ...meta]) spinner.stop() console.log() table.print() console.log() spinner.succeed(`generated ${grGreen('auto priced')} report`) }