@nuxtjs/prismic 1.5.0-alpha.0 → 1.5.0
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/prismic",
|
|
3
|
-
"version": "1.5.0
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Easily connect your Nuxt.js application to your content hosted on Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"dev": "nuxt example",
|
|
21
|
-
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
|
|
21
|
+
"release": "yarn test && standard-version && git push --follow-tags && npm publish --tag 1x",
|
|
22
22
|
"release:dry": "standard-version --dry-run",
|
|
23
23
|
"release:alpha": "yarn test && standard-version --release-as minor --prerelease alpha && git push --follow-tags && npm publish --tag alpha",
|
|
24
24
|
"release:alpha:dry": "standard-version --release-as minor --prerelease alpha --dry-run",
|
|
@@ -27,16 +27,13 @@
|
|
|
27
27
|
"test": "npm run lint && npm run unit"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@prismicio/client": "^
|
|
31
|
-
"@prismicio/vue": "^2.
|
|
32
|
-
"@slicemachine/manager": "0.1.1-dev-plugins.3",
|
|
30
|
+
"@prismicio/client": "^4.0.0 || ^5.1.0",
|
|
31
|
+
"@prismicio/vue": "^2.1.0",
|
|
33
32
|
"consola": "^2.15.3",
|
|
34
|
-
"
|
|
35
|
-
"prismic-dom": "^2.2.7"
|
|
33
|
+
"prismic-dom": "^2.2.6"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@nuxtjs/eslint-config": "latest",
|
|
39
|
-
"@prismicio/slice-simulator-vue": "^0.2.3",
|
|
40
37
|
"@types/jest": "latest",
|
|
41
38
|
"babel-eslint": "latest",
|
|
42
39
|
"eslint": "latest",
|
package/src/module.js
CHANGED
|
@@ -3,11 +3,10 @@ const fs = require('fs')
|
|
|
3
3
|
const logger = require('./logger')
|
|
4
4
|
const generate = require('./generator')
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
function install (moduleOptions) {
|
|
7
7
|
const options = {
|
|
8
8
|
preview: true,
|
|
9
9
|
previewReloadType: 'hot',
|
|
10
|
-
simulator: true,
|
|
11
10
|
components: true,
|
|
12
11
|
modern: false,
|
|
13
12
|
...moduleOptions,
|
|
@@ -23,9 +22,20 @@ async function install (moduleOptions) {
|
|
|
23
22
|
logger.warn('Options `endpoint` is required, disabling module...')
|
|
24
23
|
return
|
|
25
24
|
}
|
|
25
|
+
if (process.env.NUXT_PUBLIC_PRISMIC_ENVIRONMENT) {
|
|
26
|
+
options.endpoint = process.env.NUXT_PUBLIC_PRISMIC_ENVIRONMENT
|
|
27
|
+
try {
|
|
28
|
+
// eslint-disable-next-line no-new
|
|
29
|
+
new URL(options.endpoint)
|
|
30
|
+
} catch (error) {
|
|
31
|
+
options.endpoint = `https://${options.endpoint}.cdn.prismic.io/api/v2`
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.options.build.transpile.push('@prismicio/vue', '@prismicio/simulator')
|
|
36
|
+
|
|
26
37
|
const repo = options.endpoint.replace(/^https?:\/\//, '').replace(/(\.cdn)?\.prismic.+/, '')
|
|
27
38
|
const app = this.options.dir.app || 'app'
|
|
28
|
-
const pages = this.options.dir.pages || 'pages'
|
|
29
39
|
|
|
30
40
|
// Add in Prismic libraries to enable preview
|
|
31
41
|
if (options.preview) {
|
|
@@ -33,12 +43,6 @@ async function install (moduleOptions) {
|
|
|
33
43
|
const userPreviewPage = path.join(this.options.srcDir, app, 'prismic', 'pages', 'preview.vue')
|
|
34
44
|
const userPreviewPageExists = fs.existsSync(userPreviewPage)
|
|
35
45
|
|
|
36
|
-
if (userPreviewPageExists) {
|
|
37
|
-
logger.info(`Using user-defined preview page, available at \`${options.preview}\``)
|
|
38
|
-
} else {
|
|
39
|
-
logger.info(`Using default preview page, available at \`${options.preview}\``)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
46
|
this.addTemplate({
|
|
43
47
|
fileName: 'prismic/pages/preview.vue',
|
|
44
48
|
src: userPreviewPageExists ? userPreviewPage : path.join(__dirname, '../templates/pages/preview.vue')
|
|
@@ -52,121 +56,6 @@ async function install (moduleOptions) {
|
|
|
52
56
|
})
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
// Add in Prismic Simulator for Slice Machine
|
|
56
|
-
if (options.simulator) {
|
|
57
|
-
// Skip on existing simulator (legacy)
|
|
58
|
-
const slashSliceSimulator = path.join(this.options.srcDir, pages, 'slice-simulator.vue')
|
|
59
|
-
if (fs.existsSync(slashSliceSimulator)) {
|
|
60
|
-
logger.info('Using user-defined simulator page within the `pages` directory, available at `/slice-simulator')
|
|
61
|
-
} else {
|
|
62
|
-
// Detect Simulator provider (flavor)
|
|
63
|
-
let flavor
|
|
64
|
-
try {
|
|
65
|
-
require('@slicemachine/adapter-nuxt/simulator')
|
|
66
|
-
flavor = 'adapter'
|
|
67
|
-
} catch {
|
|
68
|
-
try {
|
|
69
|
-
require('@prismicio/slice-simulator-vue')
|
|
70
|
-
flavor = 'standalone'
|
|
71
|
-
} catch {
|
|
72
|
-
if (options.simulator !== true) {
|
|
73
|
-
logger.warn('Could not injected simulator page, `@slicemachine/adapter-nuxt` is not installed')
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Add page if flavor was detected
|
|
79
|
-
if (flavor) {
|
|
80
|
-
const simulatorPath = options.simulator === true ? '/simulator' : options.simulator
|
|
81
|
-
|
|
82
|
-
const userSimulatorPage = path.join(this.options.srcDir, app, 'prismic', 'pages', 'simulator.vue')
|
|
83
|
-
const userSimulatorPageExists = fs.existsSync(userSimulatorPage)
|
|
84
|
-
|
|
85
|
-
let registerPage = false
|
|
86
|
-
|
|
87
|
-
// Only needed for built-in Simulator
|
|
88
|
-
if (!userSimulatorPageExists) {
|
|
89
|
-
try {
|
|
90
|
-
const { createSliceMachineManager } = require('@slicemachine/manager')
|
|
91
|
-
|
|
92
|
-
const manager = createSliceMachineManager({ cwd: this.options.rootDir })
|
|
93
|
-
|
|
94
|
-
let root
|
|
95
|
-
|
|
96
|
-
try {
|
|
97
|
-
root = await manager.project.getRoot()
|
|
98
|
-
} catch {
|
|
99
|
-
root = this.options.rootDir
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
let config
|
|
103
|
-
try {
|
|
104
|
-
config = await manager.project.getSliceMachineConfig()
|
|
105
|
-
} catch {
|
|
106
|
-
let configPath
|
|
107
|
-
try {
|
|
108
|
-
configPath = await manager.project.getSliceMachineConfigPath()
|
|
109
|
-
config = JSON.parse(fs.readFileSync(configPath))
|
|
110
|
-
} catch {
|
|
111
|
-
configPath = path.join(root, 'sm.json')
|
|
112
|
-
config = JSON.parse(fs.readFileSync(configPath))
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!Array.isArray(config.libraries)) {
|
|
116
|
-
throw new TypeError(`\`${configPath}\` is missing \`libraries\` array`)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const rawLibraries = config.libraries
|
|
120
|
-
const libraries = []
|
|
121
|
-
|
|
122
|
-
for (const rawLibrary of rawLibraries) {
|
|
123
|
-
if (/^[@~.]\//.test(rawLibrary)) {
|
|
124
|
-
const libraryAbsolutePath = path.resolve(root, rawLibrary.replace(/^[@~.]/, '.'))
|
|
125
|
-
const libraryRelativePath = path.relative(this.options.rootDir, libraryAbsolutePath).replaceAll('\\', '/')
|
|
126
|
-
libraries.push(`~~/${libraryRelativePath}`)
|
|
127
|
-
} else {
|
|
128
|
-
libraries.push(rawLibrary)
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this.addTemplate({
|
|
133
|
-
fileName: 'prismic/all-slices.js',
|
|
134
|
-
src: path.join(__dirname, '../templates/all-slices.js'),
|
|
135
|
-
options: { libraries }
|
|
136
|
-
})
|
|
137
|
-
this.addTemplate({
|
|
138
|
-
fileName: 'prismic/pages/simulator.vue',
|
|
139
|
-
src: path.join(__dirname, `../templates/pages/simulator-${flavor}.vue`)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
registerPage = true
|
|
143
|
-
logger.info(`Using default simulator page, available at \`${simulatorPath}\``)
|
|
144
|
-
} catch (error) {
|
|
145
|
-
logger.warn("Could not resolve slice libraries, simulator page won't work\n\n", error)
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
this.addTemplate({
|
|
149
|
-
fileName: 'prismic/pages/simulator.vue',
|
|
150
|
-
src: userSimulatorPage
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
registerPage = true
|
|
154
|
-
logger.info(`Using user-defined simulator page, available at \`${simulatorPath}\``)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (registerPage) {
|
|
158
|
-
this.extendRoutes((routes, resolve) => {
|
|
159
|
-
routes.unshift({
|
|
160
|
-
name: 'prismic-slice-simulator',
|
|
161
|
-
path: simulatorPath,
|
|
162
|
-
component: resolve(this.options.buildDir, 'prismic/pages/simulator.vue')
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
59
|
// Add components
|
|
171
60
|
if (options.components) {
|
|
172
61
|
this.addPlugin({
|
package/templates/all-slices.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<SliceSimulator #default="{ slices }">
|
|
3
|
-
<SliceZone :slices="slices" :components="components" />
|
|
4
|
-
</SliceSimulator>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script>
|
|
8
|
-
import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";
|
|
9
|
-
|
|
10
|
-
import components from "../all-slices.js";
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
components: {
|
|
14
|
-
SliceSimulator
|
|
15
|
-
},
|
|
16
|
-
data() {
|
|
17
|
-
return { components };
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
</script>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<SliceSimulator #default="{ slices }" :state="{}">
|
|
3
|
-
<SliceZone :slices="slices" :components="components" />
|
|
4
|
-
</SliceSimulator>
|
|
5
|
-
</template>
|
|
6
|
-
|
|
7
|
-
<script>
|
|
8
|
-
import { SliceSimulator } from "@prismicio/slice-simulator-vue";
|
|
9
|
-
|
|
10
|
-
import components from "../all-slices.js";
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
components: {
|
|
14
|
-
SliceSimulator
|
|
15
|
-
},
|
|
16
|
-
data() {
|
|
17
|
-
return { components };
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
</script>
|