i18nexus-cli
Version:
Command line interface (CLI) for accessing the i18nexus API
57 lines (45 loc) • 1.39 kB
JavaScript
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}`;
let resetConfirmed;
if (opt.resetConfirmed) {
resetConfirmed = true;
}
if (opt.retainConfirmed) {
resetConfirmed = false;
}
if (opt.resetConfirmed && opt.retainConfirmed) {
resetConfirmed = undefined;
}
const response = await handleFetch(url, {
method: 'PATCH',
body: JSON.stringify({
id: opt.id,
key: opt.key,
value: opt.value,
namespace: opt.namespace,
description: opt.notes,
ai_instructions: opt.aiInstructions,
reset_confirmed: resetConfirmed
}),
headers: {
Authorization: `Bearer ${opt.pat}`,
'Content-Type': 'application/json'
}
});
if (response.status !== 200) {
return handleError(response, null, message => {
if (message.includes('reset_confirmed')) {
return 'This string contains confirmed translations. To update this string, run this command again with either --reset-confirmed or --retain-confirmed.';
}
return message;
});
}
await response.json();
console.log(colors.green('Updated string'));
};
module.exports = addString;