@slicemachine/adapter-sveltekit 0.0.0 → 0.3.10-dev-adapter-svelte-kit.3
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 +202 -0
- package/README.md +98 -0
- package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
- package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
- package/dist/_node_modules/data-uri-to-buffer/dist/index.js +41 -0
- package/dist/_node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
- package/dist/_node_modules/fetch-blob/file.cjs +61 -0
- package/dist/_node_modules/fetch-blob/file.cjs.map +1 -0
- package/dist/_node_modules/fetch-blob/file.js +61 -0
- package/dist/_node_modules/fetch-blob/file.js.map +1 -0
- package/dist/_node_modules/fetch-blob/index.cjs +223 -0
- package/dist/_node_modules/fetch-blob/index.cjs.map +1 -0
- package/dist/_node_modules/fetch-blob/index.js +223 -0
- package/dist/_node_modules/fetch-blob/index.js.map +1 -0
- package/dist/_node_modules/fetch-blob/streams.cjs +43 -0
- package/dist/_node_modules/fetch-blob/streams.cjs.map +1 -0
- package/dist/_node_modules/fetch-blob/streams.js +42 -0
- package/dist/_node_modules/fetch-blob/streams.js.map +1 -0
- package/dist/_node_modules/formdata-polyfill/esm.min.cjs +116 -0
- package/dist/_node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
- package/dist/_node_modules/formdata-polyfill/esm.min.js +116 -0
- package/dist/_node_modules/formdata-polyfill/esm.min.js.map +1 -0
- package/dist/_node_modules/node-domexception/index.cjs +11 -0
- package/dist/_node_modules/node-domexception/index.cjs.map +1 -0
- package/dist/_node_modules/node-domexception/index.js +10 -0
- package/dist/_node_modules/node-domexception/index.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/body.cjs +262 -0
- package/dist/_node_modules/node-fetch/src/body.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/body.js +262 -0
- package/dist/_node_modules/node-fetch/src/body.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
- package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/abort-error.js +10 -0
- package/dist/_node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/base.cjs +17 -0
- package/dist/_node_modules/node-fetch/src/errors/base.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/base.js +17 -0
- package/dist/_node_modules/node-fetch/src/errors/base.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs +19 -0
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.js +19 -0
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/headers.cjs +190 -0
- package/dist/_node_modules/node-fetch/src/headers.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/headers.js +190 -0
- package/dist/_node_modules/node-fetch/src/headers.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/index.cjs +292 -0
- package/dist/_node_modules/node-fetch/src/index.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/index.js +292 -0
- package/dist/_node_modules/node-fetch/src/index.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/request.cjs +206 -0
- package/dist/_node_modules/node-fetch/src/request.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/request.js +206 -0
- package/dist/_node_modules/node-fetch/src/request.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/response.cjs +122 -0
- package/dist/_node_modules/node-fetch/src/response.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/response.js +123 -0
- package/dist/_node_modules/node-fetch/src/response.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/get-search.cjs +12 -0
- package/dist/_node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/get-search.js +12 -0
- package/dist/_node_modules/node-fetch/src/utils/get-search.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.js +8 -0
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/is.cjs +28 -0
- package/dist/_node_modules/node-fetch/src/utils/is.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/is.js +28 -0
- package/dist/_node_modules/node-fetch/src/utils/is.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs +356 -0
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js +356 -0
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/referrer.cjs +149 -0
- package/dist/_node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/referrer.js +149 -0
- package/dist/_node_modules/node-fetch/src/utils/referrer.js.map +1 -0
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3822 -0
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3822 -0
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
- package/dist/_virtual/_commonjsHelpers.cjs +5 -0
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
- package/dist/_virtual/_commonjsHelpers.js +5 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/ponyfill.es2018.cjs +5 -0
- package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
- package/dist/_virtual/ponyfill.es2018.js +5 -0
- package/dist/_virtual/ponyfill.es2018.js.map +1 -0
- package/dist/constants.cjs +5 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/hooks/project-init.cjs +211 -0
- package/dist/hooks/project-init.cjs.map +1 -0
- package/dist/hooks/project-init.d.ts +3 -0
- package/dist/hooks/project-init.js +194 -0
- package/dist/hooks/project-init.js.map +1 -0
- package/dist/hooks/slice-create.cjs +69 -0
- package/dist/hooks/slice-create.cjs.map +1 -0
- package/dist/hooks/slice-create.d.ts +3 -0
- package/dist/hooks/slice-create.js +69 -0
- package/dist/hooks/slice-create.js.map +1 -0
- package/dist/hooks/sliceSimulator-setup-read.cjs +144 -0
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -0
- package/dist/hooks/sliceSimulator-setup-read.d.ts +3 -0
- package/dist/hooks/sliceSimulator-setup-read.js +144 -0
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -0
- package/dist/hooks/snippet-read.cjs +114 -0
- package/dist/hooks/snippet-read.cjs.map +1 -0
- package/dist/hooks/snippet-read.d.ts +3 -0
- package/dist/hooks/snippet-read.js +114 -0
- package/dist/hooks/snippet-read.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/checkIsTypeScriptProject.cjs +8 -0
- package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -0
- package/dist/lib/checkIsTypeScriptProject.d.ts +8 -0
- package/dist/lib/checkIsTypeScriptProject.js +8 -0
- package/dist/lib/checkIsTypeScriptProject.js.map +1 -0
- package/dist/lib/getJSFileExtension.cjs +12 -0
- package/dist/lib/getJSFileExtension.cjs.map +1 -0
- package/dist/lib/getJSFileExtension.d.ts +5 -0
- package/dist/lib/getJSFileExtension.js +12 -0
- package/dist/lib/getJSFileExtension.js.map +1 -0
- package/dist/lib/pascalCase.cjs +8 -0
- package/dist/lib/pascalCase.cjs.map +1 -0
- package/dist/lib/pascalCase.d.ts +8 -0
- package/dist/lib/pascalCase.js +8 -0
- package/dist/lib/pascalCase.js.map +1 -0
- package/dist/lib/rejectIfNecessary.cjs +10 -0
- package/dist/lib/rejectIfNecessary.cjs.map +1 -0
- package/dist/lib/rejectIfNecessary.d.ts +1 -0
- package/dist/lib/rejectIfNecessary.js +10 -0
- package/dist/lib/rejectIfNecessary.js.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +67 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js +50 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
- package/dist/packages/adapter-sveltekit/package.json.cjs +5 -0
- package/dist/packages/adapter-sveltekit/package.json.cjs.map +1 -0
- package/dist/packages/adapter-sveltekit/package.json.js +5 -0
- package/dist/packages/adapter-sveltekit/package.json.js.map +1 -0
- package/dist/plugin.cjs +204 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +204 -0
- package/dist/plugin.js.map +1 -0
- package/dist/simulator/SliceSimulator.svelte +65 -0
- package/dist/simulator/SliceSimulator.svelte.d.ts +35 -0
- package/dist/simulator/index.d.ts +1 -0
- package/dist/simulator/index.js +1 -0
- package/dist/types.d.ts +21 -0
- package/package.json +111 -2
- package/src/constants.ts +5 -0
- package/src/hooks/project-init.ts +265 -0
- package/src/hooks/slice-create.ts +120 -0
- package/src/hooks/sliceSimulator-setup-read.ts +203 -0
- package/src/hooks/snippet-read.ts +163 -0
- package/src/index.ts +3 -0
- package/src/lib/checkIsTypeScriptProject.ts +18 -0
- package/src/lib/getJSFileExtension.ts +22 -0
- package/src/lib/pascalCase.ts +12 -0
- package/src/lib/rejectIfNecessary.ts +16 -0
- package/src/lib/upsertSliceLibraryIndexFile.ts +77 -0
- package/src/plugin.ts +275 -0
- package/src/simulator/SliceSimulator.svelte +65 -0
- package/src/simulator/index.ts +1 -0
- package/src/types.ts +23 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
4
|
+
exports.commonjsGlobal = commonjsGlobal;
|
|
5
|
+
//# sourceMappingURL=_commonjsHelpers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_commonjsHelpers.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
2
|
+
export {
|
|
3
|
+
commonjsGlobal
|
|
4
|
+
};
|
|
5
|
+
//# sourceMappingURL=_commonjsHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_commonjsHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ponyfill.es2018.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ponyfill.es2018.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const NON_EDITABLE_FILE_BANNER = "// Code generated by Slice Machine. DO NOT EDIT.";
|
|
4
|
+
exports.NON_EDITABLE_FILE_BANNER = NON_EDITABLE_FILE_BANNER;
|
|
5
|
+
//# sourceMappingURL=constants.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["/**\n * Banner text added to files that should not be edited by users.\n */\nexport const NON_EDITABLE_FILE_BANNER =\n\t\"// Code generated by Slice Machine. DO NOT EDIT.\";\n"],"names":[],"mappings":";;AAGO,MAAM,2BACZ;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../src/constants.ts"],"sourcesContent":["/**\n * Banner text added to files that should not be edited by users.\n */\nexport const NON_EDITABLE_FILE_BANNER =\n\t\"// Code generated by Slice Machine. DO NOT EDIT.\";\n"],"names":[],"mappings":"AAGO,MAAM,2BACZ;"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const fs = require("@slicemachine/plugin-kit/fs");
|
|
5
|
+
const commonTags = require("common-tags");
|
|
6
|
+
const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
|
|
7
|
+
const getJSFileExtension = require("../lib/getJSFileExtension.cjs");
|
|
8
|
+
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
9
|
+
const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
12
|
+
if (e) {
|
|
13
|
+
for (const k in e) {
|
|
14
|
+
if (k !== "default") {
|
|
15
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: () => e[k]
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
27
|
+
var __freeze = Object.freeze;
|
|
28
|
+
var __defProp = Object.defineProperty;
|
|
29
|
+
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
|
|
30
|
+
var _a;
|
|
31
|
+
const installDependencies = async ({ installDependencies: installDependencies2 }) => {
|
|
32
|
+
await installDependencies2({
|
|
33
|
+
dependencies: {
|
|
34
|
+
"@prismicio/client": "latest",
|
|
35
|
+
"@prismicio/svelte": "latest"
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const createPrismicIOFile = async ({ helpers, options }) => {
|
|
40
|
+
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
41
|
+
helpers,
|
|
42
|
+
options
|
|
43
|
+
});
|
|
44
|
+
const extension = await getJSFileExtension.getJSFileExtension({ helpers, options });
|
|
45
|
+
const filename = path__namespace.join(`src/lib/prismicio.${extension}`);
|
|
46
|
+
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
let createClientContents;
|
|
50
|
+
if (isTypeScriptProject) {
|
|
51
|
+
createClientContents = commonTags.source`
|
|
52
|
+
/**
|
|
53
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
54
|
+
* query content from the Prismic API.
|
|
55
|
+
*
|
|
56
|
+
* @param config - Configuration for the Prismic client.
|
|
57
|
+
*/
|
|
58
|
+
export const createClient = (config: prismic.ClientConfig = {}) => {
|
|
59
|
+
const client = prismic.createClient(repositoryName, {
|
|
60
|
+
routes,
|
|
61
|
+
...config,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return client;
|
|
65
|
+
};
|
|
66
|
+
`;
|
|
67
|
+
} else {
|
|
68
|
+
createClientContents = commonTags.source`
|
|
69
|
+
/**
|
|
70
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
71
|
+
* query content from the Prismic API.
|
|
72
|
+
*
|
|
73
|
+
* @param {prismic.ClientConfig} config - Configuration for the Prismic client.
|
|
74
|
+
*/
|
|
75
|
+
export const createClient = (config = {}) => {
|
|
76
|
+
const client = prismic.createClient(repositoryName, {
|
|
77
|
+
routes,
|
|
78
|
+
...config,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return client;
|
|
82
|
+
};
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
let contents;
|
|
86
|
+
if (isTypeScriptProject) {
|
|
87
|
+
contents = commonTags.source`
|
|
88
|
+
import * as prismic from "@prismicio/client";
|
|
89
|
+
import config from "../../slicemachine.config.json";
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The project's Prismic repository name.
|
|
93
|
+
*/
|
|
94
|
+
export const repositoryName = config.repositoryName;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
|
|
98
|
+
*
|
|
99
|
+
* {@link https://prismic.io/docs/route-resolver#route-resolver}
|
|
100
|
+
*/
|
|
101
|
+
// TODO: Update the routes array to match your project's route structure.
|
|
102
|
+
const routes: prismic.ClientConfig["routes"] = [
|
|
103
|
+
{
|
|
104
|
+
type: "homepage",
|
|
105
|
+
path: "/",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
type: "page",
|
|
109
|
+
path: "/:uid",
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
${createClientContents}
|
|
114
|
+
`;
|
|
115
|
+
} else {
|
|
116
|
+
contents = commonTags.source`
|
|
117
|
+
import * as prismic from "@prismicio/client";
|
|
118
|
+
import config from "../../slicemachine.config.json";
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The project's Prismic repository name.
|
|
122
|
+
*/
|
|
123
|
+
export const repositoryName = config.repositoryName;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
|
|
127
|
+
*
|
|
128
|
+
* {@link https://prismic.io/docs/route-resolver#route-resolver}
|
|
129
|
+
*
|
|
130
|
+
* @type {prismic.ClientConfig["routes"]}
|
|
131
|
+
*/
|
|
132
|
+
// TODO: Update the routes array to match your project's route structure.
|
|
133
|
+
const routes = [
|
|
134
|
+
{
|
|
135
|
+
type: "homepage",
|
|
136
|
+
path: "/",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
type: "page",
|
|
140
|
+
path: "/:uid",
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
${createClientContents}
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
await fs.writeProjectFile({
|
|
148
|
+
filename,
|
|
149
|
+
contents,
|
|
150
|
+
format: options.format,
|
|
151
|
+
helpers
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
155
|
+
const filename = path__namespace.join("src", "routes", "slice-simulator", "+page.svelte");
|
|
156
|
+
if (await fs.checkHasProjectFile({ filename, helpers })) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const contents = commonTags.source(_a || (_a = __template(["\n <script>\n import { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n import { SliceZone } from '@prismicio/svelte';\n import { components } from '$lib/slices';\n <\/script>\n\n <SliceSimulator let:slices>\n <SliceZone {slices} {components} />\n </SliceSimulator>\n "])));
|
|
160
|
+
await fs.writeProjectFile({
|
|
161
|
+
filename,
|
|
162
|
+
contents,
|
|
163
|
+
format: options.format,
|
|
164
|
+
formatOptions: {
|
|
165
|
+
prettier: {
|
|
166
|
+
plugins: ["prettier-plugin-svelte"],
|
|
167
|
+
parser: "svelte"
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
helpers
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
174
|
+
var _a2;
|
|
175
|
+
const project = await helpers.getProject();
|
|
176
|
+
(_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://localhost:3000/slice-simulator");
|
|
177
|
+
if (await fs.checkHasProjectFile({
|
|
178
|
+
filename: "./src/lib",
|
|
179
|
+
helpers
|
|
180
|
+
}) && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
|
|
181
|
+
const sliceLibrary = await actions.readSliceLibrary({
|
|
182
|
+
libraryID: project.config.libraries[0]
|
|
183
|
+
});
|
|
184
|
+
if (sliceLibrary.sliceIDs.length < 1) {
|
|
185
|
+
project.config.libraries = ["./src/lib/slices"];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
await helpers.updateSliceMachineConfig(project.config, {
|
|
189
|
+
format: options.format
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
const upsertSliceLibraryIndexFiles = async (context) => {
|
|
193
|
+
var _a2;
|
|
194
|
+
if (!context.project.config.libraries) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
await Promise.all((_a2 = context.project.config.libraries) == null ? void 0 : _a2.map(async (libraryID) => {
|
|
198
|
+
await upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({ libraryID, ...context });
|
|
199
|
+
}));
|
|
200
|
+
};
|
|
201
|
+
const projectInit = async ({ installDependencies: _installDependencies }, context) => {
|
|
202
|
+
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
203
|
+
installDependencies({ installDependencies: _installDependencies }),
|
|
204
|
+
modifySliceMachineConfig(context),
|
|
205
|
+
createPrismicIOFile(context),
|
|
206
|
+
createSliceSimulatorPage(context),
|
|
207
|
+
upsertSliceLibraryIndexFiles(context)
|
|
208
|
+
]));
|
|
209
|
+
};
|
|
210
|
+
exports.projectInit = projectInit;
|
|
211
|
+
//# sourceMappingURL=project-init.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-init.cjs","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/svelte\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/lib/prismicio.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet createClientContents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcreateClientContents = source`\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (config: prismic.ClientConfig = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcreateClientContents = source`\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param {prismic.ClientConfig} config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (config = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport config from \"../../slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName = config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t{\n\t\t\t\t\ttype: \"homepage\",\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"page\",\n\t\t\t\t\tpath: \"/:uid\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport config from \"../../slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName = config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t{\n\t\t\t\t\ttype: \"homepage\",\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"page\",\n\t\t\t\t\tpath: \"/:uid\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"slice-simulator\",\n\t\t\"+page.svelte\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\t<script>\n\t\t\timport { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n\t\t\timport { SliceZone } from '@prismicio/svelte';\n\t\t\timport { components } from '$lib/slices';\n\t\t</script>\n\n\t\t<SliceSimulator let:slices>\n\t\t\t<SliceZone {slices} {components} />\n\t\t</SliceSimulator>\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://localhost:3000/slice-simulator\";\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\t(await checkHasProjectFile({\n\t\t\tfilename: \"./src/lib\",\n\t\t\thelpers,\n\t\t})) &&\n\t\tproject.config.libraries &&\n\t\tJSON.stringify(project.config.libraries) === JSON.stringify([\"./slices\"])\n\t) {\n\t\tconst sliceLibrary = await actions.readSliceLibrary({\n\t\t\tlibraryID: project.config.libraries[0],\n\t\t});\n\n\t\tif (sliceLibrary.sliceIDs.length < 1) {\n\t\t\tproject.config.libraries = [\"./src/lib/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst upsertSliceLibraryIndexFiles = async (\n\tcontext: SliceMachineContext<PluginOptions>,\n) => {\n\tif (!context.project.config.libraries) {\n\t\treturn;\n\t}\n\n\tawait Promise.all(\n\t\tcontext.project.config.libraries?.map(async (libraryID) => {\n\t\t\tawait upsertSliceLibraryIndexFile({ libraryID, ...context });\n\t\t}),\n\t);\n};\n\nexport const projectInit: ProjectInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tinstallDependencies({ installDependencies: _installDependencies }),\n\t\t\tmodifySliceMachineConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tupsertSliceLibraryIndexFiles(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkIsTypeScriptProject","getJSFileExtension","path","checkHasProjectFile","source","writeProjectFile","_a","upsertSliceLibraryIndexFile","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AAuBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7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pC,YACG;;AACH,MAAI,CAAC,QAAQ,QAAQ,OAAO,WAAW;AACtC;AAAA,EACA;AAEK,QAAA,QAAQ,KACbG,MAAA,QAAQ,QAAQ,OAAO,cAAvB,gBAAAA,IAAkC,IAAI,OAAO,cAAa;AACzD,UAAMC,4BAA4B,4BAAA,EAAE,WAAW,GAAG,QAAS,CAAA;AAAA,EAC3D,EAAC;AAEJ;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEFC,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,yBAAyB,OAAO;AAAA,IAChC,oBAAoB,OAAO;AAAA,IAC3B,yBAAyB,OAAO;AAAA,IAChC,6BAA6B,OAAO;AAAA,EACpC,CAAA,CAAC;AAEJ;;"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { checkHasProjectFile, writeProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
3
|
+
import { source } from "common-tags";
|
|
4
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
|
|
5
|
+
import { getJSFileExtension } from "../lib/getJSFileExtension.js";
|
|
6
|
+
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
7
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
|
|
8
|
+
var __freeze = Object.freeze;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
|
|
11
|
+
var _a;
|
|
12
|
+
const installDependencies = async ({ installDependencies: installDependencies2 }) => {
|
|
13
|
+
await installDependencies2({
|
|
14
|
+
dependencies: {
|
|
15
|
+
"@prismicio/client": "latest",
|
|
16
|
+
"@prismicio/svelte": "latest"
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const createPrismicIOFile = async ({ helpers, options }) => {
|
|
21
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
22
|
+
helpers,
|
|
23
|
+
options
|
|
24
|
+
});
|
|
25
|
+
const extension = await getJSFileExtension({ helpers, options });
|
|
26
|
+
const filename = path.join(`src/lib/prismicio.${extension}`);
|
|
27
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
let createClientContents;
|
|
31
|
+
if (isTypeScriptProject) {
|
|
32
|
+
createClientContents = source`
|
|
33
|
+
/**
|
|
34
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
35
|
+
* query content from the Prismic API.
|
|
36
|
+
*
|
|
37
|
+
* @param config - Configuration for the Prismic client.
|
|
38
|
+
*/
|
|
39
|
+
export const createClient = (config: prismic.ClientConfig = {}) => {
|
|
40
|
+
const client = prismic.createClient(repositoryName, {
|
|
41
|
+
routes,
|
|
42
|
+
...config,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return client;
|
|
46
|
+
};
|
|
47
|
+
`;
|
|
48
|
+
} else {
|
|
49
|
+
createClientContents = source`
|
|
50
|
+
/**
|
|
51
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
52
|
+
* query content from the Prismic API.
|
|
53
|
+
*
|
|
54
|
+
* @param {prismic.ClientConfig} config - Configuration for the Prismic client.
|
|
55
|
+
*/
|
|
56
|
+
export const createClient = (config = {}) => {
|
|
57
|
+
const client = prismic.createClient(repositoryName, {
|
|
58
|
+
routes,
|
|
59
|
+
...config,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return client;
|
|
63
|
+
};
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
let contents;
|
|
67
|
+
if (isTypeScriptProject) {
|
|
68
|
+
contents = source`
|
|
69
|
+
import * as prismic from "@prismicio/client";
|
|
70
|
+
import config from "../../slicemachine.config.json";
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The project's Prismic repository name.
|
|
74
|
+
*/
|
|
75
|
+
export const repositoryName = config.repositoryName;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
|
|
79
|
+
*
|
|
80
|
+
* {@link https://prismic.io/docs/route-resolver#route-resolver}
|
|
81
|
+
*/
|
|
82
|
+
// TODO: Update the routes array to match your project's route structure.
|
|
83
|
+
const routes: prismic.ClientConfig["routes"] = [
|
|
84
|
+
{
|
|
85
|
+
type: "homepage",
|
|
86
|
+
path: "/",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: "page",
|
|
90
|
+
path: "/:uid",
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
${createClientContents}
|
|
95
|
+
`;
|
|
96
|
+
} else {
|
|
97
|
+
contents = source`
|
|
98
|
+
import * as prismic from "@prismicio/client";
|
|
99
|
+
import config from "../../slicemachine.config.json";
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The project's Prismic repository name.
|
|
103
|
+
*/
|
|
104
|
+
export const repositoryName = config.repositoryName;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
|
|
108
|
+
*
|
|
109
|
+
* {@link https://prismic.io/docs/route-resolver#route-resolver}
|
|
110
|
+
*
|
|
111
|
+
* @type {prismic.ClientConfig["routes"]}
|
|
112
|
+
*/
|
|
113
|
+
// TODO: Update the routes array to match your project's route structure.
|
|
114
|
+
const routes = [
|
|
115
|
+
{
|
|
116
|
+
type: "homepage",
|
|
117
|
+
path: "/",
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
type: "page",
|
|
121
|
+
path: "/:uid",
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
${createClientContents}
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
await writeProjectFile({
|
|
129
|
+
filename,
|
|
130
|
+
contents,
|
|
131
|
+
format: options.format,
|
|
132
|
+
helpers
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
136
|
+
const filename = path.join("src", "routes", "slice-simulator", "+page.svelte");
|
|
137
|
+
if (await checkHasProjectFile({ filename, helpers })) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const contents = source(_a || (_a = __template(["\n <script>\n import { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n import { SliceZone } from '@prismicio/svelte';\n import { components } from '$lib/slices';\n <\/script>\n\n <SliceSimulator let:slices>\n <SliceZone {slices} {components} />\n </SliceSimulator>\n "])));
|
|
141
|
+
await writeProjectFile({
|
|
142
|
+
filename,
|
|
143
|
+
contents,
|
|
144
|
+
format: options.format,
|
|
145
|
+
formatOptions: {
|
|
146
|
+
prettier: {
|
|
147
|
+
plugins: ["prettier-plugin-svelte"],
|
|
148
|
+
parser: "svelte"
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
helpers
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
155
|
+
var _a2;
|
|
156
|
+
const project = await helpers.getProject();
|
|
157
|
+
(_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://localhost:3000/slice-simulator");
|
|
158
|
+
if (await checkHasProjectFile({
|
|
159
|
+
filename: "./src/lib",
|
|
160
|
+
helpers
|
|
161
|
+
}) && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
|
|
162
|
+
const sliceLibrary = await actions.readSliceLibrary({
|
|
163
|
+
libraryID: project.config.libraries[0]
|
|
164
|
+
});
|
|
165
|
+
if (sliceLibrary.sliceIDs.length < 1) {
|
|
166
|
+
project.config.libraries = ["./src/lib/slices"];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
await helpers.updateSliceMachineConfig(project.config, {
|
|
170
|
+
format: options.format
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const upsertSliceLibraryIndexFiles = async (context) => {
|
|
174
|
+
var _a2;
|
|
175
|
+
if (!context.project.config.libraries) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
await Promise.all((_a2 = context.project.config.libraries) == null ? void 0 : _a2.map(async (libraryID) => {
|
|
179
|
+
await upsertSliceLibraryIndexFile({ libraryID, ...context });
|
|
180
|
+
}));
|
|
181
|
+
};
|
|
182
|
+
const projectInit = async ({ installDependencies: _installDependencies }, context) => {
|
|
183
|
+
rejectIfNecessary(await Promise.allSettled([
|
|
184
|
+
installDependencies({ installDependencies: _installDependencies }),
|
|
185
|
+
modifySliceMachineConfig(context),
|
|
186
|
+
createPrismicIOFile(context),
|
|
187
|
+
createSliceSimulatorPage(context),
|
|
188
|
+
upsertSliceLibraryIndexFiles(context)
|
|
189
|
+
]));
|
|
190
|
+
};
|
|
191
|
+
export {
|
|
192
|
+
projectInit
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingURL=project-init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tcheckHasProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSFileExtension } from \"../lib/getJSFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/client\": \"latest\",\n\t\t\t\"@prismicio/svelte\": \"latest\",\n\t\t},\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\tconst extension = await getJSFileExtension({ helpers, options });\n\tconst filename = path.join(`src/lib/prismicio.${extension}`);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tlet createClientContents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcreateClientContents = source`\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (config: prismic.ClientConfig = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcreateClientContents = source`\n\t\t\t/**\n\t\t\t * Creates a Prismic client for the project's repository. The client is used to\n\t\t\t * query content from the Prismic API.\n\t\t\t *\n\t\t\t * @param {prismic.ClientConfig} config - Configuration for the Prismic client.\n\t\t\t */\n\t\t\texport const createClient = (config = {}) => {\n\t\t\t\tconst client = prismic.createClient(repositoryName, {\n\t\t\t\t\troutes,\n\t\t\t\t\t...config,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport config from \"../../slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName = config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes: prismic.ClientConfig[\"routes\"] = [\n\t\t\t\t{\n\t\t\t\t\ttype: \"homepage\",\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"page\",\n\t\t\t\t\tpath: \"/:uid\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport config from \"../../slicemachine.config.json\";\n\n\t\t\t/**\n\t\t\t * The project's Prismic repository name.\n\t\t\t */\n\t\t\texport const repositoryName = config.repositoryName;\n\n\t\t\t/**\n\t\t\t * A list of Route Resolver objects that define how a document's \\`url\\` field is resolved.\n\t\t\t *\n\t\t\t * {@link https://prismic.io/docs/route-resolver#route-resolver}\n\t\t\t *\n\t\t\t * @type {prismic.ClientConfig[\"routes\"]}\n\t\t\t */\n\t\t\t// TODO: Update the routes array to match your project's route structure.\n\t\t\tconst routes = [\n\t\t\t\t{\n\t\t\t\t\ttype: \"homepage\",\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttype: \"page\",\n\t\t\t\t\tpath: \"/:uid\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\t${createClientContents}\n\t\t`;\n\t}\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst filename = path.join(\n\t\t\"src\",\n\t\t\"routes\",\n\t\t\"slice-simulator\",\n\t\t\"+page.svelte\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst contents = source`\n\t\t<script>\n\t\t\timport { SliceSimulator } from '@slicemachine/adapter-sveltekit/simulator';\n\t\t\timport { SliceZone } from '@prismicio/svelte';\n\t\t\timport { components } from '$lib/slices';\n\t\t</script>\n\n\t\t<SliceSimulator let:slices>\n\t\t\t<SliceZone {slices} {components} />\n\t\t</SliceSimulator>\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://localhost:3000/slice-simulator\";\n\n\t// Nest the default Slice Library in the src directory if it exists and\n\t// is empty.\n\tif (\n\t\t(await checkHasProjectFile({\n\t\t\tfilename: \"./src/lib\",\n\t\t\thelpers,\n\t\t})) &&\n\t\tproject.config.libraries &&\n\t\tJSON.stringify(project.config.libraries) === JSON.stringify([\"./slices\"])\n\t) {\n\t\tconst sliceLibrary = await actions.readSliceLibrary({\n\t\t\tlibraryID: project.config.libraries[0],\n\t\t});\n\n\t\tif (sliceLibrary.sliceIDs.length < 1) {\n\t\t\tproject.config.libraries = [\"./src/lib/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\n\t});\n};\n\nconst upsertSliceLibraryIndexFiles = async (\n\tcontext: SliceMachineContext<PluginOptions>,\n) => {\n\tif (!context.project.config.libraries) {\n\t\treturn;\n\t}\n\n\tawait Promise.all(\n\t\tcontext.project.config.libraries?.map(async (libraryID) => {\n\t\t\tawait upsertSliceLibraryIndexFile({ libraryID, ...context });\n\t\t}),\n\t);\n};\n\nexport const projectInit: ProjectInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tinstallDependencies({ installDependencies: _installDependencies }),\n\t\t\tmodifySliceMachineConfig(context),\n\t\t\tcreatePrismicIOFile(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tupsertSliceLibraryIndexFiles(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","_a"],"mappings":";;;;;;;;;;AAAA,IAAA;AAuBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,qBAAqB;AAAA,IACrB;AAAA,EAAA,CACD;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AACvB,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AACD,QAAM,YAAY,MAAM,mBAAmB,EAAE,SAAS,QAAS,CAAA;AAC/D,QAAM,WAAW,KAAK,KAAK,qBAAqB,WAAW;AAE3D,MAAI,MAAM,oBAAoB,EAAE,UAAU,QAAS,CAAA,GAAG;AACrD;AAAA,EACA;AAEG,MAAA;AAEJ,MAAI,qBAAqB;AACD,2BAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA,OAgBjB;AACiB,2BAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBvB;AAEG,MAAA;AAEJ,MAAI,qBAAqB;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UAAU,CAAC,GACvE;AACK,UAAA,eAAe,MAAM,QAAQ,iBAAiB;AAAA,MACnD,WAAW,QAAQ,OAAO,UAAU,CAAC;AAAA,IAAA,CACrC;AAEG,QAAA,aAAa,SAAS,SAAS,GAAG;AAC7B,cAAA,OAAO,YAAY,CAAC,kBAAkB;AAAA,IAC9C;AAAA,EACD;AAEK,QAAA,QAAQ,yBAAyB,QAAQ,QAAQ;AAAA,IACtD,QAAQ,QAAQ;AAAA,EAAA,CAChB;AACF;AAEA,MAAM,+BAA+B,OACpC,YACG;;AACH,MAAI,CAAC,QAAQ,QAAQ,OAAO,WAAW;AACtC;AAAA,EACA;AAEK,QAAA,QAAQ,KACbA,MAAA,QAAQ,QAAQ,OAAO,cAAvB,gBAAAA,IAAkC,IAAI,OAAO,cAAa;AACzD,UAAM,4BAA4B,EAAE,WAAW,GAAG,QAAS,CAAA;AAAA,EAC3D,EAAC;AAEJ;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,yBAAyB,OAAO;AAAA,IAChC,oBAAoB,OAAO;AAAA,IAC3B,yBAAyB,OAAO;AAAA,IAChC,6BAA6B,OAAO;AAAA,EACpC,CAAA,CAAC;AAEJ;"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fs = require("@slicemachine/plugin-kit/fs");
|
|
4
|
+
const commonTags = require("common-tags");
|
|
5
|
+
const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
|
|
6
|
+
const pascalCase = require("../lib/pascalCase.cjs");
|
|
7
|
+
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
8
|
+
const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
|
|
9
|
+
var __freeze = Object.freeze;
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
|
|
12
|
+
var _a, _b;
|
|
13
|
+
const createComponentFile = async ({ data, helpers, actions, options }) => {
|
|
14
|
+
const pascalName = pascalCase.pascalCase(data.model.name);
|
|
15
|
+
let contents;
|
|
16
|
+
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
17
|
+
helpers,
|
|
18
|
+
options
|
|
19
|
+
});
|
|
20
|
+
if (isTypeScriptProject) {
|
|
21
|
+
contents = commonTags.source(_a || (_a = __template([`
|
|
22
|
+
<script lang="ts">
|
|
23
|
+
import type { Content, SliceZone } from '@prismicio/client';
|
|
24
|
+
|
|
25
|
+
export let slice: Content.`, "Slice;\n export let slices: SliceZone;\n export let index: number;\n export let context: unknown;\n <\/script>\n\n <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n Placeholder component for {slice.slice_type} (variation: {slice.variation}) Slices\n </section>\n "])), pascalName);
|
|
26
|
+
} else {
|
|
27
|
+
contents = commonTags.source(_b || (_b = __template(['\n <script>\n /** @type {import("@prismicio/client").Content.', 'Slice} */\n export let slice;\n /** @type {import("@prismicio/client").SliceZone} */\n export let slices;\n /** @type {number} */\n export let index;\n /** @type {unknown} */\n export let context;\n <\/script>\n\n <section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n Placeholder component for {slice.slice_type} (variation: {slice.variation}) Slices\n </section>\n '])), pascalName);
|
|
28
|
+
}
|
|
29
|
+
await fs.writeSliceFile({
|
|
30
|
+
libraryID: data.libraryID,
|
|
31
|
+
model: data.model,
|
|
32
|
+
filename: "index.svelte",
|
|
33
|
+
contents,
|
|
34
|
+
format: options.format,
|
|
35
|
+
actions,
|
|
36
|
+
helpers,
|
|
37
|
+
formatOptions: {
|
|
38
|
+
prettier: {
|
|
39
|
+
plugins: ["prettier-plugin-svelte"],
|
|
40
|
+
parser: "svelte"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
const sliceCreate = async (data, context) => {
|
|
46
|
+
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
47
|
+
fs.writeSliceModel({
|
|
48
|
+
libraryID: data.libraryID,
|
|
49
|
+
model: data.model,
|
|
50
|
+
format: context.options.format,
|
|
51
|
+
helpers: context.helpers
|
|
52
|
+
}),
|
|
53
|
+
createComponentFile({ data, ...context })
|
|
54
|
+
]));
|
|
55
|
+
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
56
|
+
upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({
|
|
57
|
+
libraryID: data.libraryID,
|
|
58
|
+
...context
|
|
59
|
+
}),
|
|
60
|
+
fs.upsertGlobalTypeScriptTypes({
|
|
61
|
+
filename: context.options.generatedTypesFilePath,
|
|
62
|
+
format: context.options.format,
|
|
63
|
+
helpers: context.helpers,
|
|
64
|
+
actions: context.actions
|
|
65
|
+
})
|
|
66
|
+
]));
|
|
67
|
+
};
|
|
68
|
+
exports.sliceCreate = sliceCreate;
|
|
69
|
+
//# sourceMappingURL=slice-create.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slice-create.cjs","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tupsertGlobalTypeScriptTypes,\n\twriteSliceFile,\n\twriteSliceModel,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { source } from \"common-tags\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createComponentFile = async ({\n\tdata,\n\thelpers,\n\tactions,\n\toptions,\n}: Args) => {\n\tconst pascalName = pascalCase(data.model.name);\n\n\tlet contents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tcontents = source`\n\t\t\t<script lang=\"ts\">\n\t\t\t\timport type { Content, SliceZone } from '@prismicio/client';\n\n\t\t\t\texport let slice: Content.${pascalName}Slice;\n\t\t\t\texport let slices: SliceZone;\n\t\t\t\texport let index: number;\n\t\t\t\texport let context: unknown;\n\t\t\t</script>\n\n\t\t\t<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n\t\t\t\tPlaceholder component for {slice.slice_type} (variation: {slice.variation}) Slices\n\t\t\t</section>\n\t\t`;\n\t} else {\n\t\tcontents = source`\n\t\t\t<script>\n\t\t\t\t/** @type {import(\"@prismicio/client\").Content.${pascalName}Slice} */\n\t\t\t\texport let slice;\n\t\t\t\t/** @type {import(\"@prismicio/client\").SliceZone} */\n\t\t\t\texport let slices;\n\t\t\t\t/** @type {number} */\n\t\t\t\texport let index;\n\t\t\t\t/** @type {unknown} */\n\t\t\t\texport let context;\n\t\t\t</script>\n\n\t\t\t<section data-slice-type={slice.slice_type} data-slice-variation={slice.variation}>\n\t\t\t\tPlaceholder component for {slice.slice_type} (variation: {slice.variation}) Slices\n\t\t\t</section>\n\t\t`;\n\t}\n\n\tawait writeSliceFile({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\tfilename: \"index.svelte\",\n\t\tcontents,\n\t\tformat: options.format,\n\t\tactions,\n\t\thelpers,\n\t\tformatOptions: {\n\t\t\tprettier: {\n\t\t\t\tplugins: [\"prettier-plugin-svelte\"],\n\t\t\t\tparser: \"svelte\",\n\t\t\t},\n\t\t},\n\t});\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\twriteSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t}),\n\t\t\tcreateComponentFile({ data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t\tactions: context.actions,\n\t\t\t}),\n\t\t]),\n\t);\n};\n"],"names":["pascalCase","checkIsTypeScriptProject","source","writeSliceFile","rejectIfNecessary","writeSliceModel","upsertSliceLibraryIndexFile","upsertGlobalTypeScriptTypes"],"mappings":";;;;;;;;;;;AAKA,IAAA,IAAA;AAkBA,MAAM,sBAAsB,OAAO,EAClC,MACA,SACA,SACA,cACU;AACV,QAAM,aAAaA,WAAA,WAAW,KAAK,MAAM,IAAI;AAEzC,MAAA;AAEE,QAAA,sBAAsB,MAAMC,kDAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,MAAI,qBAAqB;AACxB,eAAWC,WAAAA,OAAM,OAAA,KAAA,WAAA,CAAA;AAAA;AAAA;AAAA;AAAA,iCAIuB,gUAAV,CAAA,IAAA,UAAA;AAAA,EAAA,OAUxB;AACK,eAAAA,WAAA,OAAA,OAAA,KAAM,kFAE4C,+aAAV,CAAA,IAAA,UAAA;AAAA,EAcnD;AAED,QAAMC,kBAAe;AAAA,IACpB,WAAW,KAAK;AAAA,IAChB,OAAO,KAAK;AAAA,IACZ,UAAU;AAAA,IACV;AAAA,I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