@slicemachine/adapter-next 0.0.10 → 0.0.12
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/hooks/command-init.cjs +10 -3
- package/dist/hooks/command-init.cjs.map +1 -1
- package/dist/hooks/command-init.js +10 -3
- package/dist/hooks/command-init.js.map +1 -1
- package/dist/hooks/slice-create.cjs +8 -3
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +8 -3
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +10 -2
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.js +10 -2
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
- package/dist/lib/checkIsTypeScriptProject.cjs +9 -0
- package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -0
- package/dist/lib/checkIsTypeScriptProject.d.ts +8 -0
- package/dist/lib/checkIsTypeScriptProject.js +9 -0
- package/dist/lib/checkIsTypeScriptProject.js.map +1 -0
- package/dist/lib/getJSOrTSXFileExtension.cjs +8 -3
- package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.d.ts +7 -1
- package/dist/lib/getJSOrTSXFileExtension.js +8 -3
- package/dist/lib/getJSOrTSXFileExtension.js.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +6 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js +6 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/command-init.ts +11 -3
- package/src/hooks/slice-create.ts +12 -3
- package/src/hooks/sliceSimulator-setup-read.ts +11 -2
- package/src/lib/checkIsTypeScriptProject.ts +17 -0
- package/src/lib/getJSOrTSXFileExtension.ts +18 -5
- package/src/lib/upsertSliceLibraryIndexFile.ts +7 -1
|
@@ -6,6 +6,7 @@ const commonTags = require("common-tags");
|
|
|
6
6
|
const checkPathExists = require("../lib/checkPathExists.cjs");
|
|
7
7
|
const getJSOrTSXFileExtension = require("../lib/getJSOrTSXFileExtension.cjs");
|
|
8
8
|
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
9
|
+
const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
|
|
9
10
|
function _interopNamespaceDefault(e) {
|
|
10
11
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
12
|
if (e) {
|
|
@@ -28,6 +29,8 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
|
|
|
28
29
|
await installDependencies2({
|
|
29
30
|
dependencies: {
|
|
30
31
|
"@prismicio/client": "latest",
|
|
32
|
+
"@prismicio/helpers": "latest",
|
|
33
|
+
"@prismicio/react": "latest",
|
|
31
34
|
"@prismicio/next": "latest"
|
|
32
35
|
}
|
|
33
36
|
});
|
|
@@ -39,12 +42,16 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
|
|
|
39
42
|
});
|
|
40
43
|
};
|
|
41
44
|
const createPrismicIOFile = async ({ helpers, options }) => {
|
|
42
|
-
const
|
|
45
|
+
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
46
|
+
helpers,
|
|
47
|
+
options
|
|
48
|
+
});
|
|
49
|
+
const filePath = helpers.joinPathFromRoot(isTypeScriptProject ? "prismicio.ts" : "prismicio.js");
|
|
43
50
|
if (await checkPathExists.checkPathExists(filePath)) {
|
|
44
51
|
return;
|
|
45
52
|
}
|
|
46
53
|
let contents;
|
|
47
|
-
if (
|
|
54
|
+
if (isTypeScriptProject) {
|
|
48
55
|
contents = commonTags.stripIndent`
|
|
49
56
|
import * as prismic from "@prismicio/client";
|
|
50
57
|
import * as prismicNext from "@prismicio/next";
|
|
@@ -154,7 +161,7 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
154
161
|
};
|
|
155
162
|
const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
156
163
|
const srcDirectoryExists = await checkPathExists.checkPathExists(helpers.joinPathFromRoot("src"));
|
|
157
|
-
const filePath = helpers.joinPathFromRoot(srcDirectoryExists ? "src/pages" : "pages", `slice-simulator.${getJSOrTSXFileExtension.getJSOrTSXFileExtension(options)}`);
|
|
164
|
+
const filePath = helpers.joinPathFromRoot(srcDirectoryExists ? "src/pages" : "pages", `slice-simulator.${await getJSOrTSXFileExtension.getJSOrTSXFileExtension({ helpers, options })}`);
|
|
158
165
|
if (await checkPathExists.checkPathExists(filePath)) {
|
|
159
166
|
return;
|
|
160
167
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-init.cjs","sources":["../../../src/hooks/command-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tCommandInitHook,\n\tCommandInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: CommandInitHookData[\"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/next\": \"latest\",\n\t\t},\n\t});\n\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/types\": \"latest\",\n\t\t},\n\t\tdev: true,\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst filePath = helpers.joinPathFromRoot(\n\t\
|
|
1
|
+
{"version":3,"file":"command-init.cjs","sources":["../../../src/hooks/command-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tCommandInitHook,\n\tCommandInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: CommandInitHookData[\"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/helpers\": \"latest\",\n\t\t\t\"@prismicio/react\": \"latest\",\n\t\t\t\"@prismicio/next\": \"latest\",\n\t\t},\n\t});\n\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/types\": \"latest\",\n\t\t},\n\t\tdev: true,\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\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tisTypeScriptProject ? \"prismicio.ts\" : \"prismicio.js\",\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\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\n\t\t\t * 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/**\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: prismicNext.CreateClientConfig = {}) => {\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\tprismicNext.enableAutoPreviews({\n\t\t\t\t\tclient,\n\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\treq: config.req,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\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\n\t\t\t * 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/**\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 {prismicNext.CreateClientConfig} 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\tprismicNext.enableAutoPreviews({\n\t\t\t\t\tclient,\n\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\treq: config.req,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst srcDirectoryExists = await checkPathExists(\n\t\thelpers.joinPathFromRoot(\"src\"),\n\t);\n\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tsrcDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t`slice-simulator.${await getJSOrTSXFileExtension({ helpers, options })}`,\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\n\tlet contents = stripIndent`\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\timport { components } from \"../slices\";\n\n\t\tconst SliceSimulatorPage = () => {\n\t\t\treturn (\n\t\t\t\t<SliceSimulator\n\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t/>\n\t\t\t);\n\t\t};\n\n\t\texport default SliceSimulatorPage;\n\t`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const commandInit: CommandInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tawait installDependencies({ installDependencies: _installDependencies }),\n\t\t\tawait createPrismicIOFile(context),\n\t\t\tawait createSliceSimulatorPage(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkIsTypeScriptProject","checkPathExists","stripIndent","fs","getJSOrTSXFileExtension","path","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,sBAAsB;AAAA,MACtB,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,IACnB;AAAA,EAAA,CACD;AAED,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,oBAAoB;AAAA,IACpB;AAAA,IACD,KAAK;AAAA,EAAA,CACL;AACF;AAIA,MAAM,sBAAsB,OAAO,EAClC,SACA,cAC6B;AACvB,QAAA,sBAAsB,MAAMC,kDAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,QAAM,WAAW,QAAQ,iBACxB,sBAAsB,iBAAiB,cAAc;AAGlD,MAAA,MAAMC,gBAAAA,gBAAgB,QAAQ,GAAG;AACpC;AAAA,EACA;AAEG,MAAA;A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AAAE,cAAG,MAAME,gBAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AAE1D,MAAI,WAAWH,WAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAAAA;AAiBf,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEFG,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,MAAM,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACvE,MAAM,oBAAoB,OAAO;AAAA,IACjC,MAAM,yBAAyB,OAAO;AAAA,EACtC,CAAA,CAAC;AAEJ;;"}
|
|
@@ -4,10 +4,13 @@ import { stripIndent } from "common-tags";
|
|
|
4
4
|
import { checkPathExists } from "../lib/checkPathExists.js";
|
|
5
5
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension.js";
|
|
6
6
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
7
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
|
|
7
8
|
const installDependencies = async ({ installDependencies: installDependencies2 }) => {
|
|
8
9
|
await installDependencies2({
|
|
9
10
|
dependencies: {
|
|
10
11
|
"@prismicio/client": "latest",
|
|
12
|
+
"@prismicio/helpers": "latest",
|
|
13
|
+
"@prismicio/react": "latest",
|
|
11
14
|
"@prismicio/next": "latest"
|
|
12
15
|
}
|
|
13
16
|
});
|
|
@@ -19,12 +22,16 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
|
|
|
19
22
|
});
|
|
20
23
|
};
|
|
21
24
|
const createPrismicIOFile = async ({ helpers, options }) => {
|
|
22
|
-
const
|
|
25
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
26
|
+
helpers,
|
|
27
|
+
options
|
|
28
|
+
});
|
|
29
|
+
const filePath = helpers.joinPathFromRoot(isTypeScriptProject ? "prismicio.ts" : "prismicio.js");
|
|
23
30
|
if (await checkPathExists(filePath)) {
|
|
24
31
|
return;
|
|
25
32
|
}
|
|
26
33
|
let contents;
|
|
27
|
-
if (
|
|
34
|
+
if (isTypeScriptProject) {
|
|
28
35
|
contents = stripIndent`
|
|
29
36
|
import * as prismic from "@prismicio/client";
|
|
30
37
|
import * as prismicNext from "@prismicio/next";
|
|
@@ -134,7 +141,7 @@ const createPrismicIOFile = async ({ helpers, options }) => {
|
|
|
134
141
|
};
|
|
135
142
|
const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
136
143
|
const srcDirectoryExists = await checkPathExists(helpers.joinPathFromRoot("src"));
|
|
137
|
-
const filePath = helpers.joinPathFromRoot(srcDirectoryExists ? "src/pages" : "pages", `slice-simulator.${getJSOrTSXFileExtension(options)}`);
|
|
144
|
+
const filePath = helpers.joinPathFromRoot(srcDirectoryExists ? "src/pages" : "pages", `slice-simulator.${await getJSOrTSXFileExtension({ helpers, options })}`);
|
|
138
145
|
if (await checkPathExists(filePath)) {
|
|
139
146
|
return;
|
|
140
147
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-init.js","sources":["../../../src/hooks/command-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tCommandInitHook,\n\tCommandInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: CommandInitHookData[\"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/next\": \"latest\",\n\t\t},\n\t});\n\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/types\": \"latest\",\n\t\t},\n\t\tdev: true,\n\t});\n};\n\ntype CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;\n\nconst createPrismicIOFile = async ({\n\thelpers,\n\toptions,\n}: CreatePrismicIOFileArgs) => {\n\tconst filePath = helpers.joinPathFromRoot(\n\t\
|
|
1
|
+
{"version":3,"file":"command-init.js","sources":["../../../src/hooks/command-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tCommandInitHook,\n\tCommandInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: CommandInitHookData[\"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/helpers\": \"latest\",\n\t\t\t\"@prismicio/react\": \"latest\",\n\t\t\t\"@prismicio/next\": \"latest\",\n\t\t},\n\t});\n\n\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t\"@prismicio/types\": \"latest\",\n\t\t},\n\t\tdev: true,\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\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tisTypeScriptProject ? \"prismicio.ts\" : \"prismicio.js\",\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tlet contents: string;\n\n\tif (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\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\n\t\t\t * 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/**\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: prismicNext.CreateClientConfig = {}) => {\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\tprismicNext.enableAutoPreviews({\n\t\t\t\t\tclient,\n\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\treq: config.req,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\timport * as prismic from \"@prismicio/client\";\n\t\t\timport * as prismicNext from \"@prismicio/next\";\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\n\t\t\t * 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/**\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 {prismicNext.CreateClientConfig} 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\tprismicNext.enableAutoPreviews({\n\t\t\t\t\tclient,\n\t\t\t\t\tpreviewData: config.previewData,\n\t\t\t\t\treq: config.req,\n\t\t\t\t});\n\n\t\t\t\treturn client;\n\t\t\t};\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst srcDirectoryExists = await checkPathExists(\n\t\thelpers.joinPathFromRoot(\"src\"),\n\t);\n\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tsrcDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t`slice-simulator.${await getJSOrTSXFileExtension({ helpers, options })}`,\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\n\tlet contents = stripIndent`\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\timport { components } from \"../slices\";\n\n\t\tconst SliceSimulatorPage = () => {\n\t\t\treturn (\n\t\t\t\t<SliceSimulator\n\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t/>\n\t\t\t);\n\t\t};\n\n\t\texport default SliceSimulatorPage;\n\t`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const commandInit: CommandInitHook<PluginOptions> = async (\n\t{ installDependencies: _installDependencies },\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tawait installDependencies({ installDependencies: _installDependencies }),\n\t\t\tawait createPrismicIOFile(context),\n\t\t\tawait createSliceSimulatorPage(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies"],"mappings":";;;;;;;AAoBA,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,qBAAqB;AAAA,MACrB,sBAAsB;AAAA,MACtB,oBAAoB;AAAA,MACpB,mBAAmB;AAAA,IACnB;AAAA,EAAA,CACD;AAED,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,oBAAoB;AAAA,IACpB;AAAA,IACD,KAAK;AAAA,EAAA,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SAAS,QAAA,CAAS,GAAG;AAGrE,MAAA,MAAM,gBAAgB,QAAQ,GAAG;AACpC;AAAA,EACA;AAEK,QAAA,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AAE1D,MAAI,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBf,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,MAAM,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACvE,MAAM,oBAAoB,OAAO;AAAA,IACjC,MAAM,yBAAyB,OAAO;AAAA,EACtC,CAAA,CAAC;AAEJ;"}
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const commonTags = require("common-tags");
|
|
4
4
|
const fs = require("node:fs/promises");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
-
const
|
|
6
|
+
const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
|
|
7
7
|
const getJSOrTSXFileExtension = require("../lib/getJSOrTSXFileExtension.cjs");
|
|
8
8
|
const pascalCase = require("../lib/pascalCase.cjs");
|
|
9
9
|
const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
|
|
10
10
|
const upsertGlobalContentTypes = require("../lib/upsertGlobalContentTypes.cjs");
|
|
11
|
+
const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
|
|
11
12
|
function _interopNamespaceDefault(e) {
|
|
12
13
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
14
|
if (e) {
|
|
@@ -35,11 +36,15 @@ const createModelFile = async ({ dir, data, helpers, options }) => {
|
|
|
35
36
|
await fs__namespace.writeFile(filePath, contents);
|
|
36
37
|
};
|
|
37
38
|
const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
38
|
-
const filePath = path__namespace.join(dir, `index.${getJSOrTSXFileExtension.getJSOrTSXFileExtension(options)}`);
|
|
39
|
+
const filePath = path__namespace.join(dir, `index.${await getJSOrTSXFileExtension.getJSOrTSXFileExtension({ helpers, options })}`);
|
|
39
40
|
const model = data.model;
|
|
40
41
|
const pascalName = pascalCase.pascalCase(model.name);
|
|
41
42
|
let contents;
|
|
42
|
-
|
|
43
|
+
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
44
|
+
helpers,
|
|
45
|
+
options
|
|
46
|
+
});
|
|
47
|
+
if (isTypeScriptProject) {
|
|
43
48
|
contents = commonTags.stripIndent`
|
|
44
49
|
import { Content } from "@prismicio/client";
|
|
45
50
|
import { SliceComponentProps } from "@prismicio/react";
|
|
@@ -1 +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 { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport {
|
|
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 { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertGlobalContentTypes } from \"../lib/upsertGlobalContentTypes\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdir: string;\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createModelFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(dir, \"model.json\");\n\n\tlet contents = JSON.stringify(data.model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nconst createComponentFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(\n\t\tdir,\n\t\t`index.${await getJSOrTSXFileExtension({ helpers, options })}`,\n\t);\n\tconst model = data.model;\n\tconst pascalName = pascalCase(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 = stripIndent`\n\t\t\timport { Content } from \"@prismicio/client\";\n\t\t\timport { SliceComponentProps } from \"@prismicio/react\";\n\n\t\t\t/**\n\t\t\t * Props for \\`${pascalName}\\`.\n\t\t\t */\n\t\t\texport type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;\n\n\t\t\t/**\n\t\t\t * Component for \"${model.name}\" Slices.\n\t\t\t */\n\t\t\tconst ${pascalName} = ({ slice }: ${pascalName}Props): JSX.Element => {\n\t\t\t\treturn (\n\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t>\n\t\t\t\t\t\tPlaceholder component for ${model.id} (variation: {slice.variation}) Slices\n\t\t\t\t\t</section>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default ${pascalName}\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t/**\n\t\t\t * @typedef {import(\"@prismicio/client\").Content.${pascalName}Slice} ${pascalName}Slice\n\t\t\t * @typedef {import(\"@prismicio/react\").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props\n\t\t\t * @param {${pascalName}Props}\n\t\t\t */\n\t\t\tconst ${pascalName} = ({ slice }) => {\n\t\t\t\treturn (\n\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t>\n\t\t\t\t\t\tPlaceholder component for ${model.id} (variation: {slice.variation}) Slices\n\t\t\t\t\t</section>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default ${pascalName};\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst dir = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.model.name),\n\t);\n\n\tawait fs.mkdir(dir, { recursive: true });\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tcreateModelFile({ dir, data, ...context }),\n\t\t\tcreateComponentFile({ dir, data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertGlobalContentTypes(context),\n\t\t\tupsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),\n\t\t]),\n\t);\n};\n"],"names":["path","fs","getJSOrTSXFileExtension","pascalCase","checkIsTypeScriptProject","stripIndent","rejectIfNecessary","upsertGlobalContentTypes","upsertSliceLibraryIndexFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAM,kBAAkB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AACvE,QAAM,WAAWA,gBAAK,KAAK,KA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G5B,QAAMF,cAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AAGtCK,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,IACzC,oBAAoB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,EAC7C,CAAA,CAAC;AAIFA,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxBC,yBAAAA,yBAAyB,OAAO;AAAA,IAChCC,wDAA4B,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS;AAAA,EACrE,CAAA,CAAC;AAEJ;;"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { stripIndent } from "common-tags";
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
|
|
5
5
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension.js";
|
|
6
6
|
import { pascalCase } from "../lib/pascalCase.js";
|
|
7
7
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
8
8
|
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes.js";
|
|
9
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
|
|
9
10
|
const createModelFile = async ({ dir, data, helpers, options }) => {
|
|
10
11
|
const filePath = path.join(dir, "model.json");
|
|
11
12
|
let contents = JSON.stringify(data.model);
|
|
@@ -15,11 +16,15 @@ const createModelFile = async ({ dir, data, helpers, options }) => {
|
|
|
15
16
|
await fs.writeFile(filePath, contents);
|
|
16
17
|
};
|
|
17
18
|
const createComponentFile = async ({ dir, data, helpers, options }) => {
|
|
18
|
-
const filePath = path.join(dir, `index.${getJSOrTSXFileExtension(options)}`);
|
|
19
|
+
const filePath = path.join(dir, `index.${await getJSOrTSXFileExtension({ helpers, options })}`);
|
|
19
20
|
const model = data.model;
|
|
20
21
|
const pascalName = pascalCase(model.name);
|
|
21
22
|
let contents;
|
|
22
|
-
|
|
23
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
24
|
+
helpers,
|
|
25
|
+
options
|
|
26
|
+
});
|
|
27
|
+
if (isTypeScriptProject) {
|
|
23
28
|
contents = stripIndent`
|
|
24
29
|
import { Content } from "@prismicio/client";
|
|
25
30
|
import { SliceComponentProps } from "@prismicio/react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertGlobalContentTypes } from \"../lib/upsertGlobalContentTypes\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdir: string;\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createModelFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(dir, \"model.json\");\n\n\tlet contents = JSON.stringify(data.model);\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nconst createComponentFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(\n\t\tdir,\n\t\t`index.${await getJSOrTSXFileExtension({ helpers, options })}`,\n\t);\n\tconst model = data.model;\n\tconst pascalName = pascalCase(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 = stripIndent`\n\t\t\timport { Content } from \"@prismicio/client\";\n\t\t\timport { SliceComponentProps } from \"@prismicio/react\";\n\n\t\t\t/**\n\t\t\t * Props for \\`${pascalName}\\`.\n\t\t\t */\n\t\t\texport type ${pascalName}Props = SliceComponentProps<Content.${pascalName}Slice>;\n\n\t\t\t/**\n\t\t\t * Component for \"${model.name}\" Slices.\n\t\t\t */\n\t\t\tconst ${pascalName} = ({ slice }: ${pascalName}Props): JSX.Element => {\n\t\t\t\treturn (\n\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t>\n\t\t\t\t\t\tPlaceholder component for ${model.id} (variation: {slice.variation}) Slices\n\t\t\t\t\t</section>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default ${pascalName}\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t/**\n\t\t\t * @typedef {import(\"@prismicio/client\").Content.${pascalName}Slice} ${pascalName}Slice\n\t\t\t * @typedef {import(\"@prismicio/react\").SliceComponentProps<${pascalName}Slice>} ${pascalName}Props\n\t\t\t * @param {${pascalName}Props}\n\t\t\t */\n\t\t\tconst ${pascalName} = ({ slice }) => {\n\t\t\t\treturn (\n\t\t\t\t\t<section\n\t\t\t\t\t\tdata-slice-type={slice.slice_type}\n\t\t\t\t\t\tdata-slice-variation={slice.variation}\n\t\t\t\t\t>\n\t\t\t\t\t\tPlaceholder component for ${model.id} (variation: {slice.variation}) Slices\n\t\t\t\t\t</section>\n\t\t\t\t);\n\t\t\t};\n\n\t\t\texport default ${pascalName};\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst dir = context.helpers.joinPathFromRoot(\n\t\tdata.libraryID,\n\t\tpascalCase(data.model.name),\n\t);\n\n\tawait fs.mkdir(dir, { recursive: true });\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tcreateModelFile({ dir, data, ...context }),\n\t\t\tcreateComponentFile({ dir, data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertGlobalContentTypes(context),\n\t\t\tupsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),\n\t\t]),\n\t);\n};\n"],"names":[],"mappings":";;;;;;;;;AAuBA,MAAM,kBAAkB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AACvE,QAAM,WAAW,KAAK,KAAK,KAAK,YAAY;AAE5C,MAAI,WAAW,KAAK,UAAU,KAAK,KAAK;AAExC,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;AAEA,MAAM,sBAAsB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AACrE,QAAA,WAAW,KAAK,KACrB,KACA,SAAS,MAAM,wBAAwB,EAAE,SAAS,SAAS,GAAG;AAE/D,QAAM,QAAQ,KAAK;AACb,QAAA,aAAa,WAAW,MAAM,IAAI;AAEpC,MAAA;AAEE,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,MAAI,qBAAqB;AACb,eAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AAAA;AAAA,iBAEH,iDAAiD;AAAA;AAAA;AAAA,uBAG3C,MAAM;AAAA;AAAA,WAElB,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAML,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKpB;AAAA;AAAA,EAAA,OAEZ;AACK,eAAA;AAAA;AAAA,sDAEyC,oBAAoB;AAAA,iEACT,qBAAqB;AAAA,gBACtE;AAAA;AAAA,WAEL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAMuB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKpB;AAAA;AAAA,EAElB;AAED,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AACG,QAAA,MAAM,QAAQ,QAAQ,iBAC3B,KAAK,WACL,WAAW,KAAK,MAAM,IAAI,CAAC;AAG5B,QAAM,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AAGtC,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,IACzC,oBAAoB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,EAC7C,CAAA,CAAC;AAIF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,yBAAyB,OAAO;AAAA,IAChC,4BAA4B,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS;AAAA,EACrE,CAAA,CAAC;AAEJ;"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const commonTags = require("common-tags");
|
|
4
4
|
const node_module = require("node:module");
|
|
5
5
|
const index = require("../node_modules/node-fetch/src/index.cjs");
|
|
6
|
+
const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
|
|
6
7
|
const getJSOrTSXFileExtension = require("../lib/getJSOrTSXFileExtension.cjs");
|
|
7
8
|
const REQUIRED_DEPENDENCIES = [
|
|
8
9
|
"@prismicio/react",
|
|
@@ -55,10 +56,17 @@ const createStep1 = async ({ project, helpers }) => {
|
|
|
55
56
|
};
|
|
56
57
|
};
|
|
57
58
|
const createStep2 = async ({ helpers, options }) => {
|
|
58
|
-
const fileName = `slice-simulator.${getJSOrTSXFileExtension.getJSOrTSXFileExtension(
|
|
59
|
+
const fileName = `slice-simulator.${await getJSOrTSXFileExtension.getJSOrTSXFileExtension({
|
|
60
|
+
helpers,
|
|
61
|
+
options
|
|
62
|
+
})}`;
|
|
59
63
|
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
60
64
|
let fileContents;
|
|
61
|
-
|
|
65
|
+
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
66
|
+
helpers,
|
|
67
|
+
options
|
|
68
|
+
});
|
|
69
|
+
if (isTypeScriptProject) {
|
|
62
70
|
fileContents = await helpers.format(commonTags.source`
|
|
63
71
|
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
64
72
|
import { SliceZone } from "@prismicio/react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliceSimulator-setup-read.cjs","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch from \"node-fetch\";\n\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${getJSOrTSXFileExtension(
|
|
1
|
+
{"version":3,"file":"sliceSimulator-setup-read.cjs","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch from \"node-fetch\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${await getJSOrTSXFileExtension({\n\t\thelpers,\n\t\toptions,\n\t})}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tlet fileContents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage(): JSX.Element {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t} else {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t}\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tconst res = await fetch(project.config.localSliceSimulatorURL);\n\n\t\t\tif (!res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(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AAM,MAAMG,MAAM,QAAA,QAAQ,OAAO,sBAAsB;AAEzD,UAAA,CAAC,IAAI,IAAI;AACL,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAASH,WAAAA;AAAAA;AAAAA;AAAAA,QAAA;AAAA,MAIV;AAAA,IACF;AAAA,EAAA;AAEF;AAEa,MAAA,0BAET,OAAO,OAAO,YAAW;AAC5B,SAAO,QAAQ,IAAI;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { source } from "common-tags";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import fetch from "../node_modules/node-fetch/src/index.js";
|
|
4
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
|
|
4
5
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension.js";
|
|
5
6
|
const REQUIRED_DEPENDENCIES = [
|
|
6
7
|
"@prismicio/react",
|
|
@@ -53,10 +54,17 @@ const createStep1 = async ({ project, helpers }) => {
|
|
|
53
54
|
};
|
|
54
55
|
};
|
|
55
56
|
const createStep2 = async ({ helpers, options }) => {
|
|
56
|
-
const fileName = `slice-simulator.${getJSOrTSXFileExtension(
|
|
57
|
+
const fileName = `slice-simulator.${await getJSOrTSXFileExtension({
|
|
58
|
+
helpers,
|
|
59
|
+
options
|
|
60
|
+
})}`;
|
|
57
61
|
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
58
62
|
let fileContents;
|
|
59
|
-
|
|
63
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
64
|
+
helpers,
|
|
65
|
+
options
|
|
66
|
+
});
|
|
67
|
+
if (isTypeScriptProject) {
|
|
60
68
|
fileContents = await helpers.format(source`
|
|
61
69
|
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
62
70
|
import { SliceZone } from "@prismicio/react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sliceSimulator-setup-read.js","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch from \"node-fetch\";\n\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${getJSOrTSXFileExtension(
|
|
1
|
+
{"version":3,"file":"sliceSimulator-setup-read.js","sources":["../../../src/hooks/sliceSimulator-setup-read.ts"],"sourcesContent":["import type {\n\tSliceMachineContext,\n\tSliceSimulatorSetupReadHook,\n\tSliceSimulatorSetupStep,\n} from \"@slicemachine/plugin-kit\";\nimport { source } from \"common-tags\";\nimport { createRequire } from \"node:module\";\nimport fetch from \"node-fetch\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { getJSOrTSXFileExtension } from \"../lib/getJSOrTSXFileExtension\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst REQUIRED_DEPENDENCIES = [\n\t\"@prismicio/react\",\n\t\"@prismicio/client\",\n\t\"@prismicio/helpers\",\n];\n\ntype Args = SliceMachineContext<PluginOptions>;\n\nconst createStep1 = async ({\n\tproject,\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst require = createRequire(project.root);\n\n\treturn {\n\t\ttitle: \"Install packages\",\n\t\tdescription: \"The simulator requires some dependencies.\",\n\t\t// TODO: Create a plugin runner helper to provide the correct\n\t\t// package manager\n\t\tbody: source`\n\t\t\tThe simulator requires extra dependencies. Run the following command to install them.\n\n\t\t\t~~~sh\n\t\t\tnpm install --save ${REQUIRED_DEPENDENCIES.join(\" \")}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst missingDependencies: string[] = [];\n\n\t\t\tfor (const dependency of REQUIRED_DEPENDENCIES) {\n\t\t\t\ttry {\n\t\t\t\t\t// `require.resolve()` is preferred\n\t\t\t\t\t// over `import()` because we don't\n\t\t\t\t\t// want to load the module. Loading a\n\t\t\t\t\t// module could introduce side-effects.\n\t\t\t\t\trequire.resolve(dependency, {\n\t\t\t\t\t\tpaths: [helpers.joinPathFromRoot(\"node_modules\")],\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tmissingDependencies.push(dependency);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingDependencies.length >= REQUIRED_DEPENDENCIES.length) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing all dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tInstall the required dependencies to continue.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tif (missingDependencies.length > 0) {\n\t\t\t\tconst formattedMissingDependencies = missingDependencies\n\t\t\t\t\t.map((missingDependency) => `\\`${missingDependency}\\``)\n\t\t\t\t\t.join(\", \");\n\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing some dependencies\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe following dependencies are missing: ${formattedMissingDependencies}\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nconst createStep2 = async ({\n\thelpers,\n\toptions,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst fileName = `slice-simulator.${await getJSOrTSXFileExtension({\n\t\thelpers,\n\t\toptions,\n\t})}`;\n\tconst filePath = helpers.joinPathFromRoot(\"pages\", fileName);\n\n\tlet fileContents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage(): JSX.Element {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t} else {\n\t\tfileContents = await helpers.format(\n\t\t\tsource`\n\t\t\t\timport { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t\t\t\timport { SliceZone } from \"@prismicio/react\";\n\n\t\t\t\timport { components } from \"../slices\";\n\n\t\t\t\texport default function SliceSimulatorPage() {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<SliceSimulator\n\t\t\t\t\t\t\tsliceZone={(props) => <SliceZone {...props} components={components} />}\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t`,\n\t\t\tfilePath,\n\t\t\t{\n\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t},\n\t\t);\n\t}\n\n\treturn {\n\t\ttitle: \"Create a page for the simulator\",\n\t\tdescription: `In your \\`pages\\` directory, create a file called \\`${fileName}\\` containing this code.`,\n\t\tbody: source`\n\t\t\tIn your \\`pages\\` directory, create a file called \\`${fileName}\\` and add the following code. This route will be used to simulate and develop your components.\n\n\t\t\t~~~tsx\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t};\n};\n\nconst createStep3 = async ({\n\thelpers,\n}: Args): Promise<SliceSimulatorSetupStep> => {\n\tconst filePath = helpers.joinPathFromRoot(\"slicemachine.config.json\");\n\tconst fileContents = await helpers.format(\n\t\tsource`\n\t\t\t{\n\t\t\t\t\"localSliceSimulatorURL\": \"http://localhost:3000/slice-simulator\"\n\t\t\t}\n\t\t`,\n\t\tfilePath,\n\t\t{\n\t\t\tincludeNewlineAtEnd: false,\n\t\t},\n\t);\n\n\treturn {\n\t\ttitle: \"Update `slicemachine.config.json`\",\n\t\tdescription: `Update your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.`,\n\t\tbody: source`\n\t\t\tUpdate your \\`slicemachine.config.json\\` file with a \\`localSliceSimulatorURL\\` property pointing to your \\`/slice-simulator\\` page.\n\n\t\t\t~~~json\n\t\t\t${fileContents}\n\t\t\t~~~\n\t\t`,\n\t\tvalidate: async () => {\n\t\t\tconst project = await helpers.getProject();\n\n\t\t\tif (!(\"localSliceSimulatorURL\" in project.config)) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Missing `localSliceSimulatorURL` property\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tA \\`localSliceSimulatorURL\\` property was not found in your \\`slicemachine.config.json\\` file.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Test if the URL is valid.\n\t\t\ttry {\n\t\t\t\tif (project.config.localSliceSimulatorURL) {\n\t\t\t\t\tnew URL(project.config.localSliceSimulatorURL);\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Error(\"Undefined Slice Simulator URL\");\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"An invalid URL was provided\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tThe \\`localSliceSimulatorURL\\` property should be of the shape \\`http://localhost:PORT/PATH\\`. See the codeblock for an example.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Check if the URL is accessible.\n\t\t\tconst res = await fetch(project.config.localSliceSimulatorURL);\n\n\t\t\tif (!res.ok) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: \"Unable to connect to simulator page\",\n\t\t\t\t\tmessage: source`\n\t\t\t\t\t\tCheck that the \\`localSliceSimulatorURL\\` property in \\`slicemachine.config.json\\` is correct and try again. See the [troubleshooting page](https://prismic.io/docs/technologies/setup-slice-simulator-nextjs) for more details.\n\t\t\t\t\t`,\n\t\t\t\t};\n\t\t\t}\n\t\t},\n\t};\n};\n\nexport const sliceSimulatorSetupRead: SliceSimulatorSetupReadHook<\n\tPluginOptions\n> = async (_data, context) => {\n\treturn Promise.all([\n\t\tcreateStep1(context),\n\t\tcreateStep2(context),\n\t\tcreateStep3(context),\n\t]);\n};\n"],"names":["require"],"mappings":";;;;;AAcA,MAAM,wBAAwB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;;AAKD,MAAM,cAAc,OAAO,EAC1B,SACA,cAC4C;AACtC,QAAAA,WAAU,cAAc,QAAQ,IAAI;AAEnC,SAAA;AAAA,IACN,OAAO;AAAA,IACP,aAAa;AAAA;AAAA;AAAA,IAGb,MAAM;AAAA;AAAA;AAAA;AAAA,wBAIgB,sBAAsB,KAAK,GAAG;AAAA;AAAA;AAAA,IAGpD,UAAU,YAAW;AACpB,YAAM,sBAAgC,CAAA;AAEtC,iBAAW,cAAc,uBAAuB;AAC3C,YAAA;AAKH,UAAAA,SAAQ,QAAQ,YAAY;AAAA,YAC3B,OAAO,CAAC,QAAQ,iBAAiB,cAAc,CAAC;AAAA,UAAA,CAChD;AAAA,QAAA,QACA;AACD,8BAAoB,KAAK,UAAU;AAAA,QACnC;AAAA,MACD;AAEG,UAAA,oBAAoB,UAAU,sBAAsB,QAAQ;AACxD,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAEG,UAAA,oBAAoB,SAAS,GAAG;AAC7B,cAAA,+BAA+B,oBACnC,IAA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AAAA,IAGH,UAAU,YAAW;AACd,YAAA,UAAU,MAAM,QAAQ;AAE1B,UAAA,EAAE,4BAA4B,QAAQ,SAAS;AAC3C,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAGG,UAAA;AACC,YAAA,QAAQ,OAAO,wBAAwB;AACtC,cAAA,IAAI,QAAQ,OAAO,sBAAsB;AAAA,QAAA,OACvC;AACA,gBAAA,IAAI,MAAM,+BAA+B;AAAA,QAC/C;AAAA,MAAA,QACA;AACM,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAGD,YAAM,MAAM,MAAM,MAAM,QAAQ,OAAO,sBAAsB;AAEzD,UAAA,CAAC,IAAI,IAAI;AACL,eAAA;AAAA,UACN,OAAO;AAAA,UACP,SAAS;AAAA;AAAA;AAAA,QAAA;AAAA,MAIV;AAAA,IACF;AAAA,EAAA;AAEF;AAEa,MAAA,0BAET,OAAO,OAAO,YAAW;AAC5B,SAAO,QAAQ,IAAI;AAAA,IAClB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,IACnB,YAAY,OAAO;AAAA,EAAA,CACnB;AACF;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const checkPathExists = require("./checkPathExists.cjs");
|
|
4
|
+
const checkIsTypeScriptProject = async (args) => {
|
|
5
|
+
const tsConfigPath = args.helpers.joinPathFromRoot("tsconfig.json");
|
|
6
|
+
return args.options.typescript ?? await checkPathExists.checkPathExists(tsConfigPath);
|
|
7
|
+
};
|
|
8
|
+
exports.checkIsTypeScriptProject = checkIsTypeScriptProject;
|
|
9
|
+
//# sourceMappingURL=checkIsTypeScriptProject.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkIsTypeScriptProject.cjs","sources":["../../../src/lib/checkIsTypeScriptProject.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\n\nimport { PluginOptions } from \"../types\";\nimport { checkPathExists } from \"./checkPathExists\";\n\ntype CheckIsTypeScriptProjectArgs = {\n\thelpers: SliceMachineContext<PluginOptions>[\"helpers\"];\n\toptions: SliceMachineContext<PluginOptions>[\"options\"];\n};\n\nexport const checkIsTypeScriptProject = async (\n\targs: CheckIsTypeScriptProjectArgs,\n): Promise<boolean> => {\n\tconst tsConfigPath = args.helpers.joinPathFromRoot(\"tsconfig.json\");\n\n\treturn args.options.typescript ?? (await checkPathExists(tsConfigPath));\n};\n"],"names":["checkPathExists"],"mappings":";;;AAUa,MAAA,2BAA2B,OACvC,SACqB;AACrB,QAAM,eAAe,KAAK,QAAQ,iBAAiB,eAAe;AAElE,SAAO,KAAK,QAAQ,cAAe,MAAMA,gCAAgB,YAAY;AACtE;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
import { PluginOptions } from "../types";
|
|
3
|
+
type CheckIsTypeScriptProjectArgs = {
|
|
4
|
+
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
5
|
+
options: SliceMachineContext<PluginOptions>["options"];
|
|
6
|
+
};
|
|
7
|
+
export declare const checkIsTypeScriptProject: (args: CheckIsTypeScriptProjectArgs) => Promise<boolean>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { checkPathExists } from "./checkPathExists.js";
|
|
2
|
+
const checkIsTypeScriptProject = async (args) => {
|
|
3
|
+
const tsConfigPath = args.helpers.joinPathFromRoot("tsconfig.json");
|
|
4
|
+
return args.options.typescript ?? await checkPathExists(tsConfigPath);
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
checkIsTypeScriptProject
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=checkIsTypeScriptProject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkIsTypeScriptProject.js","sources":["../../../src/lib/checkIsTypeScriptProject.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\n\nimport { PluginOptions } from \"../types\";\nimport { checkPathExists } from \"./checkPathExists\";\n\ntype CheckIsTypeScriptProjectArgs = {\n\thelpers: SliceMachineContext<PluginOptions>[\"helpers\"];\n\toptions: SliceMachineContext<PluginOptions>[\"options\"];\n};\n\nexport const checkIsTypeScriptProject = async (\n\targs: CheckIsTypeScriptProjectArgs,\n): Promise<boolean> => {\n\tconst tsConfigPath = args.helpers.joinPathFromRoot(\"tsconfig.json\");\n\n\treturn args.options.typescript ?? (await checkPathExists(tsConfigPath));\n};\n"],"names":[],"mappings":";AAUa,MAAA,2BAA2B,OACvC,SACqB;AACrB,QAAM,eAAe,KAAK,QAAQ,iBAAiB,eAAe;AAElE,SAAO,KAAK,QAAQ,cAAe,MAAM,gBAAgB,YAAY;AACtE;"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const checkIsTypeScriptProject = require("./checkIsTypeScriptProject.cjs");
|
|
4
|
+
const getJSOrTSXFileExtension = async (args) => {
|
|
5
|
+
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
6
|
+
helpers: args.helpers,
|
|
7
|
+
options: args.options
|
|
8
|
+
});
|
|
9
|
+
if (isTypeScriptProject) {
|
|
5
10
|
return "tsx";
|
|
6
|
-
} else if (
|
|
11
|
+
} else if (args.options.jsxExtension) {
|
|
7
12
|
return "jsx";
|
|
8
13
|
} else {
|
|
9
14
|
return "js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getJSOrTSXFileExtension.cjs","sources":["../../../src/lib/getJSOrTSXFileExtension.ts"],"sourcesContent":["import type { PluginOptions } from \"../types\";\n\nexport const getJSOrTSXFileExtension = (\n\
|
|
1
|
+
{"version":3,"file":"getJSOrTSXFileExtension.cjs","sources":["../../../src/lib/getJSOrTSXFileExtension.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"./checkIsTypeScriptProject\";\n\ntype GetJSOrTSXFileExtensionArgs = {\n\thelpers: SliceMachineContext<PluginOptions>[\"helpers\"];\n\toptions: SliceMachineContext<PluginOptions>[\"options\"];\n};\n\nexport const getJSOrTSXFileExtension = async (\n\targs: GetJSOrTSXFileExtensionArgs,\n): Promise<string> => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers: args.helpers,\n\t\toptions: args.options,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\treturn \"tsx\";\n\t} else if (args.options.jsxExtension) {\n\t\treturn \"jsx\";\n\t} else {\n\t\treturn \"js\";\n\t}\n};\n"],"names":["checkIsTypeScriptProject"],"mappings":";;;AAUa,MAAA,0BAA0B,OACtC,SACoB;AACd,QAAA,sBAAsB,MAAMA,kDAAyB;AAAA,IAC1D,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,EAAA,CACd;AAED,MAAI,qBAAqB;AACjB,WAAA;AAAA,EAAA,WACG,KAAK,QAAQ,cAAc;AAC9B,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACP;AACF;;"}
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
1
2
|
import type { PluginOptions } from "../types";
|
|
2
|
-
|
|
3
|
+
type GetJSOrTSXFileExtensionArgs = {
|
|
4
|
+
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
5
|
+
options: SliceMachineContext<PluginOptions>["options"];
|
|
6
|
+
};
|
|
7
|
+
export declare const getJSOrTSXFileExtension: (args: GetJSOrTSXFileExtensionArgs) => Promise<string>;
|
|
8
|
+
export {};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { checkIsTypeScriptProject } from "./checkIsTypeScriptProject.js";
|
|
2
|
+
const getJSOrTSXFileExtension = async (args) => {
|
|
3
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
4
|
+
helpers: args.helpers,
|
|
5
|
+
options: args.options
|
|
6
|
+
});
|
|
7
|
+
if (isTypeScriptProject) {
|
|
3
8
|
return "tsx";
|
|
4
|
-
} else if (
|
|
9
|
+
} else if (args.options.jsxExtension) {
|
|
5
10
|
return "jsx";
|
|
6
11
|
} else {
|
|
7
12
|
return "js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getJSOrTSXFileExtension.js","sources":["../../../src/lib/getJSOrTSXFileExtension.ts"],"sourcesContent":["import type { PluginOptions } from \"../types\";\n\nexport const getJSOrTSXFileExtension = (\n\
|
|
1
|
+
{"version":3,"file":"getJSOrTSXFileExtension.js","sources":["../../../src/lib/getJSOrTSXFileExtension.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"./checkIsTypeScriptProject\";\n\ntype GetJSOrTSXFileExtensionArgs = {\n\thelpers: SliceMachineContext<PluginOptions>[\"helpers\"];\n\toptions: SliceMachineContext<PluginOptions>[\"options\"];\n};\n\nexport const getJSOrTSXFileExtension = async (\n\targs: GetJSOrTSXFileExtensionArgs,\n): Promise<string> => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers: args.helpers,\n\t\toptions: args.options,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\treturn \"tsx\";\n\t} else if (args.options.jsxExtension) {\n\t\treturn \"jsx\";\n\t} else {\n\t\treturn \"js\";\n\t}\n};\n"],"names":[],"mappings":";AAUa,MAAA,0BAA0B,OACtC,SACoB;AACd,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,EAAA,CACd;AAED,MAAI,qBAAqB;AACjB,WAAA;AAAA,EAAA,WACG,KAAK,QAAQ,cAAc;AAC9B,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACP;AACF;"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const commonTags = require("common-tags");
|
|
4
4
|
const fs = require("node:fs/promises");
|
|
5
5
|
const constants = require("../constants.cjs");
|
|
6
|
+
const checkIsTypeScriptProject = require("./checkIsTypeScriptProject.cjs");
|
|
6
7
|
const pascalCase = require("./pascalCase.cjs");
|
|
7
8
|
function _interopNamespaceDefault(e) {
|
|
8
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -22,7 +23,11 @@ function _interopNamespaceDefault(e) {
|
|
|
22
23
|
}
|
|
23
24
|
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
24
25
|
const upsertSliceLibraryIndexFile = async (args) => {
|
|
25
|
-
const
|
|
26
|
+
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
27
|
+
helpers: args.helpers,
|
|
28
|
+
options: args.options
|
|
29
|
+
});
|
|
30
|
+
const filePath = args.helpers.joinPathFromRoot(args.libraryID, isTypeScriptProject ? "index.ts" : "index.js");
|
|
26
31
|
const slices = await args.actions.readAllSliceModelsForLibrary({
|
|
27
32
|
libraryID: args.libraryID
|
|
28
33
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertSliceLibraryIndexFile.cjs","sources":["../../../src/lib/upsertSliceLibraryIndexFile.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpsertSliceLibraryIndexFileArgs = {\n\tlibraryID: string;\n} & SliceMachineContext<PluginOptions>;\n\nexport const upsertSliceLibraryIndexFile = async (\n\targs: UpsertSliceLibraryIndexFileArgs,\n): Promise<void> => {\n\tconst filePath = args.helpers.joinPathFromRoot(\n\t\targs.libraryID,\n\t\
|
|
1
|
+
{"version":3,"file":"upsertSliceLibraryIndexFile.cjs","sources":["../../../src/lib/upsertSliceLibraryIndexFile.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { checkIsTypeScriptProject } from \"./checkIsTypeScriptProject\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpsertSliceLibraryIndexFileArgs = {\n\tlibraryID: string;\n} & SliceMachineContext<PluginOptions>;\n\nexport const upsertSliceLibraryIndexFile = async (\n\targs: UpsertSliceLibraryIndexFileArgs,\n): Promise<void> => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers: args.helpers,\n\t\toptions: args.options,\n\t});\n\n\tconst filePath = args.helpers.joinPathFromRoot(\n\t\targs.libraryID,\n\t\tisTypeScriptProject ? \"index.ts\" : \"index.js\",\n\t);\n\n\tconst slices = await args.actions.readAllSliceModelsForLibrary({\n\t\tlibraryID: args.libraryID,\n\t});\n\n\tlet contents: string;\n\n\tif (args.options.lazyLoadSlices) {\n\t\tcontents = stripIndent`\n\t\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\t\timport dynamic from 'next/dynamic'\n\n\t\t\texport const components = {\n\t\t\t\t${slices\n\t\t\t\t\t.map((slice) => {\n\t\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\t\tconst dirName = pascalCase(slice.model.name);\n\n\t\t\t\t\t\treturn `${id}: dynamic(() => import('./${dirName}'))`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\",\\n\")}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\t\t${slices\n\t\t\t\t.map((slice) => {\n\t\t\t\t\tconst componentName = pascalCase(slice.model.name);\n\t\t\t\t\tconst dirName = pascalCase(slice.model.name);\n\n\t\t\t\t\treturn `import ${componentName} from \"./${dirName}\";`;\n\t\t\t\t})\n\t\t\t\t.join(\"\\n\")}\n\n\t\t\texport const components = {\n\t\t\t\t${slices\n\t\t\t\t\t.map((slice) => {\n\t\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\t\tconst componentName = pascalCase(slice.model.name);\n\n\t\t\t\t\t\treturn `${id}: ${componentName},`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")}\n\t\t\t}\n\t\t`;\n\t}\n\n\tif (args.options.format) {\n\t\tcontents = await args.helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["checkIsTypeScriptProject","stripIndent","NON_EDITABLE_FILE_BANNER","pascalCase","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAca,MAAA,8BAA8B,OAC1C,SACkB;AACZ,QAAA,sBAAsB,MAAMA,kDAAyB;AAAA,IAC1D,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,EAAA,CACd;AAEK,QAAA,WAAW,KAAK,QAAQ,iBAC7B,KAAK,WACL,sBAAsB,aAAa,UAAU;AAG9C,QAAM,SAAS,MAAM,KAAK,QAAQ,6BAA6B;AAAA,IAC9D,WAAW,KAAK;AAAA,EAAA,CAChB;AAEG,MAAA;AAEA,MAAA,KAAK,QAAQ,gBAAgB;AACrB,eAAAC,WAAAA;AAAAA,KACRC;;;;;MAKC,OACA,IAAI,CAAC,UAAS;AACR,YAAA,KAAK,MAAM,MAAM;AACvB,YAAM,UAAUC,WAAA,WAAW,MAAM,MAAM,IAAI;AAE3C,aAAO,GAAG,+BAA+B;AAAA,IAAA,CACzC,EACA,KAAK,KAAK;AAAA;AAAA;AAAA,EAAA,OAGR;AACK,eAAAF,WAAAA;AAAAA,KACRC;;KAEA,OACA,IAAI,CAAC,UAAS;AACd,YAAM,gBAAgBC,WAAA,WAAW,MAAM,MAAM,IAAI;AACjD,YAAM,UAAUA,WAAA,WAAW,MAAM,MAAM,IAAI;AAE3C,aAAO,UAAU,yBAAyB;AAAA,IAAA,CAC1C,EACA,KAAK,IAAI;AAAA;AAAA;AAAA,MAGR,OACA,IAAI,CAAC,UAAS;AACR,YAAA,KAAK,MAAM,MAAM;AACvB,YAAM,gBAAgBA,WAAA,WAAW,MAAM,MAAM,IAAI;AAEjD,aAAO,GAAG,OAAO;AAAA,IAAA,CACjB,EACA,KAAK,IAAI;AAAA;AAAA;AAAA,EAGb;AAEG,MAAA,KAAK,QAAQ,QAAQ;AACxB,eAAW,MAAM,KAAK,QAAQ,OAAO,UAAU,QAAQ;AAAA,EACvD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { stripIndent } from "common-tags";
|
|
2
2
|
import * as fs from "node:fs/promises";
|
|
3
3
|
import { NON_EDITABLE_FILE_BANNER } from "../constants.js";
|
|
4
|
+
import { checkIsTypeScriptProject } from "./checkIsTypeScriptProject.js";
|
|
4
5
|
import { pascalCase } from "./pascalCase.js";
|
|
5
6
|
const upsertSliceLibraryIndexFile = async (args) => {
|
|
6
|
-
const
|
|
7
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
8
|
+
helpers: args.helpers,
|
|
9
|
+
options: args.options
|
|
10
|
+
});
|
|
11
|
+
const filePath = args.helpers.joinPathFromRoot(args.libraryID, isTypeScriptProject ? "index.ts" : "index.js");
|
|
7
12
|
const slices = await args.actions.readAllSliceModelsForLibrary({
|
|
8
13
|
libraryID: args.libraryID
|
|
9
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertSliceLibraryIndexFile.js","sources":["../../../src/lib/upsertSliceLibraryIndexFile.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpsertSliceLibraryIndexFileArgs = {\n\tlibraryID: string;\n} & SliceMachineContext<PluginOptions>;\n\nexport const upsertSliceLibraryIndexFile = async (\n\targs: UpsertSliceLibraryIndexFileArgs,\n): Promise<void> => {\n\tconst filePath = args.helpers.joinPathFromRoot(\n\t\targs.libraryID,\n\t\
|
|
1
|
+
{"version":3,"file":"upsertSliceLibraryIndexFile.js","sources":["../../../src/lib/upsertSliceLibraryIndexFile.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\nimport { PluginOptions } from \"../types\";\n\nimport { checkIsTypeScriptProject } from \"./checkIsTypeScriptProject\";\nimport { pascalCase } from \"./pascalCase\";\n\ntype UpsertSliceLibraryIndexFileArgs = {\n\tlibraryID: string;\n} & SliceMachineContext<PluginOptions>;\n\nexport const upsertSliceLibraryIndexFile = async (\n\targs: UpsertSliceLibraryIndexFileArgs,\n): Promise<void> => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers: args.helpers,\n\t\toptions: args.options,\n\t});\n\n\tconst filePath = args.helpers.joinPathFromRoot(\n\t\targs.libraryID,\n\t\tisTypeScriptProject ? \"index.ts\" : \"index.js\",\n\t);\n\n\tconst slices = await args.actions.readAllSliceModelsForLibrary({\n\t\tlibraryID: args.libraryID,\n\t});\n\n\tlet contents: string;\n\n\tif (args.options.lazyLoadSlices) {\n\t\tcontents = stripIndent`\n\t\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\t\timport dynamic from 'next/dynamic'\n\n\t\t\texport const components = {\n\t\t\t\t${slices\n\t\t\t\t\t.map((slice) => {\n\t\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\t\tconst dirName = pascalCase(slice.model.name);\n\n\t\t\t\t\t\treturn `${id}: dynamic(() => import('./${dirName}'))`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\",\\n\")}\n\t\t\t}\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t${NON_EDITABLE_FILE_BANNER}\n\n\t\t\t${slices\n\t\t\t\t.map((slice) => {\n\t\t\t\t\tconst componentName = pascalCase(slice.model.name);\n\t\t\t\t\tconst dirName = pascalCase(slice.model.name);\n\n\t\t\t\t\treturn `import ${componentName} from \"./${dirName}\";`;\n\t\t\t\t})\n\t\t\t\t.join(\"\\n\")}\n\n\t\t\texport const components = {\n\t\t\t\t${slices\n\t\t\t\t\t.map((slice) => {\n\t\t\t\t\t\tconst id = slice.model.id;\n\t\t\t\t\t\tconst componentName = pascalCase(slice.model.name);\n\n\t\t\t\t\t\treturn `${id}: ${componentName},`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")}\n\t\t\t}\n\t\t`;\n\t}\n\n\tif (args.options.format) {\n\t\tcontents = await args.helpers.format(contents, filePath);\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":[],"mappings":";;;;;AAca,MAAA,8BAA8B,OAC1C,SACkB;AACZ,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,EAAA,CACd;AAEK,QAAA,WAAW,KAAK,QAAQ,iBAC7B,KAAK,WACL,sBAAsB,aAAa,UAAU;AAG9C,QAAM,SAAS,MAAM,KAAK,QAAQ,6BAA6B;AAAA,IAC9D,WAAW,KAAK;AAAA,EAAA,CAChB;AAEG,MAAA;AAEA,MAAA,KAAK,QAAQ,gBAAgB;AACrB,eAAA;AAAA,KACR;AAAA;AAAA;AAAA;AAAA;AAAA,MAKC,OACA,IAAI,CAAC,UAAS;AACR,YAAA,KAAK,MAAM,MAAM;AACvB,YAAM,UAAU,WAAW,MAAM,MAAM,IAAI;AAE3C,aAAO,GAAG,+BAA+B;AAAA,IAAA,CACzC,EACA,KAAK,KAAK;AAAA;AAAA;AAAA,EAAA,OAGR;AACK,eAAA;AAAA,KACR;AAAA;AAAA,KAEA,OACA,IAAI,CAAC,UAAS;AACd,YAAM,gBAAgB,WAAW,MAAM,MAAM,IAAI;AACjD,YAAM,UAAU,WAAW,MAAM,MAAM,IAAI;AAE3C,aAAO,UAAU,yBAAyB;AAAA,IAAA,CAC1C,EACA,KAAK,IAAI;AAAA;AAAA;AAAA,MAGR,OACA,IAAI,CAAC,UAAS;AACR,YAAA,KAAK,MAAM,MAAM;AACvB,YAAM,gBAAgB,WAAW,MAAM,MAAM,IAAI;AAEjD,aAAO,GAAG,OAAO;AAAA,IAAA,CACjB,EACA,KAAK,IAAI;AAAA;AAAA;AAAA,EAGb;AAEG,MAAA,KAAK,QAAQ,QAAQ;AACxB,eAAW,MAAM,KAAK,QAAQ,OAAO,UAAU,QAAQ;AAAA,EACvD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
|
|
|
12
12
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
13
13
|
|
|
14
14
|
import type { PluginOptions } from "../types";
|
|
15
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
15
16
|
|
|
16
17
|
type InstallDependenciesArgs = {
|
|
17
18
|
installDependencies: CommandInitHookData["installDependencies"];
|
|
@@ -23,6 +24,8 @@ const installDependencies = async ({
|
|
|
23
24
|
await installDependencies({
|
|
24
25
|
dependencies: {
|
|
25
26
|
"@prismicio/client": "latest",
|
|
27
|
+
"@prismicio/helpers": "latest",
|
|
28
|
+
"@prismicio/react": "latest",
|
|
26
29
|
"@prismicio/next": "latest",
|
|
27
30
|
},
|
|
28
31
|
});
|
|
@@ -41,8 +44,13 @@ const createPrismicIOFile = async ({
|
|
|
41
44
|
helpers,
|
|
42
45
|
options,
|
|
43
46
|
}: CreatePrismicIOFileArgs) => {
|
|
47
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
48
|
+
helpers,
|
|
49
|
+
options,
|
|
50
|
+
});
|
|
51
|
+
|
|
44
52
|
const filePath = helpers.joinPathFromRoot(
|
|
45
|
-
|
|
53
|
+
isTypeScriptProject ? "prismicio.ts" : "prismicio.js",
|
|
46
54
|
);
|
|
47
55
|
|
|
48
56
|
if (await checkPathExists(filePath)) {
|
|
@@ -51,7 +59,7 @@ const createPrismicIOFile = async ({
|
|
|
51
59
|
|
|
52
60
|
let contents: string;
|
|
53
61
|
|
|
54
|
-
if (
|
|
62
|
+
if (isTypeScriptProject) {
|
|
55
63
|
contents = stripIndent`
|
|
56
64
|
import * as prismic from "@prismicio/client";
|
|
57
65
|
import * as prismicNext from "@prismicio/next";
|
|
@@ -174,7 +182,7 @@ const createSliceSimulatorPage = async ({
|
|
|
174
182
|
|
|
175
183
|
const filePath = helpers.joinPathFromRoot(
|
|
176
184
|
srcDirectoryExists ? "src/pages" : "pages",
|
|
177
|
-
`slice-simulator.${getJSOrTSXFileExtension(options)}`,
|
|
185
|
+
`slice-simulator.${await getJSOrTSXFileExtension({ helpers, options })}`,
|
|
178
186
|
);
|
|
179
187
|
|
|
180
188
|
if (await checkPathExists(filePath)) {
|
|
@@ -7,11 +7,12 @@ import { stripIndent } from "common-tags";
|
|
|
7
7
|
import * as fs from "node:fs/promises";
|
|
8
8
|
import * as path from "node:path";
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
11
11
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
|
|
12
12
|
import { pascalCase } from "../lib/pascalCase";
|
|
13
13
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
14
14
|
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
15
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
|
|
15
16
|
|
|
16
17
|
import type { PluginOptions } from "../types";
|
|
17
18
|
|
|
@@ -33,13 +34,21 @@ const createModelFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
36
|
-
const filePath = path.join(
|
|
37
|
+
const filePath = path.join(
|
|
38
|
+
dir,
|
|
39
|
+
`index.${await getJSOrTSXFileExtension({ helpers, options })}`,
|
|
40
|
+
);
|
|
37
41
|
const model = data.model;
|
|
38
42
|
const pascalName = pascalCase(model.name);
|
|
39
43
|
|
|
40
44
|
let contents: string;
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
47
|
+
helpers,
|
|
48
|
+
options,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (isTypeScriptProject) {
|
|
43
52
|
contents = stripIndent`
|
|
44
53
|
import { Content } from "@prismicio/client";
|
|
45
54
|
import { SliceComponentProps } from "@prismicio/react";
|
|
@@ -7,6 +7,7 @@ import { source } from "common-tags";
|
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
import fetch from "node-fetch";
|
|
9
9
|
|
|
10
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
10
11
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
|
|
11
12
|
|
|
12
13
|
import type { PluginOptions } from "../types";
|
|
@@ -83,12 +84,20 @@ const createStep2 = async ({
|
|
|
83
84
|
helpers,
|
|
84
85
|
options,
|
|
85
86
|
}: Args): Promise<SliceSimulatorSetupStep> => {
|
|
86
|
-
const fileName = `slice-simulator.${getJSOrTSXFileExtension(
|
|
87
|
+
const fileName = `slice-simulator.${await getJSOrTSXFileExtension({
|
|
88
|
+
helpers,
|
|
89
|
+
options,
|
|
90
|
+
})}`;
|
|
87
91
|
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
88
92
|
|
|
89
93
|
let fileContents: string;
|
|
90
94
|
|
|
91
|
-
|
|
95
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
96
|
+
helpers,
|
|
97
|
+
options,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (isTypeScriptProject) {
|
|
92
101
|
fileContents = await helpers.format(
|
|
93
102
|
source`
|
|
94
103
|
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
|
|
3
|
+
import { PluginOptions } from "../types";
|
|
4
|
+
import { checkPathExists } from "./checkPathExists";
|
|
5
|
+
|
|
6
|
+
type CheckIsTypeScriptProjectArgs = {
|
|
7
|
+
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
8
|
+
options: SliceMachineContext<PluginOptions>["options"];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const checkIsTypeScriptProject = async (
|
|
12
|
+
args: CheckIsTypeScriptProjectArgs,
|
|
13
|
+
): Promise<boolean> => {
|
|
14
|
+
const tsConfigPath = args.helpers.joinPathFromRoot("tsconfig.json");
|
|
15
|
+
|
|
16
|
+
return args.options.typescript ?? (await checkPathExists(tsConfigPath));
|
|
17
|
+
};
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
|
|
1
3
|
import type { PluginOptions } from "../types";
|
|
4
|
+
import { checkIsTypeScriptProject } from "./checkIsTypeScriptProject";
|
|
5
|
+
|
|
6
|
+
type GetJSOrTSXFileExtensionArgs = {
|
|
7
|
+
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
8
|
+
options: SliceMachineContext<PluginOptions>["options"];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const getJSOrTSXFileExtension = async (
|
|
12
|
+
args: GetJSOrTSXFileExtensionArgs,
|
|
13
|
+
): Promise<string> => {
|
|
14
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
15
|
+
helpers: args.helpers,
|
|
16
|
+
options: args.options,
|
|
17
|
+
});
|
|
2
18
|
|
|
3
|
-
|
|
4
|
-
pluginOptions: PluginOptions,
|
|
5
|
-
): string => {
|
|
6
|
-
if (pluginOptions.typescript) {
|
|
19
|
+
if (isTypeScriptProject) {
|
|
7
20
|
return "tsx";
|
|
8
|
-
} else if (
|
|
21
|
+
} else if (args.options.jsxExtension) {
|
|
9
22
|
return "jsx";
|
|
10
23
|
} else {
|
|
11
24
|
return "js";
|
|
@@ -5,6 +5,7 @@ import { NON_EDITABLE_FILE_BANNER } from "../constants";
|
|
|
5
5
|
|
|
6
6
|
import { PluginOptions } from "../types";
|
|
7
7
|
|
|
8
|
+
import { checkIsTypeScriptProject } from "./checkIsTypeScriptProject";
|
|
8
9
|
import { pascalCase } from "./pascalCase";
|
|
9
10
|
|
|
10
11
|
type UpsertSliceLibraryIndexFileArgs = {
|
|
@@ -14,9 +15,14 @@ type UpsertSliceLibraryIndexFileArgs = {
|
|
|
14
15
|
export const upsertSliceLibraryIndexFile = async (
|
|
15
16
|
args: UpsertSliceLibraryIndexFileArgs,
|
|
16
17
|
): Promise<void> => {
|
|
18
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
19
|
+
helpers: args.helpers,
|
|
20
|
+
options: args.options,
|
|
21
|
+
});
|
|
22
|
+
|
|
17
23
|
const filePath = args.helpers.joinPathFromRoot(
|
|
18
24
|
args.libraryID,
|
|
19
|
-
|
|
25
|
+
isTypeScriptProject ? "index.ts" : "index.js",
|
|
20
26
|
);
|
|
21
27
|
|
|
22
28
|
const slices = await args.actions.readAllSliceModelsForLibrary({
|