Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wpdas committed Mar 28, 2024
1 parent 2e4be24 commit 7b6a787
Show file tree
Hide file tree
Showing 15 changed files with 2,069 additions and 279 deletions.
17 changes: 15 additions & 2 deletions lib/actions/loadFilesInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const fs = require("fs");
const helpers = require("../helpers");
const { removeComments } = require("../parse");
const handleNames = require("./handleNames");
const removeCommentsFromTSX = require("../parsers/removeCommentsFromTSX");

/**
* To be like:
Expand Down Expand Up @@ -47,9 +48,21 @@ const processFileSchema = (filePath) => {
let fileContent = fs.readFileSync(filePath, "utf8");

// Remove comments from file
fileContent = removeComments(fileContent);

// INFO: Esta sendo usado para remover comentários de arquivos jsx também
fileContent = removeCommentsFromTSX(fileContent);
// fileContent = removeComments(fileContent);
// removeCommentsFromTSX
// console.log("FIM - FILE", filePath);

// if (fileContent.includes("Footer") && !fileContent.includes("App")) {
// console.log("CHEEECKKIIII:", fileContent);
// throw new Error("OI");
// }

// console.log("A");
// TODO: verificar se esta pegando imports de comentários
const fileImportsPath = helpers.getImportsPath(fileContent);
// console.log("B");
// const fileImportsElements = helpers.getFileImportsElements(fileContent);

// console.log("\n\n");
Expand Down
28 changes: 2 additions & 26 deletions lib/actions/processChildrenWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,12 @@ function removeEndCharacter(text, endChar) {
* @param {string} htmlContent
*/
const processChildrenWidget = (htmlContent, fileSchemas) => {
console.log("WIDGETS =========");
console.log("CHILD htmlContent:", htmlContent);
const componentElements = extractTopLevelJSXElements(htmlContent);
console.log("CHILD elements:", componentElements);
const finalElements = [];

// Pega cada elemnto JSX dentro do htmlContent
componentElements.forEach((htmlElement) => {
const componentElementName = getHtmlElementName(htmlElement);
console.log("CHILD: element name:", componentElementName);

// Evita processar um elemento mais de uma vez
// if (!processedFiles.includes(componentElementName)) {
// processedFiles.push(componentElementName);

const componentSchema = fileSchemas.find(
(item) => item.widgetName === componentElementName,
Expand All @@ -58,11 +50,10 @@ const processChildrenWidget = (htmlContent, fileSchemas) => {
// for um componente stateful
if (componentSchema && !componentSchema.isModule) {
let childProps = extractPropsFromJSX(htmlElement);
console.log("CHILD: props:", childProps);

let childChildren = extractJSXChildren(htmlElement);
console.log("CHILD: children:", childChildren);
// Se tiver child dentro deste child (childChildren), chama essa mesma função recursivamente
// INFO: Se tiver child dentro deste child (childChildren), chama essa mesma função recursivamente?
// ja esta sendo feito pelo "transformSchemaToWidgets"
// TODO:
if (childChildren) {
// childChildren = processChildrenWidget(childChildren, fileSchemas);
Expand All @@ -71,10 +62,8 @@ const processChildrenWidget = (htmlContent, fileSchemas) => {

const importItemPropsStringSequence =
convertObjectToArray(childProps).join(",");
console.log("CHILD: array props joint:", importItemPropsStringSequence);

htmlElement = `const TempMethod = () => { return ${htmlElement} \n}`;
console.log("CHILD: html element Babel bundle:", htmlElement);

htmlElement = replaceJSXElement(
htmlElement,
Expand All @@ -89,17 +78,9 @@ const processChildrenWidget = (htmlContent, fileSchemas) => {
"",
);

console.log("CHILD: converted to widget:", htmlElement);

htmlElement = removeLastLineFromText(htmlElement);
htmlElement = removeEndCharacter(htmlElement, "\n");
htmlElement = removeEndCharacter(htmlElement, ";");

// TODO: talvez tenha que remover o ";" no final

console.log("CHILD: converted to widget:", htmlElement);
// htmlContent.push(htmlContent);
// }
}

finalElements.push(htmlElement);
Expand All @@ -108,12 +89,7 @@ const processChildrenWidget = (htmlContent, fileSchemas) => {
// Filtra o array final para ter somente os items presentes no
// array de elementos iniciais + Widgets.

console.log("CHILD Elements:", componentElements);
console.log("CHILD Final Elements:", finalElements);
console.log("\n");

const finalChildrenHtmlContent = `<>\n${finalElements.join("\n")}\n</>`;
console.log("FINAL:", finalChildrenHtmlContent);
return finalChildrenHtmlContent;
};

Expand Down
Loading

0 comments on commit 7b6a787

Please sign in to comment.