UNPKG

@gameroom/cli

Version:

A command line tool for Gameroom

29 lines (21 loc) 945 B
const pluralize = require('pluralize'), { models: { Selection } } = require('../emporium'), { getStorable, grGreen, parse, prettyPrint } = require('../helpers'), { spinner } = require('../refs') module.exports = async ({ Model, resource, attributes }) => { if (pluralize.isPlural(resource)) resource = pluralize.singular(resource) spinner.text = `creating ${grGreen(resource)}` spinner.start() if (attributes) { attributes = parse(attributes) } else { attributes = {} } let object = new Model() const selections = await Selection.get() for (const selection of selections) if (Object.keys(object).includes(`${selection.resource}_id`)) attributes[`${selection.resource}_id`] = selection.object.id for (const key of Object.keys(attributes)) spinner.info(`${key}: ${attributes[key]}`) object = await Model.create(attributes) spinner.succeed(`created ${grGreen(resource)}`).stop() prettyPrint(object) }