Skip to content

Commit

Permalink
fix: additional changes to (0fae3ee) to handle moduleDetection:force, c…
Browse files Browse the repository at this point in the history
…loses #172
  • Loading branch information
nshenderov committed Oct 22, 2024
1 parent c13b0d2 commit c35b27c
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions server/src/services/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,41 @@
const fs = require('fs');

module.exports = ({ strapi }) => {
return {
getConfig() {
const appDir = process.cwd();
const isTsProject = fs.existsSync(`${appDir}/dist`);
const readConfigFile = () => {
const appDir = process.cwd();
const isTSProject = fs.existsSync(`${appDir}/dist`);
const envName = process.env.NODE_ENV;

const cfgDir = isTsProject ? `${appDir}/dist/config` : `${appDir}/config`;
const cfgFileName = 'ckeditor.js';
const envName = process.env.NODE_ENV;
const cfgDir = isTSProject ? `${appDir}/dist/config` : `${appDir}/config`;
const cfgFileName = 'ckeditor.js';

const envFilePath = `${cfgDir}/env/${envName}/${cfgFileName}`;
const baseFilePath = `${cfgDir}/${cfgFileName}`;
let fileToRead;
const envFilePath = `${cfgDir}/env/${envName}/${cfgFileName}`;
const baseFilePath = `${cfgDir}/${cfgFileName}`;

if (fs.existsSync(envFilePath)) {
return fs.readFileSync(envFilePath, 'utf8');
} else if (fs.existsSync(baseFilePath)) {
return fs.readFileSync(baseFilePath, 'utf8');
} else {
return null;
}
};

if (fs.existsSync(envFilePath)) {
fileToRead = envFilePath;
} else if (fs.existsSync(baseFilePath)) {
fileToRead = baseFilePath;
const trimConfig = (str) => {
for (const func of ['const CKEConfig', 'function CKEConfig']) {
const idx = str.indexOf(func);
if (idx >= 0) {
return str.substring(idx) + `\nglobalThis.SH_CKE_CONFIG = CKEConfig()`;
}
}
};

return {
getConfig() {
const configFileContent = readConfigFile();
const config = configFileContent && trimConfig(configFileContent);

return fileToRead ?
fs.readFileSync(fileToRead, 'utf8') +
`\nglobalThis.SH_CKE_CONFIG = CKEConfig()`
: `globalThis.SH_CKE_CONFIG = null`;
return config || `globalThis.SH_CKE_CONFIG = null`;
},
};
};

0 comments on commit c35b27c

Please sign in to comment.