@pinegrow/nuxt-module 3.0.0-beta.81 → 3.0.0-beta.83
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/dist/module.json +1 -1
- package/dist/module.mjs +27 -27
- package/dist/runtime/nitro-plugin.mjs +188 -46
- package/package.json +2 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addServerPlugin, useNitro, addVitePlugin } from '@nuxt/kit';
|
|
2
2
|
|
|
3
3
|
const module = defineNuxtModule({
|
|
4
|
+
async setup(moduleOptions, nuxt) {
|
|
5
|
+
if (moduleOptions.liveDesigner) {
|
|
6
|
+
const nuxtInstance = nuxt;
|
|
7
|
+
let pluginInstance;
|
|
8
|
+
const { resolve } = createResolver(import.meta.url);
|
|
9
|
+
addServerPlugin(resolve("./runtime/nitro-plugin.mjs"));
|
|
10
|
+
nuxt.hook("listen", async (listenerServer) => {
|
|
11
|
+
try {
|
|
12
|
+
const { liveDesigner } = await import('./chunks/live-designer.mjs');
|
|
13
|
+
const nitroApp = useNitro();
|
|
14
|
+
pluginInstance = liveDesigner({
|
|
15
|
+
...moduleOptions.liveDesigner,
|
|
16
|
+
listenerServer,
|
|
17
|
+
nuxtInstance,
|
|
18
|
+
nitroApp
|
|
19
|
+
});
|
|
20
|
+
addVitePlugin(pluginInstance);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.log(err);
|
|
23
|
+
console.log(
|
|
24
|
+
"Pinegrow: @pinegrow/nuxt-module was unable to load @pinegrow/vite-plugin live-designer!"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
},
|
|
4
30
|
meta: {
|
|
5
31
|
// Usually npm package name of your module
|
|
6
32
|
name: "pinegrow",
|
|
@@ -66,33 +92,7 @@ const module = defineNuxtModule({
|
|
|
66
92
|
}
|
|
67
93
|
}
|
|
68
94
|
},
|
|
69
|
-
hooks: {}
|
|
70
|
-
async setup(moduleOptions, nuxt) {
|
|
71
|
-
if (moduleOptions.liveDesigner) {
|
|
72
|
-
const { resolve } = createResolver(import.meta.url);
|
|
73
|
-
addServerPlugin(resolve("./runtime/nitro-plugin.mjs"));
|
|
74
|
-
const nuxtInstance = nuxt;
|
|
75
|
-
let pluginInstance;
|
|
76
|
-
nuxt.hook("listen", async (listenerServer) => {
|
|
77
|
-
try {
|
|
78
|
-
const { liveDesigner } = await import('./chunks/live-designer.mjs');
|
|
79
|
-
const nitroApp = useNitro();
|
|
80
|
-
pluginInstance = liveDesigner({
|
|
81
|
-
...moduleOptions.liveDesigner,
|
|
82
|
-
listenerServer,
|
|
83
|
-
nuxtInstance,
|
|
84
|
-
nitroApp
|
|
85
|
-
});
|
|
86
|
-
addVitePlugin(pluginInstance);
|
|
87
|
-
} catch (err) {
|
|
88
|
-
console.log(err);
|
|
89
|
-
console.log(
|
|
90
|
-
"Pinegrow: @pinegrow/nuxt-module was unable to load @pinegrow/vite-plugin live-designer!"
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
95
|
+
hooks: {}
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
export { module as default };
|
|
@@ -1,30 +1,46 @@
|
|
|
1
1
|
import { defineNitroPlugin } from 'nitropack/runtime/plugin'
|
|
2
|
+
// import { fileURLToPath, URL } from 'node:url'
|
|
3
|
+
// import htmlParser from 'node-html-parser'
|
|
2
4
|
import path from 'path'
|
|
3
5
|
import fs from 'fs'
|
|
4
6
|
|
|
5
|
-
export default defineNitroPlugin(nitroApp => {
|
|
7
|
+
export default defineNitroPlugin(async nitroApp => {
|
|
6
8
|
// const nitroInstance = nitroApp
|
|
9
|
+
// const runtimeConfig = await nitroInstance.hooks.callHook(
|
|
10
|
+
// 'nitro-runtime'
|
|
11
|
+
// )
|
|
7
12
|
|
|
8
|
-
nitroApp.hooks.hook('render:html', (
|
|
9
|
-
// console.log('render:html',
|
|
10
|
-
//
|
|
13
|
+
nitroApp.hooks.hook('render:html', async (htmlContext, { event }) => {
|
|
14
|
+
// console.log('render:html', htmlContext)
|
|
15
|
+
// htmlContext.bodyAppend.push('<hr>Appended by custom plugin')
|
|
16
|
+
|
|
17
|
+
// const runtimeConfig = await nitroInstance.hooks.callHook(
|
|
18
|
+
// 'transform-index-html',
|
|
19
|
+
// htmlContext
|
|
20
|
+
// )
|
|
21
|
+
const projectRoot = process.cwd()
|
|
22
|
+
|
|
23
|
+
// https://github.com/unjs/nitro/discussions/1080
|
|
11
24
|
|
|
12
25
|
const addons = [
|
|
13
26
|
{
|
|
14
27
|
name: 'pgia',
|
|
15
28
|
resources: [
|
|
16
29
|
{
|
|
17
|
-
|
|
30
|
+
// condition: 'interactions',
|
|
18
31
|
parentResource: `public/pgia`, // relative to project root, must exists
|
|
19
32
|
// source: `<script src="pgia/index.js"></script>`,
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
injectTo: 'head-append',
|
|
34
|
+
tag: 'script',
|
|
35
|
+
children: `
|
|
36
|
+
/* Pinegrow Interactions, do not remove */ (function(){try{if(!document.documentElement.hasAttribute('data-pg-ia-disabled')) { window.pgia_small_mq=typeof pgia_small_mq=='string'?pgia_small_mq:'(max-width:767px)';window.pgia_large_mq=typeof pgia_large_mq=='string'?pgia_large_mq:'(min-width:768px)';var style = document.createElement('style');var pgcss='html:not(.pg-ia-no-preview) [data-pg-ia-hide=""] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show=""] {opacity:1;visibility:visible;display:block;}';if(document.documentElement.hasAttribute('data-pg-id') && document.documentElement.hasAttribute('data-pg-mobile')) {pgia_small_mq='(min-width:0)';pgia_large_mq='(min-width:99999px)'} pgcss+='@media ' + pgia_small_mq + '{ html:not(.pg-ia-no-preview) [data-pg-ia-hide="mobile"] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show="mobile"] {opacity:1;visibility:visible;display:block;}}';pgcss+='@media ' + pgia_large_mq + '{html:not(.pg-ia-no-preview) [data-pg-ia-hide="desktop"] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show="desktop"] {opacity:1;visibility:visible;display:block;}}';style.innerHTML=pgcss;document.querySelector('head').appendChild(style);}}catch(e){console&&console.log(e);}})()`,
|
|
22
37
|
},
|
|
23
38
|
{
|
|
24
|
-
|
|
39
|
+
// condition: 'interactions',
|
|
25
40
|
parentResource: `public/pgia`, // relative to project root, must exists
|
|
26
|
-
|
|
27
|
-
|
|
41
|
+
injectTo: 'body-append',
|
|
42
|
+
tag: 'script',
|
|
43
|
+
attrs: { src: '/pgia/lib/index.js' },
|
|
28
44
|
},
|
|
29
45
|
],
|
|
30
46
|
},
|
|
@@ -32,50 +48,176 @@ export default defineNitroPlugin(nitroApp => {
|
|
|
32
48
|
|
|
33
49
|
addons.forEach(addon => {
|
|
34
50
|
addon.resources.forEach(resource => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
if (
|
|
52
|
+
!resource.condition /*|| this.customOptions[resource.condition] */
|
|
53
|
+
) {
|
|
54
|
+
try {
|
|
55
|
+
let parentResourceExists = true
|
|
56
|
+
|
|
57
|
+
if (resource.parentResource) {
|
|
58
|
+
const resourcePath = path.resolve(
|
|
59
|
+
projectRoot,
|
|
60
|
+
resource.parentResource
|
|
61
|
+
)
|
|
62
|
+
parentResourceExists =
|
|
63
|
+
parentResourceExists &&
|
|
64
|
+
fs.existsSync(resourcePath)
|
|
65
|
+
}
|
|
47
66
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (parentResourceExists) {
|
|
68
|
+
const attrContent = Object.entries(
|
|
69
|
+
resource.attrs || {}
|
|
70
|
+
).reduce((acc, [key, value]) => {
|
|
71
|
+
return `${acc}${key}${
|
|
72
|
+
value && value !== true ? `="${value}"` : ''
|
|
73
|
+
}`
|
|
74
|
+
}, '')
|
|
75
|
+
|
|
76
|
+
switch (resource.injectTo) {
|
|
77
|
+
case 'head-prepend':
|
|
78
|
+
case 'head-append':
|
|
79
|
+
htmlContext.head.push(`<${
|
|
80
|
+
resource.tag
|
|
81
|
+
} ${attrContent}>
|
|
82
|
+
${resource.children || ''}
|
|
83
|
+
</${resource.tag}>`)
|
|
84
|
+
break
|
|
85
|
+
|
|
86
|
+
case 'body-prepend':
|
|
87
|
+
htmlContext.bodyPrepend.push(`<${
|
|
88
|
+
resource.tag
|
|
89
|
+
} ${attrContent}>
|
|
90
|
+
${resource.children || ''}
|
|
91
|
+
</${resource.tag}>`)
|
|
92
|
+
break
|
|
93
|
+
|
|
94
|
+
case 'body-append':
|
|
95
|
+
htmlContext.bodyAppend.push(`<${
|
|
96
|
+
resource.tag
|
|
97
|
+
} ${attrContent}>
|
|
98
|
+
${resource.children || ''}
|
|
99
|
+
</${resource.tag}>`)
|
|
100
|
+
break
|
|
101
|
+
}
|
|
70
102
|
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.log(err)
|
|
71
105
|
}
|
|
72
|
-
} catch (err) {
|
|
73
|
-
// console.log(err)
|
|
74
106
|
}
|
|
75
107
|
})
|
|
76
108
|
})
|
|
109
|
+
|
|
110
|
+
// const dev_server_url = event.req.headers.referer // event.req.headers.host
|
|
111
|
+
// const pinegrow_url = process.env.pinegrow_url
|
|
112
|
+
|
|
113
|
+
// if (pinegrow_url) {
|
|
114
|
+
// const pinegrow_base_url = new URL(pinegrow_url)
|
|
115
|
+
// pinegrow_base_url.port = pinegrow_base_url.port - 1
|
|
116
|
+
|
|
117
|
+
// htmlContext.head = htmlContext.head.reduce((acc, headItem) => {
|
|
118
|
+
// if (headItem.startsWith('<link')) {
|
|
119
|
+
// try {
|
|
120
|
+
// const linkNode = htmlParser.parse(headItem, 'text/html')
|
|
121
|
+
// // .childNodes[0]
|
|
122
|
+
// const linkHref = linkNode.getAttribute('href')
|
|
123
|
+
// const linkPath = path.resolve(
|
|
124
|
+
// projectRoot,
|
|
125
|
+
// `${linkHref}` // `.${linkHref}`
|
|
126
|
+
// )
|
|
127
|
+
// if (fs.existsSync(linkPath)) {
|
|
128
|
+
// linkNode.setAttribute(
|
|
129
|
+
// 'href',
|
|
130
|
+
// new URL(
|
|
131
|
+
// path.relative(projectRoot, linkHref),
|
|
132
|
+
// pinegrow_base_url
|
|
133
|
+
// ).href
|
|
134
|
+
// )
|
|
135
|
+
// }
|
|
136
|
+
// return [...acc, linkNode.outerHTML]
|
|
137
|
+
// } catch (err) {
|
|
138
|
+
// // console.log(err)
|
|
139
|
+
// }
|
|
140
|
+
// }
|
|
141
|
+
// return [...acc, headItem]
|
|
142
|
+
// }, [])
|
|
143
|
+
|
|
144
|
+
// // Auto add css file from public folder, so that pinegrow thinks it is loaded from internal server
|
|
145
|
+
// const publicFolder = path.resolve(projectRoot, 'public')
|
|
146
|
+
// if (isExistsAndDirectory(publicFolder)) {
|
|
147
|
+
// fs.readdirSync(publicFolder).forEach(fileName => {
|
|
148
|
+
// const folderPath = publicFolder
|
|
149
|
+
// const filePath = path.resolve(folderPath, fileName)
|
|
150
|
+
// const fileExtn = path.extname(fileName)
|
|
151
|
+
|
|
152
|
+
// if (isFile(filePath) && fileExtn === '.css') {
|
|
153
|
+
// const linkHref = new URL(
|
|
154
|
+
// path.relative(projectRoot, filePath),
|
|
155
|
+
// dev_server_url //pinegrow_base_url
|
|
156
|
+
// ).href
|
|
157
|
+
// htmlContext.head.push(
|
|
158
|
+
// `<link ref="stylesheet" href="${linkHref}">`
|
|
159
|
+
// // `<link ref="stylesheet" href="./${linkHref}">`
|
|
160
|
+
// )
|
|
161
|
+
// // const linkHref = new URL(
|
|
162
|
+
// // path.relative(projectRoot, filePath),
|
|
163
|
+
// // pinegrow_base_url
|
|
164
|
+
// // ).href
|
|
165
|
+
// // // const linkHref = path.relative(projectRoot, filePath)
|
|
166
|
+
// // htmlContext.head.push(
|
|
167
|
+
// // // `<link ref="stylesheet" href="${linkHref}">`
|
|
168
|
+
// // `<link ref="stylesheet" href="${linkHref}">`
|
|
169
|
+
// // )
|
|
170
|
+
// // htmlContext.head.push(
|
|
171
|
+
// // // `<link ref="stylesheet" href="${linkHref}">`
|
|
172
|
+
// // `<link ref="stylesheet" href="file://${filePath}">`
|
|
173
|
+
// // )
|
|
174
|
+
// }
|
|
175
|
+
// })
|
|
176
|
+
// }
|
|
177
|
+
// }
|
|
77
178
|
})
|
|
78
179
|
// nitroApp.hooks.hook('render:response', (response, { event }) => {
|
|
79
180
|
// console.log('render:response', response)
|
|
80
181
|
// })
|
|
81
182
|
})
|
|
183
|
+
|
|
184
|
+
// var isExistsAndFile = filePath => isExistsPath(filePath) && isFile(filePath)
|
|
185
|
+
|
|
186
|
+
// var isExistsAndDirectory = filePath =>
|
|
187
|
+
// isExistsPath(filePath) && isDirectory(filePath)
|
|
188
|
+
|
|
189
|
+
// var isExistsPath = (filePath, root) => {
|
|
190
|
+
// const fullPath = toAbsolutePath(filePath, root)
|
|
191
|
+
// return !!(fullPath && fs.existsSync(fullPath))
|
|
192
|
+
// }
|
|
193
|
+
|
|
194
|
+
// var isFile = (filePath, root) => {
|
|
195
|
+
// const fullPath = toAbsolutePath(filePath, root)
|
|
196
|
+
// return !!(fullPath && fs.statSync(fullPath).isFile())
|
|
197
|
+
// }
|
|
198
|
+
|
|
199
|
+
// var isDirectory = (filePath, root) => {
|
|
200
|
+
// const fullPath = toAbsolutePath(filePath, root)
|
|
201
|
+
// return !!(fullPath && fs.statSync(fullPath).isDirectory())
|
|
202
|
+
// }
|
|
203
|
+
|
|
204
|
+
// var toAbsolutePath = (filePath, root, searchDir) => {
|
|
205
|
+
// try {
|
|
206
|
+
// if (path.isAbsolute(filePath)) {
|
|
207
|
+
// return filePath
|
|
208
|
+
// } else {
|
|
209
|
+
// if (root) {
|
|
210
|
+
// if (searchDir) {
|
|
211
|
+
// return path.resolve(root, searchDir, filePath)
|
|
212
|
+
// } else {
|
|
213
|
+
// return path.resolve(root, filePath)
|
|
214
|
+
// }
|
|
215
|
+
// } else {
|
|
216
|
+
// // No root, no project
|
|
217
|
+
// return false
|
|
218
|
+
// }
|
|
219
|
+
// }
|
|
220
|
+
// } catch (err) {
|
|
221
|
+
// console.log(err)
|
|
222
|
+
// }
|
|
223
|
+
// }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pinegrow/nuxt-module",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.83",
|
|
4
4
|
"description": "Pinegrow Nuxt Module",
|
|
5
5
|
"author": "Pinegrow (http://pinegrow.com/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@nuxt/kit": "latest",
|
|
38
|
-
"@pinegrow/vite-plugin": "3.0.0-beta.
|
|
38
|
+
"@pinegrow/vite-plugin": "3.0.0-beta.83"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@nuxt/module-builder": "latest",
|