@rxap/plugin-localazy
Version:
This package provides executors and generators for integrating Localazy, a translation management platform, into Nx workspaces. It allows for downloading and uploading translations, managing configuration, and initializing Localazy within a project. The p
162 lines • 6.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = runExecutor;
const tslib_1 = require("tslib");
const plugin_utilities_1 = require("@rxap/plugin-utilities");
const workspace_utilities_1 = require("@rxap/workspace-utilities");
const process = require("process");
const get_auto_tag_1 = require("../../lib/get-auto-tag");
const load_keys_from_file_1 = require("../../lib/load-keys-from-file");
const normalize_tag_1 = require("../../lib/normalize-tag");
function runExecutor(options, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g;
if (process.env.LOCALAZY_WRITE_KEY) {
options.writeKey = process.env.LOCALAZY_WRITE_KEY;
}
if (process.env.LOCALAZY_READ_KEY) {
options.readKey = process.env.LOCALAZY_READ_KEY;
}
const projectConfiguration = (0, plugin_utilities_1.GetProjectConfiguration)(context);
const downloadTarget = (0, workspace_utilities_1.GetTarget)(projectConfiguration, 'localazy-download');
const downloadTargetOptions = (0, workspace_utilities_1.GetTargetOptions)(downloadTarget, context.configurationName);
(_a = options.readKey) !== null && _a !== void 0 ? _a : (options.readKey = downloadTargetOptions.readKey);
(_b = options.writeKey) !== null && _b !== void 0 ? _b : (options.writeKey = downloadTargetOptions.writeKey);
(_c = options.configJson) !== null && _c !== void 0 ? _c : (options.configJson = downloadTargetOptions.configJson);
(_d = options.workingDirectory) !== null && _d !== void 0 ? _d : (options.workingDirectory = downloadTargetOptions.workingDirectory);
(_e = options.keysJson) !== null && _e !== void 0 ? _e : (options.keysJson = downloadTargetOptions.keysJson);
if (!options.readKey || !options.writeKey) {
const fromFile = (0, load_keys_from_file_1.LoadKeysFromFile)(context.projectName);
(_f = options.readKey) !== null && _f !== void 0 ? _f : (options.readKey = fromFile.read);
(_g = options.writeKey) !== null && _g !== void 0 ? _g : (options.writeKey = fromFile.write);
}
if (!options.writeKey) {
console.log('The write key is not set');
if (!process.env.CI) {
console.log('Detecting a non CI environment. Exit with success');
return {
success: true
};
}
return {
success: false,
error: 'Could not find write key',
};
}
if (!options.readKey) {
console.log('The read key is not set');
return {
success: false,
error: 'Could not find read key',
};
}
const args = ['localazy', 'upload'];
if (options.readKey) {
args.push('--read-key ' + options.readKey);
}
if (options.writeKey) {
args.push('--write-key ' + options.writeKey);
}
if (options.configJson) {
args.push('--config "' + options.configJson + '"');
}
if (options.workingDirectory) {
args.push('--working-dir "' + options.workingDirectory + '"');
}
if (options.keysJson) {
args.push('--keys "' + options.keysJson + '"');
}
if (options.version) {
args.push('--app-version ' + options.version);
}
if (options.dryRun) {
args.push('--simulate');
}
if (options.quite) {
args.push('--quiet');
}
if (options.force) {
args.push('--force');
}
if (options.branch) {
args.push(`--branch ${options.branch}`);
}
if (options.param) {
args.push(`--param ${options.param}`);
}
if (options.failOnMissingGroups) {
args.push('--failOnMissingGroups');
}
if (options.project) {
args.push('--project ' + options.project);
}
if (options.async) {
args.push('--async');
}
if (options.disableContentLength) {
args.push('--disable-content-length');
}
try {
yield (0, plugin_utilities_1.YarnRun)(args);
}
catch (e) {
console.error(`Could not run 'localazy upload'`, e.message);
return {
success: false,
error: e.message,
};
}
if (options.autoTag) {
console.log('Get auto tag');
const tag = (0, get_auto_tag_1.GetAutoTag)();
if (tag) {
console.log('Set auto tag', tag);
options.tag = tag;
}
else {
console.log('Could not get auto tag');
}
}
else {
console.log('Skip auto tag');
}
if (options.tag) {
options.tag = (0, normalize_tag_1.NormalizeTag)(options.tag);
try {
const args = ['localazy', 'tag'];
if (options.readKey) {
args.push('--read-key ' + options.readKey);
}
if (options.writeKey) {
args.push('--write-key ' + options.writeKey);
}
if (options.configJson) {
args.push('--config "' + options.configJson + '"');
}
if (options.workingDirectory) {
args.push('--working-dir "' + options.workingDirectory + '"');
}
if (options.keysJson) {
args.push('--keys "' + options.keysJson + '"');
}
args.push('publish', options.tag);
console.log('Publish tag', options.tag);
yield (0, plugin_utilities_1.YarnRun)(args);
}
catch (e) {
console.error(`Could not run 'localazy tag publish ${options.tag}'`, e.message);
return {
success: false,
error: e.message,
};
}
}
else {
console.log('Skip tag publish');
}
return {
success: true,
};
});
}
//# sourceMappingURL=executor.js.map