strapi-layout-plugin 1.0.4 → 1.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/register.js +58 -0
- package/server/bootstrap.js +0 -43
package/package.json
CHANGED
package/server/register.js
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
3
6
|
module.exports = ({ strapi }) => {
|
|
7
|
+
// --- Auto-seed & Inject components before Strapi loads models ---
|
|
8
|
+
try {
|
|
9
|
+
const pluginComponentsDir = path.join(__dirname, 'components');
|
|
10
|
+
const appComponentsDir = path.join(strapi.dirs.app.src, 'components');
|
|
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
|
|
34
|
+
const veloxDir = path.join(appComponentsDir, 'velox');
|
|
35
|
+
const sharedDir = path.join(appComponentsDir, 'shared');
|
|
36
|
+
|
|
37
|
+
if (!fs.existsSync(appComponentsDir)) fs.mkdirSync(appComponentsDir, { recursive: true });
|
|
38
|
+
if (!fs.existsSync(veloxDir)) fs.mkdirSync(veloxDir, { recursive: true });
|
|
39
|
+
if (!fs.existsSync(sharedDir)) fs.mkdirSync(sharedDir, { recursive: true });
|
|
40
|
+
|
|
41
|
+
const filesToCopy = [
|
|
42
|
+
{ src: path.join(pluginComponentsDir, 'velox', 'header.json'), dest: path.join(veloxDir, 'header.json') },
|
|
43
|
+
{ src: path.join(pluginComponentsDir, 'velox', 'footer.json'), dest: path.join(veloxDir, 'footer.json') },
|
|
44
|
+
{ src: path.join(pluginComponentsDir, 'velox', 'link.json'), dest: path.join(veloxDir, 'link.json') },
|
|
45
|
+
{ src: path.join(pluginComponentsDir, 'velox', 'social-link.json'), dest: path.join(veloxDir, 'social-link.json') },
|
|
46
|
+
{ src: path.join(pluginComponentsDir, 'velox', 'footer-column.json'), dest: path.join(veloxDir, 'footer-column.json') },
|
|
47
|
+
{ src: path.join(pluginComponentsDir, 'shared', 'seo.json'), dest: path.join(sharedDir, 'seo.json') }
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
filesToCopy.forEach(({ src, dest }) => {
|
|
51
|
+
if (!fs.existsSync(dest) && fs.existsSync(src)) {
|
|
52
|
+
fs.copyFileSync(src, dest);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
strapi.log.info('[strapi-layout-plugin] Injected and seeded layout components during register phase.');
|
|
57
|
+
} catch (error) {
|
|
58
|
+
strapi.log.error('[strapi-layout-plugin] Failed to auto-seed components:', error);
|
|
59
|
+
}
|
|
60
|
+
// -------------------------------------------------------
|
|
61
|
+
|
|
4
62
|
const graphqlPlugin = strapi.plugin('graphql');
|
|
5
63
|
|
|
6
64
|
if (!graphqlPlugin) {
|
package/server/bootstrap.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
|
|
6
|
-
module.exports = async ({ strapi }) => {
|
|
7
|
-
try {
|
|
8
|
-
const pluginComponentsDir = path.join(__dirname, 'components');
|
|
9
|
-
const appComponentsDir = path.join(strapi.dirs.app.src, 'components');
|
|
10
|
-
|
|
11
|
-
// Create velox and shared dirs if they don't exist
|
|
12
|
-
const veloxDir = path.join(appComponentsDir, 'velox');
|
|
13
|
-
const sharedDir = path.join(appComponentsDir, 'shared');
|
|
14
|
-
|
|
15
|
-
if (!fs.existsSync(appComponentsDir)) fs.mkdirSync(appComponentsDir, { recursive: true });
|
|
16
|
-
if (!fs.existsSync(veloxDir)) fs.mkdirSync(veloxDir, { recursive: true });
|
|
17
|
-
if (!fs.existsSync(sharedDir)) fs.mkdirSync(sharedDir, { recursive: true });
|
|
18
|
-
|
|
19
|
-
// Files to copy
|
|
20
|
-
const filesToCopy = [
|
|
21
|
-
{ src: path.join(pluginComponentsDir, 'velox', 'header.json'), dest: path.join(veloxDir, 'header.json') },
|
|
22
|
-
{ src: path.join(pluginComponentsDir, 'velox', 'footer.json'), dest: path.join(veloxDir, 'footer.json') },
|
|
23
|
-
{ src: path.join(pluginComponentsDir, 'velox', 'link.json'), dest: path.join(veloxDir, 'link.json') },
|
|
24
|
-
{ src: path.join(pluginComponentsDir, 'velox', 'social-link.json'), dest: path.join(veloxDir, 'social-link.json') },
|
|
25
|
-
{ src: path.join(pluginComponentsDir, 'velox', 'footer-column.json'), dest: path.join(veloxDir, 'footer-column.json') },
|
|
26
|
-
{ src: path.join(pluginComponentsDir, 'shared', 'seo.json'), dest: path.join(sharedDir, 'seo.json') }
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
let copied = false;
|
|
30
|
-
filesToCopy.forEach(({ src, dest }) => {
|
|
31
|
-
if (!fs.existsSync(dest) && fs.existsSync(src)) {
|
|
32
|
-
fs.copyFileSync(src, dest);
|
|
33
|
-
copied = true;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
if (copied) {
|
|
38
|
-
strapi.log.info('[strapi-layout-plugin] Seeded layout components into src/components. Please restart Strapi if components do not show up.');
|
|
39
|
-
}
|
|
40
|
-
} catch (error) {
|
|
41
|
-
strapi.log.error('[strapi-layout-plugin] Failed to auto-seed components:', error);
|
|
42
|
-
}
|
|
43
|
-
};
|