@slicemachine/adapter-nuxt 0.3.39-beta.6 → 0.3.39-beta.8
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.
|
@@ -46,7 +46,7 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
const configurePrismicModule = async ({ helpers
|
|
49
|
+
const configurePrismicModule = async ({ helpers }) => {
|
|
50
50
|
let nuxtConfigFilename = "nuxt.config.js";
|
|
51
51
|
if (!await fs.checkHasProjectFile({ filename: nuxtConfigFilename, helpers })) {
|
|
52
52
|
nuxtConfigFilename = "nuxt.config.ts";
|
|
@@ -71,8 +71,6 @@ const configurePrismicModule = async ({ helpers, options }) => {
|
|
|
71
71
|
config.modules || (config.modules = []);
|
|
72
72
|
config.modules.push(NUXT_PRISMIC);
|
|
73
73
|
}
|
|
74
|
-
const ENDPOINT_REPLACE_KEY = "___prismicEndpoint___";
|
|
75
|
-
const ENDPOINT_REPLACE_VALUE = "apiEndpoint || repositoryName";
|
|
76
74
|
if (!hasInlinedConfiguration) {
|
|
77
75
|
mod.imports.$add({
|
|
78
76
|
from: "./slicemachine.config.json",
|
|
@@ -83,17 +81,9 @@ const configurePrismicModule = async ({ helpers, options }) => {
|
|
|
83
81
|
imported: "repositoryName"
|
|
84
82
|
});
|
|
85
83
|
config.prismic || (config.prismic = {});
|
|
86
|
-
config.prismic.endpoint = magicast.builders.raw(
|
|
84
|
+
config.prismic.endpoint = magicast.builders.raw("apiEndpoint || repositoryName");
|
|
87
85
|
}
|
|
88
|
-
|
|
89
|
-
let { code } = magicast.generateCode(ast);
|
|
90
|
-
code = code.replace(ENDPOINT_REPLACE_KEY, ENDPOINT_REPLACE_VALUE);
|
|
91
|
-
await fs.writeProjectFile({
|
|
92
|
-
filename: nuxtConfigFilename,
|
|
93
|
-
contents: code,
|
|
94
|
-
format: options.format,
|
|
95
|
-
helpers
|
|
96
|
-
});
|
|
86
|
+
await magicast.writeFile(mod, nuxtConfigPath);
|
|
97
87
|
};
|
|
98
88
|
const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
99
89
|
const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
|
|
@@ -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 { builders, generateCode, loadFile } 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\toptions,\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_REPLACE_KEY = \"___prismicEndpoint___\";\n\tconst ENDPOINT_REPLACE_VALUE = \"apiEndpoint || repositoryName\";\n\tif (!hasInlinedConfiguration) {\n\t\t// Import Slice Machine configuration\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./slicemachine.config.json\",\n\t\t\timported: \"apiEndpoint\",\n\t\t});\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./slicemachine.config.json\",\n\t\t\timported: \"repositoryName\",\n\t\t});\n\n\t\t// Add inline configuration\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = builders.raw(ENDPOINT_REPLACE_KEY);\n\t}\n\n\tconst ast = \"$ast\" in mod ? mod.$ast : mod;\n\tlet { code } = generateCode(ast);\n\t// This is a workaround to magicast not supporting \"LogicalExpression\" node type\n\tcode = code.replace(ENDPOINT_REPLACE_KEY, ENDPOINT_REPLACE_VALUE);\n\tawait writeProjectFile({\n\t\tfilename: nuxtConfigFilename,\n\t\tcontents: code,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\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","builders","generateCode","writeProjectFile","checkIsTypeScriptProject","path","stripIndent","readProjectFile","deleteProjectFile","checkHasSrcDirectory","_a","rejectIfNecessary"],"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,MAAMC,GAAAA,oBAAoB,EAAE,UAAU,oBAAoB,QAAA,CAAS,GAAI;AACvD,yBAAA;AAIpB,QAAA,CAAE,MAAMA,GAAAA,oBAAoB,EAAE,UAAU,oBAAoB,QAAA,CAAS,GACpE;AACD;AAAA,IACA;AAAA,EACD;AAEK,QAAA,iBAAi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,oBAAiB;AAAA,MACtB,UAAU;AAAA,MACV,UAAU;AAAA,MACV,QAAQ,QAAQ;AAAA,MAChB;AAAA,IAAA,CACA;AAAA,EACD;AAGD,QAAMK,qBAAkB;AAAA,IACvB,UAAU;AAAA,IACV;AAAA,EAAA,CACA;AACF;AAEA,MAAM,2BAA2B,OAAO,EACvC,SACA,SACA,cACwC;;AACxC,QAAM,kBAAkB,MAAMC,qBAAAA,qBAAqB,EAAE,QAAS,CAAA;AACxD,QAAA,UAAU,MAAM,QAAQ;AAG9B,GAAAC,MAAA,QAAQ,QAAO,2BAAfA,IAAe,yBACd;AAID,MACC,mBACA,QAAQ,OAAO,aACf,KAAK,UAAU,QAAQ,OAAO,SAAS,MAAM,KAAK,UAAU,CAAC,UAAU,CAAC,GACvE;AACK,UAAA,eAAe,MAAM,QAAQ,iBAAiB;AAAA,MACnD,WAAW,QAAQ,OAAO,UAAU,CAAC;AAAA,IAAA,CACrC;AAEG,QAAA,aAAa,SAAS,SAAS,GAAG;AAC7B,cAAA,OAAO,YAAY,CAAC,cAAc;AAAA,IAC1C;AAAA,EACD;AAEK,QAAA,QAAQ,yBAAyB,QAAQ,QAAQ;AAAA,IACtD,QAAQ,QAAQ;AAAA,EAAA,CAChB;AACF;AAEO,MAAM,cAA8C,OAC1D,EAAE,qBAAqB,qBAAA,GACvB,YACG;AAEFC,sCAAA,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.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 { builders, loadFile, writeFile } 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}: 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\tif (!hasInlinedConfiguration) {\n\t\t// Import Slice Machine configuration\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./slicemachine.config.json\",\n\t\t\timported: \"apiEndpoint\",\n\t\t});\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./slicemachine.config.json\",\n\t\t\timported: \"repositoryName\",\n\t\t});\n\n\t\t// Add inline configuration\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = builders.raw(\"apiEndpoint || repositoryName\");\n\t}\n\n\tawait writeFile(mod, 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","builders","writeFile","checkIsTypeScriptProject","path","stripIndent","writeProjectFile","readProjectFile","deleteProjectFile","checkHasSrcDirectory","_a","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AAqBA,MAAM,eAAe;AAMrB,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AACzB,M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B,yBAAyB,OAAO;AAAA,IAChC,mBAAmB,OAAO;AAAA,IAC1B,yBAAyB,OAAO;AAAA,EAChC,CAAA,CAAC;AAEJ;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { checkHasProjectFile, writeProjectFile, readProjectFile, deleteProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
3
3
|
import { stripIndent } from "common-tags";
|
|
4
|
-
import { loadFile, builders,
|
|
4
|
+
import { loadFile, builders, writeFile } from "magicast";
|
|
5
5
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
|
|
6
6
|
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
|
|
7
7
|
import { checkHasSrcDirectory } from "../lib/checkHasSrcDirectory.js";
|
|
@@ -27,7 +27,7 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
|
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
const configurePrismicModule = async ({ helpers
|
|
30
|
+
const configurePrismicModule = async ({ helpers }) => {
|
|
31
31
|
let nuxtConfigFilename = "nuxt.config.js";
|
|
32
32
|
if (!await checkHasProjectFile({ filename: nuxtConfigFilename, helpers })) {
|
|
33
33
|
nuxtConfigFilename = "nuxt.config.ts";
|
|
@@ -52,8 +52,6 @@ const configurePrismicModule = async ({ helpers, options }) => {
|
|
|
52
52
|
config.modules || (config.modules = []);
|
|
53
53
|
config.modules.push(NUXT_PRISMIC);
|
|
54
54
|
}
|
|
55
|
-
const ENDPOINT_REPLACE_KEY = "___prismicEndpoint___";
|
|
56
|
-
const ENDPOINT_REPLACE_VALUE = "apiEndpoint || repositoryName";
|
|
57
55
|
if (!hasInlinedConfiguration) {
|
|
58
56
|
mod.imports.$add({
|
|
59
57
|
from: "./slicemachine.config.json",
|
|
@@ -64,17 +62,9 @@ const configurePrismicModule = async ({ helpers, options }) => {
|
|
|
64
62
|
imported: "repositoryName"
|
|
65
63
|
});
|
|
66
64
|
config.prismic || (config.prismic = {});
|
|
67
|
-
config.prismic.endpoint = builders.raw(
|
|
65
|
+
config.prismic.endpoint = builders.raw("apiEndpoint || repositoryName");
|
|
68
66
|
}
|
|
69
|
-
|
|
70
|
-
let { code } = generateCode(ast);
|
|
71
|
-
code = code.replace(ENDPOINT_REPLACE_KEY, ENDPOINT_REPLACE_VALUE);
|
|
72
|
-
await writeProjectFile({
|
|
73
|
-
filename: nuxtConfigFilename,
|
|
74
|
-
contents: code,
|
|
75
|
-
format: options.format,
|
|
76
|
-
helpers
|
|
77
|
-
});
|
|
67
|
+
await writeFile(mod, nuxtConfigPath);
|
|
78
68
|
};
|
|
79
69
|
const createSliceSimulatorPage = async ({ helpers, options }) => {
|
|
80
70
|
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
@@ -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 { builders, generateCode, loadFile } 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\toptions,\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_REPLACE_KEY = \"___prismicEndpoint___\";\n\tconst ENDPOINT_REPLACE_VALUE = \"apiEndpoint || repositoryName\";\n\tif (!hasInlinedConfiguration) {\n\t\t// Import Slice Machine configuration\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./slicemachine.config.json\",\n\t\t\timported: \"apiEndpoint\",\n\t\t});\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./slicemachine.config.json\",\n\t\t\timported: \"repositoryName\",\n\t\t});\n\n\t\t// Add inline configuration\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = builders.raw(ENDPOINT_REPLACE_KEY);\n\t}\n\n\tconst ast = \"$ast\" in mod ? mod.$ast : mod;\n\tlet { code } = generateCode(ast);\n\t// This is a workaround to magicast not supporting \"LogicalExpression\" node type\n\tcode = code.replace(ENDPOINT_REPLACE_KEY, ENDPOINT_REPLACE_VALUE);\n\tawait writeProjectFile({\n\t\tfilename: nuxtConfigFilename,\n\t\tcontents: code,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\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,oBAA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A0B,cAAc,SACxC,WAAW;AAIR,MAAA,CAAE,MAAM,oBAAoB,EAAE,UAAU,kBAAkB,QAAA,CAAS,GAAI;AAC1E,UAAM,iBAAiB;AAAA,MACtB,UAAU;AAAA,MACV,UAAU;AAAA,MACV,QAAQ,QAAQ;AAAA,MAChB;AAAA,IAAA,CACA;AAAA,EACD;AAGD,QAAM,kBAAkB;AAAA,IACvB,UAAU;AAAA,IACV;AAAA,EAAA,CACA;AACF;AAEA,MAAM,2BAA2B,OAAO,EACvC,SACA,SACA,cACwC;;AACxC,QAAM,kBAAkB,MAAM,qBAAqB,EAAE,QAAS,CAAA;AACxD,QAAA,UAAU,MAAM,QAAQ;AAG9B,GAAAC,MAAA,QAAQ,QAAO,2BAAfA,IAAe,yBACd;AAID,MACC,mBACA,QAAQ,OAAO,aACf,KAAK,UAAU,QAAQ,OAAO,SAAS,MAAM,KAAK,UAAU,CAAC,UAAU,CAAC,GACvE;AACK,UAAA,eAAe,MAAM,QAAQ,iBAAiB;AAAA,MACnD,WAAW,QAAQ,OAAO,UAAU,CAAC;AAAA,IAAA,CACrC;AAEG,QAAA,aAAa,SAAS,SAAS,GAAG;AAC7B,cAAA,OAAO,YAAY,CAAC,cAAc;AAAA,IAC1C;AAAA,EACD;AAEK,QAAA,QAAQ,yBAAyB,QAAQ,QAAQ;AAAA,IACtD,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 { builders, loadFile, writeFile } 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}: 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\tif (!hasInlinedConfiguration) {\n\t\t// Import Slice Machine configuration\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./slicemachine.config.json\",\n\t\t\timported: \"apiEndpoint\",\n\t\t});\n\t\tmod.imports.$add({\n\t\t\tfrom: \"./slicemachine.config.json\",\n\t\t\timported: \"repositoryName\",\n\t\t});\n\n\t\t// Add inline configuration\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = builders.raw(\"apiEndpoint || repositoryName\");\n\t}\n\n\tawait writeFile(mod, 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,cAA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6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/adapter-nuxt",
|
|
3
|
-
"version": "0.3.39-beta.
|
|
3
|
+
"version": "0.3.39-beta.8",
|
|
4
4
|
"description": "Slice Machine adapter for Nuxt 3.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -61,12 +61,12 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@prismicio/simulator": "^0.1.4",
|
|
63
63
|
"@prismicio/types-internal": "^2.2.0",
|
|
64
|
-
"@slicemachine/plugin-kit": "0.4.39-beta.
|
|
64
|
+
"@slicemachine/plugin-kit": "0.4.39-beta.8",
|
|
65
65
|
"common-tags": "^1.8.2",
|
|
66
66
|
"fp-ts": "^2.13.1",
|
|
67
67
|
"io-ts": "^2.2.20",
|
|
68
68
|
"io-ts-types": "^0.5.19",
|
|
69
|
-
"magicast": "^0.3.
|
|
69
|
+
"magicast": "^0.3.4",
|
|
70
70
|
"monocle-ts": "^2.3.13",
|
|
71
71
|
"newtype-ts": "^0.3.5",
|
|
72
72
|
"pascal-case": "^3.1.2",
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
writeProjectFile,
|
|
12
12
|
} from "@slicemachine/plugin-kit/fs";
|
|
13
13
|
import { stripIndent } from "common-tags";
|
|
14
|
-
import { builders,
|
|
14
|
+
import { builders, loadFile, writeFile } from "magicast";
|
|
15
15
|
|
|
16
16
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
17
17
|
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
@@ -51,7 +51,6 @@ type ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;
|
|
|
51
51
|
|
|
52
52
|
const configurePrismicModule = async ({
|
|
53
53
|
helpers,
|
|
54
|
-
options,
|
|
55
54
|
}: ConfigurePrismicModuleArgs) => {
|
|
56
55
|
let nuxtConfigFilename = "nuxt.config.js";
|
|
57
56
|
|
|
@@ -96,8 +95,6 @@ const configurePrismicModule = async ({
|
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
// Append Prismic module configuration
|
|
99
|
-
const ENDPOINT_REPLACE_KEY = "___prismicEndpoint___";
|
|
100
|
-
const ENDPOINT_REPLACE_VALUE = "apiEndpoint || repositoryName";
|
|
101
98
|
if (!hasInlinedConfiguration) {
|
|
102
99
|
// Import Slice Machine configuration
|
|
103
100
|
mod.imports.$add({
|
|
@@ -111,19 +108,10 @@ const configurePrismicModule = async ({
|
|
|
111
108
|
|
|
112
109
|
// Add inline configuration
|
|
113
110
|
config.prismic ||= {};
|
|
114
|
-
config.prismic.endpoint = builders.raw(
|
|
111
|
+
config.prismic.endpoint = builders.raw("apiEndpoint || repositoryName");
|
|
115
112
|
}
|
|
116
113
|
|
|
117
|
-
|
|
118
|
-
let { code } = generateCode(ast);
|
|
119
|
-
// This is a workaround to magicast not supporting "LogicalExpression" node type
|
|
120
|
-
code = code.replace(ENDPOINT_REPLACE_KEY, ENDPOINT_REPLACE_VALUE);
|
|
121
|
-
await writeProjectFile({
|
|
122
|
-
filename: nuxtConfigFilename,
|
|
123
|
-
contents: code,
|
|
124
|
-
format: options.format,
|
|
125
|
-
helpers,
|
|
126
|
-
});
|
|
114
|
+
await writeFile(mod, nuxtConfigPath);
|
|
127
115
|
};
|
|
128
116
|
|
|
129
117
|
type CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;
|