prismic 1.1.0 → 1.2.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/dist/{builders-hKD4IrLX-ClhMQQkN.mjs → builders-hKD4IrLX-BrpqCAS2.mjs} +1 -1
- package/dist/index.mjs +115 -101
- package/dist/nextjs-HiDO_p-p.mjs +318 -0
- package/dist/nuxt-CDrqbn0o.mjs +59 -0
- package/dist/string-BUjs_2AH.mjs +7 -0
- package/dist/{sveltekit-BMDXAfYz.mjs → sveltekit-Qx8xJZOd.mjs} +45 -35
- package/package.json +1 -1
- package/src/adapters/index.ts +177 -0
- package/src/{frameworks → adapters}/nextjs.templates.ts +102 -102
- package/src/adapters/nextjs.ts +211 -0
- package/src/adapters/nuxt.ts +232 -0
- package/src/adapters/sveltekit.ts +226 -0
- package/src/clients/core.ts +104 -0
- package/src/clients/wroom.ts +111 -0
- package/src/commands/init.ts +57 -69
- package/src/commands/login.ts +12 -29
- package/src/commands/logout.ts +8 -28
- package/src/commands/preview-add.ts +57 -0
- package/src/commands/preview-list.ts +54 -0
- package/src/commands/preview-remove.ts +51 -0
- package/src/commands/preview-set-simulator.ts +60 -0
- package/src/commands/preview.ts +28 -0
- package/src/commands/sync.ts +49 -87
- package/src/commands/webhook-create.ts +89 -0
- package/src/commands/webhook-disable.ts +60 -0
- package/src/commands/webhook-enable.ts +60 -0
- package/src/commands/webhook-list.ts +43 -0
- package/src/commands/webhook-remove.ts +52 -0
- package/src/commands/webhook-set-triggers.ts +93 -0
- package/src/commands/webhook-view.ts +65 -0
- package/src/commands/webhook.ts +43 -0
- package/src/commands/whoami.ts +7 -28
- package/src/config.ts +2 -11
- package/src/index.ts +122 -105
- package/src/lib/command.ts +188 -0
- package/src/lib/file.ts +13 -1
- package/src/lib/packageJson.ts +70 -1
- package/src/lib/segment.ts +26 -30
- package/src/project.ts +54 -0
- package/dist/frameworks-DtGBrEuY.mjs +0 -17
- package/dist/nextjs-2qjzSaQI.mjs +0 -312
- package/dist/nuxt-DKsgbqpV.mjs +0 -59
- package/src/frameworks/index.ts +0 -398
- package/src/frameworks/nextjs.ts +0 -211
- package/src/frameworks/nuxt.ts +0 -252
- package/src/frameworks/sveltekit.ts +0 -234
- /package/src/{frameworks → adapters}/nuxt.templates.ts +0 -0
- /package/src/{frameworks → adapters}/sveltekit.templates.ts +0 -0
package/src/frameworks/nuxt.ts
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
|
|
3
|
-
import { builders, loadFile, writeFile as magicastWriteFile } from "magicast";
|
|
4
|
-
import { readFile, rm } from "node:fs/promises";
|
|
5
|
-
import { relative } from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
|
|
8
|
-
import type { Framework } from ".";
|
|
9
|
-
|
|
10
|
-
import { FrameworkAdapter } from ".";
|
|
11
|
-
import { readConfig, updateConfig } from "../config";
|
|
12
|
-
import { exists, writeFileRecursive } from "../lib/file";
|
|
13
|
-
import { getNpmPackageVersion } from "../lib/packageJson";
|
|
14
|
-
import { dedent } from "../lib/string";
|
|
15
|
-
import { sliceSimulatorPageTemplate, sliceTemplate } from "./nuxt.templates";
|
|
16
|
-
|
|
17
|
-
const NUXT_PRISMIC = "@nuxtjs/prismic";
|
|
18
|
-
|
|
19
|
-
export class NuxtFramework extends FrameworkAdapter {
|
|
20
|
-
readonly id: Framework = "nuxt";
|
|
21
|
-
|
|
22
|
-
async getDependencies(): Promise<Record<string, string>> {
|
|
23
|
-
return {
|
|
24
|
-
"@prismicio/client": `^${await getNpmPackageVersion("@prismicio/client")}`,
|
|
25
|
-
[NUXT_PRISMIC]: `^${await getNpmPackageVersion(NUXT_PRISMIC)}`,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async initProject(): Promise<void> {
|
|
30
|
-
await super.initProject();
|
|
31
|
-
|
|
32
|
-
await this.#configureNuxtModule();
|
|
33
|
-
await this.#createSliceSimulatorPage();
|
|
34
|
-
await this.#moveOrDeleteAppVue();
|
|
35
|
-
await this.#modifySliceLibraryPath();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async createSliceComponent(
|
|
39
|
-
model: SharedSlice,
|
|
40
|
-
sliceDirectory: URL,
|
|
41
|
-
): Promise<{ componentPath: URL }> {
|
|
42
|
-
const componentPath = new URL("index.vue", sliceDirectory);
|
|
43
|
-
const contents = sliceTemplate({
|
|
44
|
-
name: model.name,
|
|
45
|
-
typescript: await this.checkIsTypeScriptProject(),
|
|
46
|
-
});
|
|
47
|
-
await writeFileRecursive(componentPath, contents);
|
|
48
|
-
return { componentPath };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
getSliceImportPath(relativeDirectory: string): string {
|
|
52
|
-
return `./${relativeDirectory}/index.vue`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async getDefaultSliceLibraryPath(_projectRoot: URL): Promise<URL> {
|
|
56
|
-
const srcDir = await this.#getSrcDir();
|
|
57
|
-
return new URL("slices/", srcDir);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async getClientFilePath(): Promise<string | null> {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async getSlicesDirectoryPath(): Promise<string> {
|
|
65
|
-
const projectRoot = await this.getProjectRoot();
|
|
66
|
-
const appDir = new URL("app/", projectRoot);
|
|
67
|
-
if (await exists(appDir)) return "app/slices/";
|
|
68
|
-
const srcDir = new URL("src/", projectRoot);
|
|
69
|
-
if (await exists(srcDir)) return "src/slices/";
|
|
70
|
-
return "slices/";
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getSliceComponentExtensions(): string[] {
|
|
74
|
-
return [".vue"];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async getRoutePath(route: string): Promise<{ path: string; extensions: string[] } | null> {
|
|
78
|
-
if (route === "/slice-simulator") {
|
|
79
|
-
return { path: "pages/slice-simulator", extensions: [".vue"] };
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
protected override async generateSliceLibraryIndexContents(
|
|
85
|
-
slices: { library: URL; directory: URL; model: SharedSlice }[],
|
|
86
|
-
): Promise<string> {
|
|
87
|
-
const componentLines = await Promise.all(
|
|
88
|
-
slices.map(async (slice) => {
|
|
89
|
-
const relativeDirectory = relative(
|
|
90
|
-
fileURLToPath(slice.library),
|
|
91
|
-
fileURLToPath(slice.directory),
|
|
92
|
-
);
|
|
93
|
-
return `${slice.model.id}: defineAsyncComponent(() => import("./${relativeDirectory}/index.vue"))`;
|
|
94
|
-
}),
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
return dedent`
|
|
98
|
-
// Code generated by Prismic. DO NOT EDIT.
|
|
99
|
-
|
|
100
|
-
import { defineAsyncComponent } from "vue";
|
|
101
|
-
import { defineSliceZoneComponents } from "@prismicio/vue";
|
|
102
|
-
|
|
103
|
-
export const components = defineSliceZoneComponents({
|
|
104
|
-
${componentLines.join(",\n")}
|
|
105
|
-
});
|
|
106
|
-
`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
async #getSrcDir(): Promise<URL> {
|
|
110
|
-
const projectRoot = await this.getProjectRoot();
|
|
111
|
-
const appDir = new URL("app/", projectRoot);
|
|
112
|
-
if (await exists(appDir)) return appDir;
|
|
113
|
-
const srcDir = new URL("src/", projectRoot);
|
|
114
|
-
if (await exists(srcDir)) return srcDir;
|
|
115
|
-
return projectRoot;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async #configureNuxtModule(): Promise<void> {
|
|
119
|
-
const projectRoot = await this.getProjectRoot();
|
|
120
|
-
|
|
121
|
-
let configUrl = new URL("nuxt.config.js", projectRoot);
|
|
122
|
-
if (!(await exists(configUrl))) {
|
|
123
|
-
configUrl = new URL("nuxt.config.ts", projectRoot);
|
|
124
|
-
}
|
|
125
|
-
if (!(await exists(configUrl))) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const filepath = fileURLToPath(configUrl);
|
|
130
|
-
const mod = await loadFile(filepath);
|
|
131
|
-
const config =
|
|
132
|
-
mod.exports.default.$type === "function-call"
|
|
133
|
-
? mod.exports.default.$args[0]
|
|
134
|
-
: mod.exports.default;
|
|
135
|
-
|
|
136
|
-
// Check if @nuxtjs/prismic is already registered
|
|
137
|
-
let hasInlinedConfiguration = false;
|
|
138
|
-
const hasPrismicModuleRegistered = (config.modules || []).find(
|
|
139
|
-
(registration: string | [string, unknown]) => {
|
|
140
|
-
if (typeof registration === "string") {
|
|
141
|
-
return registration === NUXT_PRISMIC;
|
|
142
|
-
} else if (Array.isArray(registration)) {
|
|
143
|
-
hasInlinedConfiguration = !!registration[1];
|
|
144
|
-
return registration[0] === NUXT_PRISMIC;
|
|
145
|
-
}
|
|
146
|
-
return false;
|
|
147
|
-
},
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
if (!hasPrismicModuleRegistered) {
|
|
151
|
-
config.modules ||= [];
|
|
152
|
-
config.modules.push(NUXT_PRISMIC);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Append Prismic module configuration if not inlined
|
|
156
|
-
if (!hasInlinedConfiguration) {
|
|
157
|
-
mod.imports.$prepend({
|
|
158
|
-
from: "./prismic.config.json",
|
|
159
|
-
imported: "repositoryName",
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
config.prismic ||= {};
|
|
163
|
-
config.prismic.endpoint = builders.raw("repositoryName");
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
await magicastWriteFile(mod, filepath);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async #createSliceSimulatorPage(): Promise<void> {
|
|
170
|
-
const projectRoot = await this.getProjectRoot();
|
|
171
|
-
const typescript = await this.checkIsTypeScriptProject();
|
|
172
|
-
|
|
173
|
-
// Check for existing pages directories in priority order
|
|
174
|
-
const appPagesDir = new URL("app/pages/", projectRoot);
|
|
175
|
-
const srcPagesDir = new URL("src/pages/", projectRoot);
|
|
176
|
-
const pagesDir = new URL("pages/", projectRoot);
|
|
177
|
-
|
|
178
|
-
let targetDir: URL;
|
|
179
|
-
if (await exists(appPagesDir)) {
|
|
180
|
-
targetDir = appPagesDir;
|
|
181
|
-
} else if (await exists(srcPagesDir)) {
|
|
182
|
-
targetDir = srcPagesDir;
|
|
183
|
-
} else if (await exists(pagesDir)) {
|
|
184
|
-
targetDir = pagesDir;
|
|
185
|
-
} else {
|
|
186
|
-
targetDir = new URL("pages/", await this.#getSrcDir());
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const filePath = new URL("slice-simulator.vue", targetDir);
|
|
190
|
-
|
|
191
|
-
if (await exists(filePath)) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const contents = sliceSimulatorPageTemplate({ typescript });
|
|
196
|
-
await writeFileRecursive(filePath, contents);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async #moveOrDeleteAppVue(): Promise<void> {
|
|
200
|
-
const srcDir = await this.#getSrcDir();
|
|
201
|
-
const appVuePath = new URL("app.vue", srcDir);
|
|
202
|
-
|
|
203
|
-
if (!(await exists(appVuePath))) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const contents = await readFile(appVuePath, "utf8");
|
|
208
|
-
|
|
209
|
-
if (!contents.includes("<NuxtWelcome")) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const indexVuePath = new URL("pages/index.vue", srcDir);
|
|
214
|
-
|
|
215
|
-
if (!(await exists(indexVuePath))) {
|
|
216
|
-
await writeFileRecursive(indexVuePath, contents);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
await rm(appVuePath);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
async #modifySliceLibraryPath(): Promise<void> {
|
|
223
|
-
const projectRoot = await this.getProjectRoot();
|
|
224
|
-
const hasAppDir = await exists(new URL("app/", projectRoot));
|
|
225
|
-
const hasSrcDir = await exists(new URL("src/", projectRoot));
|
|
226
|
-
|
|
227
|
-
if (!hasAppDir && !hasSrcDir) {
|
|
228
|
-
return;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
let config;
|
|
232
|
-
try {
|
|
233
|
-
config = await readConfig();
|
|
234
|
-
} catch {
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const libraries = config.libraries;
|
|
239
|
-
if (!libraries || JSON.stringify(libraries) !== JSON.stringify(["./slices"])) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Only modify if the default library has no slices yet
|
|
244
|
-
const slices = await this.getSlices();
|
|
245
|
-
if (slices.length > 0) {
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const newLibrary = hasAppDir ? "./app/slices" : "./src/slices";
|
|
250
|
-
await updateConfig({ libraries: [newLibrary] });
|
|
251
|
-
}
|
|
252
|
-
}
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import type { SharedSlice } from "@prismicio/types-internal/lib/customtypes";
|
|
2
|
-
|
|
3
|
-
import { loadFile } from "magicast";
|
|
4
|
-
import { writeFile } from "node:fs/promises";
|
|
5
|
-
import { createRequire } from "node:module";
|
|
6
|
-
|
|
7
|
-
import type { Framework } from ".";
|
|
8
|
-
|
|
9
|
-
import { FrameworkAdapter } from ".";
|
|
10
|
-
import { exists, writeFileRecursive } from "../lib/file";
|
|
11
|
-
import { getNpmPackageVersion } from "../lib/packageJson";
|
|
12
|
-
import { dedent } from "../lib/string";
|
|
13
|
-
import {
|
|
14
|
-
previewAPIRouteTemplate,
|
|
15
|
-
prismicIOFileTemplate,
|
|
16
|
-
rootLayoutTemplate,
|
|
17
|
-
sliceSimulatorPageTemplate,
|
|
18
|
-
sliceTemplate,
|
|
19
|
-
} from "./sveltekit.templates";
|
|
20
|
-
|
|
21
|
-
export class SvelteKitFramework extends FrameworkAdapter {
|
|
22
|
-
readonly id: Framework = "sveltekit";
|
|
23
|
-
|
|
24
|
-
async getDependencies(): Promise<Record<string, string>> {
|
|
25
|
-
return {
|
|
26
|
-
"@prismicio/client": `^${await getNpmPackageVersion("@prismicio/client")}`,
|
|
27
|
-
"@prismicio/svelte": `^${await getNpmPackageVersion("@prismicio/svelte")}`,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async initProject(): Promise<void> {
|
|
32
|
-
await super.initProject();
|
|
33
|
-
|
|
34
|
-
await this.#createPrismicIOFile();
|
|
35
|
-
await this.#createSliceSimulatorPage();
|
|
36
|
-
await this.#createPreviewRouteMatcher();
|
|
37
|
-
await this.#createPreviewAPIRoute();
|
|
38
|
-
await this.#createPreviewRouteDirectory();
|
|
39
|
-
await this.#createRootLayoutServerFile();
|
|
40
|
-
await this.#createRootLayoutFile();
|
|
41
|
-
await this.#modifyViteConfig();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async createSliceComponent(
|
|
45
|
-
model: SharedSlice,
|
|
46
|
-
sliceDirectory: URL,
|
|
47
|
-
): Promise<{ componentPath: URL }> {
|
|
48
|
-
const componentPath = new URL("index.svelte", sliceDirectory);
|
|
49
|
-
const contents = sliceTemplate({
|
|
50
|
-
name: model.name,
|
|
51
|
-
typescript: await this.checkIsTypeScriptProject(),
|
|
52
|
-
version: await this.#getSvelteMajor(),
|
|
53
|
-
});
|
|
54
|
-
await writeFileRecursive(componentPath, contents);
|
|
55
|
-
return { componentPath };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
getSliceImportPath(relativeDirectory: string): string {
|
|
59
|
-
return `./${relativeDirectory}/index.svelte`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async getDefaultSliceLibraryPath(projectRoot: URL): Promise<URL> {
|
|
63
|
-
return new URL("src/lib/slices/", projectRoot);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async getClientFilePath(): Promise<string | null> {
|
|
67
|
-
return "src/lib/prismicio.ts";
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async getSlicesDirectoryPath(): Promise<string> {
|
|
71
|
-
return "src/lib/slices/";
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getSliceComponentExtensions(): string[] {
|
|
75
|
-
return [".svelte"];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async getRoutePath(route: string): Promise<{ path: string; extensions: string[] } | null> {
|
|
79
|
-
switch (route) {
|
|
80
|
-
case "/slice-simulator":
|
|
81
|
-
return { path: "src/routes/slice-simulator/+page", extensions: [".svelte"] };
|
|
82
|
-
case "/api/preview":
|
|
83
|
-
return { path: "src/routes/api/preview/+server", extensions: [".ts", ".js"] };
|
|
84
|
-
default:
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async #createPrismicIOFile(): Promise<void> {
|
|
90
|
-
const extension = await this.getJsFileExtension();
|
|
91
|
-
const projectRoot = await this.getProjectRoot();
|
|
92
|
-
const filePath = new URL(`src/lib/prismicio.${extension}`, projectRoot);
|
|
93
|
-
|
|
94
|
-
if (await exists(filePath)) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const typescript = await this.checkIsTypeScriptProject();
|
|
99
|
-
const contents = prismicIOFileTemplate({ typescript });
|
|
100
|
-
await writeFileRecursive(filePath, contents);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
async #createSliceSimulatorPage(): Promise<void> {
|
|
104
|
-
const projectRoot = await this.getProjectRoot();
|
|
105
|
-
const filePath = new URL("src/routes/slice-simulator/+page.svelte", projectRoot);
|
|
106
|
-
|
|
107
|
-
if (await exists(filePath)) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const contents = sliceSimulatorPageTemplate({
|
|
112
|
-
version: await this.#getSvelteMajor(),
|
|
113
|
-
});
|
|
114
|
-
await writeFileRecursive(filePath, contents);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
async #createPreviewRouteMatcher(): Promise<void> {
|
|
118
|
-
const extension = await this.getJsFileExtension();
|
|
119
|
-
const projectRoot = await this.getProjectRoot();
|
|
120
|
-
const filePath = new URL(`src/params/preview.${extension}`, projectRoot);
|
|
121
|
-
|
|
122
|
-
if (await exists(filePath)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const contents = dedent`
|
|
127
|
-
export function match(param) {
|
|
128
|
-
return param === 'preview';
|
|
129
|
-
}
|
|
130
|
-
`;
|
|
131
|
-
await writeFileRecursive(filePath, contents);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async #createPreviewAPIRoute(): Promise<void> {
|
|
135
|
-
const extension = await this.getJsFileExtension();
|
|
136
|
-
const projectRoot = await this.getProjectRoot();
|
|
137
|
-
const filePath = new URL(`src/routes/api/preview/+server.${extension}`, projectRoot);
|
|
138
|
-
|
|
139
|
-
if (await exists(filePath)) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const typescript = await this.checkIsTypeScriptProject();
|
|
144
|
-
const contents = previewAPIRouteTemplate({ typescript });
|
|
145
|
-
await writeFileRecursive(filePath, contents);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async #createPreviewRouteDirectory(): Promise<void> {
|
|
149
|
-
const projectRoot = await this.getProjectRoot();
|
|
150
|
-
const filePath = new URL("src/routes/[[preview=preview]]/README.md", projectRoot);
|
|
151
|
-
|
|
152
|
-
if (await exists(filePath)) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const contents = dedent`
|
|
157
|
-
This directory adds support for optional \`/preview\` routes. Do not remove this directory.
|
|
158
|
-
|
|
159
|
-
All routes within this directory will be served using the following URLs:
|
|
160
|
-
|
|
161
|
-
- \`/example-route\` (prerendered)
|
|
162
|
-
- \`/preview/example-route\` (server-rendered)
|
|
163
|
-
|
|
164
|
-
See <https://prismic.io/docs/svelte-preview> for more information.
|
|
165
|
-
`;
|
|
166
|
-
await writeFileRecursive(filePath, contents);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async #createRootLayoutServerFile(): Promise<void> {
|
|
170
|
-
const extension = await this.getJsFileExtension();
|
|
171
|
-
const projectRoot = await this.getProjectRoot();
|
|
172
|
-
const filePath = new URL(`src/routes/+layout.server.${extension}`, projectRoot);
|
|
173
|
-
|
|
174
|
-
if (await exists(filePath)) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const contents = dedent`
|
|
179
|
-
export const prerender = "auto";
|
|
180
|
-
`;
|
|
181
|
-
await writeFileRecursive(filePath, contents);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
async #createRootLayoutFile(): Promise<void> {
|
|
185
|
-
const projectRoot = await this.getProjectRoot();
|
|
186
|
-
const filePath = new URL("src/routes/+layout.svelte", projectRoot);
|
|
187
|
-
|
|
188
|
-
if (await exists(filePath)) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const contents = rootLayoutTemplate({
|
|
193
|
-
version: await this.#getSvelteMajor(),
|
|
194
|
-
});
|
|
195
|
-
await writeFileRecursive(filePath, contents);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async #modifyViteConfig(): Promise<void> {
|
|
199
|
-
const projectRoot = await this.getProjectRoot();
|
|
200
|
-
let configUrl = new URL("vite.config.js", projectRoot);
|
|
201
|
-
if (!(await exists(configUrl))) {
|
|
202
|
-
configUrl = new URL("vite.config.ts", projectRoot);
|
|
203
|
-
}
|
|
204
|
-
if (!(await exists(configUrl))) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const filepath = configUrl.pathname;
|
|
209
|
-
const mod = await loadFile(filepath);
|
|
210
|
-
if (mod.exports.default.$type !== "function-call") {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const config = mod.exports.default.$args[0];
|
|
215
|
-
config.server ??= {};
|
|
216
|
-
config.server.fs ??= {};
|
|
217
|
-
config.server.fs.allow ??= [];
|
|
218
|
-
if (!config.server.fs.allow.includes("./prismic.config.json")) {
|
|
219
|
-
config.server.fs.allow.push("./prismic.config.json");
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const contents = mod.generate().code.replace(/\n\s*\n(?=\s*server:)/, "\n");
|
|
223
|
-
await writeFile(configUrl, contents);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async #getSvelteMajor(): Promise<number> {
|
|
227
|
-
const projectRoot = await this.getProjectRoot();
|
|
228
|
-
const require = createRequire(new URL("package.json", projectRoot));
|
|
229
|
-
const { version } = require("svelte/package.json");
|
|
230
|
-
const major = Number.parseInt(version.split(".")[0]);
|
|
231
|
-
if (Number.isNaN(major)) return Infinity;
|
|
232
|
-
return major;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
File without changes
|
|
File without changes
|