Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MOB-76 Update logic for exporting copies for JS #63

Open
wants to merge 4 commits into
base: pv/MOB-80-update-dependency-versions
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
MOB-76 Changes based on review suggestions
  • Loading branch information
pankajvaghela committed Feb 6, 2023
commit 9f2b3b67be6d4e4fa047ab82787deeaaf3a028b3
9 changes: 5 additions & 4 deletions src/actions/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { accessiblityKeywords, groupKeywords, outputTypes } = require("../model/k
const { groupByKey } = require("../utils/arrayUtils");
const { flatten } = require("../utils/arrayUtils");
const Handlebars = require("handlebars");
const LodashUpdateWith = require("lodash.updatewith");
const lodashUpdateWith = require("lodash.updatewith");

const percentEncodingPattern = /%(?!\d+{{.}})/;

Expand Down Expand Up @@ -44,7 +44,7 @@ const renderLocalizationView = (view, outputType, language, basePath) => {
return localizationTemplate(outputType)
.map((source) => Handlebars.compile(source))
.map((template) => template(view))
.map((renderedTemplate) => postTemplateRenderFormatting(renderedTemplate, outputType))
.map((renderedTemplate) => formatToJSon(renderedTemplate, outputType))
.map((render) => ({ path: outputPath, data: render }));
};

Expand All @@ -65,13 +65,14 @@ const renderCodeGenView = (view, outputType, basePath) => {
}
};

const postTemplateRenderFormatting = (renderedTemplate, outputType) => {
// Converts 1-1 key mapping to a JSON object
const formatToJSon = (renderedTemplate, outputType) => {
if (outputType === outputTypes.JS) {
// Convert 1-on-1 key mapping to a JSON object
const renderedTemplateAsJSON = JSON.parse(renderedTemplate);
const localizationObject = {};
Object.keys(renderedTemplateAsJSON).forEach((key) => {
LodashUpdateWith(localizationObject, key, () => renderedTemplateAsJSON[key], Object);
lodashUpdateWith(localizationObject, key, () => renderedTemplateAsJSON[key], Object);
});

return JSON.stringify(localizationObject, null, 2);
Expand Down