@_sh/strapi-plugin-ckeditor 3.0.5 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/services/config.js +34 -16
package/package.json
CHANGED
|
@@ -1,25 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const fs = require(
|
|
3
|
+
const fs = require('fs');
|
|
4
4
|
|
|
5
5
|
module.exports = ({ strapi }) => {
|
|
6
|
+
const readConfigFile = () => {
|
|
7
|
+
const appDir = process.cwd();
|
|
8
|
+
const isTSProject = fs.existsSync(`${appDir}/dist`);
|
|
9
|
+
const envName = process.env.NODE_ENV;
|
|
10
|
+
|
|
11
|
+
const cfgDir = isTSProject ? `${appDir}/dist/config` : `${appDir}/config`;
|
|
12
|
+
const cfgFileName = 'ckeditor.js';
|
|
13
|
+
|
|
14
|
+
const envFilePath = `${cfgDir}/env/${envName}/${cfgFileName}`;
|
|
15
|
+
const baseFilePath = `${cfgDir}/${cfgFileName}`;
|
|
16
|
+
|
|
17
|
+
if (fs.existsSync(envFilePath)) {
|
|
18
|
+
return fs.readFileSync(envFilePath, 'utf8');
|
|
19
|
+
} else if (fs.existsSync(baseFilePath)) {
|
|
20
|
+
return fs.readFileSync(baseFilePath, 'utf8');
|
|
21
|
+
} else {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const trimConfig = (str) => {
|
|
27
|
+
for (const func of ['const CKEConfig', 'function CKEConfig']) {
|
|
28
|
+
const idx = str.indexOf(func);
|
|
29
|
+
if (idx >= 0) {
|
|
30
|
+
return str.substring(idx) + `\nglobalThis.SH_CKE_CONFIG = CKEConfig()`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
6
35
|
return {
|
|
7
36
|
getConfig() {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const fileName = "ckeditor";
|
|
11
|
-
|
|
12
|
-
for (const ext of ["js", "ts"]) {
|
|
13
|
-
const filePath = `${appDir}/config/${fileName}.${ext}`;
|
|
14
|
-
if (fs.existsSync(filePath)) {
|
|
15
|
-
return (
|
|
16
|
-
fs.readFileSync(filePath, "utf8") +
|
|
17
|
-
`\nglobalThis.SH_CKE_CONFIG = CKEConfig()`
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
37
|
+
const configFileContent = readConfigFile();
|
|
38
|
+
const config = configFileContent && trimConfig(configFileContent);
|
|
21
39
|
|
|
22
|
-
return `globalThis.SH_CKE_CONFIG = null`;
|
|
40
|
+
return config || `globalThis.SH_CKE_CONFIG = null`;
|
|
23
41
|
},
|
|
24
42
|
};
|
|
25
43
|
};
|