UNPKG

i18nexus-cli

Version:

Command line interface (CLI) for accessing the i18nexus API

43 lines (35 loc) 1.03 kB
const colors = require('colors'); const handleError = require('../handleError'); const handleFetch = require('../handleFetch'); const baseUrl = require('../baseUrl'); const addString = async opt => { let url = `${baseUrl}/project_resources/base_strings.json`; url += `?api_key=${opt.apiKey}`; const response = await handleFetch(url, { method: 'POST', body: JSON.stringify({ key: opt.key, value: opt.value, namespace: opt.namespace, description: opt.notes, ai_instructions: opt.aiInstructions }), headers: { Authorization: `Bearer ${opt.pat}`, 'Content-Type': 'application/json' } }); if (response.status !== 200) { return handleError(response); } await response.json(); if (opt.namespace) { console.log( colors.green(`New string added to namespace "${opt.namespace}":`) ); } else { console.log(colors.green(`New string added:`)); } console.log(colors.green(`"${opt.key}": "${opt.value}"`)); }; module.exports = addString;