Remove env-config.js (#9331)

Fixes #5340 which had been open for a long time
This commit is contained in:
Félix Malfait
2025-01-03 15:18:02 +01:00
committed by GitHub
parent 03b1da82c1
commit e5754d2152
7 changed files with 54 additions and 32 deletions

View File

@ -13,23 +13,29 @@ export function generateFrontConfig(): void {
},
};
const configString = `window._env_ = ${JSON.stringify(
configObject.window._env_,
null,
2,
)};`;
const configString = `<!-- BEGIN: Twenty Config -->
<script id="twenty-env-config">
window._env_ = ${JSON.stringify(configObject.window._env_, null, 2)};
</script>
<!-- END: Twenty Config -->`;
const distPath = path.join(__dirname, '../..', 'front');
const filePath = path.join(distPath, 'env-config.js');
const indexPath = path.join(distPath, 'index.html');
if (!fs.existsSync(distPath)) {
fs.mkdirSync(distPath, { recursive: true });
if (!fs.existsSync(indexPath)) {
console.log(
'Frontend build not found, assuming it is served independently',
);
return;
}
if (
!fs.existsSync(filePath) ||
fs.readFileSync(filePath, 'utf8') !== configString
) {
fs.writeFileSync(filePath, configString, 'utf8');
}
let indexContent = fs.readFileSync(indexPath, 'utf8');
indexContent = indexContent.replace(
/<!-- BEGIN: Twenty Config -->[\s\S]*?<!-- END: Twenty Config -->/,
configString,
);
fs.writeFileSync(indexPath, indexContent, 'utf8');
}