@slicemachine/adapter-nuxt 0.3.42-alpha.aa-support-nuxt-4.2 → 0.3.42-alpha.aa-contributing.4

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.
@@ -4,9 +4,9 @@ const path = require("node:path");
4
4
  const fs = require("@slicemachine/plugin-kit/fs");
5
5
  const commonTags = require("common-tags");
6
6
  const magicast = require("magicast");
7
- const buildSrcPath = require("../lib/buildSrcPath.cjs");
8
7
  const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
9
8
  const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
9
+ const checkHasSrcDirectory = require("../lib/checkHasSrcDirectory.cjs");
10
10
  function _interopNamespaceDefault(e) {
11
11
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
12
  if (e) {
@@ -30,12 +30,21 @@ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __f
30
30
  var _a;
31
31
  const NUXT_PRISMIC = "@nuxtjs/prismic";
32
32
  const installDependencies = async ({ installDependencies: installDependencies2 }) => {
33
- await installDependencies2({
34
- dependencies: {
35
- [NUXT_PRISMIC]: "^3.3.0"
36
- },
37
- dev: true
38
- });
33
+ try {
34
+ await installDependencies2({
35
+ dependencies: {
36
+ [NUXT_PRISMIC]: "^3.0.0"
37
+ },
38
+ dev: true
39
+ });
40
+ } catch (error) {
41
+ await installDependencies2({
42
+ dependencies: {
43
+ [NUXT_PRISMIC]: "rc"
44
+ },
45
+ dev: true
46
+ });
47
+ }
39
48
  };
40
49
  const configurePrismicModule = async ({ helpers }) => {
41
50
  let nuxtConfigFilename = "nuxt.config.js";
@@ -81,31 +90,11 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
81
90
  helpers,
82
91
  options
83
92
  });
84
- const appPagesDirectoryExists = await fs.checkHasProjectFile({
85
- filename: "app/pages",
86
- helpers
87
- });
88
93
  const srcPagesDirectoryExists = await fs.checkHasProjectFile({
89
94
  filename: "src/pages",
90
95
  helpers
91
96
  });
92
- const pagesDirectoryExists = await fs.checkHasProjectFile({
93
- filename: "pages",
94
- helpers
95
- });
96
- let filename;
97
- if (appPagesDirectoryExists) {
98
- filename = path__namespace.join("app/pages", "slice-simulator.vue");
99
- } else if (srcPagesDirectoryExists) {
100
- filename = path__namespace.join("src/pages", "slice-simulator.vue");
101
- } else if (pagesDirectoryExists) {
102
- filename = path__namespace.join("pages", "slice-simulator.vue");
103
- } else {
104
- filename = await buildSrcPath.buildSrcPath({
105
- filename: path__namespace.join("pages", "slice-simulator.vue"),
106
- helpers
107
- });
108
- }
97
+ const filename = path__namespace.join(srcPagesDirectoryExists ? "src/pages" : "pages", "slice-simulator.vue");
109
98
  if (await fs.checkHasProjectFile({ filename, helpers })) {
110
99
  return;
111
100
  }
@@ -122,7 +111,11 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
122
111
  });
123
112
  };
124
113
  const moveOrDeleteAppVue = async ({ helpers, options }) => {
125
- const filenameAppVue = await buildSrcPath.buildSrcPath({ filename: "app.vue", helpers });
114
+ const srcDirectoryExists = await fs.checkHasProjectFile({
115
+ filename: "src",
116
+ helpers
117
+ });
118
+ const filenameAppVue = path__namespace.join(srcDirectoryExists ? "src" : "", "app.vue");
126
119
  if (!await fs.checkHasProjectFile({ filename: filenameAppVue, helpers })) {
127
120
  return;
128
121
  }
@@ -134,10 +127,11 @@ const moveOrDeleteAppVue = async ({ helpers, options }) => {
134
127
  if (!filecontentAppVue.includes("<NuxtWelcome")) {
135
128
  return;
136
129
  }
137
- const filenameIndexVue = await buildSrcPath.buildSrcPath({
138
- filename: path__namespace.join("pages/index.vue"),
130
+ const srcPagesDirectoryExists = await fs.checkHasProjectFile({
131
+ filename: "src/pages",
139
132
  helpers
140
133
  });
134
+ const filenameIndexVue = path__namespace.join(srcPagesDirectoryExists ? "src/pages" : "pages", "index.vue");
141
135
  if (!await fs.checkHasProjectFile({ filename: filenameIndexVue, helpers })) {
142
136
  await fs.writeProjectFile({
143
137
  filename: filenameIndexVue,
@@ -153,22 +147,15 @@ const moveOrDeleteAppVue = async ({ helpers, options }) => {
153
147
  };
154
148
  const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
155
149
  var _a2;
156
- const hasAppDirectory = await fs.checkHasProjectFile({
157
- filename: "app",
158
- helpers
159
- });
160
- const hasSrcDirectory = await fs.checkHasProjectFile({
161
- filename: "src",
162
- helpers
163
- });
150
+ const hasSrcDirectory = await checkHasSrcDirectory.checkHasSrcDirectory({ helpers });
164
151
  const project = await helpers.getProject();
165
152
  (_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://localhost:3000/slice-simulator");
166
- if ((hasAppDirectory || hasSrcDirectory) && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
153
+ if (hasSrcDirectory && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
167
154
  const sliceLibrary = await actions.readSliceLibrary({
168
155
  libraryID: project.config.libraries[0]
169
156
  });
170
157
  if (sliceLibrary.sliceIDs.length < 1) {
171
- project.config.libraries = hasAppDirectory ? ["./app/slices"] : ["./src/slices"];
158
+ project.config.libraries = ["./src/slices"];
172
159
  }
173
160
  }
174
161
  await helpers.updateSliceMachineConfig(project.config, {
@@ -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, loadFile, writeFile } from \"magicast\";\n\nimport { buildSrcPath } from \"../lib/buildSrcPath\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\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\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t[NUXT_PRISMIC]: \"^3.3.0\",\n\t\t},\n\t\tdev: true,\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 appPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"app/pages\",\n\t\thelpers,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst pagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"pages\",\n\t\thelpers,\n\t});\n\n\tlet filename: string;\n\t// We first give priority to existing `pages` directory, then to `srcDir`\n\t// because there could be conflicts with legacy `app` directory.\n\tif (appPagesDirectoryExists) {\n\t\tfilename = path.join(\"app/pages\", \"slice-simulator.vue\");\n\t} else if (srcPagesDirectoryExists) {\n\t\tfilename = path.join(\"src/pages\", \"slice-simulator.vue\");\n\t} else if (pagesDirectoryExists) {\n\t\tfilename = path.join(\"pages\", \"slice-simulator.vue\");\n\t} else {\n\t\tfilename = await buildSrcPath({\n\t\t\tfilename: path.join(\"pages\", \"slice-simulator.vue\"),\n\t\t\thelpers,\n\t\t});\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 filenameAppVue = await buildSrcPath({ filename: \"app.vue\", helpers });\n\n\t// If there's no `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\n\t// 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 filenameIndexVue = await buildSrcPath({\n\t\tfilename: path.join(\"pages/index.vue\"),\n\t\thelpers,\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 hasAppDirectory = await checkHasProjectFile({\n\t\tfilename: \"app\",\n\t\thelpers,\n\t});\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\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 `app` or `src` directory if it\n\t// exists and is empty.\n\tif (\n\t\t(hasAppDirectory || hasSrcDirectory) &&\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 = hasAppDirectory\n\t\t\t\t? [\"./app/slices\"]\n\t\t\t\t: [\"./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","buildSrcPath","stripIndent","writeProjectFile","readProjectFile","deleteProjectFile","_a","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AAqBA,MAAM,eAAe;AAMrB,MAAM,sBAAsB,OAAO,EAClC,qBAAAA,2BAC6B;AAC7B,QAAMA,qBAAoB;A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AA,IAClB;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,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,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,iBAAiB,QAAQ,iBAAiB,kBAAkB;AAE5D,QAAA,MAAM,MAAMC,kBAAS,cAAc;AACzC,QAAM,SACL,IAAI,QAAQ,QAAQ,UAAU,kBAC3B,IAAI,QAAQ,QAA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C,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;;"}
@@ -2,21 +2,30 @@ 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
4
  import { loadFile, builders, writeFile } from "magicast";
5
- import { buildSrcPath } from "../lib/buildSrcPath.js";
6
5
  import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
7
6
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
7
+ import { checkHasSrcDirectory } from "../lib/checkHasSrcDirectory.js";
8
8
  var __freeze = Object.freeze;
9
9
  var __defProp = Object.defineProperty;
10
10
  var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
11
11
  var _a;
12
12
  const NUXT_PRISMIC = "@nuxtjs/prismic";
13
13
  const installDependencies = async ({ installDependencies: installDependencies2 }) => {
14
- await installDependencies2({
15
- dependencies: {
16
- [NUXT_PRISMIC]: "^3.3.0"
17
- },
18
- dev: true
19
- });
14
+ try {
15
+ await installDependencies2({
16
+ dependencies: {
17
+ [NUXT_PRISMIC]: "^3.0.0"
18
+ },
19
+ dev: true
20
+ });
21
+ } catch (error) {
22
+ await installDependencies2({
23
+ dependencies: {
24
+ [NUXT_PRISMIC]: "rc"
25
+ },
26
+ dev: true
27
+ });
28
+ }
20
29
  };
21
30
  const configurePrismicModule = async ({ helpers }) => {
22
31
  let nuxtConfigFilename = "nuxt.config.js";
@@ -62,31 +71,11 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
62
71
  helpers,
63
72
  options
64
73
  });
65
- const appPagesDirectoryExists = await checkHasProjectFile({
66
- filename: "app/pages",
67
- helpers
68
- });
69
74
  const srcPagesDirectoryExists = await checkHasProjectFile({
70
75
  filename: "src/pages",
71
76
  helpers
72
77
  });
73
- const pagesDirectoryExists = await checkHasProjectFile({
74
- filename: "pages",
75
- helpers
76
- });
77
- let filename;
78
- if (appPagesDirectoryExists) {
79
- filename = path.join("app/pages", "slice-simulator.vue");
80
- } else if (srcPagesDirectoryExists) {
81
- filename = path.join("src/pages", "slice-simulator.vue");
82
- } else if (pagesDirectoryExists) {
83
- filename = path.join("pages", "slice-simulator.vue");
84
- } else {
85
- filename = await buildSrcPath({
86
- filename: path.join("pages", "slice-simulator.vue"),
87
- helpers
88
- });
89
- }
78
+ const filename = path.join(srcPagesDirectoryExists ? "src/pages" : "pages", "slice-simulator.vue");
90
79
  if (await checkHasProjectFile({ filename, helpers })) {
91
80
  return;
92
81
  }
@@ -103,7 +92,11 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
103
92
  });
104
93
  };
105
94
  const moveOrDeleteAppVue = async ({ helpers, options }) => {
106
- const filenameAppVue = await buildSrcPath({ filename: "app.vue", helpers });
95
+ const srcDirectoryExists = await checkHasProjectFile({
96
+ filename: "src",
97
+ helpers
98
+ });
99
+ const filenameAppVue = path.join(srcDirectoryExists ? "src" : "", "app.vue");
107
100
  if (!await checkHasProjectFile({ filename: filenameAppVue, helpers })) {
108
101
  return;
109
102
  }
@@ -115,10 +108,11 @@ const moveOrDeleteAppVue = async ({ helpers, options }) => {
115
108
  if (!filecontentAppVue.includes("<NuxtWelcome")) {
116
109
  return;
117
110
  }
118
- const filenameIndexVue = await buildSrcPath({
119
- filename: path.join("pages/index.vue"),
111
+ const srcPagesDirectoryExists = await checkHasProjectFile({
112
+ filename: "src/pages",
120
113
  helpers
121
114
  });
115
+ const filenameIndexVue = path.join(srcPagesDirectoryExists ? "src/pages" : "pages", "index.vue");
122
116
  if (!await checkHasProjectFile({ filename: filenameIndexVue, helpers })) {
123
117
  await writeProjectFile({
124
118
  filename: filenameIndexVue,
@@ -134,22 +128,15 @@ const moveOrDeleteAppVue = async ({ helpers, options }) => {
134
128
  };
135
129
  const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
136
130
  var _a2;
137
- const hasAppDirectory = await checkHasProjectFile({
138
- filename: "app",
139
- helpers
140
- });
141
- const hasSrcDirectory = await checkHasProjectFile({
142
- filename: "src",
143
- helpers
144
- });
131
+ const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
145
132
  const project = await helpers.getProject();
146
133
  (_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://localhost:3000/slice-simulator");
147
- if ((hasAppDirectory || hasSrcDirectory) && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
134
+ if (hasSrcDirectory && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
148
135
  const sliceLibrary = await actions.readSliceLibrary({
149
136
  libraryID: project.config.libraries[0]
150
137
  });
151
138
  if (sliceLibrary.sliceIDs.length < 1) {
152
- project.config.libraries = hasAppDirectory ? ["./app/slices"] : ["./src/slices"];
139
+ project.config.libraries = ["./src/slices"];
153
140
  }
154
141
  }
155
142
  await helpers.updateSliceMachineConfig(project.config, {
@@ -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, loadFile, writeFile } from \"magicast\";\n\nimport { buildSrcPath } from \"../lib/buildSrcPath\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\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\tawait installDependencies({\n\t\tdependencies: {\n\t\t\t[NUXT_PRISMIC]: \"^3.3.0\",\n\t\t},\n\t\tdev: true,\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 appPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"app/pages\",\n\t\thelpers,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst pagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"pages\",\n\t\thelpers,\n\t});\n\n\tlet filename: string;\n\t// We first give priority to existing `pages` directory, then to `srcDir`\n\t// because there could be conflicts with legacy `app` directory.\n\tif (appPagesDirectoryExists) {\n\t\tfilename = path.join(\"app/pages\", \"slice-simulator.vue\");\n\t} else if (srcPagesDirectoryExists) {\n\t\tfilename = path.join(\"src/pages\", \"slice-simulator.vue\");\n\t} else if (pagesDirectoryExists) {\n\t\tfilename = path.join(\"pages\", \"slice-simulator.vue\");\n\t} else {\n\t\tfilename = await buildSrcPath({\n\t\t\tfilename: path.join(\"pages\", \"slice-simulator.vue\"),\n\t\t\thelpers,\n\t\t});\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 filenameAppVue = await buildSrcPath({ filename: \"app.vue\", helpers });\n\n\t// If there's no `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\n\t// 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 filenameIndexVue = await buildSrcPath({\n\t\tfilename: path.join(\"pages/index.vue\"),\n\t\thelpers,\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 hasAppDirectory = await checkHasProjectFile({\n\t\tfilename: \"app\",\n\t\thelpers,\n\t});\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers,\n\t});\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 `app` or `src` directory if it\n\t// exists and is empty.\n\tif (\n\t\t(hasAppDirectory || hasSrcDirectory) &&\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 = hasAppDirectory\n\t\t\t\t? [\"./app/slices\"]\n\t\t\t\t: [\"./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;AAC7B,QAAMA,qBAAoB;AAAA,IACzB,cAAc;AAAA,MACb,CAAC,YAAY,GAAG;AAAA,IAChB;AAAA,IACD,KAAK;AAAA,EAAA,CACL;AACF;AAIA,MAAM,yBAAyB,OAAO,EACrC,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,OAAO,iBAAiB,UAAU;AACrC,aAAO,iBAAiB;AAAA,IACd,WAAA,MAAM,QAAQ,YAAY,GAAG;AACb,gCAAA,CAAC,CAAC,aAAa,CAAC;AAEnC,aAAA,aAAa,CAAC,MAAM;AAAA,IAC3B;AAEM,WAAA;AAAA,EAAA,CACP;AAGF,MAAI,CAAC,4BAA4B;AAChC,WAAO,YAAP,OAAO,UAAY;AACZ,WAAA,QAAQ,KAAK,YAAY;AAAA,EAChC;AAGD,MAAI,CAAC,yBAAyB;AAE7B,QA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QAAQ,iBAAiB;AAAA,MACnD,WAAW,QAAQ,OAAO,UAAU,CAAC;AAAA,IAAA,CACrC;AAEG,QAAA,aAAa,SAAS,SAAS,GAAG;AACrC,cAAQ,OAAO,YAAY,kBACxB,CAAC,cAAc,IACf,CAAC,cAAc;AAAA,IAClB;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,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,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,kBA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O,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;"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const fs = require("@slicemachine/plugin-kit/fs");
4
+ async function checkHasSrcDirectory(args) {
5
+ return await fs.checkHasProjectFile({
6
+ filename: "src",
7
+ helpers: args.helpers
8
+ });
9
+ }
10
+ exports.checkHasSrcDirectory = checkHasSrcDirectory;
11
+ //# sourceMappingURL=checkHasSrcDirectory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkHasSrcDirectory.cjs","sources":["../../../src/lib/checkHasSrcDirectory.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nimport { PluginOptions } from \"../types\";\n\ntype CheckHasSrcDirectoryArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"helpers\"\n>;\n\nexport async function checkHasSrcDirectory(\n\targs: CheckHasSrcDirectoryArgs,\n): Promise<boolean> {\n\treturn await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n}\n"],"names":["checkHasProjectFile"],"mappings":";;;AAUA,eAAsB,qBACrB,MAA8B;AAE9B,SAAO,MAAMA,GAAAA,oBAAoB;AAAA,IAChC,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACF;;"}
@@ -0,0 +1,5 @@
1
+ import { SliceMachineContext } from "@slicemachine/plugin-kit";
2
+ import { PluginOptions } from "../types";
3
+ type CheckHasSrcDirectoryArgs = Pick<SliceMachineContext<PluginOptions>, "helpers">;
4
+ export declare function checkHasSrcDirectory(args: CheckHasSrcDirectoryArgs): Promise<boolean>;
5
+ export {};
@@ -0,0 +1,11 @@
1
+ import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
2
+ async function checkHasSrcDirectory(args) {
3
+ return await checkHasProjectFile({
4
+ filename: "src",
5
+ helpers: args.helpers
6
+ });
7
+ }
8
+ export {
9
+ checkHasSrcDirectory
10
+ };
11
+ //# sourceMappingURL=checkHasSrcDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkHasSrcDirectory.js","sources":["../../../src/lib/checkHasSrcDirectory.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nimport { PluginOptions } from \"../types\";\n\ntype CheckHasSrcDirectoryArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"helpers\"\n>;\n\nexport async function checkHasSrcDirectory(\n\targs: CheckHasSrcDirectoryArgs,\n): Promise<boolean> {\n\treturn await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n}\n"],"names":[],"mappings":";AAUA,eAAsB,qBACrB,MAA8B;AAE9B,SAAO,MAAM,oBAAoB;AAAA,IAChC,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/adapter-nuxt",
3
- "version": "0.3.42-alpha.aa-support-nuxt-4.2",
3
+ "version": "0.3.42-alpha.aa-contributing.4",
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.4.1",
64
- "@slicemachine/plugin-kit": "0.4.42-alpha.aa-support-nuxt-4.2",
64
+ "@slicemachine/plugin-kit": "0.4.42-alpha.aa-contributing.4",
65
65
  "common-tags": "^1.8.2",
66
66
  "fp-ts": "^2.13.1",
67
67
  "io-ts": "^2.2.20",
@@ -13,9 +13,9 @@ import {
13
13
  import { stripIndent } from "common-tags";
14
14
  import { builders, loadFile, writeFile } from "magicast";
15
15
 
16
- import { buildSrcPath } from "../lib/buildSrcPath";
17
16
  import { rejectIfNecessary } from "../lib/rejectIfNecessary";
18
17
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
18
+ import { checkHasSrcDirectory } from "../lib/checkHasSrcDirectory";
19
19
 
20
20
  import type { PluginOptions } from "../types";
21
21
 
@@ -28,12 +28,23 @@ type InstallDependenciesArgs = {
28
28
  const installDependencies = async ({
29
29
  installDependencies,
30
30
  }: InstallDependenciesArgs) => {
31
- await installDependencies({
32
- dependencies: {
33
- [NUXT_PRISMIC]: "^3.3.0",
34
- },
35
- dev: true,
36
- });
31
+ try {
32
+ await installDependencies({
33
+ dependencies: {
34
+ [NUXT_PRISMIC]: "^3.0.0",
35
+ },
36
+ dev: true,
37
+ });
38
+ } catch (error) {
39
+ // TODO: Remove when latest is published and documented
40
+ // Fallback to RC if latest is still not available
41
+ await installDependencies({
42
+ dependencies: {
43
+ [NUXT_PRISMIC]: "rc",
44
+ },
45
+ dev: true,
46
+ });
47
+ }
37
48
  };
38
49
 
39
50
  type ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;
@@ -114,36 +125,15 @@ const createSliceSimulatorPage = async ({
114
125
  options,
115
126
  });
116
127
 
117
- const appPagesDirectoryExists = await checkHasProjectFile({
118
- filename: "app/pages",
119
- helpers,
120
- });
121
-
122
128
  const srcPagesDirectoryExists = await checkHasProjectFile({
123
129
  filename: "src/pages",
124
130
  helpers,
125
131
  });
126
132
 
127
- const pagesDirectoryExists = await checkHasProjectFile({
128
- filename: "pages",
129
- helpers,
130
- });
131
-
132
- let filename: string;
133
- // We first give priority to existing `pages` directory, then to `srcDir`
134
- // because there could be conflicts with legacy `app` directory.
135
- if (appPagesDirectoryExists) {
136
- filename = path.join("app/pages", "slice-simulator.vue");
137
- } else if (srcPagesDirectoryExists) {
138
- filename = path.join("src/pages", "slice-simulator.vue");
139
- } else if (pagesDirectoryExists) {
140
- filename = path.join("pages", "slice-simulator.vue");
141
- } else {
142
- filename = await buildSrcPath({
143
- filename: path.join("pages", "slice-simulator.vue"),
144
- helpers,
145
- });
146
- }
133
+ const filename = path.join(
134
+ srcPagesDirectoryExists ? "src/pages" : "pages",
135
+ "slice-simulator.vue",
136
+ );
147
137
 
148
138
  if (await checkHasProjectFile({ filename, helpers })) {
149
139
  return;
@@ -179,9 +169,14 @@ const moveOrDeleteAppVue = async ({
179
169
  helpers,
180
170
  options,
181
171
  }: CreateSliceSimulatorPageArgs) => {
182
- const filenameAppVue = await buildSrcPath({ filename: "app.vue", helpers });
172
+ const srcDirectoryExists = await checkHasProjectFile({
173
+ filename: "src",
174
+ helpers,
175
+ });
183
176
 
184
- // If there's no `app.vue`, there's nothing to do.
177
+ const filenameAppVue = path.join(srcDirectoryExists ? "src" : "", "app.vue");
178
+
179
+ // If there's not `app.vue`, there's nothing to do.
185
180
  if (!(await checkHasProjectFile({ filename: filenameAppVue, helpers }))) {
186
181
  return;
187
182
  }
@@ -192,17 +187,21 @@ const moveOrDeleteAppVue = async ({
192
187
  encoding: "utf-8",
193
188
  });
194
189
 
195
- // We check for app.vue to contain Nuxt default welcome component to determine
196
- // if we need to consider it as the default one or not.
190
+ // 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.
197
191
  if (!filecontentAppVue.includes("<NuxtWelcome")) {
198
192
  return;
199
193
  }
200
194
 
201
- const filenameIndexVue = await buildSrcPath({
202
- filename: path.join("pages/index.vue"),
195
+ const srcPagesDirectoryExists = await checkHasProjectFile({
196
+ filename: "src/pages",
203
197
  helpers,
204
198
  });
205
199
 
200
+ const filenameIndexVue = path.join(
201
+ srcPagesDirectoryExists ? "src/pages" : "pages",
202
+ "index.vue",
203
+ );
204
+
206
205
  // If we don't have an `index.vue` we create one with the content of `app.vue`
207
206
  if (!(await checkHasProjectFile({ filename: filenameIndexVue, helpers }))) {
208
207
  await writeProjectFile({
@@ -225,24 +224,17 @@ const modifySliceMachineConfig = async ({
225
224
  options,
226
225
  actions,
227
226
  }: SliceMachineContext<PluginOptions>) => {
228
- const hasAppDirectory = await checkHasProjectFile({
229
- filename: "app",
230
- helpers,
231
- });
232
- const hasSrcDirectory = await checkHasProjectFile({
233
- filename: "src",
234
- helpers,
235
- });
227
+ const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
236
228
  const project = await helpers.getProject();
237
229
 
238
230
  // Add Slice Simulator URL.
239
231
  project.config.localSliceSimulatorURL ||=
240
232
  "http://localhost:3000/slice-simulator";
241
233
 
242
- // Nest the default Slice Library in the `app` or `src` directory if it
243
- // exists and is empty.
234
+ // Nest the default Slice Library in the src directory if it exists and
235
+ // is empty.
244
236
  if (
245
- (hasAppDirectory || hasSrcDirectory) &&
237
+ hasSrcDirectory &&
246
238
  project.config.libraries &&
247
239
  JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])
248
240
  ) {
@@ -251,9 +243,7 @@ const modifySliceMachineConfig = async ({
251
243
  });
252
244
 
253
245
  if (sliceLibrary.sliceIDs.length < 1) {
254
- project.config.libraries = hasAppDirectory
255
- ? ["./app/slices"]
256
- : ["./src/slices"];
246
+ project.config.libraries = ["./src/slices"];
257
247
  }
258
248
  }
259
249
 
@@ -0,0 +1,18 @@
1
+ import { SliceMachineContext } from "@slicemachine/plugin-kit";
2
+ import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
3
+
4
+ import { PluginOptions } from "../types";
5
+
6
+ type CheckHasSrcDirectoryArgs = Pick<
7
+ SliceMachineContext<PluginOptions>,
8
+ "helpers"
9
+ >;
10
+
11
+ export async function checkHasSrcDirectory(
12
+ args: CheckHasSrcDirectoryArgs,
13
+ ): Promise<boolean> {
14
+ return await checkHasProjectFile({
15
+ filename: "src",
16
+ helpers: args.helpers,
17
+ });
18
+ }
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const path = require("node:path");
4
- const fs = require("@slicemachine/plugin-kit/fs");
5
- function _interopNamespaceDefault(e) {
6
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
- if (e) {
8
- for (const k in e) {
9
- if (k !== "default") {
10
- const d = Object.getOwnPropertyDescriptor(e, k);
11
- Object.defineProperty(n, k, d.get ? d : {
12
- enumerable: true,
13
- get: () => e[k]
14
- });
15
- }
16
- }
17
- }
18
- n.default = e;
19
- return Object.freeze(n);
20
- }
21
- const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
22
- async function buildSrcPath(args) {
23
- const hasAppDirectory = await fs.checkHasProjectFile({
24
- filename: "app",
25
- helpers: args.helpers
26
- });
27
- if (hasAppDirectory) {
28
- return path__namespace.join("app", args.filename);
29
- }
30
- const hasSrcDirectory = await fs.checkHasProjectFile({
31
- filename: "src",
32
- helpers: args.helpers
33
- });
34
- if (hasSrcDirectory) {
35
- return path__namespace.join("src", args.filename);
36
- }
37
- return args.filename;
38
- }
39
- exports.buildSrcPath = buildSrcPath;
40
- //# sourceMappingURL=buildSrcPath.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildSrcPath.cjs","sources":["../../../src/lib/buildSrcPath.ts"],"sourcesContent":["// TODO: If Nuxt provides a way to read `nuxt.config.js`'s `srcDir` value, we\n// can use the exact value given. The current implementation does not support\n// custom values different than \"app\" or \"src\".\n\nimport * as path from \"node:path\";\n\nimport { SliceMachineHelpers } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nexport async function buildSrcPath(args: {\n\tfilename: string;\n\thelpers: SliceMachineHelpers;\n}): Promise<string> {\n\tconst hasAppDirectory = await checkHasProjectFile({\n\t\tfilename: \"app\",\n\t\thelpers: args.helpers,\n\t});\n\tif (hasAppDirectory) {\n\t\treturn path.join(\"app\", args.filename);\n\t}\n\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n\tif (hasSrcDirectory) {\n\t\treturn path.join(\"src\", args.filename);\n\t}\n\n\treturn args.filename;\n}\n"],"names":["checkHasProjectFile","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;AASA,eAAsB,aAAa,MAGlC;AACM,QAAA,kBAAkB,MAAMA,uBAAoB;AAAA,IACjD,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACD,MAAI,iBAAiB;AACpB,WAAOC,gBAAK,KAAK,OAAO,KAAK,QAAQ;AAAA,EACrC;AAEK,QAAA,kBAAkB,MAAMD,uBAAoB;AAAA,IACjD,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACD,MAAI,iBAAiB;AACpB,WAAOC,gBAAK,KAAK,OAAO,KAAK,QAAQ;AAAA,EACrC;AAED,SAAO,KAAK;AACb;;"}
@@ -1,5 +0,0 @@
1
- import { SliceMachineHelpers } from "@slicemachine/plugin-kit";
2
- export declare function buildSrcPath(args: {
3
- filename: string;
4
- helpers: SliceMachineHelpers;
5
- }): Promise<string>;
@@ -1,23 +0,0 @@
1
- import * as path from "node:path";
2
- import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
3
- async function buildSrcPath(args) {
4
- const hasAppDirectory = await checkHasProjectFile({
5
- filename: "app",
6
- helpers: args.helpers
7
- });
8
- if (hasAppDirectory) {
9
- return path.join("app", args.filename);
10
- }
11
- const hasSrcDirectory = await checkHasProjectFile({
12
- filename: "src",
13
- helpers: args.helpers
14
- });
15
- if (hasSrcDirectory) {
16
- return path.join("src", args.filename);
17
- }
18
- return args.filename;
19
- }
20
- export {
21
- buildSrcPath
22
- };
23
- //# sourceMappingURL=buildSrcPath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildSrcPath.js","sources":["../../../src/lib/buildSrcPath.ts"],"sourcesContent":["// TODO: If Nuxt provides a way to read `nuxt.config.js`'s `srcDir` value, we\n// can use the exact value given. The current implementation does not support\n// custom values different than \"app\" or \"src\".\n\nimport * as path from \"node:path\";\n\nimport { SliceMachineHelpers } from \"@slicemachine/plugin-kit\";\nimport { checkHasProjectFile } from \"@slicemachine/plugin-kit/fs\";\n\nexport async function buildSrcPath(args: {\n\tfilename: string;\n\thelpers: SliceMachineHelpers;\n}): Promise<string> {\n\tconst hasAppDirectory = await checkHasProjectFile({\n\t\tfilename: \"app\",\n\t\thelpers: args.helpers,\n\t});\n\tif (hasAppDirectory) {\n\t\treturn path.join(\"app\", args.filename);\n\t}\n\n\tconst hasSrcDirectory = await checkHasProjectFile({\n\t\tfilename: \"src\",\n\t\thelpers: args.helpers,\n\t});\n\tif (hasSrcDirectory) {\n\t\treturn path.join(\"src\", args.filename);\n\t}\n\n\treturn args.filename;\n}\n"],"names":[],"mappings":";;AASA,eAAsB,aAAa,MAGlC;AACM,QAAA,kBAAkB,MAAM,oBAAoB;AAAA,IACjD,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACD,MAAI,iBAAiB;AACpB,WAAO,KAAK,KAAK,OAAO,KAAK,QAAQ;AAAA,EACrC;AAEK,QAAA,kBAAkB,MAAM,oBAAoB;AAAA,IACjD,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AACD,MAAI,iBAAiB;AACpB,WAAO,KAAK,KAAK,OAAO,KAAK,QAAQ;AAAA,EACrC;AAED,SAAO,KAAK;AACb;"}
@@ -1,31 +0,0 @@
1
- // TODO: If Nuxt provides a way to read `nuxt.config.js`'s `srcDir` value, we
2
- // can use the exact value given. The current implementation does not support
3
- // custom values different than "app" or "src".
4
-
5
- import * as path from "node:path";
6
-
7
- import { SliceMachineHelpers } from "@slicemachine/plugin-kit";
8
- import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
9
-
10
- export async function buildSrcPath(args: {
11
- filename: string;
12
- helpers: SliceMachineHelpers;
13
- }): Promise<string> {
14
- const hasAppDirectory = await checkHasProjectFile({
15
- filename: "app",
16
- helpers: args.helpers,
17
- });
18
- if (hasAppDirectory) {
19
- return path.join("app", args.filename);
20
- }
21
-
22
- const hasSrcDirectory = await checkHasProjectFile({
23
- filename: "src",
24
- helpers: args.helpers,
25
- });
26
- if (hasSrcDirectory) {
27
- return path.join("src", args.filename);
28
- }
29
-
30
- return args.filename;
31
- }