@pinegrow/nuxt-module 3.0.0-beta.9 → 3.0.0-beta.91

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @pinegrow/nuxt-module
2
2
 
3
- ## Nuxt module for Pinegrow
3
+ ## Pinegrow Nuxt module
4
4
 
5
5
  http://www.pinegrow.com
package/dist/module.d.ts CHANGED
@@ -2,10 +2,13 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  interface ModuleOptions {
4
4
  liveDesigner?: {
5
+ [key in string]?: any;
6
+ } & {
5
7
  repoRoot?: string;
6
8
  configPath?: string;
7
9
  plugins?: string[];
8
- usingStandaloneVueDevtools?: boolean;
10
+ devtoolsKey?: string;
11
+ vscodeTunnelUrl?: string;
9
12
  customTypes?: {
10
13
  default?: {};
11
14
  };
package/dist/module.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "pinegrow",
3
3
  "configKey": "pinegrow",
4
4
  "compatibility": {
5
- "nuxt": "^3.0.0 || ~3.0.0-rc"
5
+ "nuxt": "^3.1.0"
6
6
  },
7
- "version": "3.0.0-beta.8"
7
+ "version": "3.0.0-beta.90"
8
8
  }
package/dist/module.mjs CHANGED
@@ -1,34 +1,23 @@
1
- import { defineNuxtModule, addVitePlugin } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addServerPlugin, useNitro, addVitePlugin } from '@nuxt/kit';
2
2
 
3
3
  const module = defineNuxtModule({
4
- meta: {
5
- name: "pinegrow",
6
- configKey: "pinegrow",
7
- compatibility: {
8
- nuxt: "^3.0.0 || ~3.0.0-rc"
9
- }
10
- },
11
- defaults: {
12
- liveDesigner: {
13
- plugins: [],
14
- usingStandaloneVueDevtools: false,
15
- customTypes: {
16
- default: {}
17
- }
18
- }
19
- },
20
- hooks: {},
21
4
  async setup(moduleOptions, nuxt) {
22
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"));
23
10
  nuxt.hook("listen", async (listenerServer) => {
24
11
  try {
25
12
  const { liveDesigner } = await import('./chunks/live-designer.mjs');
26
- addVitePlugin(
27
- liveDesigner({
28
- ...moduleOptions.liveDesigner,
29
- listenerServer
30
- })
31
- );
13
+ const nitroApp = useNitro();
14
+ pluginInstance = liveDesigner({
15
+ ...moduleOptions.liveDesigner,
16
+ listenerServer,
17
+ nuxtInstance,
18
+ nitroApp
19
+ });
20
+ addVitePlugin(pluginInstance);
32
21
  } catch (err) {
33
22
  console.log(err);
34
23
  console.log(
@@ -37,7 +26,73 @@ const module = defineNuxtModule({
37
26
  }
38
27
  });
39
28
  }
40
- }
29
+ },
30
+ meta: {
31
+ // Usually npm package name of your module
32
+ name: "pinegrow",
33
+ // The key in `nuxt.config` that holds your module options
34
+ configKey: "pinegrow",
35
+ // Compatibility constraints
36
+ compatibility: {
37
+ // Semver version of supported nuxt versions
38
+ nuxt: "^3.1.0"
39
+ }
40
+ },
41
+ // Default configuration options for your module
42
+ defaults: {
43
+ liveDesigner: {
44
+ // repoRoot: './',
45
+ // configPath: './',
46
+ plugins: [],
47
+ // devtoolsKey: 'devtools',
48
+ // vscodeTunnelUrl: 'https://vscode.dev/tunnel/hostname',
49
+ // iconsets: [],
50
+ // routerHistoryMode: 'html5',
51
+ // mergeWithPackageJson: {
52
+ // dependencies: {},
53
+ // devDependencies: {},
54
+ // },
55
+ customTypes: {
56
+ // To apply type overrides to a specific component (overrides above default fn),
57
+ // ComponentName: { prop: { customType: 'icon' } },
58
+ // VRating: {
59
+ // ripple: {
60
+ // customType: "boolean",
61
+ // },
62
+ // },
63
+ // VSelect: {
64
+ // variant: {
65
+ // customType: 'select',
66
+ // options: ['plain', 'outlined', 'underlined', 'solo'],
67
+ // default: ''
68
+ // },
69
+ // density: {
70
+ // customType: 'select',
71
+ // options: ['default', 'compact', 'comfortable']
72
+ // },
73
+ // disabled: {
74
+ // customType: 'boolean'
75
+ // },
76
+ // appendIcon: {
77
+ // customType: 'icon'
78
+ // },
79
+ // }
80
+ // To apply type overrides to all components,
81
+ // all: { prop: { customType: 'icon' } },
82
+ default: {
83
+ // density: {
84
+ // customType: "select",
85
+ // // add options when customType is 'select'
86
+ // options: ["default", "compact", "comfortable"],
87
+ // },
88
+ }
89
+ },
90
+ tailwindcss: {
91
+ cssPath: "./assets/css/tailwind.css"
92
+ }
93
+ }
94
+ },
95
+ hooks: {}
41
96
  });
42
97
 
43
98
  export { module as default };
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,223 @@
1
+ import { defineNitroPlugin } from 'nitropack/runtime/plugin'
2
+ // import { fileURLToPath, URL } from 'node:url'
3
+ // import htmlParser from 'node-html-parser'
4
+ import path from 'path'
5
+ import fs from 'fs'
6
+
7
+ export default defineNitroPlugin(async nitroApp => {
8
+ // const nitroInstance = nitroApp
9
+ // const runtimeConfig = await nitroInstance.hooks.callHook(
10
+ // 'nitro-runtime'
11
+ // )
12
+
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
24
+
25
+ const addons = [
26
+ {
27
+ name: 'pgia',
28
+ resources: [
29
+ {
30
+ // condition: 'interactions',
31
+ parentResource: `public/pgia`, // relative to project root, must exists
32
+ // source: `<script src="pgia/index.js"></script>`,
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);}})()`,
37
+ },
38
+ {
39
+ // condition: 'interactions',
40
+ parentResource: `public/pgia`, // relative to project root, must exists
41
+ injectTo: 'body-append',
42
+ tag: 'script',
43
+ attrs: { src: '/pgia/lib/index.js' },
44
+ },
45
+ ],
46
+ },
47
+ ]
48
+
49
+ addons.forEach(addon => {
50
+ addon.resources.forEach(resource => {
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
+ }
66
+
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
+ }
102
+ }
103
+ } catch (err) {
104
+ console.log(err)
105
+ }
106
+ }
107
+ })
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
+ // }
178
+ })
179
+ // nitroApp.hooks.hook('render:response', (response, { event }) => {
180
+ // console.log('render:response', response)
181
+ // })
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.9",
3
+ "version": "3.0.0-beta.91",
4
4
  "description": "Pinegrow Nuxt Module",
5
5
  "author": "Pinegrow (http://pinegrow.com/)",
6
6
  "license": "MIT",
@@ -28,16 +28,24 @@
28
28
  "dev:build": "nuxi build playground",
29
29
  "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
30
30
  "publish-beta": "npm run increment-beta-version && npm publish",
31
- "increment-beta-version": "npm version prerelease --preid=beta"
31
+ "increment-beta-version": "npm version prerelease --preid=beta",
32
+ "lint": "npm run lint:fix && npm run format",
33
+ "lint:fix": "eslint --ext .js,.cjs,.ts,.vue --ignore-path .gitignore --fix ./src",
34
+ "format": "prettier --write ."
32
35
  },
33
36
  "dependencies": {
34
37
  "@nuxt/kit": "latest",
35
- "@pinegrow/vite-plugin": "latest"
38
+ "@pinegrow/vite-plugin": "3.0.0-beta.91"
36
39
  },
37
40
  "devDependencies": {
38
41
  "@nuxt/module-builder": "latest",
39
- "@nuxtjs/eslint-config-typescript": "latest",
40
- "eslint": "latest",
41
- "nuxt": "rc"
42
+ "@nuxt/eslint-config": "^0.1.1",
43
+ "nuxt": "^3.1.0",
44
+ "eslint": "^8.35.0",
45
+ "eslint-config-prettier": "^8.7.0",
46
+ "prettier": "^2.8.4"
47
+ },
48
+ "peerDependencies": {
49
+ "nuxt": "^3.1.0"
42
50
  }
43
51
  }