cimpress-translations-cli
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -1,35 +0,7 @@ | ||
'use strict'; | ||
"use strict"; | ||
var exec = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { | ||
var token; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
log('Retrieving Auth0 token...'); | ||
_context.next = 3; | ||
return getAccessToken(program.clientId, program.clientSecret); | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
case 3: | ||
token = _context.sent; | ||
_context.next = 6; | ||
return downloadTranslations(token, program); | ||
case 6: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function exec() { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
var program = require('commander'); | ||
@@ -40,19 +12,53 @@ | ||
var getAccessToken = require("./tools/accessToken").getAccessToken; | ||
var downloadTranslations = require("./tools/translations").downloadTranslations; | ||
var printError = require("./tools/helpers").printError; | ||
var log = require("./tools/helpers").log; | ||
program.version(packageInfo.version).option('-a, --application-id <id>', 'Cimpress Translation Application ID (as defined in https://translations.cimpress.io').option('-c, --client-id <id>', 'Auth0 Client ID').option('-s, --client-secret <secret>', 'Auth0 Client Secret').option('-t, --translations-file <filepath>', 'File where a single file with all languages is created.').parse(process.argv); | ||
program.on('--help', function () {}); | ||
if (!program.applicationId || !program.clientId || !program.clientSecret || !program.translationsFile) { | ||
printError('Not all required parameters have been provided'); | ||
program.outputHelp(); | ||
process.exit(1); | ||
printError('Not all required parameters have been provided'); | ||
program.outputHelp(); | ||
process.exit(1); | ||
} | ||
function exec() { | ||
return _exec.apply(this, arguments); | ||
} | ||
function _exec() { | ||
_exec = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee() { | ||
var token; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
log('Retrieving Auth0 token...'); | ||
_context.next = 3; | ||
return getAccessToken(program.clientId, program.clientSecret); | ||
case 3: | ||
token = _context.sent; | ||
_context.next = 6; | ||
return downloadTranslations(token, program); | ||
case 6: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return _exec.apply(this, arguments); | ||
} | ||
exec().catch(function (e) { | ||
printError(e); | ||
process.exit(1); | ||
printError(e); | ||
process.exit(1); | ||
}); |
@@ -1,41 +0,47 @@ | ||
'use strict'; | ||
"use strict"; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var axios = require('axios'); | ||
var getAccessToken = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(clientId, clientSecret) { | ||
var response; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return axios.post('https://cimpress.auth0.com/oauth/token', { | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
audience: 'https://api.cimpress.io/', | ||
grant_type: 'client_credentials' | ||
}); | ||
var getAccessToken = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(clientId, clientSecret) { | ||
var response; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return axios.post('https://cimpress.auth0.com/oauth/token', { | ||
client_id: clientId, | ||
client_secret: clientSecret, | ||
audience: 'https://api.cimpress.io/', | ||
grant_type: 'client_credentials' | ||
}); | ||
case 2: | ||
response = _context.sent; | ||
return _context.abrupt('return', response.data.access_token); | ||
case 2: | ||
response = _context.sent; | ||
return _context.abrupt("return", response.data.access_token); | ||
case 4: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, undefined); | ||
})); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function getAccessToken(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
return function getAccessToken(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
module.exports = { | ||
getAccessToken: getAccessToken | ||
getAccessToken: getAccessToken | ||
}; |
@@ -1,34 +0,34 @@ | ||
'use strict'; | ||
"use strict"; | ||
// eslint-disable-next-line | ||
var log = function log(m, a) { | ||
return console.log('[translations-cli]', m, a || ''); | ||
}; | ||
return console.log('[translations-cli]', m, a || ''); | ||
}; // eslint-disable-next-line | ||
// eslint-disable-next-line | ||
var error = function error(m, a) { | ||
return console.error('[translations-cli]', m, a || ''); | ||
return console.error('[translations-cli]', m, a || ''); | ||
}; | ||
var printError = function printError(e) { | ||
var printed = false; | ||
var printed = false; | ||
if (e && e.message) { | ||
error('Message: ', e.message); | ||
printed = true; | ||
} | ||
if (e && e.message) { | ||
error('Message: ', e.message); | ||
printed = true; | ||
} | ||
if (e && e.response) { | ||
error('Response status: ', e.response.status + ' ' + e.response.statusText); | ||
printed = true; | ||
} | ||
if (e && e.response) { | ||
error('Response status: ', e.response.status + ' ' + e.response.statusText); | ||
printed = true; | ||
} | ||
if (!printed) { | ||
error(e); | ||
} | ||
if (!printed) { | ||
error(e); | ||
} | ||
}; | ||
module.exports = { | ||
log: log, | ||
printError: printError | ||
log: log, | ||
printError: printError | ||
}; |
@@ -1,6 +0,9 @@ | ||
'use strict'; | ||
"use strict"; | ||
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
@@ -12,59 +15,56 @@ | ||
var downloadTranslations = function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(token, params) { | ||
var translationClient, description, languagePromises, translations; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
translationClient = new CimpressTranslationsClient(null, 'Bearer ' + token); | ||
var downloadTranslations = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(token, params) { | ||
var translationClient, description, languagePromises, translations; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
translationClient = new CimpressTranslationsClient(null, "Bearer ".concat(token)); | ||
log("Retrieving service ".concat(params.applicationId, " description...")); | ||
_context.next = 4; | ||
return translationClient.describeService(params.applicationId); | ||
case 4: | ||
description = _context.sent; | ||
log("Retrieving service ".concat(params.applicationId, " description... DONE. Found languages: ").concat(JSON.stringify(description.languages.map(function (s) { | ||
return s.blobId; | ||
})))); | ||
languagePromises = []; | ||
translations = {}; | ||
description.languages.forEach(function (lang) { | ||
log("Retrieving language translation for ".concat(lang.blobId)); | ||
languagePromises.push(translationClient.getLanguageBlob(params.applicationId, lang.blobId).then(function (blob) { | ||
return translations[blob.blobId] = blob.data; | ||
})); | ||
}); | ||
_context.next = 11; | ||
return Promise.all(languagePromises); | ||
log('Retrieving service ' + params.applicationId + ' description...'); | ||
_context.next = 4; | ||
return translationClient.describeService(params.applicationId); | ||
case 11: | ||
if (!fs.existsSync(path.dirname(params.translationsFile))) { | ||
log('Creating translations folder...'); | ||
fs.mkdirSync(path.dirname(params.translationsFile)); | ||
} | ||
case 4: | ||
description = _context.sent; | ||
log("Storing translations into ".concat(params.translationsFile)); | ||
fs.writeFileSync(params.translationsFile, JSON.stringify(translations, null, 4)); | ||
case 14: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
log('Retrieving service ' + params.applicationId + ' description... DONE. Found languages: ' + JSON.stringify(description.languages.map(function (s) { | ||
return s.blobId; | ||
}))); | ||
languagePromises = []; | ||
translations = {}; | ||
description.languages.forEach(function (lang) { | ||
log('Retrieving language translation for ' + lang.blobId); | ||
languagePromises.push(translationClient.getLanguageBlob(params.applicationId, lang.blobId).then(function (blob) { | ||
return translations[blob.blobId] = blob.data; | ||
})); | ||
}); | ||
_context.next = 11; | ||
return Promise.all(languagePromises); | ||
case 11: | ||
if (!fs.existsSync(path.dirname(params.translationsFile))) { | ||
log('Creating translations folder...'); | ||
fs.mkdirSync(path.dirname(params.translationsFile)); | ||
} | ||
log('Storing translations into ' + params.translationsFile); | ||
fs.writeFileSync(params.translationsFile, JSON.stringify(translations, null, 4)); | ||
case 14: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, undefined); | ||
})); | ||
return function downloadTranslations(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
return function downloadTranslations(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
module.exports.downloadTranslations = downloadTranslations; |
{ | ||
"name": "cimpress-translations-cli", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A simple client to retrieve translations in CI environment", | ||
@@ -10,3 +10,3 @@ "main": "./lib/index.js", | ||
"scripts": { | ||
"build": "node ./node_modules/babel-cli/bin/babel.js src -d lib", | ||
"build": "babel src -d lib", | ||
"code-check": "eslint --ext .js --ext .jsx src" | ||
@@ -34,7 +34,6 @@ }, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-env": "^2.4.1", | ||
"babel-plugin-transform-runtime": "^6.23.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-preset-env": "^1.7.0", | ||
"@babel/cli": "^7.1.2", | ||
"@babel/core": "^7.1.2", | ||
"@babel/plugin-transform-runtime": "^7.1.0", | ||
"@babel/preset-env": "^7.1.0", | ||
"eslint": "^5.6.1" | ||
@@ -41,0 +40,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
169
10934