@pinegrow/nuxt-module 3.0.0-beta.13 → 3.0.0-beta.130

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,67 @@
1
- # @pinegrow/nuxt-module
1
+ <!-- [![@pinegrow/nuxt-module](https://tailwindcss.nuxtjs.org/social-card.png)](https://tailwindcss.nuxtjs.org) -->
2
2
 
3
- ## Nuxt module for Pinegrow
3
+ # Pinegrow Nuxt Module
4
4
 
5
- http://www.pinegrow.com
5
+ [![npm version][npm-version-src]][npm-version-href]
6
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
7
+ [![License][license-src]][license-href]
8
+
9
+ [Nuxt](https://nuxt.com/) module for [Pinegrow](https://pinegrow.com) ⚡️
10
+
11
+ Pinegrow Nuxt Module enables connection and interaction between your Vite Dev-Server and Pinegrow apps (currently only Vue Designer).
12
+
13
+ - [📖 &nbsp;Documentation](https://pinegrow.com/vue-designer)
14
+
15
+ ## Features
16
+
17
+ - 🎨&nbsp; Visually live-design your Vite-powered Nuxt apps
18
+ - ⚙️&nbsp; Smartly integrates into your Nuxt workflow in dev-mode only
19
+ - ✨&nbsp; No lock-in, Pinegrow is an open-tool ❤️
20
+
21
+ ## Quick Setup
22
+
23
+ 1. Install: Add `@pinegrow/nuxt-module` to your project
24
+
25
+ ```bash
26
+ # Using npm
27
+ npm install --save-dev @pinegrow/nuxt-module
28
+
29
+ # Using pnpm
30
+ pnpm add --save-dev @pinegrow/nuxt-module
31
+ ```
32
+
33
+ 2. Configure: Add `@pinegrow/nuxt-module` to your Nuxt Integrations array `nuxt.config.{js,ts}`
34
+
35
+ ```js
36
+ //nuxt.config.js (or) nuxt.config.ts
37
+
38
+ export default defineNuxtConfig({
39
+ modules: [
40
+ '@pinegrow/nuxt-module',
41
+ //...
42
+ ],
43
+ pinegrow: {
44
+ liveDesigner: {
45
+ //...
46
+ },
47
+ },
48
+ //...
49
+ })
50
+ ```
51
+
52
+ Now, open your project in your Pinegrow app (currently only Vue Designer). ✨
53
+
54
+ ## License
55
+
56
+ [MIT License](./LICENSE)
57
+
58
+ Copyright (c) Pinegrow
59
+
60
+ <!-- Badges -->
61
+
62
+ [npm-version-src]: https://img.shields.io/npm/v/@pinegrow/nuxt-module/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
63
+ [npm-version-href]: https://npmjs.com/package/@pinegrow/nuxt-module
64
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@pinegrow/nuxt-module.svg?style=flat&colorA=18181B&colorB=28CF8D
65
+ [npm-downloads-href]: https://npmjs.com/package/@pinegrow/nuxt-module
66
+ [license-src]: https://img.shields.io/npm/l/@pinegrow/nuxt-module.svg?style=flat&colorA=18181B&colorB=28CF8D
67
+ [license-href]: https://npmjs.com/package/@pinegrow/nuxt-module
@@ -1,6 +1,7 @@
1
1
  import pkg from '@pinegrow/vite-plugin';
2
2
 
3
3
  // import { liveDesigner } from '@pinegrow/vite-plugin/dev'
4
+
4
5
  const liveDesigner = pkg.liveDesigner;
5
6
 
6
7
  export { liveDesigner };
package/dist/module.d.ts CHANGED
@@ -1,16 +1,15 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { LiveDesignerOptions } from '@pinegrow/vite-plugin';
2
3
 
3
- interface ModuleOptions {
4
+ interface PinegrowNuxtModuleOptions {
5
+ /**
6
+ * Pinegrow Live Designer options
7
+ * For details, check https://pinegrow.com/vue-designer
8
+ */
4
9
  liveDesigner?: {
5
- repoRoot?: string;
6
- configPath?: string;
7
- plugins?: string[];
8
- usingStandaloneVueDevtools?: boolean;
9
- customTypes?: {
10
- default?: {};
11
- };
12
- };
10
+ [key in string]?: any;
11
+ } & LiveDesignerOptions;
13
12
  }
14
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
13
+ declare const _default: _nuxt_schema.NuxtModule<PinegrowNuxtModuleOptions>;
15
14
 
16
- export { ModuleOptions, _default as default };
15
+ export { PinegrowNuxtModuleOptions, _default as default };
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.12"
7
+ "version": "3.0.0-beta.129"
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,35 @@ 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
+ // devtoolsKey: 'devtools',
47
+ // routerHistoryMode: 'html5',
48
+ plugins: [],
49
+ tailwindcss: {
50
+ configPath: "@/tailwind.config.js",
51
+ cssPath: "@/assets/css/tailwind.css"
52
+ // restartOnConfigUpdate: false,
53
+ // restartOnThemeUpdate: false,
54
+ }
55
+ }
56
+ },
57
+ hooks: {}
41
58
  });
42
59
 
43
60
  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/dist/types.d.ts CHANGED
@@ -1,10 +1,7 @@
1
1
 
2
- import { ModuleOptions } from './module'
2
+ import { } from './module'
3
3
 
4
- declare module '@nuxt/schema' {
5
- interface NuxtConfig { ['pinegrow']?: Partial<ModuleOptions> }
6
- interface NuxtOptions { ['pinegrow']?: ModuleOptions }
7
- }
8
4
 
9
5
 
10
- export { ModuleOptions, default } from './module'
6
+
7
+ export { PinegrowNuxtModuleOptions, default } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinegrow/nuxt-module",
3
- "version": "3.0.0-beta.13",
3
+ "version": "3.0.0-beta.130",
4
4
  "description": "Pinegrow Nuxt Module",
5
5
  "author": "Pinegrow (http://pinegrow.com/)",
6
6
  "license": "MIT",
@@ -19,7 +19,9 @@
19
19
  "types": "./dist/types.d.ts",
20
20
  "keywords": [
21
21
  "pinegrow",
22
- "nuxt module"
22
+ "vue-designer",
23
+ "nuxt-module",
24
+ "@pinegrow/nuxt-module"
23
25
  ],
24
26
  "scripts": {
25
27
  "build": "npm run dev:prepare && npm run build:module",
@@ -28,16 +30,24 @@
28
30
  "dev:build": "nuxi build playground",
29
31
  "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
30
32
  "publish-beta": "npm run increment-beta-version && npm publish",
31
- "increment-beta-version": "npm version prerelease --preid=beta"
33
+ "increment-beta-version": "npm version prerelease --preid=beta",
34
+ "lint": "npm run lint:fix && npm run format",
35
+ "lint:fix": "eslint --ext .js,.cjs,.ts,.vue --ignore-path .gitignore --fix ./src",
36
+ "format": "prettier --write ."
32
37
  },
33
38
  "dependencies": {
34
39
  "@nuxt/kit": "latest",
35
- "@pinegrow/vite-plugin": "latest"
40
+ "@pinegrow/vite-plugin": "3.0.0-beta.130"
36
41
  },
37
42
  "devDependencies": {
38
43
  "@nuxt/module-builder": "latest",
39
- "@nuxtjs/eslint-config-typescript": "latest",
40
- "eslint": "latest",
41
- "nuxt": "rc"
44
+ "@nuxt/eslint-config": "^0.1.1",
45
+ "nuxt": "^3.1.0",
46
+ "eslint": "^8.35.0",
47
+ "eslint-config-prettier": "^8.7.0",
48
+ "prettier": "^2.8.4"
49
+ },
50
+ "peerDependencies": {
51
+ "nuxt": "^3.1.0"
42
52
  }
43
53
  }