strapi-layout-plugin 1.0.5 → 1.0.7
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/index.js +0 -2
- package/server/register.js +24 -6
package/package.json
CHANGED
package/server/index.js
CHANGED
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
const controllers = require('./controllers');
|
|
4
4
|
const routes = require('./routes');
|
|
5
5
|
const contentTypes = require('./content-types');
|
|
6
|
-
const bootstrap = require('./bootstrap');
|
|
7
6
|
|
|
8
7
|
module.exports = {
|
|
9
8
|
controllers,
|
|
10
9
|
routes,
|
|
11
10
|
contentTypes,
|
|
12
|
-
bootstrap,
|
|
13
11
|
};
|
package/server/register.js
CHANGED
|
@@ -4,11 +4,33 @@ const fs = require('fs');
|
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
6
|
module.exports = ({ strapi }) => {
|
|
7
|
-
// --- Auto-seed components before Strapi loads models ---
|
|
7
|
+
// --- Auto-seed & Inject components before Strapi loads models ---
|
|
8
8
|
try {
|
|
9
9
|
const pluginComponentsDir = path.join(__dirname, 'components');
|
|
10
10
|
const appComponentsDir = path.join(strapi.dirs.app.src, 'components');
|
|
11
11
|
|
|
12
|
+
// 1. Inject directly into memory to prevent database.init crash
|
|
13
|
+
const componentsToInject = {
|
|
14
|
+
'velox.header': require('./components/velox/header.json'),
|
|
15
|
+
'velox.footer': require('./components/velox/footer.json'),
|
|
16
|
+
'velox.link': require('./components/velox/link.json'),
|
|
17
|
+
'velox.social-link': require('./components/velox/social-link.json'),
|
|
18
|
+
'velox.footer-column': require('./components/velox/footer-column.json'),
|
|
19
|
+
'shared.seo': require('./components/shared/seo.json')
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
if (!strapi.components) {
|
|
23
|
+
strapi.components = {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
for (const [uid, schema] of Object.entries(componentsToInject)) {
|
|
27
|
+
if (!strapi.components[uid]) {
|
|
28
|
+
// Mock the structure Strapi expects for components
|
|
29
|
+
strapi.components[uid] = Object.assign({}, schema, { uid, category: uid.split('.')[0] });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 2. Also copy to physical files so user can see them in UI
|
|
12
34
|
const veloxDir = path.join(appComponentsDir, 'velox');
|
|
13
35
|
const sharedDir = path.join(appComponentsDir, 'shared');
|
|
14
36
|
|
|
@@ -25,17 +47,13 @@ module.exports = ({ strapi }) => {
|
|
|
25
47
|
{ src: path.join(pluginComponentsDir, 'shared', 'seo.json'), dest: path.join(sharedDir, 'seo.json') }
|
|
26
48
|
];
|
|
27
49
|
|
|
28
|
-
let copied = false;
|
|
29
50
|
filesToCopy.forEach(({ src, dest }) => {
|
|
30
51
|
if (!fs.existsSync(dest) && fs.existsSync(src)) {
|
|
31
52
|
fs.copyFileSync(src, dest);
|
|
32
|
-
copied = true;
|
|
33
53
|
}
|
|
34
54
|
});
|
|
35
55
|
|
|
36
|
-
|
|
37
|
-
strapi.log.info('[strapi-layout-plugin] Seeded layout components into src/components during register phase.');
|
|
38
|
-
}
|
|
56
|
+
strapi.log.info('[strapi-layout-plugin] Injected and seeded layout components during register phase.');
|
|
39
57
|
} catch (error) {
|
|
40
58
|
strapi.log.error('[strapi-layout-plugin] Failed to auto-seed components:', error);
|
|
41
59
|
}
|