UNPKG

@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

87 lines 3.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createNodesV2 = void 0; exports.normalizeOptions = normalizeOptions; const tslib_1 = require("tslib"); const workspace_utilities_1 = require("@rxap/workspace-utilities"); const path_1 = require("path"); require("colors"); function normalizeOptions(options) { return options !== null && options !== void 0 ? options : {}; } exports.createNodesV2 = [ '**/localazy.json', (configFilePaths, options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const normalizedOptions = normalizeOptions(options); const includedConfigFilePaths = yield Promise.all(configFilePaths.map((configFilePath) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { if (yield shouldHaveProjectConfiguration(configFilePath, normalizedOptions, context)) { return configFilePath; } return undefined; }))).then((configFilePathOrUndefinedList) => configFilePathOrUndefinedList.filter((value) => value !== undefined)); const results = yield Promise.all(includedConfigFilePaths.map((configFilePath) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const [projectPath, projectConfiguration] = yield createProjectConfiguration(configFilePath, normalizedOptions, context); return [configFilePath, projectPath, projectConfiguration]; }))); return results.map(([configFilePath, projectPath, projectConfiguration]) => [ configFilePath, { projects: { [projectPath]: projectConfiguration, }, }, ]); }), ]; function shouldHaveProjectConfiguration(configFilePath, options, context) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const projectPath = (0, path_1.dirname)(configFilePath); const tree = new workspace_utilities_1.FsTree(context.workspaceRoot); if (!(0, workspace_utilities_1.FindProjectByPath)(tree, projectPath)) { // console.log(`The folder of the file '${ configFilePath }' is not the root of a project. Skipping`.yellow); return false; } return true; }); } function createProjectConfiguration(configFilePath, options, context) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const projectPath = (0, path_1.dirname)(configFilePath); const targets = {}; const tree = new workspace_utilities_1.FsTree(context.workspaceRoot); const projectConfiguration = (0, workspace_utilities_1.FindProjectByPath)(tree, projectPath); if (!projectConfiguration) { throw new Error(`Could not find project in '${projectPath}'`); } targets['localazy-download'] = createLocalazyDownloadTarget(projectPath); targets['localazy-upload'] = createLocalazyUploadTarget(); return [ projectPath, { targets, }, ]; }); } function createLocalazyDownloadTarget(projectPath) { return { executor: '@rxap/plugin-localazy:download', inputs: [ { env: 'CI_COMMIT_SHA', }, ], outputs: ['{projectRoot}/src/i18n'], cache: true, options: { workingDirectory: projectPath, }, }; } function createLocalazyUploadTarget() { return { executor: '@rxap/plugin-localazy:upload', dependsOn: ['extract-i18n'], inputs: ['{projectRoot}/src/i18n/messages.xlf'], }; } //# sourceMappingURL=plugin.js.map