@slicemachine/adapter-nuxt 0.3.10 → 0.3.11-dev-next-release.2

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.
Files changed (207) hide show
  1. package/dist/hooks/project-init.cjs +26 -29
  2. package/dist/hooks/project-init.cjs.map +1 -1
  3. package/dist/hooks/project-init.js +26 -28
  4. package/dist/hooks/project-init.js.map +1 -1
  5. package/dist/hooks/slice-create.cjs +28 -46
  6. package/dist/hooks/slice-create.cjs.map +1 -1
  7. package/dist/hooks/slice-create.js +28 -28
  8. package/dist/hooks/slice-create.js.map +1 -1
  9. package/dist/lib/checkHasSrcDirectory.cjs +5 -2
  10. package/dist/lib/checkHasSrcDirectory.cjs.map +1 -1
  11. package/dist/lib/checkHasSrcDirectory.js +5 -2
  12. package/dist/lib/checkHasSrcDirectory.js.map +1 -1
  13. package/dist/lib/checkIsTypeScriptProject.cjs +2 -3
  14. package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -1
  15. package/dist/lib/checkIsTypeScriptProject.js +2 -3
  16. package/dist/lib/checkIsTypeScriptProject.js.map +1 -1
  17. package/dist/lib/getJSFileExtension.cjs +12 -0
  18. package/dist/lib/getJSFileExtension.cjs.map +1 -0
  19. package/dist/lib/getJSFileExtension.d.ts +5 -0
  20. package/dist/lib/getJSFileExtension.js +12 -0
  21. package/dist/lib/getJSFileExtension.js.map +1 -0
  22. package/dist/lib/upsertSliceLibraryIndexFile.cjs +30 -22
  23. package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
  24. package/dist/lib/upsertSliceLibraryIndexFile.js +30 -21
  25. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
  26. package/dist/plugin.cjs +178 -36
  27. package/dist/plugin.cjs.map +1 -1
  28. package/dist/plugin.js +178 -36
  29. package/dist/plugin.js.map +1 -1
  30. package/dist/types.d.ts +22 -0
  31. package/package.json +4 -6
  32. package/src/hooks/project-init.ts +32 -36
  33. package/src/hooks/slice-create.ts +39 -34
  34. package/src/lib/checkHasSrcDirectory.ts +5 -2
  35. package/src/lib/checkIsTypeScriptProject.ts +5 -4
  36. package/src/lib/getJSFileExtension.ts +22 -0
  37. package/src/lib/upsertSliceLibraryIndexFile.ts +55 -36
  38. package/src/plugin.ts +247 -37
  39. package/src/types.ts +25 -0
  40. package/dist/hooks/customType-asset-delete.cjs +0 -31
  41. package/dist/hooks/customType-asset-delete.cjs.map +0 -1
  42. package/dist/hooks/customType-asset-delete.d.ts +0 -3
  43. package/dist/hooks/customType-asset-delete.js +0 -14
  44. package/dist/hooks/customType-asset-delete.js.map +0 -1
  45. package/dist/hooks/customType-asset-read.cjs +0 -34
  46. package/dist/hooks/customType-asset-read.cjs.map +0 -1
  47. package/dist/hooks/customType-asset-read.d.ts +0 -3
  48. package/dist/hooks/customType-asset-read.js +0 -17
  49. package/dist/hooks/customType-asset-read.js.map +0 -1
  50. package/dist/hooks/customType-asset-update.cjs +0 -34
  51. package/dist/hooks/customType-asset-update.cjs.map +0 -1
  52. package/dist/hooks/customType-asset-update.d.ts +0 -3
  53. package/dist/hooks/customType-asset-update.js +0 -16
  54. package/dist/hooks/customType-asset-update.js.map +0 -1
  55. package/dist/hooks/customType-create.cjs +0 -43
  56. package/dist/hooks/customType-create.cjs.map +0 -1
  57. package/dist/hooks/customType-create.d.ts +0 -3
  58. package/dist/hooks/customType-create.js +0 -25
  59. package/dist/hooks/customType-create.js.map +0 -1
  60. package/dist/hooks/customType-delete.cjs +0 -32
  61. package/dist/hooks/customType-delete.cjs.map +0 -1
  62. package/dist/hooks/customType-delete.d.ts +0 -3
  63. package/dist/hooks/customType-delete.js +0 -15
  64. package/dist/hooks/customType-delete.js.map +0 -1
  65. package/dist/hooks/customType-read.cjs +0 -31
  66. package/dist/hooks/customType-read.cjs.map +0 -1
  67. package/dist/hooks/customType-read.d.ts +0 -3
  68. package/dist/hooks/customType-read.js +0 -14
  69. package/dist/hooks/customType-read.js.map +0 -1
  70. package/dist/hooks/customType-rename.cjs +0 -6
  71. package/dist/hooks/customType-rename.cjs.map +0 -1
  72. package/dist/hooks/customType-rename.d.ts +0 -1
  73. package/dist/hooks/customType-rename.js +0 -6
  74. package/dist/hooks/customType-rename.js.map +0 -1
  75. package/dist/hooks/customType-update.cjs +0 -6
  76. package/dist/hooks/customType-update.cjs.map +0 -1
  77. package/dist/hooks/customType-update.d.ts +0 -1
  78. package/dist/hooks/customType-update.js +0 -6
  79. package/dist/hooks/customType-update.js.map +0 -1
  80. package/dist/hooks/customTypeLibrary-read.cjs +0 -55
  81. package/dist/hooks/customTypeLibrary-read.cjs.map +0 -1
  82. package/dist/hooks/customTypeLibrary-read.d.ts +0 -3
  83. package/dist/hooks/customTypeLibrary-read.js +0 -37
  84. package/dist/hooks/customTypeLibrary-read.js.map +0 -1
  85. package/dist/hooks/slice-asset-delete.cjs +0 -33
  86. package/dist/hooks/slice-asset-delete.cjs.map +0 -1
  87. package/dist/hooks/slice-asset-delete.d.ts +0 -3
  88. package/dist/hooks/slice-asset-delete.js +0 -16
  89. package/dist/hooks/slice-asset-delete.js.map +0 -1
  90. package/dist/hooks/slice-asset-read.cjs +0 -36
  91. package/dist/hooks/slice-asset-read.cjs.map +0 -1
  92. package/dist/hooks/slice-asset-read.d.ts +0 -3
  93. package/dist/hooks/slice-asset-read.js +0 -19
  94. package/dist/hooks/slice-asset-read.js.map +0 -1
  95. package/dist/hooks/slice-asset-update.cjs +0 -36
  96. package/dist/hooks/slice-asset-update.cjs.map +0 -1
  97. package/dist/hooks/slice-asset-update.d.ts +0 -3
  98. package/dist/hooks/slice-asset-update.js +0 -18
  99. package/dist/hooks/slice-asset-update.js.map +0 -1
  100. package/dist/hooks/slice-delete.cjs +0 -41
  101. package/dist/hooks/slice-delete.cjs.map +0 -1
  102. package/dist/hooks/slice-delete.d.ts +0 -3
  103. package/dist/hooks/slice-delete.js +0 -24
  104. package/dist/hooks/slice-delete.js.map +0 -1
  105. package/dist/hooks/slice-read.cjs +0 -62
  106. package/dist/hooks/slice-read.cjs.map +0 -1
  107. package/dist/hooks/slice-read.d.ts +0 -3
  108. package/dist/hooks/slice-read.js +0 -44
  109. package/dist/hooks/slice-read.js.map +0 -1
  110. package/dist/hooks/slice-rename.cjs +0 -51
  111. package/dist/hooks/slice-rename.cjs.map +0 -1
  112. package/dist/hooks/slice-rename.d.ts +0 -3
  113. package/dist/hooks/slice-rename.js +0 -34
  114. package/dist/hooks/slice-rename.js.map +0 -1
  115. package/dist/hooks/slice-update.cjs +0 -14
  116. package/dist/hooks/slice-update.cjs.map +0 -1
  117. package/dist/hooks/slice-update.d.ts +0 -3
  118. package/dist/hooks/slice-update.js +0 -14
  119. package/dist/hooks/slice-update.js.map +0 -1
  120. package/dist/hooks/sliceLibrary-read.cjs +0 -52
  121. package/dist/hooks/sliceLibrary-read.cjs.map +0 -1
  122. package/dist/hooks/sliceLibrary-read.d.ts +0 -3
  123. package/dist/hooks/sliceLibrary-read.js +0 -34
  124. package/dist/hooks/sliceLibrary-read.js.map +0 -1
  125. package/dist/lib/buildCustomTypeAssetPath.cjs +0 -29
  126. package/dist/lib/buildCustomTypeAssetPath.cjs.map +0 -1
  127. package/dist/lib/buildCustomTypeAssetPath.d.ts +0 -9
  128. package/dist/lib/buildCustomTypeAssetPath.js +0 -12
  129. package/dist/lib/buildCustomTypeAssetPath.js.map +0 -1
  130. package/dist/lib/buildCustomTypeDirectoryPath.cjs +0 -26
  131. package/dist/lib/buildCustomTypeDirectoryPath.cjs.map +0 -1
  132. package/dist/lib/buildCustomTypeDirectoryPath.d.ts +0 -8
  133. package/dist/lib/buildCustomTypeDirectoryPath.js +0 -9
  134. package/dist/lib/buildCustomTypeDirectoryPath.js.map +0 -1
  135. package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs +0 -7
  136. package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs.map +0 -1
  137. package/dist/lib/buildCustomTypeLibraryDirectoryPath.d.ts +0 -7
  138. package/dist/lib/buildCustomTypeLibraryDirectoryPath.js +0 -7
  139. package/dist/lib/buildCustomTypeLibraryDirectoryPath.js.map +0 -1
  140. package/dist/lib/buildSliceAssetPath.cjs +0 -34
  141. package/dist/lib/buildSliceAssetPath.cjs.map +0 -1
  142. package/dist/lib/buildSliceAssetPath.d.ts +0 -11
  143. package/dist/lib/buildSliceAssetPath.js +0 -17
  144. package/dist/lib/buildSliceAssetPath.js.map +0 -1
  145. package/dist/lib/buildSliceDirectoryPath.cjs +0 -30
  146. package/dist/lib/buildSliceDirectoryPath.cjs.map +0 -1
  147. package/dist/lib/buildSliceDirectoryPath.d.ts +0 -10
  148. package/dist/lib/buildSliceDirectoryPath.js +0 -13
  149. package/dist/lib/buildSliceDirectoryPath.js.map +0 -1
  150. package/dist/lib/buildSliceLibraryDirectoryPath.cjs +0 -7
  151. package/dist/lib/buildSliceLibraryDirectoryPath.cjs.map +0 -1
  152. package/dist/lib/buildSliceLibraryDirectoryPath.d.ts +0 -8
  153. package/dist/lib/buildSliceLibraryDirectoryPath.js +0 -7
  154. package/dist/lib/buildSliceLibraryDirectoryPath.js.map +0 -1
  155. package/dist/lib/checkPathExists.cjs +0 -30
  156. package/dist/lib/checkPathExists.cjs.map +0 -1
  157. package/dist/lib/checkPathExists.d.ts +0 -2
  158. package/dist/lib/checkPathExists.js +0 -13
  159. package/dist/lib/checkPathExists.js.map +0 -1
  160. package/dist/lib/isSharedSliceModel.cjs +0 -7
  161. package/dist/lib/isSharedSliceModel.cjs.map +0 -1
  162. package/dist/lib/isSharedSliceModel.d.ts +0 -335
  163. package/dist/lib/isSharedSliceModel.js +0 -7
  164. package/dist/lib/isSharedSliceModel.js.map +0 -1
  165. package/dist/lib/readJSONFile.cjs +0 -26
  166. package/dist/lib/readJSONFile.cjs.map +0 -1
  167. package/dist/lib/readJSONFile.d.ts +0 -1
  168. package/dist/lib/readJSONFile.js +0 -9
  169. package/dist/lib/readJSONFile.js.map +0 -1
  170. package/dist/lib/updateSliceModelFile.cjs +0 -33
  171. package/dist/lib/updateSliceModelFile.cjs.map +0 -1
  172. package/dist/lib/updateSliceModelFile.d.ts +0 -9
  173. package/dist/lib/updateSliceModelFile.js +0 -15
  174. package/dist/lib/updateSliceModelFile.js.map +0 -1
  175. package/dist/lib/upsertGlobalContentTypes.cjs +0 -56
  176. package/dist/lib/upsertGlobalContentTypes.cjs.map +0 -1
  177. package/dist/lib/upsertGlobalContentTypes.d.ts +0 -12
  178. package/dist/lib/upsertGlobalContentTypes.js +0 -38
  179. package/dist/lib/upsertGlobalContentTypes.js.map +0 -1
  180. package/src/hooks/customType-asset-delete.ts +0 -18
  181. package/src/hooks/customType-asset-read.ts +0 -22
  182. package/src/hooks/customType-asset-update.ts +0 -20
  183. package/src/hooks/customType-create.ts +0 -45
  184. package/src/hooks/customType-delete.ts +0 -21
  185. package/src/hooks/customType-read.ts +0 -24
  186. package/src/hooks/customType-rename.ts +0 -3
  187. package/src/hooks/customType-update.ts +0 -3
  188. package/src/hooks/customTypeLibrary-read.ts +0 -58
  189. package/src/hooks/slice-asset-delete.ts +0 -21
  190. package/src/hooks/slice-asset-read.ts +0 -25
  191. package/src/hooks/slice-asset-update.ts +0 -23
  192. package/src/hooks/slice-delete.ts +0 -41
  193. package/src/hooks/slice-read.ts +0 -69
  194. package/src/hooks/slice-rename.ts +0 -46
  195. package/src/hooks/slice-update.ts +0 -19
  196. package/src/hooks/sliceLibrary-read.ts +0 -48
  197. package/src/lib/buildCustomTypeAssetPath.ts +0 -24
  198. package/src/lib/buildCustomTypeDirectoryPath.ts +0 -20
  199. package/src/lib/buildCustomTypeLibraryDirectoryPath.ts +0 -13
  200. package/src/lib/buildSliceAssetPath.ts +0 -32
  201. package/src/lib/buildSliceDirectoryPath.ts +0 -26
  202. package/src/lib/buildSliceLibraryDirectoryPath.ts +0 -14
  203. package/src/lib/checkPathExists.ts +0 -12
  204. package/src/lib/isSharedSliceModel.ts +0 -14
  205. package/src/lib/readJSONFile.ts +0 -7
  206. package/src/lib/updateSliceModelFile.ts +0 -33
  207. package/src/lib/upsertGlobalContentTypes.ts +0 -61
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("node:fs/promises");
4
3
  const path = require("node:path");
4
+ const fs = require("@slicemachine/plugin-kit/fs");
5
5
  const commonTags = require("common-tags");
6
6
  const magicast = require("magicast");
7
- const checkPathExists = require("../lib/checkPathExists.cjs");
8
7
  const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
9
8
  const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
10
9
  const checkHasSrcDirectory = require("../lib/checkHasSrcDirectory.cjs");
@@ -24,7 +23,6 @@ function _interopNamespaceDefault(e) {
24
23
  n.default = e;
25
24
  return Object.freeze(n);
26
25
  }
27
- const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
28
26
  const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
29
27
  var __freeze = Object.freeze;
30
28
  var __defProp = Object.defineProperty;
@@ -49,13 +47,14 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
49
47
  }
50
48
  };
51
49
  const configurePrismicModule = async ({ helpers, project }) => {
52
- let nuxtConfigPath = helpers.joinPathFromRoot("nuxt.config.js");
53
- if (!await checkPathExists.checkPathExists(nuxtConfigPath)) {
54
- nuxtConfigPath = helpers.joinPathFromRoot("nuxt.config.ts");
55
- if (!await checkPathExists.checkPathExists(nuxtConfigPath)) {
50
+ let nuxtConfigFilename = "nuxt.config.js";
51
+ if (!await fs.checkHasProjectFile({ filename: nuxtConfigFilename, helpers })) {
52
+ nuxtConfigFilename = "nuxt.config.ts";
53
+ if (!await fs.checkHasProjectFile({ filename: nuxtConfigFilename, helpers })) {
56
54
  return;
57
55
  }
58
56
  }
57
+ const nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);
59
58
  const mod = await magicast.loadFile(nuxtConfigPath);
60
59
  const config = mod.exports.default.$type === "function-call" ? mod.exports.default.$args[0] : mod.exports.default;
61
60
  let hasInlinedConfiguration = false;
@@ -84,39 +83,37 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
84
83
  helpers,
85
84
  options
86
85
  });
87
- const srcPagesDirectoryExists = await checkPathExists.checkPathExists(helpers.joinPathFromRoot("src/pages"));
88
- const filePath = helpers.joinPathFromRoot(srcPagesDirectoryExists ? "src/pages" : "pages", "slice-simulator.vue");
89
- if (await checkPathExists.checkPathExists(filePath)) {
86
+ const srcPagesDirectoryExists = await fs.checkHasProjectFile({
87
+ filename: "src/pages",
88
+ helpers
89
+ });
90
+ const filename = path__namespace.join(srcPagesDirectoryExists ? "src/pages" : "pages", "slice-simulator.vue");
91
+ if (await fs.checkHasProjectFile({ filename, helpers })) {
90
92
  return;
91
93
  }
92
- await fs__namespace.mkdir(path__namespace.dirname(filePath), { recursive: true });
93
94
  const scriptAttributes = ["setup"];
94
95
  if (isTypeScriptProject) {
95
96
  scriptAttributes.push('lang="ts"');
96
97
  }
97
- let contents = commonTags.stripIndent(_a || (_a = __template(['\n <template>\n <SliceSimulator #default="{ slices }">\n <SliceZone :slices="slices" :components="components" />\n </SliceSimulator>\n </template>\n\n <script ', '>\n import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";\n import { components } from "~/slices";\n <\/script>\n '])), scriptAttributes.join(" "));
98
- if (options.format) {
99
- contents = await helpers.format(contents, filePath, {
100
- prettier: { parser: "vue" }
101
- });
102
- }
103
- await fs__namespace.writeFile(filePath, contents);
98
+ const contents = commonTags.stripIndent(_a || (_a = __template(['\n <template>\n <SliceSimulator #default="{ slices }">\n <SliceZone :slices="slices" :components="components" />\n </SliceSimulator>\n </template>\n\n <script ', '>\n import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";\n import { components } from "~/slices";\n <\/script>\n '])), scriptAttributes.join(" "));
99
+ await fs.writeProjectFile({
100
+ filename,
101
+ contents,
102
+ format: options.format,
103
+ helpers
104
+ });
104
105
  };
105
- const modifySliceMachineConfig = async ({ helpers, options }) => {
106
+ const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
106
107
  var _a2;
107
108
  const hasSrcDirectory = await checkHasSrcDirectory.checkHasSrcDirectory({ helpers });
108
109
  const project = await helpers.getProject();
109
110
  (_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://localhost:3000/slice-simulator");
110
- if (hasSrcDirectory && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
111
- try {
112
- const entries = await fs__namespace.readdir(helpers.joinPathFromRoot("slices"));
113
- if (!entries.map((entry) => path__namespace.parse(entry).name).includes("index")) {
114
- project.config.libraries = ["./src/slices"];
115
- }
116
- } catch (error) {
117
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
118
- project.config.libraries = ["./src/slices"];
119
- }
111
+ if (hasSrcDirectory && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
112
+ const sliceLibrary = await actions.readSliceLibrary({
113
+ libraryID: project.config.libraries[0]
114
+ });
115
+ if (sliceLibrary.sliceIDs.length < 1) {
116
+ project.config.libraries = ["./src/slices"];
120
117
  }
121
118
  }
122
119
  await helpers.updateSliceMachineConfig(project.config, {
@@ -1 +1 @@
1
- {"version":3,"file":"project-init.cjs","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport { loadFile, writeFile, type ASTNode } from \"magicast\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\ttry {\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"^3.0.0\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t} catch (error) {\n\t\t// TODO: Remove when latest is published and documented\n\t\t// Fallback to RC if latest is still not available\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"rc\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t}\n};\n\ntype ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n\tproject,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigPath = helpers.joinPathFromRoot(\"nuxt.config.js\");\n\n\tif (!(await checkPathExists(nuxtConfigPath))) {\n\t\tnuxtConfigPath = helpers.joinPathFromRoot(\"nuxt.config.ts\");\n\n\t\t// nuxt.config.* not found\n\t\tif (!(await checkPathExists(nuxtConfigPath))) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tconst endpoint = project.config.repositoryName;\n\tif (!hasInlinedConfiguration) {\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = endpoint;\n\t}\n\n\tawait writeFile(mod as unknown as ASTNode, nuxtConfigPath);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkPathExists(\n\t\thelpers.joinPathFromRoot(\"src/pages\"),\n\t);\n\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"slice-simulator.vue\",\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tlet 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\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath, {\n\t\t\tprettier: { parser: \"vue\" },\n\t\t});\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\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\tJSON.stringify(project.config.libraries) === JSON.stringify([\"./slices\"])\n\t) {\n\t\ttry {\n\t\t\tconst entries = await fs.readdir(helpers.joinPathFromRoot(\"slices\"));\n\n\t\t\tif (!entries.map((entry) => path.parse(entry).name).includes(\"index\")) {\n\t\t\t\tproject.config.libraries = [\"./src/slices\"];\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t\"code\" in error &&\n\t\t\t\terror.code === \"ENOENT\"\n\t\t\t) {\n\t\t\t\t// The directory does not exist, which means we\n\t\t\t\t// can safely nest the library.\n\t\t\t\tproject.config.libraries = [\"./src/slices\"];\n\t\t\t}\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\tmodifySliceMachineConfig(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkPathExists","loadFile","writeFile","checkIsTypeScriptProject","fs","path","stripIndent","checkHasSrcDirectory","_a","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AAiBA,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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MAAM,SAAS,UACd;AAGO,gBAAA,OAAO,YAAY,CAAC,cAAc;AAAA,MAC1C;AAAA,IACD;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;AAEFI,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,oBAAoB,EAAE,qBAAqB,sBAAsB;AAAA,IACjE,uBAAuB,OAAO;AAAA,IAC9B,yBAAyB,OAAO;AAAA,IAChC,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\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\nimport { loadFile, writeFile, type ASTNode } from \"magicast\";\n\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\ttry {\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"^3.0.0\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t} catch (error) {\n\t\t// TODO: Remove when latest is published and documented\n\t\t// Fallback to RC if latest is still not available\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"rc\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t}\n};\n\ntype ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n\tproject,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigFilename = \"nuxt.config.js\";\n\n\tif (!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))) {\n\t\tnuxtConfigFilename = \"nuxt.config.ts\";\n\n\t\t// nuxt.config.* not found\n\t\tif (\n\t\t\t!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tconst endpoint = project.config.repositoryName;\n\tif (!hasInlinedConfiguration) {\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = endpoint;\n\t}\n\n\tawait writeFile(mod as unknown as ASTNode, nuxtConfigPath);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filename = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"slice-simulator.vue\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tconst contents = stripIndent`\n\t\t<template>\n\t\t\t<SliceSimulator #default=\"{ slices }\">\n\t\t\t\t<SliceZone :slices=\"slices\" :components=\"components\" />\n\t\t\t</SliceSimulator>\n\t\t</template>\n\n\t\t<script ${scriptAttributes.join(\" \")}>\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-nuxt/simulator\";\n\t\timport { components } from \"~/slices\";\n\t\t</script>\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst 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\tmodifySliceMachineConfig(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","checkHasProjectFile","loadFile","writeFile","checkIsTypeScriptProject","path","stripIndent","writeProjectFile","checkHasSrcDirectory","_a","rejectIfNecessary"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAA;AAmBA,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,iBAAiB,QAAQ,iBAAiB,kBAAkB;AAE5D,QAAA,MAAM,MAAMC,kBAAS,cA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MC,oBAAiB;AAAA,IACtB;AAAA,IACA;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB;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,yBAAyB,OAAO;AAAA,EAChC,CAAA,CAAC;AAEJ;;"}
@@ -1,8 +1,7 @@
1
- import * as fs from "node:fs/promises";
2
1
  import * as path from "node:path";
2
+ import { checkHasProjectFile, writeProjectFile } from "@slicemachine/plugin-kit/fs";
3
3
  import { stripIndent } from "common-tags";
4
4
  import { loadFile, writeFile } from "magicast";
5
- import { checkPathExists } from "../lib/checkPathExists.js";
6
5
  import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
7
6
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
8
7
  import { checkHasSrcDirectory } from "../lib/checkHasSrcDirectory.js";
@@ -29,13 +28,14 @@ const installDependencies = async ({ installDependencies: installDependencies2 }
29
28
  }
30
29
  };
31
30
  const configurePrismicModule = async ({ helpers, project }) => {
32
- let nuxtConfigPath = helpers.joinPathFromRoot("nuxt.config.js");
33
- if (!await checkPathExists(nuxtConfigPath)) {
34
- nuxtConfigPath = helpers.joinPathFromRoot("nuxt.config.ts");
35
- if (!await checkPathExists(nuxtConfigPath)) {
31
+ let nuxtConfigFilename = "nuxt.config.js";
32
+ if (!await checkHasProjectFile({ filename: nuxtConfigFilename, helpers })) {
33
+ nuxtConfigFilename = "nuxt.config.ts";
34
+ if (!await checkHasProjectFile({ filename: nuxtConfigFilename, helpers })) {
36
35
  return;
37
36
  }
38
37
  }
38
+ const nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);
39
39
  const mod = await loadFile(nuxtConfigPath);
40
40
  const config = mod.exports.default.$type === "function-call" ? mod.exports.default.$args[0] : mod.exports.default;
41
41
  let hasInlinedConfiguration = false;
@@ -64,39 +64,37 @@ const createSliceSimulatorPage = async ({ helpers, options }) => {
64
64
  helpers,
65
65
  options
66
66
  });
67
- const srcPagesDirectoryExists = await checkPathExists(helpers.joinPathFromRoot("src/pages"));
68
- const filePath = helpers.joinPathFromRoot(srcPagesDirectoryExists ? "src/pages" : "pages", "slice-simulator.vue");
69
- if (await checkPathExists(filePath)) {
67
+ const srcPagesDirectoryExists = await checkHasProjectFile({
68
+ filename: "src/pages",
69
+ helpers
70
+ });
71
+ const filename = path.join(srcPagesDirectoryExists ? "src/pages" : "pages", "slice-simulator.vue");
72
+ if (await checkHasProjectFile({ filename, helpers })) {
70
73
  return;
71
74
  }
72
- await fs.mkdir(path.dirname(filePath), { recursive: true });
73
75
  const scriptAttributes = ["setup"];
74
76
  if (isTypeScriptProject) {
75
77
  scriptAttributes.push('lang="ts"');
76
78
  }
77
- let contents = stripIndent(_a || (_a = __template(['\n <template>\n <SliceSimulator #default="{ slices }">\n <SliceZone :slices="slices" :components="components" />\n </SliceSimulator>\n </template>\n\n <script ', '>\n import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";\n import { components } from "~/slices";\n <\/script>\n '])), scriptAttributes.join(" "));
78
- if (options.format) {
79
- contents = await helpers.format(contents, filePath, {
80
- prettier: { parser: "vue" }
81
- });
82
- }
83
- await fs.writeFile(filePath, contents);
79
+ const contents = stripIndent(_a || (_a = __template(['\n <template>\n <SliceSimulator #default="{ slices }">\n <SliceZone :slices="slices" :components="components" />\n </SliceSimulator>\n </template>\n\n <script ', '>\n import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";\n import { components } from "~/slices";\n <\/script>\n '])), scriptAttributes.join(" "));
80
+ await writeProjectFile({
81
+ filename,
82
+ contents,
83
+ format: options.format,
84
+ helpers
85
+ });
84
86
  };
85
- const modifySliceMachineConfig = async ({ helpers, options }) => {
87
+ const modifySliceMachineConfig = async ({ helpers, options, actions }) => {
86
88
  var _a2;
87
89
  const hasSrcDirectory = await checkHasSrcDirectory({ helpers });
88
90
  const project = await helpers.getProject();
89
91
  (_a2 = project.config).localSliceSimulatorURL || (_a2.localSliceSimulatorURL = "http://localhost:3000/slice-simulator");
90
- if (hasSrcDirectory && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
91
- try {
92
- const entries = await fs.readdir(helpers.joinPathFromRoot("slices"));
93
- if (!entries.map((entry) => path.parse(entry).name).includes("index")) {
94
- project.config.libraries = ["./src/slices"];
95
- }
96
- } catch (error) {
97
- if (error instanceof Error && "code" in error && error.code === "ENOENT") {
98
- project.config.libraries = ["./src/slices"];
99
- }
92
+ if (hasSrcDirectory && project.config.libraries && JSON.stringify(project.config.libraries) === JSON.stringify(["./slices"])) {
93
+ const sliceLibrary = await actions.readSliceLibrary({
94
+ libraryID: project.config.libraries[0]
95
+ });
96
+ if (sliceLibrary.sliceIDs.length < 1) {
97
+ project.config.libraries = ["./src/slices"];
100
98
  }
101
99
  }
102
100
  await helpers.updateSliceMachineConfig(project.config, {
@@ -1 +1 @@
1
- {"version":3,"file":"project-init.js","sources":["../../../src/hooks/project-init.ts"],"sourcesContent":["import * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport type {\n\tProjectInitHook,\n\tProjectInitHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport { loadFile, writeFile, type ASTNode } from \"magicast\";\n\nimport { checkPathExists } from \"../lib/checkPathExists\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\ttry {\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"^3.0.0\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t} catch (error) {\n\t\t// TODO: Remove when latest is published and documented\n\t\t// Fallback to RC if latest is still not available\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"rc\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t}\n};\n\ntype ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n\tproject,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigPath = helpers.joinPathFromRoot(\"nuxt.config.js\");\n\n\tif (!(await checkPathExists(nuxtConfigPath))) {\n\t\tnuxtConfigPath = helpers.joinPathFromRoot(\"nuxt.config.ts\");\n\n\t\t// nuxt.config.* not found\n\t\tif (!(await checkPathExists(nuxtConfigPath))) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tconst endpoint = project.config.repositoryName;\n\tif (!hasInlinedConfiguration) {\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = endpoint;\n\t}\n\n\tawait writeFile(mod as unknown as ASTNode, nuxtConfigPath);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkPathExists(\n\t\thelpers.joinPathFromRoot(\"src/pages\"),\n\t);\n\n\tconst filePath = helpers.joinPathFromRoot(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"slice-simulator.vue\",\n\t);\n\n\tif (await checkPathExists(filePath)) {\n\t\treturn;\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tlet 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\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath, {\n\t\t\tprettier: { parser: \"vue\" },\n\t\t});\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nconst modifySliceMachineConfig = async ({\n\thelpers,\n\toptions,\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\tJSON.stringify(project.config.libraries) === JSON.stringify([\"./slices\"])\n\t) {\n\t\ttry {\n\t\t\tconst entries = await fs.readdir(helpers.joinPathFromRoot(\"slices\"));\n\n\t\t\tif (!entries.map((entry) => path.parse(entry).name).includes(\"index\")) {\n\t\t\t\tproject.config.libraries = [\"./src/slices\"];\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof Error &&\n\t\t\t\t\"code\" in error &&\n\t\t\t\terror.code === \"ENOENT\"\n\t\t\t) {\n\t\t\t\t// The directory does not exist, which means we\n\t\t\t\t// can safely nest the library.\n\t\t\t\tproject.config.libraries = [\"./src/slices\"];\n\t\t\t}\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\tmodifySliceMachineConfig(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","_a"],"mappings":";;;;;;;;;;;AAAA,IAAA;AAiBA,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;AAC5B,MAAA,iBAAiB,QAAQ,iBAAiB,gBAAgB;AAE9D,MAAI,CAAE,MAAM,gBAAgB,cAAc,GAAI;AAC5B,qBAAA,QAAQ,iBAAiB,gBAAgB;AAG1D,QAAI,CAAE,MAAM,gBAAgB,cAAc,GAAI;AAC7C;AAAA,IACA;AAAA,EACD;AAEK,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,M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A,IAAe,yBACd;AAID,MACC,mBACA,KAAK,UAAU,QAAQ,OAAO,SAAS,MAAM,KAAK,UAAU,CAAC,UAAU,CAAC,GACvE;AACG,QAAA;AACH,YAAM,UAAU,MAAM,GAAG,QAAQ,QAAQ,iBAAiB,QAAQ,CAAC;AAEnE,UAAI,CAAC,QAAQ,IAAI,CAAC,UAAU,KAAK,MAAM,KAAK,EAAE,IAAI,EAAE,SAAS,OAAO,GAAG;AAC9D,gBAAA,OAAO,YAAY,CAAC,cAAc;AAAA,MAC1C;AAAA,aACO;AACR,UACC,iBAAiB,SACjB,UAAU,SACV,MAAM,SAAS,UACd;AAGO,gBAAA,OAAO,YAAY,CAAC,cAAc;AAAA,MAC1C;AAAA,IACD;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,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\twriteProjectFile,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\nimport { loadFile, writeFile, type ASTNode } from \"magicast\";\n\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { checkHasSrcDirectory } from \"../lib/checkHasSrcDirectory\";\n\nimport type { PluginOptions } from \"../types\";\n\nconst NUXT_PRISMIC = \"@nuxtjs/prismic\";\n\ntype InstallDependenciesArgs = {\n\tinstallDependencies: ProjectInitHookData[\"installDependencies\"];\n};\n\nconst installDependencies = async ({\n\tinstallDependencies,\n}: InstallDependenciesArgs) => {\n\ttry {\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"^3.0.0\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t} catch (error) {\n\t\t// TODO: Remove when latest is published and documented\n\t\t// Fallback to RC if latest is still not available\n\t\tawait installDependencies({\n\t\t\tdependencies: {\n\t\t\t\t[NUXT_PRISMIC]: \"rc\",\n\t\t\t},\n\t\t\tdev: true,\n\t\t});\n\t}\n};\n\ntype ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;\n\nconst configurePrismicModule = async ({\n\thelpers,\n\tproject,\n}: ConfigurePrismicModuleArgs) => {\n\tlet nuxtConfigFilename = \"nuxt.config.js\";\n\n\tif (!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))) {\n\t\tnuxtConfigFilename = \"nuxt.config.ts\";\n\n\t\t// nuxt.config.* not found\n\t\tif (\n\t\t\t!(await checkHasProjectFile({ filename: nuxtConfigFilename, helpers }))\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst nuxtConfigPath = helpers.joinPathFromRoot(nuxtConfigFilename);\n\n\tconst mod = await loadFile(nuxtConfigPath);\n\tconst config =\n\t\tmod.exports.default.$type === \"function-call\"\n\t\t\t? mod.exports.default.$args[0]\n\t\t\t: mod.exports.default;\n\n\t// Register Prismic module\n\tlet hasInlinedConfiguration = false;\n\tconst hasPrismicModuleRegistered = (config.modules || []).find(\n\t\t(registration: string | [string, unknown]) => {\n\t\t\tif (typeof registration === \"string\") {\n\t\t\t\treturn registration === NUXT_PRISMIC;\n\t\t\t} else if (Array.isArray(registration)) {\n\t\t\t\thasInlinedConfiguration = !!registration[1];\n\n\t\t\t\treturn registration[0] === NUXT_PRISMIC;\n\t\t\t}\n\n\t\t\treturn false;\n\t\t},\n\t);\n\n\tif (!hasPrismicModuleRegistered) {\n\t\tconfig.modules ||= [];\n\t\tconfig.modules.push(NUXT_PRISMIC);\n\t}\n\n\t// Append Prismic module configuration\n\tconst endpoint = project.config.repositoryName;\n\tif (!hasInlinedConfiguration) {\n\t\tconfig.prismic ||= {};\n\t\tconfig.prismic.endpoint = endpoint;\n\t}\n\n\tawait writeFile(mod as unknown as ASTNode, nuxtConfigPath);\n};\n\ntype CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;\n\nconst createSliceSimulatorPage = async ({\n\thelpers,\n\toptions,\n}: CreateSliceSimulatorPageArgs) => {\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tconst srcPagesDirectoryExists = await checkHasProjectFile({\n\t\tfilename: \"src/pages\",\n\t\thelpers,\n\t});\n\n\tconst filename = path.join(\n\t\tsrcPagesDirectoryExists ? \"src/pages\" : \"pages\",\n\t\t\"slice-simulator.vue\",\n\t);\n\n\tif (await checkHasProjectFile({ filename, helpers })) {\n\t\treturn;\n\t}\n\n\tconst scriptAttributes = [\"setup\"];\n\tif (isTypeScriptProject) {\n\t\tscriptAttributes.push('lang=\"ts\"');\n\t}\n\n\tconst contents = stripIndent`\n\t\t<template>\n\t\t\t<SliceSimulator #default=\"{ slices }\">\n\t\t\t\t<SliceZone :slices=\"slices\" :components=\"components\" />\n\t\t\t</SliceSimulator>\n\t\t</template>\n\n\t\t<script ${scriptAttributes.join(\" \")}>\n\t\timport { SliceSimulator } from \"@slicemachine/adapter-nuxt/simulator\";\n\t\timport { components } from \"~/slices\";\n\t\t</script>\n\t`;\n\n\tawait writeProjectFile({\n\t\tfilename,\n\t\tcontents,\n\t\tformat: options.format,\n\t\thelpers,\n\t});\n};\n\nconst 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\tmodifySliceMachineConfig(context),\n\t\t]),\n\t);\n};\n"],"names":["installDependencies","_a"],"mappings":";;;;;;;;;;AAAA,IAAA;AAmBA,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,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icemachine/plugin-kit/fs");
3
4
  const commonTags = require("common-tags");
4
- const fs = require("node:fs/promises");
5
- const path = require("node:path");
6
- const buildSliceDirectoryPath = require("../lib/buildSliceDirectoryPath.cjs");
7
- const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
8
- const updateSliceModelFile = require("../lib/updateSliceModelFile.cjs");
9
- const upsertGlobalContentTypes = require("../lib/upsertGlobalContentTypes.cjs");
10
- const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
11
5
  const checkIsTypeScriptProject = require("../lib/checkIsTypeScriptProject.cjs");
12
6
  const pascalCase = require("../lib/pascalCase.cjs");
13
- function _interopNamespaceDefault(e) {
14
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
15
- if (e) {
16
- for (const k in e) {
17
- if (k !== "default") {
18
- const d = Object.getOwnPropertyDescriptor(e, k);
19
- Object.defineProperty(n, k, d.get ? d : {
20
- enumerable: true,
21
- get: () => e[k]
22
- });
23
- }
24
- }
25
- }
26
- n.default = e;
27
- return Object.freeze(n);
28
- }
29
- const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
30
- const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
7
+ const rejectIfNecessary = require("../lib/rejectIfNecessary.cjs");
8
+ const upsertSliceLibraryIndexFile = require("../lib/upsertSliceLibraryIndexFile.cjs");
31
9
  var __freeze = Object.freeze;
32
10
  var __defProp = Object.defineProperty;
33
11
  var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
34
12
  var _a, _b;
35
- const createComponentFile = async ({ dir, data, helpers, options }) => {
36
- const filePath = path__namespace.join(dir, "index.vue");
37
- const model = data.model;
38
- const pascalName = pascalCase.pascalCase(model.name);
13
+ const createComponentFile = async ({ data, helpers, actions, options }) => {
14
+ const pascalName = pascalCase.pascalCase(data.model.name);
39
15
  let contents;
40
16
  const isTypeScriptProject = await checkIsTypeScriptProject.checkIsTypeScriptProject({
41
17
  helpers,
42
18
  options
43
19
  });
44
20
  if (isTypeScriptProject) {
45
- contents = commonTags.stripIndent(_a || (_a = __template(['\n <script setup lang="ts">\n import { Content } from "@prismicio/client";\n\n // The array passed to `getSliceComponentProps` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n "], ['\n <script setup lang="ts">\n import { Content } from "@prismicio/client";\n\n // The array passed to \\`getSliceComponentProps\\` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n "])), pascalName, model.id);
21
+ contents = commonTags.stripIndent(_a || (_a = __template(['\n <script setup lang="ts">\n import { Content } from "@prismicio/client";\n\n // The array passed to `getSliceComponentProps` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n "], ['\n <script setup lang="ts">\n import { Content } from "@prismicio/client";\n\n // The array passed to \\`getSliceComponentProps\\` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n "])), pascalName, data.model.id);
46
22
  } else {
47
23
  contents = commonTags.stripIndent(_b || (_b = __template(['\n <script setup>\n // The array passed to `getSliceComponentProps` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps(["slice", "index", "slices", "context"]));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n '], ['\n <script setup>\n // The array passed to \\`getSliceComponentProps\\` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps(["slice", "index", "slices", "context"]));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n '])));
48
24
  }
49
- if (options.format) {
50
- contents = await helpers.format(contents, filePath, {
51
- prettier: { parser: "vue" }
52
- });
53
- }
54
- await fs__namespace.writeFile(filePath, contents);
55
- };
56
- const sliceCreate = async (data, context) => {
57
- const dir = buildSliceDirectoryPath.buildSliceDirectoryPath({
25
+ await fs.writeSliceFile({
58
26
  libraryID: data.libraryID,
59
27
  model: data.model,
60
- helpers: context.helpers
28
+ filename: "index.vue",
29
+ contents,
30
+ format: options.format,
31
+ actions,
32
+ helpers
61
33
  });
62
- await fs__namespace.mkdir(dir, { recursive: true });
34
+ };
35
+ const sliceCreate = async (data, context) => {
63
36
  rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
64
- updateSliceModelFile.updateSliceModelFile({
37
+ fs.writeSliceModel({
65
38
  libraryID: data.libraryID,
66
39
  model: data.model,
67
- ...context
40
+ format: context.options.format,
41
+ helpers: context.helpers
68
42
  }),
69
- createComponentFile({ dir, data, ...context })
43
+ createComponentFile({ data, ...context })
70
44
  ]));
71
45
  rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
72
- upsertGlobalContentTypes.upsertGlobalContentTypes(context),
73
- upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
46
+ upsertSliceLibraryIndexFile.upsertSliceLibraryIndexFile({
47
+ libraryID: data.libraryID,
48
+ ...context
49
+ }),
50
+ fs.upsertGlobalTypeScriptTypes({
51
+ filename: context.options.generatedTypesFilePath,
52
+ format: context.options.format,
53
+ helpers: context.helpers,
54
+ actions: context.actions
55
+ })
74
56
  ]));
75
57
  };
76
58
  exports.sliceCreate = sliceCreate;
@@ -1 +1 @@
1
- {"version":3,"file":"slice-create.cjs","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildSliceDirectoryPath } from \"../lib/buildSliceDirectoryPath\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { updateSliceModelFile } from \"../lib/updateSliceModelFile\";\nimport { upsertGlobalContentTypes } from \"../lib/upsertGlobalContentTypes\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { pascalCase } from \"../lib/pascalCase\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdir: string;\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createComponentFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(dir, \"index.vue\");\n\tconst model = data.model;\n\tconst pascalName = pascalCase(model.name);\n\n\tlet contents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\t<script setup lang=\"ts\">\n\t\t\timport { Content } from \"@prismicio/client\";\n\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps<Content.${pascalName}Slice>(\n\t\t\t\t[\"slice\", \"index\", \"slices\", \"context\"]\n\t\t\t));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for ${model.id} (variation: {{ slice.variation }}) Slices\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t<script setup>\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps([\"slice\", \"index\", \"slices\", \"context\"]));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath, {\n\t\t\tprettier: { parser: \"vue\" },\n\t\t});\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst dir = buildSliceDirectoryPath({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\thelpers: context.helpers,\n\t});\n\n\tawait fs.mkdir(dir, { recursive: true });\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupdateSliceModelFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tcreateComponentFile({ dir, data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertGlobalContentTypes(context),\n\t\t\tupsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),\n\t\t]),\n\t);\n};\n"],"names":["path","pascalCase","checkIsTypeScriptProject","stripIndent","fs","buildSliceDirectoryPath","rejectIfNecessary","updateSliceModelFile","upsertGlobalContentTypes","upsertSliceLibraryIndexFile"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,IAAA,IAAA;AAmBA,MAAM,sBAAsB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AAC3E,QAAM,WAAWA,gBAAK,KAAK,KAAK,WAAW;AAC3C,QAAM,QAAQ,KAAK;AACb,QAAA,aAAaC,WAAAA,WAAW,MAAM,IAAI;AAEpC,MAAA;AAEE,QAAA,sBAAsB,MAAMC,kDAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,MAAI,qBAAqB;AACb,eAAAC,WAAA,YAAA,OAAA,KAAW,gSAMkC,8OAUjB,gFAAA,GAhBjB,yRAMkC,8OAUjB,gFAAA,CAAA,IAVO,YAUf,MAAM,EAAA;AAAA,EAAA,OAI/B;AACN,eAAWA,WAAW,YAAA,OAAA,KAAA,WAAA,CAAA,igBAAA,GAAA,CAAA,qgBAAA,CAAA,EAAA;AAAA,EAgBtB;AAED,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,UAAU;AAAA,MACnD,UAAU,EAAE,QAAQ,MAAO;AAAA,IAAA,CAC3B;AAAA,EACD;AAEK,QAAAC,cAAG,UAAU,UAAU,QAAQ;AACtC;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AACH,QAAM,MAAMC,wBAAAA,wBAAwB;AAAA,IACnC,WAAW,KAAK;AAAA,IAChB,OAAO,KAAK;AAAA,IACZ,SAAS,QAAQ;AAAA,EAAA,CACjB;AAED,QAAMD,cAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AAGtCE,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxBC,0CAAqB;AAAA,MACpB,WAAW,KAAK;AAAA,MAChB,OAAO,KAAK;AAAA,MACZ,GAAG;AAAA,IAAA,CACH;AAAA,IACD,oBAAoB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,EAC7C,CAAA,CAAC;AAIFD,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxBE,yBAAAA,yBAAyB,OAAO;AAAA,IAChCC,wDAA4B,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS;AAAA,EACrE,CAAA,CAAC;AAEJ;;"}
1
+ {"version":3,"file":"slice-create.cjs","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tupsertGlobalTypeScriptTypes,\n\twriteSliceFile,\n\twriteSliceModel,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype CreateComponentFileArgs = {\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createComponentFile = async ({\n\tdata,\n\thelpers,\n\tactions,\n\toptions,\n}: CreateComponentFileArgs) => {\n\tconst pascalName = pascalCase(data.model.name);\n\n\tlet contents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\t<script setup lang=\"ts\">\n\t\t\timport { Content } from \"@prismicio/client\";\n\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps<Content.${pascalName}Slice>(\n\t\t\t\t[\"slice\", \"index\", \"slices\", \"context\"]\n\t\t\t));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for ${data.model.id} (variation: {{ slice.variation }}) Slices\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t<script setup>\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps([\"slice\", \"index\", \"slices\", \"context\"]));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t}\n\n\tawait writeSliceFile({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\tfilename: \"index.vue\",\n\t\tcontents,\n\t\tformat: options.format,\n\t\tactions,\n\t\thelpers,\n\t});\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\twriteSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t}),\n\t\t\tcreateComponentFile({ data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t\tactions: context.actions,\n\t\t\t}),\n\t\t]),\n\t);\n};\n"],"names":["pascalCase","checkIsTypeScriptProject","stripIndent","writeSliceFile","rejectIfNecessary","writeSliceModel","upsertSliceLibraryIndexFile","upsertGlobalTypeScriptTypes"],"mappings":";;;;;;;;;;;AAKA,IAAA,IAAA;AAkBA,MAAM,sBAAsB,OAAO,EAClC,MACA,SACA,SACA,cAC6B;AAC7B,QAAM,aAAaA,WAAA,WAAW,KAAK,MAAM,IAAI;AAEzC,MAAA;AAEE,QAAA,sBAAsB,MAAMC,kDAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,MAAI,qBAAqB;AACb,eAAAC,WAAAA,YAAA,OAAA,KAAW,gSAMkC,8OAUZ,gFAAA,GAhBtB,yRAMkC,8OAUZ,gFAAA,CAAA,IAVE,YAUf,KAAK,MAAM,EAAA;AAAA,EAAA,OAIpC;AACN,eAAWA,WAAW,YAAA,OAAA,KAAA,WAAA,CAAA,igBAAA,GAAA,CAAA,qgBAAA,CAAA,EAAA;AAAA,EAgBtB;AAED,QAAMC,kBAAe;AAAA,IACpB,WAAW,KAAK;AAAA,IAChB,OAAO,KAAK;AAAA,IACZ,UAAU;AAAA,IACV;AAAA,IACA,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA;AAAA,EAAA,CACA;AACF;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AAEFC,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxBC,mBAAgB;AAAA,MACf,WAAW,KAAK;AAAA,MAChB,OAAO,KAAK;AAAA,MACZ,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,IACD,oBAAoB,EAAE,MAAM,GAAG,SAAS;AAAA,EACxC,CAAA,CAAC;AAIFD,sCAAA,MAAM,QAAQ,WAAW;AAAA,IACxBE,wDAA4B;AAAA,MAC3B,WAAW,KAAK;AAAA,MAChB,GAAG;AAAA,IAAA,CACH;AAAA,IACDC,+BAA4B;AAAA,MAC3B,UAAU,QAAQ,QAAQ;AAAA,MAC1B,QAAQ,QAAQ,QAAQ;AAAA,MACxB,SAAS,QAAQ;AAAA,MACjB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,EACD,CAAA,CAAC;AAEJ;;"}
@@ -1,56 +1,56 @@
1
+ import { writeSliceModel, upsertGlobalTypeScriptTypes, writeSliceFile } from "@slicemachine/plugin-kit/fs";
1
2
  import { stripIndent } from "common-tags";
2
- import * as fs from "node:fs/promises";
3
- import * as path from "node:path";
4
- import { buildSliceDirectoryPath } from "../lib/buildSliceDirectoryPath.js";
5
- import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
6
- import { updateSliceModelFile } from "../lib/updateSliceModelFile.js";
7
- import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes.js";
8
- import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
9
3
  import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject.js";
10
4
  import { pascalCase } from "../lib/pascalCase.js";
5
+ import { rejectIfNecessary } from "../lib/rejectIfNecessary.js";
6
+ import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile.js";
11
7
  var __freeze = Object.freeze;
12
8
  var __defProp = Object.defineProperty;
13
9
  var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", { value: __freeze(raw || cooked.slice()) }));
14
10
  var _a, _b;
15
- const createComponentFile = async ({ dir, data, helpers, options }) => {
16
- const filePath = path.join(dir, "index.vue");
17
- const model = data.model;
18
- const pascalName = pascalCase(model.name);
11
+ const createComponentFile = async ({ data, helpers, actions, options }) => {
12
+ const pascalName = pascalCase(data.model.name);
19
13
  let contents;
20
14
  const isTypeScriptProject = await checkIsTypeScriptProject({
21
15
  helpers,
22
16
  options
23
17
  });
24
18
  if (isTypeScriptProject) {
25
- contents = stripIndent(_a || (_a = __template(['\n <script setup lang="ts">\n import { Content } from "@prismicio/client";\n\n // The array passed to `getSliceComponentProps` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n "], ['\n <script setup lang="ts">\n import { Content } from "@prismicio/client";\n\n // The array passed to \\`getSliceComponentProps\\` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n "])), pascalName, model.id);
19
+ contents = stripIndent(_a || (_a = __template(['\n <script setup lang="ts">\n import { Content } from "@prismicio/client";\n\n // The array passed to `getSliceComponentProps` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n "], ['\n <script setup lang="ts">\n import { Content } from "@prismicio/client";\n\n // The array passed to \\`getSliceComponentProps\\` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps<Content.', 'Slice>(\n ["slice", "index", "slices", "context"]\n ));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for ', " (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n "])), pascalName, data.model.id);
26
20
  } else {
27
21
  contents = stripIndent(_b || (_b = __template(['\n <script setup>\n // The array passed to `getSliceComponentProps` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps(["slice", "index", "slices", "context"]));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n '], ['\n <script setup>\n // The array passed to \\`getSliceComponentProps\\` is purely optional.\n // Consider it as a visual hint for you when templating your slice.\n defineProps(getSliceComponentProps(["slice", "index", "slices", "context"]));\n <\/script>\n\n <template>\n <section\n :data-slice-type="slice.slice_type"\n :data-slice-variation="slice.variation"\n >\n Placeholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices\n </section>\n </template>\n '])));
28
22
  }
29
- if (options.format) {
30
- contents = await helpers.format(contents, filePath, {
31
- prettier: { parser: "vue" }
32
- });
33
- }
34
- await fs.writeFile(filePath, contents);
35
- };
36
- const sliceCreate = async (data, context) => {
37
- const dir = buildSliceDirectoryPath({
23
+ await writeSliceFile({
38
24
  libraryID: data.libraryID,
39
25
  model: data.model,
40
- helpers: context.helpers
26
+ filename: "index.vue",
27
+ contents,
28
+ format: options.format,
29
+ actions,
30
+ helpers
41
31
  });
42
- await fs.mkdir(dir, { recursive: true });
32
+ };
33
+ const sliceCreate = async (data, context) => {
43
34
  rejectIfNecessary(await Promise.allSettled([
44
- updateSliceModelFile({
35
+ writeSliceModel({
45
36
  libraryID: data.libraryID,
46
37
  model: data.model,
47
- ...context
38
+ format: context.options.format,
39
+ helpers: context.helpers
48
40
  }),
49
- createComponentFile({ dir, data, ...context })
41
+ createComponentFile({ data, ...context })
50
42
  ]));
51
43
  rejectIfNecessary(await Promise.allSettled([
52
- upsertGlobalContentTypes(context),
53
- upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context })
44
+ upsertSliceLibraryIndexFile({
45
+ libraryID: data.libraryID,
46
+ ...context
47
+ }),
48
+ upsertGlobalTypeScriptTypes({
49
+ filename: context.options.generatedTypesFilePath,
50
+ format: context.options.format,
51
+ helpers: context.helpers,
52
+ actions: context.actions
53
+ })
54
54
  ]));
55
55
  };
56
56
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport { stripIndent } from \"common-tags\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport { buildSliceDirectoryPath } from \"../lib/buildSliceDirectoryPath\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { updateSliceModelFile } from \"../lib/updateSliceModelFile\";\nimport { upsertGlobalContentTypes } from \"../lib/upsertGlobalContentTypes\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { pascalCase } from \"../lib/pascalCase\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype Args = {\n\tdir: string;\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createComponentFile = async ({ dir, data, helpers, options }: Args) => {\n\tconst filePath = path.join(dir, \"index.vue\");\n\tconst model = data.model;\n\tconst pascalName = pascalCase(model.name);\n\n\tlet contents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\t<script setup lang=\"ts\">\n\t\t\timport { Content } from \"@prismicio/client\";\n\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps<Content.${pascalName}Slice>(\n\t\t\t\t[\"slice\", \"index\", \"slices\", \"context\"]\n\t\t\t));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for ${model.id} (variation: {{ slice.variation }}) Slices\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t<script setup>\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps([\"slice\", \"index\", \"slices\", \"context\"]));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t}\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath, {\n\t\t\tprettier: { parser: \"vue\" },\n\t\t});\n\t}\n\n\tawait fs.writeFile(filePath, contents);\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\tconst dir = buildSliceDirectoryPath({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\thelpers: context.helpers,\n\t});\n\n\tawait fs.mkdir(dir, { recursive: true });\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupdateSliceModelFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tcreateComponentFile({ dir, data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertGlobalContentTypes(context),\n\t\t\tupsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),\n\t\t]),\n\t);\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;AAKA,IAAA,IAAA;AAmBA,MAAM,sBAAsB,OAAO,EAAE,KAAK,MAAM,SAAS,cAAmB;AAC3E,QAAM,WAAW,KAAK,KAAK,KAAK,WAAW;AAC3C,QAAM,QAAQ,KAAK;AACb,QAAA,aAAa,WAAW,MAAM,IAAI;AAEpC,MAAA;AAEE,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,MAAI,qBAAqB;AACb,eAAA,YAAA,OAAA,KAAW,gSAMkC,8OAUjB,gFAAA,GAhBjB,yRAMkC,8OAUjB,gFAAA,CAAA,IAVO,YAUf,MAAM,EAAA;AAAA,EAAA,OAI/B;AACN,eAAW,YAAW,OAAA,KAAA,WAAA,CAAA,igBAAA,GAAA,CAAA,qgBAAA,CAAA,EAAA;AAAA,EAgBtB;AAED,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,UAAU;AAAA,MACnD,UAAU,EAAE,QAAQ,MAAO;AAAA,IAAA,CAC3B;AAAA,EACD;AAEK,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;AAEa,MAAA,cAA8C,OAC1D,MACA,YACG;AACH,QAAM,MAAM,wBAAwB;AAAA,IACnC,WAAW,KAAK;AAAA,IAChB,OAAO,KAAK;AAAA,IACZ,SAAS,QAAQ;AAAA,EAAA,CACjB;AAED,QAAM,GAAG,MAAM,KAAK,EAAE,WAAW,MAAM;AAGtC,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,qBAAqB;AAAA,MACpB,WAAW,KAAK;AAAA,MAChB,OAAO,KAAK;AAAA,MACZ,GAAG;AAAA,IAAA,CACH;AAAA,IACD,oBAAoB,EAAE,KAAK,MAAM,GAAG,SAAS;AAAA,EAC7C,CAAA,CAAC;AAIF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,yBAAyB,OAAO;AAAA,IAChC,4BAA4B,EAAE,WAAW,KAAK,WAAW,GAAG,SAAS;AAAA,EACrE,CAAA,CAAC;AAEJ;"}
1
+ {"version":3,"file":"slice-create.js","sources":["../../../src/hooks/slice-create.ts"],"sourcesContent":["import type {\n\tSliceCreateHook,\n\tSliceCreateHookData,\n\tSliceMachineContext,\n} from \"@slicemachine/plugin-kit\";\nimport {\n\tupsertGlobalTypeScriptTypes,\n\twriteSliceFile,\n\twriteSliceModel,\n} from \"@slicemachine/plugin-kit/fs\";\nimport { stripIndent } from \"common-tags\";\n\nimport { checkIsTypeScriptProject } from \"../lib/checkIsTypeScriptProject\";\nimport { pascalCase } from \"../lib/pascalCase\";\nimport { rejectIfNecessary } from \"../lib/rejectIfNecessary\";\nimport { upsertSliceLibraryIndexFile } from \"../lib/upsertSliceLibraryIndexFile\";\n\nimport type { PluginOptions } from \"../types\";\n\ntype CreateComponentFileArgs = {\n\tdata: SliceCreateHookData;\n} & SliceMachineContext<PluginOptions>;\n\nconst createComponentFile = async ({\n\tdata,\n\thelpers,\n\tactions,\n\toptions,\n}: CreateComponentFileArgs) => {\n\tconst pascalName = pascalCase(data.model.name);\n\n\tlet contents: string;\n\n\tconst isTypeScriptProject = await checkIsTypeScriptProject({\n\t\thelpers,\n\t\toptions,\n\t});\n\n\tif (isTypeScriptProject) {\n\t\tcontents = stripIndent`\n\t\t\t<script setup lang=\"ts\">\n\t\t\timport { Content } from \"@prismicio/client\";\n\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps<Content.${pascalName}Slice>(\n\t\t\t\t[\"slice\", \"index\", \"slices\", \"context\"]\n\t\t\t));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for ${data.model.id} (variation: {{ slice.variation }}) Slices\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t} else {\n\t\tcontents = stripIndent`\n\t\t\t<script setup>\n\t\t\t// The array passed to \\`getSliceComponentProps\\` is purely optional.\n\t\t\t// Consider it as a visual hint for you when templating your slice.\n\t\t\tdefineProps(getSliceComponentProps([\"slice\", \"index\", \"slices\", \"context\"]));\n\t\t\t</script>\n\n\t\t\t<template>\n\t\t\t\t<section\n\t\t\t\t\t:data-slice-type=\"slice.slice_type\"\n\t\t\t\t\t:data-slice-variation=\"slice.variation\"\n\t\t\t\t>\n\t\t\t\t\tPlaceholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices\n\t\t\t\t</section>\n\t\t\t</template>\n\t\t`;\n\t}\n\n\tawait writeSliceFile({\n\t\tlibraryID: data.libraryID,\n\t\tmodel: data.model,\n\t\tfilename: \"index.vue\",\n\t\tcontents,\n\t\tformat: options.format,\n\t\tactions,\n\t\thelpers,\n\t});\n};\n\nexport const sliceCreate: SliceCreateHook<PluginOptions> = async (\n\tdata,\n\tcontext,\n) => {\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\twriteSliceModel({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\tmodel: data.model,\n\t\t\t\tformat: context.options.format,\n\t\t\t\thelpers: context.helpers,\n\t\t\t}),\n\t\t\tcreateComponentFile({ data, ...context }),\n\t\t]),\n\t);\n\n\trejectIfNecessary(\n\t\tawait Promise.allSettled([\n\t\t\tupsertSliceLibraryIndexFile({\n\t\t\t\tlibraryID: data.libraryID,\n\t\t\t\t...context,\n\t\t\t}),\n\t\t\tupsertGlobalTypeScriptTypes({\n\t\t\t\tfilename: context.options.generatedTypesFilePath,\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AAAA,MACxB,SAAS,QAAQ;AAAA,MACjB,SAAS,QAAQ;AAAA,IAAA,CACjB;AAAA,EACD,CAAA,CAAC;AAEJ;"}
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const checkPathExists = require("./checkPathExists.cjs");
3
+ const fs = require("@slicemachine/plugin-kit/fs");
4
4
  async function checkHasSrcDirectory(args) {
5
- return await checkPathExists.checkPathExists(args.helpers.joinPathFromRoot("src"));
5
+ return await fs.checkHasProjectFile({
6
+ filename: "src",
7
+ helpers: args.helpers
8
+ });
6
9
  }
7
10
  exports.checkHasSrcDirectory = checkHasSrcDirectory;
8
11
  //# sourceMappingURL=checkHasSrcDirectory.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"checkHasSrcDirectory.cjs","sources":["../../../src/lib/checkHasSrcDirectory.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\n\nimport { PluginOptions } from \"../types\";\nimport { checkPathExists } from \"./checkPathExists\";\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 checkPathExists(args.helpers.joinPathFromRoot(\"src\"));\n}\n"],"names":["checkPathExists"],"mappings":";;;AAUA,eAAsB,qBACrB,MAA8B;AAE9B,SAAO,MAAMA,gBAAgB,gBAAA,KAAK,QAAQ,iBAAiB,KAAK,CAAC;AAClE;;"}
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;;"}
@@ -1,6 +1,9 @@
1
- import { checkPathExists } from "./checkPathExists.js";
1
+ import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
2
2
  async function checkHasSrcDirectory(args) {
3
- return await checkPathExists(args.helpers.joinPathFromRoot("src"));
3
+ return await checkHasProjectFile({
4
+ filename: "src",
5
+ helpers: args.helpers
6
+ });
4
7
  }
5
8
  export {
6
9
  checkHasSrcDirectory
@@ -1 +1 @@
1
- {"version":3,"file":"checkHasSrcDirectory.js","sources":["../../../src/lib/checkHasSrcDirectory.ts"],"sourcesContent":["import { SliceMachineContext } from \"@slicemachine/plugin-kit\";\n\nimport { PluginOptions } from \"../types\";\nimport { checkPathExists } from \"./checkPathExists\";\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 checkPathExists(args.helpers.joinPathFromRoot(\"src\"));\n}\n"],"names":[],"mappings":";AAUA,eAAsB,qBACrB,MAA8B;AAE9B,SAAO,MAAM,gBAAgB,KAAK,QAAQ,iBAAiB,KAAK,CAAC;AAClE;"}
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;"}