Skip to content

Commit

Permalink
changed the way the ejected files receive their names, it is now addi…
Browse files Browse the repository at this point in the history
…ng the project name first
  • Loading branch information
wpdas committed May 22, 2024
1 parent 395b827 commit 3ff86ba
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions gateway/config/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const envConfig = document.getElementById("env-config").textContent;
const config = JSON.parse(envConfig);

export const flags = {
mainWidgetSrc: config.mainWidgetSrc,
mainWidgetLink: config.mainWidgetLink,
network: process.env.NETWORK || config.network || "mainnet",
bosLoaderUrl:
Expand Down
6 changes: 6 additions & 0 deletions gateway/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ function Home() {
const { components: redirectMap } = useRedirectMap();
const widgets = {};

// Force going to the main widget src (indexer)
if (location.pathname === "/" && flags.mainWidgetSrc) {
navigate(flags.mainWidgetSrc);
return "";
}

Object.keys(redirectMap).forEach((key) => {
const parts = key.split("/widget/");
if (!widgets[parts[0]]) {
Expand Down
10 changes: 8 additions & 2 deletions lib/actions/getProjectName.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
const { read_alem_config } = require("../config");

/**
* Get the project name
* Get the project name based on configuration
* @returns
*/
const getProjectName = () => {
const getProjectName = (skipCheckers = false) => {
const appConfig = read_alem_config();
let projectName = appConfig.name.replaceAll(" ", "-").toLowerCase();

// Se ignorar a checagem do nome final do projeto
if (skipCheckers) {
return projectName;
}

projectName = appConfig.isIndex ? "Index" : projectName;
return appConfig.options?.createLoaderWidget
? `${projectName}Loader`
Expand Down
7 changes: 6 additions & 1 deletion lib/actions/loadFilesContent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const parseAlemFeatures = require("../config/parseAlemFeatures");
const { scapeBacktick } = require("../helpers");
const getProjectName = require("./getProjectName");
const transformSchemaToWidget = require("./transformSchemaToWidget");

/**
Expand Down Expand Up @@ -41,8 +42,12 @@ const loadComponentCodesObjectByFileSchemas = (fileSchemas, network) => {

// Ejectables - Arquivos a serem criado fora do indexador principal
if (fileSchema.toBeEjected) {
// O nome do projeto deve vir na frente para evitar conflitos com outros
// aplicativos publicados na mesma conta
const newWidgetName = `${getProjectName(true)}.${fileSchema.widgetName}`;

ejectedFiles.push({
name: fileSchema.widgetName,
name: newWidgetName,
content: fileSchema.finalFileBundle,
});
}
Expand Down
6 changes: 5 additions & 1 deletion lib/actions/processChildrenWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const extractJSXChildren = require("../parsers/extractJSXChildren");
const extractPropsFromJSX = require("../parsers/extractPropsFromJSX");
const extractTopLevelJSXElements = require("../parsers/extractTopLevelJSXElements");
const replaceJSXElement = require("../parsers/replaceJSXElement");
const getProjectName = require("./getProjectName");

/**
* Usado para remover o endChar do texto se o endChar for a última caractere no texto
Expand Down Expand Up @@ -72,7 +73,10 @@ const processChildrenWidget = (htmlContent, fileSchemas, account) => {
htmlElement = `const TempMethod = () => { return ${htmlElement} \n}`;

if (componentSchema.toBeEjected) {
const src = `"${account}/widget/${componentElementName}"`;
// O nome do projeto deve vir na frente para evitar conflitos com outros
// aplicativos publicados na mesma conta
const newWidgetName = `${getProjectName(true)}.${componentElementName}`;
const src = `"${account}/widget/${newWidgetName}"`;

htmlElement = replaceJSXElement(
htmlElement,
Expand Down
6 changes: 5 additions & 1 deletion lib/actions/transformSchemaToWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const wrapCodeInGetFunction = require("../parsers/wrapCodeInGetFunction");
const getFunctionExportDeclarationKeys = require("../parsers/getFunctionExportDeclarationKeys");
const { read_alem_config } = require("../config");
const filterReturn = require("../parsers/filterReturn");
const getProjectName = require("./getProjectName");

const config = read_alem_config();

Expand Down Expand Up @@ -559,7 +560,10 @@ const swapComponentsForStatelessFiles = (fileSchemas, fileSchema) => {

// Transform components generated by .jsx / .tsx into <Widget code={code} .../>
if (importItemWidget.toBeEjected) {
const src = `"${account}/widget/${importItemWidgetComponentName}"`;
// O nome do projeto deve vir na frente para evitar conflitos com outros
// aplicativos publicados na mesma conta
const newWidgetName = `${getProjectName(true)}.${importItemWidgetComponentName}`;
const src = `"${account}/widget/${newWidgetName}"`;
fileBundle = replaceJSXElement(
fileBundle,
importItemWidgetComponentName,
Expand Down
1 change: 1 addition & 0 deletions lib/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ async function serveDevJson({ useSocket, useGateway, useOpen, port, network }) {
return res.status(404).send("Something went wrong.");
}
const envConfig = JSON.stringify({
mainWidgetSrc: `${account}/widget/${projectName}`,
mainWidgetLink: `http://127.0.0.1:${port}/${account}/widget/${projectName}`,
bosLoaderWs: `ws://127.0.0.1:${port}`,
bosLoaderUrl: `http://127.0.0.1:${port}/api/loader`,
Expand Down

0 comments on commit 3ff86ba

Please sign in to comment.