UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

28 lines (22 loc) 1.06 kB
const pluralize = require('pluralize'), { models: { Selection } } = require('../emporium'), { getStorable, grGreen, parse, prettyPrint } = require('../helpers'), { spinner } = require('../refs') module.exports = async ({ Model, resource, id, attributes }) => { if (pluralize.isPlural(resource)) resource = pluralize.singular(resource) spinner.text = `updating ${grGreen(resource)}` spinner.start() let object = new Model() if (attributes) { attributes = parse(attributes) } else { attributes = {} } attributes.id = id const selections = await Selection.get() for (const selection of selections) if (!Object.keys(attributes).includes(`${selection.resource}_id`) && Object.keys(object).includes(`${selection.resource}_id`)) attributes[`${selection.resource}_id`] = selection.object.id object = await Model.update(attributes) for (const key of Object.keys(attributes)) if (key !== 'id') spinner.info(`${key}: ${attributes[key]}`) spinner.succeed(`updated ${grGreen(resource)} ${id}`).stop() prettyPrint(object) }