@slicemachine/adapter-nuxt 0.3.17 → 0.3.18-dev-next-release.1
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/documentation-read.cjs +1 -1
- package/dist/hooks/documentation-read.cjs.map +1 -1
- package/dist/hooks/documentation-read.js +1 -1
- package/dist/hooks/documentation-read.js.map +1 -1
- package/dist/hooks/project-init.cjs +1 -1
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +1 -1
- package/dist/hooks/project-init.js.map +1 -1
- package/package.json +3 -3
- package/src/hooks/documentation-read.ts +3 -1
- package/src/hooks/project-init.ts +1 -1
|
@@ -20,7 +20,7 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
20
20
|
}
|
|
21
21
|
let fileContent;
|
|
22
22
|
if (model.repeatable) {
|
|
23
|
-
fileContent = commonTags.stripIndent(_a || (_a = __template(["\n <script ", '>\n import { components } from "~/slices";\n\n const prismic = usePrismic();\n const route = useRoute();\n const { data: page } = useAsyncData(
|
|
23
|
+
fileContent = commonTags.stripIndent(_a || (_a = __template(["\n <script ", '>\n import { components } from "~/slices";\n\n const prismic = usePrismic();\n const route = useRoute();\n const { data: page } = useAsyncData(`[', '-uid-${route.params.uid}]`, () =>\n prismic.client.getByUID("', '", route.params.uid', ')\n );\n\n useHead({\n title: page.value?.data.meta_title,\n meta: [{\n name: "description",\n content: page.value?.data.meta_description,\n }],\n });\n <\/script>\n\n <template>\n <SliceZone\n wrapper="main"\n :slices="page?.data.slices ?? []"\n :components="components"\n />\n </template>\n '], ["\n <script ", '>\n import { components } from "~/slices";\n\n const prismic = usePrismic();\n const route = useRoute();\n const { data: page } = useAsyncData(\\`[', '-uid-\\${route.params.uid}]\\`, () =>\n prismic.client.getByUID("', '", route.params.uid', ')\n );\n\n useHead({\n title: page.value?.data.meta_title,\n meta: [{\n name: "description",\n content: page.value?.data.meta_description,\n }],\n });\n <\/script>\n\n <template>\n <SliceZone\n wrapper="main"\n :slices="page?.data.slices ?? []"\n :components="components"\n />\n </template>\n '])), scriptAttributes.join(" "), model.id, model.id, isTypeScriptProject ? " as string" : "");
|
|
24
24
|
} else {
|
|
25
25
|
fileContent = commonTags.stripIndent(_b || (_b = __template(["\n <script ", '>\n import { components } from "~/slices";\n\n const prismic = usePrismic();\n const { data: page } = useAsyncData("[', ']", () =>\n prismic.client.getSingle("', '")\n );\n\n useHead({\n title: page.value?.data.meta_title,\n meta: [{\n name: "description",\n content: page.value?.data.meta_description,\n }],\n });\n <\/script>\n\n <template>\n <SliceZone\n wrapper="main"\n :slices="page?.data.slices ?? []"\n :components="components"\n />\n </template>\n '])), scriptAttributes.join(" "), model.id, model.id);
|
|
26
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentation-read.cjs","sources":["../../../src/hooks/documentation-read.ts"],"sourcesContent":["import { source, stripIndent } from \"common-tags\";\n\nimport type { DocumentationReadHook } from \"@slicemachine/plugin-kit\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\nexport const documentationRead: DocumentationReadHook<PluginOptions> = async (\n\tdata,\n\t{ options, helpers },\n) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (data.kind === \"PageSnippet\") {\n\t\tconst { model } = data.data;\n\t\tconst filePath = `${model.repeatable ? \"[uid]\" : model.id}.vue`;\n\t\tconst scriptAttributes = [\"setup\"];\n\t\tif (isTypeScriptProject) {\n\t\t\tscriptAttributes.push('lang=\"ts\"');\n\t\t}\n\n\t\tlet fileContent: string;\n\n\t\tif (model.repeatable) {\n\t\t\tfileContent = stripIndent`\n\t\t\t\t<script ${scriptAttributes.join(\" \")}>\n\t\t\t\timport { components } from \"~/slices\";\n\n\t\t\t\tconst prismic = usePrismic();\n\t\t\t\tconst route = useRoute();\n\t\t\t\tconst { data: page } = useAsyncData(
|
|
1
|
+
{"version":3,"file":"documentation-read.cjs","sources":["../../../src/hooks/documentation-read.ts"],"sourcesContent":["import { source, stripIndent } from \"common-tags\";\n\nimport type { DocumentationReadHook } from \"@slicemachine/plugin-kit\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\nexport const documentationRead: DocumentationReadHook<PluginOptions> = async (\n\tdata,\n\t{ options, helpers },\n) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (data.kind === \"PageSnippet\") {\n\t\tconst { model } = data.data;\n\t\tconst filePath = `${model.repeatable ? \"[uid]\" : model.id}.vue`;\n\t\tconst scriptAttributes = [\"setup\"];\n\t\tif (isTypeScriptProject) {\n\t\t\tscriptAttributes.push('lang=\"ts\"');\n\t\t}\n\n\t\tlet fileContent: string;\n\n\t\tif (model.repeatable) {\n\t\t\tfileContent = stripIndent`\n\t\t\t\t<script ${scriptAttributes.join(\" \")}>\n\t\t\t\timport { components } from \"~/slices\";\n\n\t\t\t\tconst prismic = usePrismic();\n\t\t\t\tconst route = useRoute();\n\t\t\t\tconst { data: page } = useAsyncData(\\`[${\n\t\t\t\t\tmodel.id\n\t\t\t\t}-uid-\\${route.params.uid}]\\`, () =>\n\t\t\t\t\tprismic.client.getByUID(\"${model.id}\", route.params.uid${\n\t\t\t\tisTypeScriptProject ? \" as string\" : \"\"\n\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tuseHead({\n\t\t\t\t\ttitle: page.value?.data.meta_title,\n\t\t\t\t\tmeta: [{\n\t\t\t\t\t\tname: \"description\",\n\t\t\t\t\t\tcontent: page.value?.data.meta_description,\n\t\t\t\t\t}],\n\t\t\t\t});\n\t\t\t\t</script>\n\n\t\t\t\t<template>\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t\twrapper=\"main\"\n\t\t\t\t\t\t:slices=\"page?.data.slices ?? []\"\n\t\t\t\t\t\t:components=\"components\"\n\t\t\t\t\t/>\n\t\t\t\t</template>\n\t\t\t`;\n\t\t} else {\n\t\t\tfileContent = stripIndent`\n\t\t\t\t<script ${scriptAttributes.join(\" \")}>\n\t\t\t\t\timport { components } from \"~/slices\";\n\n\t\t\t\t\tconst prismic = usePrismic();\n\t\t\t\t\tconst { data: page } = useAsyncData(\"[${model.id}]\", () =>\n\t\t\t\t\t\tprismic.client.getSingle(\"${model.id}\")\n\t\t\t\t\t);\n\n\t\t\t\t\tuseHead({\n\t\t\t\t\t\ttitle: page.value?.data.meta_title,\n\t\t\t\t\t\tmeta: [{\n\t\t\t\t\t\t\tname: \"description\",\n\t\t\t\t\t\t\tcontent: page.value?.data.meta_description,\n\t\t\t\t\t\t}],\n\t\t\t\t\t});\n\t\t\t\t</script>\n\n\t\t\t\t<template>\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t\twrapper=\"main\"\n\t\t\t\t\t\t:slices=\"page?.data.slices ?? []\"\n\t\t\t\t\t\t:components=\"components\"\n\t\t\t\t\t/>\n\t\t\t\t</template>\n\t\t\t`;\n\t\t}\n\n\t\tif (options.format) {\n\t\t\tfileContent = await helpers.format(\n\t\t\t\tfileContent,\n\t\t\t\thelpers.joinPathFromRoot(\"index.vue\"),\n\t\t\t\t{\n\t\t\t\t\tprettier: { parser: \"vue\" },\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tlabel: \"Composition API\",\n\t\t\t\tcontent: source`\n\t\t\t\t\t## Create your ${model.label}'s page component\n\n\t\t\t\t\tAdd a new route by creating an \\`~/pages/${filePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`~/pages/marketing/${filePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~vue [~/pages/${filePath}]\\n${fileContent}\\n~~~`}\n\n\t\t\t\t\tMake sure all of your import paths are correct. See the [install guide](https://prismic.io/docs/nuxt-3-setup) for more information.\n\t\t\t\t`,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n"],"names":["checkIsTypeScriptProject","stripIndent","source"],"mappings":";;;;;;;AAAA,IAAA,IAAA;AAOO,MAAM,oBAA0D,OACtE,MACA,EAAE,SAAS,cACR;AACG,QAAA,sBAAsB,MAAMA,kDAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAEG,MAAA,KAAK,SAAS,eAAe;AAC1B,UAAA,EAAE,MAAK,IAAK,KAAK;AACvB,UAAM,WAAW,GAAG,MAAM,aAAa,UAAU,MAAM;AACjD,UAAA,mBAAmB,CAAC,OAAO;AACjC,QAAI,qBAAqB;AACxB,uBAAiB,KAAK,WAAW;AAAA,IACjC;AAEG,QAAA;AAEJ,QAAI,MAAM,YAAY;AACP,oBAAAC,WAAAA,YAAA,OAAA,KAAW,8BACY,iKAOpC,qEACoC,uBAErC,wWAXyB,GAAA,CAAA,kBACY,mKAOpC,yEACoC,uBAErC,6WAVW,iBAAiB,KAAK,GAAG,GAMlC,MAAM,IAEqB,MAAM,IAClC,sBAAsB,eAAe,EAAA;AAAA,IAAA,OAqBhC;AACQ,oBAAAA,WAAAA,YAAA,OAAA,KAAW,WACY,CAAA,kBAAA,qIAIa,+CACX,iXAAA,CAAA,IAL5B,iBAAiB,KAAK,GAAG,GAIM,MAAM,IACjB,MAAM,EAAA;AAAA,IAoBrC;AAED,QAAI,QAAQ,QAAQ;AACnB,oBAAc,MAAM,QAAQ,OAC3B,aACA,QAAQ,iBAAiB,WAAW,GACpC;AAAA,QACC,UAAU,EAAE,QAAQ,MAAO;AAAA,QAC3B,qBAAqB;AAAA,MAAA,CACrB;AAAA,IAEF;AAEM,WAAA;AAAA,MACN;AAAA,QACC,OAAO;AAAA,QACP,SAASC,WAAAA;AAAAA,sBACS,MAAM;AAAA;AAAA,gDAEoB,0IAA0I;AAAA;AAAA;AAAA;AAAA,OAInL,mBAAmB;AAAA,EAAc;AAAA;AAAA;AAAA;AAAA;AAAA,MAIpC;AAAA,IAAA;AAAA,EAEF;AAED,SAAO;AACR;;"}
|
|
@@ -18,7 +18,7 @@ const documentationRead = async (data, { options, helpers }) => {
|
|
|
18
18
|
}
|
|
19
19
|
let fileContent;
|
|
20
20
|
if (model.repeatable) {
|
|
21
|
-
fileContent = stripIndent(_a || (_a = __template(["\n <script ", '>\n import { components } from "~/slices";\n\n const prismic = usePrismic();\n const route = useRoute();\n const { data: page } = useAsyncData(
|
|
21
|
+
fileContent = stripIndent(_a || (_a = __template(["\n <script ", '>\n import { components } from "~/slices";\n\n const prismic = usePrismic();\n const route = useRoute();\n const { data: page } = useAsyncData(`[', '-uid-${route.params.uid}]`, () =>\n prismic.client.getByUID("', '", route.params.uid', ')\n );\n\n useHead({\n title: page.value?.data.meta_title,\n meta: [{\n name: "description",\n content: page.value?.data.meta_description,\n }],\n });\n <\/script>\n\n <template>\n <SliceZone\n wrapper="main"\n :slices="page?.data.slices ?? []"\n :components="components"\n />\n </template>\n '], ["\n <script ", '>\n import { components } from "~/slices";\n\n const prismic = usePrismic();\n const route = useRoute();\n const { data: page } = useAsyncData(\\`[', '-uid-\\${route.params.uid}]\\`, () =>\n prismic.client.getByUID("', '", route.params.uid', ')\n );\n\n useHead({\n title: page.value?.data.meta_title,\n meta: [{\n name: "description",\n content: page.value?.data.meta_description,\n }],\n });\n <\/script>\n\n <template>\n <SliceZone\n wrapper="main"\n :slices="page?.data.slices ?? []"\n :components="components"\n />\n </template>\n '])), scriptAttributes.join(" "), model.id, model.id, isTypeScriptProject ? " as string" : "");
|
|
22
22
|
} else {
|
|
23
23
|
fileContent = stripIndent(_b || (_b = __template(["\n <script ", '>\n import { components } from "~/slices";\n\n const prismic = usePrismic();\n const { data: page } = useAsyncData("[', ']", () =>\n prismic.client.getSingle("', '")\n );\n\n useHead({\n title: page.value?.data.meta_title,\n meta: [{\n name: "description",\n content: page.value?.data.meta_description,\n }],\n });\n <\/script>\n\n <template>\n <SliceZone\n wrapper="main"\n :slices="page?.data.slices ?? []"\n :components="components"\n />\n </template>\n '])), scriptAttributes.join(" "), model.id, model.id);
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"documentation-read.js","sources":["../../../src/hooks/documentation-read.ts"],"sourcesContent":["import { source, stripIndent } from \"common-tags\";\n\nimport type { DocumentationReadHook } from \"@slicemachine/plugin-kit\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\nexport const documentationRead: DocumentationReadHook<PluginOptions> = async (\n\tdata,\n\t{ options, helpers },\n) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (data.kind === \"PageSnippet\") {\n\t\tconst { model } = data.data;\n\t\tconst filePath = `${model.repeatable ? \"[uid]\" : model.id}.vue`;\n\t\tconst scriptAttributes = [\"setup\"];\n\t\tif (isTypeScriptProject) {\n\t\t\tscriptAttributes.push('lang=\"ts\"');\n\t\t}\n\n\t\tlet fileContent: string;\n\n\t\tif (model.repeatable) {\n\t\t\tfileContent = stripIndent`\n\t\t\t\t<script ${scriptAttributes.join(\" \")}>\n\t\t\t\timport { components } from \"~/slices\";\n\n\t\t\t\tconst prismic = usePrismic();\n\t\t\t\tconst route = useRoute();\n\t\t\t\tconst { data: page } = useAsyncData(
|
|
1
|
+
{"version":3,"file":"documentation-read.js","sources":["../../../src/hooks/documentation-read.ts"],"sourcesContent":["import { source, stripIndent } from \"common-tags\";\n\nimport type { DocumentationReadHook } from \"@slicemachine/plugin-kit\";\n\nimport type { PluginOptions } from \"../types\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\n\nexport const documentationRead: DocumentationReadHook<PluginOptions> = async (\n\tdata,\n\t{ options, helpers },\n) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (data.kind === \"PageSnippet\") {\n\t\tconst { model } = data.data;\n\t\tconst filePath = `${model.repeatable ? \"[uid]\" : model.id}.vue`;\n\t\tconst scriptAttributes = [\"setup\"];\n\t\tif (isTypeScriptProject) {\n\t\t\tscriptAttributes.push('lang=\"ts\"');\n\t\t}\n\n\t\tlet fileContent: string;\n\n\t\tif (model.repeatable) {\n\t\t\tfileContent = stripIndent`\n\t\t\t\t<script ${scriptAttributes.join(\" \")}>\n\t\t\t\timport { components } from \"~/slices\";\n\n\t\t\t\tconst prismic = usePrismic();\n\t\t\t\tconst route = useRoute();\n\t\t\t\tconst { data: page } = useAsyncData(\\`[${\n\t\t\t\t\tmodel.id\n\t\t\t\t}-uid-\\${route.params.uid}]\\`, () =>\n\t\t\t\t\tprismic.client.getByUID(\"${model.id}\", route.params.uid${\n\t\t\t\tisTypeScriptProject ? \" as string\" : \"\"\n\t\t\t})\n\t\t\t\t);\n\n\t\t\t\tuseHead({\n\t\t\t\t\ttitle: page.value?.data.meta_title,\n\t\t\t\t\tmeta: [{\n\t\t\t\t\t\tname: \"description\",\n\t\t\t\t\t\tcontent: page.value?.data.meta_description,\n\t\t\t\t\t}],\n\t\t\t\t});\n\t\t\t\t</script>\n\n\t\t\t\t<template>\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t\twrapper=\"main\"\n\t\t\t\t\t\t:slices=\"page?.data.slices ?? []\"\n\t\t\t\t\t\t:components=\"components\"\n\t\t\t\t\t/>\n\t\t\t\t</template>\n\t\t\t`;\n\t\t} else {\n\t\t\tfileContent = stripIndent`\n\t\t\t\t<script ${scriptAttributes.join(\" \")}>\n\t\t\t\t\timport { components } from \"~/slices\";\n\n\t\t\t\t\tconst prismic = usePrismic();\n\t\t\t\t\tconst { data: page } = useAsyncData(\"[${model.id}]\", () =>\n\t\t\t\t\t\tprismic.client.getSingle(\"${model.id}\")\n\t\t\t\t\t);\n\n\t\t\t\t\tuseHead({\n\t\t\t\t\t\ttitle: page.value?.data.meta_title,\n\t\t\t\t\t\tmeta: [{\n\t\t\t\t\t\t\tname: \"description\",\n\t\t\t\t\t\t\tcontent: page.value?.data.meta_description,\n\t\t\t\t\t\t}],\n\t\t\t\t\t});\n\t\t\t\t</script>\n\n\t\t\t\t<template>\n\t\t\t\t\t<SliceZone\n\t\t\t\t\t\twrapper=\"main\"\n\t\t\t\t\t\t:slices=\"page?.data.slices ?? []\"\n\t\t\t\t\t\t:components=\"components\"\n\t\t\t\t\t/>\n\t\t\t\t</template>\n\t\t\t`;\n\t\t}\n\n\t\tif (options.format) {\n\t\t\tfileContent = await helpers.format(\n\t\t\t\tfileContent,\n\t\t\t\thelpers.joinPathFromRoot(\"index.vue\"),\n\t\t\t\t{\n\t\t\t\t\tprettier: { parser: \"vue\" },\n\t\t\t\t\tincludeNewlineAtEnd: false,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tlabel: \"Composition API\",\n\t\t\t\tcontent: source`\n\t\t\t\t\t## Create your ${model.label}'s page component\n\n\t\t\t\t\tAdd a new route by creating an \\`~/pages/${filePath}\\` file. (If the route should be nested in a child directory, you can create the file in a directory, like \\`~/pages/marketing/${filePath}\\`.)\n\n\t\t\t\t\tPaste in this code:\n\n\t\t\t\t\t${`~~~vue [~/pages/${filePath}]\\n${fileContent}\\n~~~`}\n\n\t\t\t\t\tMake sure all of your import paths are correct. See the [install guide](https://prismic.io/docs/nuxt-3-setup) for more information.\n\t\t\t\t`,\n\t\t\t},\n\t\t];\n\t}\n\n\treturn [];\n};\n"],"names":[],"mappings":";;;;;AAAA,IAAA,IAAA;AAOO,MAAM,oBAA0D,OACtE,MACA,EAAE,SAAS,cACR;AACG,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAEG,MAAA,KAAK,SAAS,eAAe;AAC1B,UAAA,EAAE,MAAK,IAAK,KAAK;AACvB,UAAM,WAAW,GAAG,MAAM,aAAa,UAAU,MAAM;AACjD,UAAA,mBAAmB,CAAC,OAAO;AACjC,QAAI,qBAAqB;AACxB,uBAAiB,KAAK,WAAW;AAAA,IACjC;AAEG,QAAA;AAEJ,QAAI,MAAM,YAAY;AACP,oBAAA,YAAA,OAAA,KAAW,8BACY,iKAOpC,qEACoC,uBAErC,wWAXyB,GAAA,CAAA,kBACY,mKAOpC,yEACoC,uBAErC,6WAVW,iBAAiB,KAAK,GAAG,GAMlC,MAAM,IAEqB,MAAM,IAClC,sBAAsB,eAAe,EAAA;AAAA,IAAA,OAqBhC;AACQ,oBAAA,YAAA,OAAA,KAAW,WACY,CAAA,kBAAA,qIAIa,+CACX,iXAAA,CAAA,IAL5B,iBAAiB,KAAK,GAAG,GAIM,MAAM,IACjB,MAAM,EAAA;AAAA,IAoBrC;AAED,QAAI,QAAQ,QAAQ;AACnB,oBAAc,MAAM,QAAQ,OAC3B,aACA,QAAQ,iBAAiB,WAAW,GACpC;AAAA,QACC,UAAU,EAAE,QAAQ,MAAO;AAAA,QAC3B,qBAAqB;AAAA,MAAA,CACrB;AAAA,IAEF;AAEM,WAAA;AAAA,MACN;AAAA,QACC,OAAO;AAAA,QACP,SAAS;AAAA,sBACS,MAAM;AAAA;AAAA,gDAEoB,0IAA0I;AAAA;AAAA;AAAA;AAAA,OAInL,mBAAmB;AAAA,EAAc;AAAA;AAAA;AAAA;AAAA;AAAA,MAIpC;AAAA,IAAA;AAAA,EAEF;AAED,SAAO;AACR;"}
|
|
@@ -142,7 +142,7 @@ const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
|
142
142
|
var _a2;
|
|
143
143
|
const hasSrcDirectory = await checkHasSrcDirectory.checkHasSrcDirectory({ helpers });
|
|
144
144
|
const project = await helpers.getProject();
|
|
145
|
-
(_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://
|
|
145
|
+
(_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://127.0.0.1:3000/slice-simulator");
|
|
146
146
|
if (hasSrcDirectory && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
|
|
147
147
|
const sliceLibrary = await actions.readSliceLibrary({
|
|
148
148
|
libraryID: project.config.libraries[0]
|
|
@@ -1 +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\tdeleteProjectFile,\n\treadProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\nimport { loadFile, writeFile, type ASTNode } from \"magicast\";\n\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\ttry {\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"^3.0.0\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t} catch (error) {\n\t\t// TODO: Remove when latest is published and documented\n\t\t// Fallback to RC if latest is still not available\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"rc\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t}\n};\n\ntype ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n\tproject,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigFilename = \"nuxt.config.js\";\n\n\tif (!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))) {\n\t\tnuxtConfigFilename = \"nuxt.config.ts\";\n\n\t\t// nuxt.config.* not found\n\t\tif (\n\t\t\t!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tconst endpoint = project.config.repositoryName;\n\tif (!hasInlinedConfiguration) {\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = endpoint;\n\t}\n\n\tawait writeFile(mod as unknown as ASTNode, nuxtConfigPath);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filename = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"slice-simulator.vue\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tconst contents = stripIndent`\n\t\t<template>\n\t\t\t<SliceSimulator #default=\"{ slices }\">\n\t\t\t\t<SliceZone :slices=\"slices\" :components=\"components\" />\n\t\t\t</SliceSimulator>\n\t\t</template>\n\n\t\t<script ${scriptAttributes.join(\" \")}>\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-nuxt/simulator\";\n\t\timport { components } from \"~/slices\";\n\t\t</script>\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 moveOrDeleteAppVue = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst srcDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\n\tconst filenameAppVue = path.join(srcDirectoryExists ? \"src\" : \"\", \"app.vue\");\n\n\t// If there's not `app.vue`, there's nothing to do.\n\tif (!(await checkHasProjectFile({ filename: filenameAppVue, helpers }))) {\n\t\treturn;\n\t}\n\n\tconst filecontentAppVue = await readProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t\tencoding: \"utf-8\",\n\t});\n\n\t// We check for app.vue to contain Nuxt default welcome component to determine if we need to consider it as the default one or not.\n\tif (!filecontentAppVue.includes(\"<NuxtWelcome\")) {\n\t\treturn;\n\t}\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filenameIndexVue = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"index.vue\",\n\t);\n\n\t// If we don't have an `index.vue` we create one with the content of `app.vue`\n\tif (!(await checkHasProjectFile({ filename: filenameIndexVue, helpers }))) {\n\t\tawait writeProjectFile({\n\t\t\tfilename: filenameIndexVue,\n\t\t\tcontents: filecontentAppVue,\n\t\t\tformat: options.format,\n\t\t\thelpers,\n\t\t});\n\t}\n\n\t// Delete `app.vue`\n\tawait deleteProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\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\thasSrcDirectory &&\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/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\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\tconfigurePrismicModule(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tmoveOrDeleteAppVue(context),\n\t\t\tmodifySliceMachineConfig(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkHasProjectFile","loadFile","writeFile","checkIsTypeScriptProject","path","stripIndent","writeProjectFile","readProjectFile","deleteProjectFile","checkHasSrcDirectory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;AAAA,IAC9B,yBAAyB,OAAO;AAAA,IAChC,mBAAmB,OAAO;AAAA,IAC1B,yBAAyB,OAAO;AAAA,EAChC,CAAA,CAAC;AAEJ;;"}
|
|
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\tdeleteProjectFile,\n\treadProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\nimport { loadFile, writeFile, type ASTNode } from \"magicast\";\n\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\ttry {\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"^3.0.0\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t} catch (error) {\n\t\t// TODO: Remove when latest is published and documented\n\t\t// Fallback to RC if latest is still not available\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"rc\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t}\n};\n\ntype ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n\tproject,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigFilename = \"nuxt.config.js\";\n\n\tif (!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))) {\n\t\tnuxtConfigFilename = \"nuxt.config.ts\";\n\n\t\t// nuxt.config.* not found\n\t\tif (\n\t\t\t!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tconst endpoint = project.config.repositoryName;\n\tif (!hasInlinedConfiguration) {\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = endpoint;\n\t}\n\n\tawait writeFile(mod as unknown as ASTNode, nuxtConfigPath);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filename = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"slice-simulator.vue\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tconst contents = stripIndent`\n\t\t<template>\n\t\t\t<SliceSimulator #default=\"{ slices }\">\n\t\t\t\t<SliceZone :slices=\"slices\" :components=\"components\" />\n\t\t\t</SliceSimulator>\n\t\t</template>\n\n\t\t<script ${scriptAttributes.join(\" \")}>\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-nuxt/simulator\";\n\t\timport { components } from \"~/slices\";\n\t\t</script>\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 moveOrDeleteAppVue = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst srcDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\n\tconst filenameAppVue = path.join(srcDirectoryExists ? \"src\" : \"\", \"app.vue\");\n\n\t// If there's not `app.vue`, there's nothing to do.\n\tif (!(await checkHasProjectFile({ filename: filenameAppVue, helpers }))) {\n\t\treturn;\n\t}\n\n\tconst filecontentAppVue = await readProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t\tencoding: \"utf-8\",\n\t});\n\n\t// We check for app.vue to contain Nuxt default welcome component to determine if we need to consider it as the default one or not.\n\tif (!filecontentAppVue.includes(\"<NuxtWelcome\")) {\n\t\treturn;\n\t}\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filenameIndexVue = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"index.vue\",\n\t);\n\n\t// If we don't have an `index.vue` we create one with the content of `app.vue`\n\tif (!(await checkHasProjectFile({ filename: filenameIndexVue, helpers }))) {\n\t\tawait writeProjectFile({\n\t\t\tfilename: filenameIndexVue,\n\t\t\tcontents: filecontentAppVue,\n\t\t\tformat: options.format,\n\t\t\thelpers,\n\t\t});\n\t}\n\n\t// Delete `app.vue`\n\tawait deleteProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://127.0.0.1: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\thasSrcDirectory &&\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/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\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\tconfigurePrismicModule(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tmoveOrDeleteAppVue(context),\n\t\t\tmodifySliceMachineConfig(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkHasProjectFile","loadFile","writeFile","checkIsTypeScriptProject","path","stripIndent","writeProjectFile","readProjectFile","deleteProjectFile","checkHasSrcDirectory","_a","rejectIfNecessary"],"mappings":";;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O;AAAA,IAChC,mBAAmB,OAAO;AAAA,IAC1B,yBAAyB,OAAO;AAAA,EAChC,CAAA,CAAC;AAEJ;;"}
|
|
@@ -123,7 +123,7 @@ const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
|
|
|
123
123
|
var _a2;
|
|
124
124
|
const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
|
|
125
125
|
const project = await helpers.getProject();
|
|
126
|
-
(_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://
|
|
126
|
+
(_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://127.0.0.1:3000/slice-simulator");
|
|
127
127
|
if (hasSrcDirectory && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
|
|
128
128
|
const sliceLibrary = await actions.readSliceLibrary({
|
|
129
129
|
libraryID: project.config.libraries[0]
|
|
@@ -1 +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\tdeleteProjectFile,\n\treadProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\nimport { loadFile, writeFile, type ASTNode } from \"magicast\";\n\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\ttry {\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"^3.0.0\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t} catch (error) {\n\t\t// TODO: Remove when latest is published and documented\n\t\t// Fallback to RC if latest is still not available\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"rc\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t}\n};\n\ntype ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n\tproject,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigFilename = \"nuxt.config.js\";\n\n\tif (!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))) {\n\t\tnuxtConfigFilename = \"nuxt.config.ts\";\n\n\t\t// nuxt.config.* not found\n\t\tif (\n\t\t\t!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tconst endpoint = project.config.repositoryName;\n\tif (!hasInlinedConfiguration) {\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = endpoint;\n\t}\n\n\tawait writeFile(mod as unknown as ASTNode, nuxtConfigPath);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filename = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"slice-simulator.vue\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tconst contents = stripIndent`\n\t\t<template>\n\t\t\t<SliceSimulator #default=\"{ slices }\">\n\t\t\t\t<SliceZone :slices=\"slices\" :components=\"components\" />\n\t\t\t</SliceSimulator>\n\t\t</template>\n\n\t\t<script ${scriptAttributes.join(\" \")}>\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-nuxt/simulator\";\n\t\timport { components } from \"~/slices\";\n\t\t</script>\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 moveOrDeleteAppVue = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst srcDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\n\tconst filenameAppVue = path.join(srcDirectoryExists ? \"src\" : \"\", \"app.vue\");\n\n\t// If there's not `app.vue`, there's nothing to do.\n\tif (!(await checkHasProjectFile({ filename: filenameAppVue, helpers }))) {\n\t\treturn;\n\t}\n\n\tconst filecontentAppVue = await readProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t\tencoding: \"utf-8\",\n\t});\n\n\t// We check for app.vue to contain Nuxt default welcome component to determine if we need to consider it as the default one or not.\n\tif (!filecontentAppVue.includes(\"<NuxtWelcome\")) {\n\t\treturn;\n\t}\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filenameIndexVue = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"index.vue\",\n\t);\n\n\t// If we don't have an `index.vue` we create one with the content of `app.vue`\n\tif (!(await checkHasProjectFile({ filename: filenameIndexVue, helpers }))) {\n\t\tawait writeProjectFile({\n\t\t\tfilename: filenameIndexVue,\n\t\t\tcontents: filecontentAppVue,\n\t\t\tformat: options.format,\n\t\t\thelpers,\n\t\t});\n\t}\n\n\t// Delete `app.vue`\n\tawait deleteProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\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\thasSrcDirectory &&\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/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\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\tconfigurePrismicModule(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tmoveOrDeleteAppVue(context),\n\t\t\tmodifySliceMachineConfig(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","_a"],"mappings":";;;;;;;;;;AAAA,IAAA;AAqBA,MAAM,eAAe;AAMrB,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AACzB,MAAA;AACH,UAAMA,qBAAoB;AAAA,MACzB,cAAc;AAAA,QACb,CAAC,YAAY,GAAG;AAAA,MAChB;AAAA,MACD,KAAK;AAAA,IAAA,CACL;AAAA,WACO;AAGR,UAAMA,qBAAoB;AAAA,MACzB,cAAc;AAAA,QACb,CAAC,YAAY,GAAG;AAAA,MAChB;AAAA,MACD,KAAK;AAAA,IAAA,CACL;AAAA,EACD;AACF;AAIA,MAAM,yBAAyB,OAAO,EACrC,SACA,cACgC;AAChC,MAAI,qBAAqB;AAErB,MAAA,CAAE,MAAM,oBAAoB,EAAE,UAAU,oBAAoB,QAAA,CAAS,GAAI;AACvD,yBAAA;AAIpB,QAAA,CAAE,MAAM,oBAAoB,EAAE,UAAU,oBAAoB,QAAA,CAAS,GACpE;AACD;AAAA,IACA;AAAA,EACD;AAEK,QAAA,iBAAiB,QAAQ,iBAAiB,kBAAkB;AAE5D,QAAA,MAAM,MAAM,SAAS,cAAc;AACzC,QAAM,SACL,IAAI,QAAQ,QAAQ,UAAU,kBAC3B,IAAI,QAAQ,QAAQ,MAAM,CAAC,IAC3B,IAAI,QAAQ;AAGhB,MAAI,0BAA0B;AAC9B,QAAM,8BAA8B,OAAO,WAAW,CAAA,GAAI,KACzD,CAAC,iBAA4C;AACxC,QAAA,OAA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D,QAAQ,QAAQ;AAAA,EAAA,CAChB;AACF;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,uBAAuB,OAAO;AAAA,IAC9B,yBAAyB,OAAO;AAAA,IAChC,mBAAmB,OAAO;AAAA,IAC1B,yBAAyB,OAAO;AAAA,EAChC,CAAA,CAAC;AAEJ;"}
|
|
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\tdeleteProjectFile,\n\treadProjectFile,\n\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\nimport { loadFile, writeFile, type ASTNode } from \"magicast\";\n\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\ttry {\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"^3.0.0\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t} catch (error) {\n\t\t// TODO: Remove when latest is published and documented\n\t\t// Fallback to RC if latest is still not available\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"rc\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t}\n};\n\ntype ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n\tproject,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigFilename = \"nuxt.config.js\";\n\n\tif (!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))) {\n\t\tnuxtConfigFilename = \"nuxt.config.ts\";\n\n\t\t// nuxt.config.* not found\n\t\tif (\n\t\t\t!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tconst endpoint = project.config.repositoryName;\n\tif (!hasInlinedConfiguration) {\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = endpoint;\n\t}\n\n\tawait writeFile(mod as unknown as ASTNode, nuxtConfigPath);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filename = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"slice-simulator.vue\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tconst contents = stripIndent`\n\t\t<template>\n\t\t\t<SliceSimulator #default=\"{ slices }\">\n\t\t\t\t<SliceZone :slices=\"slices\" :components=\"components\" />\n\t\t\t</SliceSimulator>\n\t\t</template>\n\n\t\t<script ${scriptAttributes.join(\" \")}>\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-nuxt/simulator\";\n\t\timport { components } from \"~/slices\";\n\t\t</script>\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 moveOrDeleteAppVue = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst srcDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\n\n\tconst filenameAppVue = path.join(srcDirectoryExists ? \"src\" : \"\", \"app.vue\");\n\n\t// If there's not `app.vue`, there's nothing to do.\n\tif (!(await checkHasProjectFile({ filename: filenameAppVue, helpers }))) {\n\t\treturn;\n\t}\n\n\tconst filecontentAppVue = await readProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t\tencoding: \"utf-8\",\n\t});\n\n\t// We check for app.vue to contain Nuxt default welcome component to determine if we need to consider it as the default one or not.\n\tif (!filecontentAppVue.includes(\"<NuxtWelcome\")) {\n\t\treturn;\n\t}\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filenameIndexVue = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"index.vue\",\n\t);\n\n\t// If we don't have an `index.vue` we create one with the content of `app.vue`\n\tif (!(await checkHasProjectFile({ filename: filenameIndexVue, helpers }))) {\n\t\tawait writeProjectFile({\n\t\t\tfilename: filenameIndexVue,\n\t\t\tcontents: filecontentAppVue,\n\t\t\tformat: options.format,\n\t\t\thelpers,\n\t\t});\n\t}\n\n\t// Delete `app.vue`\n\tawait deleteProjectFile({\n\t\tfilename: filenameAppVue,\n\t\thelpers,\n\t});\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\n\tactions,\n}: SliceMachineContext<PluginOptions>) => {\n\tconst hasSrcDirectory = await checkHasSrcDirectory({ helpers });\n\tconst project = await helpers.getProject();\n\n\t// Add Slice Simulator URL.\n\tproject.config.localSliceSimulatorURL ||=\n\t\t\"http://127.0.0.1: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\thasSrcDirectory &&\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/slices\"];\n\t\t}\n\t}\n\n\tawait helpers.updateSliceMachineConfig(project.config, {\n\t\tformat: options.format,\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\tconfigurePrismicModule(context),\n\t\t\tcreateSliceSimulatorPage(context),\n\t\t\tmoveO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B,OAAO;AAAA,IAC1B,yBAAyB,OAAO;AAAA,EAChC,CAAA,CAAC;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/adapter-nuxt",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18-dev-next-release.1",
|
|
4
4
|
"description": "Slice Machine adapter for Nuxt 3.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@prismicio/simulator": "^0.1.4",
|
|
63
63
|
"@prismicio/types-internal": "^2.0.0",
|
|
64
|
-
"@slicemachine/plugin-kit": "^0.4.
|
|
64
|
+
"@slicemachine/plugin-kit": "^0.4.18-dev-next-release.1",
|
|
65
65
|
"common-tags": "^1.8.2",
|
|
66
66
|
"fp-ts": "^2.13.1",
|
|
67
67
|
"io-ts": "^2.2.20",
|
|
@@ -103,5 +103,5 @@
|
|
|
103
103
|
"engines": {
|
|
104
104
|
"node": ">=14.15.0"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "80c331b966a3e9818da18024ac79b150b3f415dc"
|
|
107
107
|
}
|
|
@@ -31,7 +31,9 @@ export const documentationRead: DocumentationReadHook<PluginOptions> = async (
|
|
|
31
31
|
|
|
32
32
|
const prismic = usePrismic();
|
|
33
33
|
const route = useRoute();
|
|
34
|
-
const { data: page } = useAsyncData(
|
|
34
|
+
const { data: page } = useAsyncData(\`[${
|
|
35
|
+
model.id
|
|
36
|
+
}-uid-\${route.params.uid}]\`, () =>
|
|
35
37
|
prismic.client.getByUID("${model.id}", route.params.uid${
|
|
36
38
|
isTypeScriptProject ? " as string" : ""
|
|
37
39
|
})
|
|
@@ -220,7 +220,7 @@ const modifySliceMachineConfig = async ({
|
|
|
220
220
|
|
|
221
221
|
// Add Slice Simulator URL.
|
|
222
222
|
project.config.localSliceSimulatorURL ||=
|
|
223
|
-
"http://
|
|
223
|
+
"http://127.0.0.1:3000/slice-simulator";
|
|
224
224
|
|
|
225
225
|
// Nest the default Slice Library in the src directory if it exists and
|
|
226
226
|
// is empty.
|