@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.
- package/dist/hooks/project-init.cjs +26 -29
- package/dist/hooks/project-init.cjs.map +1 -1
- package/dist/hooks/project-init.js +26 -28
- package/dist/hooks/project-init.js.map +1 -1
- package/dist/hooks/slice-create.cjs +28 -46
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +28 -28
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/lib/checkHasSrcDirectory.cjs +5 -2
- package/dist/lib/checkHasSrcDirectory.cjs.map +1 -1
- package/dist/lib/checkHasSrcDirectory.js +5 -2
- package/dist/lib/checkHasSrcDirectory.js.map +1 -1
- package/dist/lib/checkIsTypeScriptProject.cjs +2 -3
- package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -1
- package/dist/lib/checkIsTypeScriptProject.js +2 -3
- package/dist/lib/checkIsTypeScriptProject.js.map +1 -1
- package/dist/lib/getJSFileExtension.cjs +12 -0
- package/dist/lib/getJSFileExtension.cjs.map +1 -0
- package/dist/lib/getJSFileExtension.d.ts +5 -0
- package/dist/lib/getJSFileExtension.js +12 -0
- package/dist/lib/getJSFileExtension.js.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +30 -22
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js +30 -21
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
- package/dist/plugin.cjs +178 -36
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +178 -36
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +22 -0
- package/package.json +4 -6
- package/src/hooks/project-init.ts +32 -36
- package/src/hooks/slice-create.ts +39 -34
- package/src/lib/checkHasSrcDirectory.ts +5 -2
- package/src/lib/checkIsTypeScriptProject.ts +5 -4
- package/src/lib/getJSFileExtension.ts +22 -0
- package/src/lib/upsertSliceLibraryIndexFile.ts +55 -36
- package/src/plugin.ts +247 -37
- package/src/types.ts +25 -0
- package/dist/hooks/customType-asset-delete.cjs +0 -31
- package/dist/hooks/customType-asset-delete.cjs.map +0 -1
- package/dist/hooks/customType-asset-delete.d.ts +0 -3
- package/dist/hooks/customType-asset-delete.js +0 -14
- package/dist/hooks/customType-asset-delete.js.map +0 -1
- package/dist/hooks/customType-asset-read.cjs +0 -34
- package/dist/hooks/customType-asset-read.cjs.map +0 -1
- package/dist/hooks/customType-asset-read.d.ts +0 -3
- package/dist/hooks/customType-asset-read.js +0 -17
- package/dist/hooks/customType-asset-read.js.map +0 -1
- package/dist/hooks/customType-asset-update.cjs +0 -34
- package/dist/hooks/customType-asset-update.cjs.map +0 -1
- package/dist/hooks/customType-asset-update.d.ts +0 -3
- package/dist/hooks/customType-asset-update.js +0 -16
- package/dist/hooks/customType-asset-update.js.map +0 -1
- package/dist/hooks/customType-create.cjs +0 -43
- package/dist/hooks/customType-create.cjs.map +0 -1
- package/dist/hooks/customType-create.d.ts +0 -3
- package/dist/hooks/customType-create.js +0 -25
- package/dist/hooks/customType-create.js.map +0 -1
- package/dist/hooks/customType-delete.cjs +0 -32
- package/dist/hooks/customType-delete.cjs.map +0 -1
- package/dist/hooks/customType-delete.d.ts +0 -3
- package/dist/hooks/customType-delete.js +0 -15
- package/dist/hooks/customType-delete.js.map +0 -1
- package/dist/hooks/customType-read.cjs +0 -31
- package/dist/hooks/customType-read.cjs.map +0 -1
- package/dist/hooks/customType-read.d.ts +0 -3
- package/dist/hooks/customType-read.js +0 -14
- package/dist/hooks/customType-read.js.map +0 -1
- package/dist/hooks/customType-rename.cjs +0 -6
- package/dist/hooks/customType-rename.cjs.map +0 -1
- package/dist/hooks/customType-rename.d.ts +0 -1
- package/dist/hooks/customType-rename.js +0 -6
- package/dist/hooks/customType-rename.js.map +0 -1
- package/dist/hooks/customType-update.cjs +0 -6
- package/dist/hooks/customType-update.cjs.map +0 -1
- package/dist/hooks/customType-update.d.ts +0 -1
- package/dist/hooks/customType-update.js +0 -6
- package/dist/hooks/customType-update.js.map +0 -1
- package/dist/hooks/customTypeLibrary-read.cjs +0 -55
- package/dist/hooks/customTypeLibrary-read.cjs.map +0 -1
- package/dist/hooks/customTypeLibrary-read.d.ts +0 -3
- package/dist/hooks/customTypeLibrary-read.js +0 -37
- package/dist/hooks/customTypeLibrary-read.js.map +0 -1
- package/dist/hooks/slice-asset-delete.cjs +0 -33
- package/dist/hooks/slice-asset-delete.cjs.map +0 -1
- package/dist/hooks/slice-asset-delete.d.ts +0 -3
- package/dist/hooks/slice-asset-delete.js +0 -16
- package/dist/hooks/slice-asset-delete.js.map +0 -1
- package/dist/hooks/slice-asset-read.cjs +0 -36
- package/dist/hooks/slice-asset-read.cjs.map +0 -1
- package/dist/hooks/slice-asset-read.d.ts +0 -3
- package/dist/hooks/slice-asset-read.js +0 -19
- package/dist/hooks/slice-asset-read.js.map +0 -1
- package/dist/hooks/slice-asset-update.cjs +0 -36
- package/dist/hooks/slice-asset-update.cjs.map +0 -1
- package/dist/hooks/slice-asset-update.d.ts +0 -3
- package/dist/hooks/slice-asset-update.js +0 -18
- package/dist/hooks/slice-asset-update.js.map +0 -1
- package/dist/hooks/slice-delete.cjs +0 -41
- package/dist/hooks/slice-delete.cjs.map +0 -1
- package/dist/hooks/slice-delete.d.ts +0 -3
- package/dist/hooks/slice-delete.js +0 -24
- package/dist/hooks/slice-delete.js.map +0 -1
- package/dist/hooks/slice-read.cjs +0 -62
- package/dist/hooks/slice-read.cjs.map +0 -1
- package/dist/hooks/slice-read.d.ts +0 -3
- package/dist/hooks/slice-read.js +0 -44
- package/dist/hooks/slice-read.js.map +0 -1
- package/dist/hooks/slice-rename.cjs +0 -51
- package/dist/hooks/slice-rename.cjs.map +0 -1
- package/dist/hooks/slice-rename.d.ts +0 -3
- package/dist/hooks/slice-rename.js +0 -34
- package/dist/hooks/slice-rename.js.map +0 -1
- package/dist/hooks/slice-update.cjs +0 -14
- package/dist/hooks/slice-update.cjs.map +0 -1
- package/dist/hooks/slice-update.d.ts +0 -3
- package/dist/hooks/slice-update.js +0 -14
- package/dist/hooks/slice-update.js.map +0 -1
- package/dist/hooks/sliceLibrary-read.cjs +0 -52
- package/dist/hooks/sliceLibrary-read.cjs.map +0 -1
- package/dist/hooks/sliceLibrary-read.d.ts +0 -3
- package/dist/hooks/sliceLibrary-read.js +0 -34
- package/dist/hooks/sliceLibrary-read.js.map +0 -1
- package/dist/lib/buildCustomTypeAssetPath.cjs +0 -29
- package/dist/lib/buildCustomTypeAssetPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeAssetPath.d.ts +0 -9
- package/dist/lib/buildCustomTypeAssetPath.js +0 -12
- package/dist/lib/buildCustomTypeAssetPath.js.map +0 -1
- package/dist/lib/buildCustomTypeDirectoryPath.cjs +0 -26
- package/dist/lib/buildCustomTypeDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeDirectoryPath.d.ts +0 -8
- package/dist/lib/buildCustomTypeDirectoryPath.js +0 -9
- package/dist/lib/buildCustomTypeDirectoryPath.js.map +0 -1
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.d.ts +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.js +0 -7
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.js.map +0 -1
- package/dist/lib/buildSliceAssetPath.cjs +0 -34
- package/dist/lib/buildSliceAssetPath.cjs.map +0 -1
- package/dist/lib/buildSliceAssetPath.d.ts +0 -11
- package/dist/lib/buildSliceAssetPath.js +0 -17
- package/dist/lib/buildSliceAssetPath.js.map +0 -1
- package/dist/lib/buildSliceDirectoryPath.cjs +0 -30
- package/dist/lib/buildSliceDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildSliceDirectoryPath.d.ts +0 -10
- package/dist/lib/buildSliceDirectoryPath.js +0 -13
- package/dist/lib/buildSliceDirectoryPath.js.map +0 -1
- package/dist/lib/buildSliceLibraryDirectoryPath.cjs +0 -7
- package/dist/lib/buildSliceLibraryDirectoryPath.cjs.map +0 -1
- package/dist/lib/buildSliceLibraryDirectoryPath.d.ts +0 -8
- package/dist/lib/buildSliceLibraryDirectoryPath.js +0 -7
- package/dist/lib/buildSliceLibraryDirectoryPath.js.map +0 -1
- package/dist/lib/checkPathExists.cjs +0 -30
- package/dist/lib/checkPathExists.cjs.map +0 -1
- package/dist/lib/checkPathExists.d.ts +0 -2
- package/dist/lib/checkPathExists.js +0 -13
- package/dist/lib/checkPathExists.js.map +0 -1
- package/dist/lib/isSharedSliceModel.cjs +0 -7
- package/dist/lib/isSharedSliceModel.cjs.map +0 -1
- package/dist/lib/isSharedSliceModel.d.ts +0 -335
- package/dist/lib/isSharedSliceModel.js +0 -7
- package/dist/lib/isSharedSliceModel.js.map +0 -1
- package/dist/lib/readJSONFile.cjs +0 -26
- package/dist/lib/readJSONFile.cjs.map +0 -1
- package/dist/lib/readJSONFile.d.ts +0 -1
- package/dist/lib/readJSONFile.js +0 -9
- package/dist/lib/readJSONFile.js.map +0 -1
- package/dist/lib/updateSliceModelFile.cjs +0 -33
- package/dist/lib/updateSliceModelFile.cjs.map +0 -1
- package/dist/lib/updateSliceModelFile.d.ts +0 -9
- package/dist/lib/updateSliceModelFile.js +0 -15
- package/dist/lib/updateSliceModelFile.js.map +0 -1
- package/dist/lib/upsertGlobalContentTypes.cjs +0 -56
- package/dist/lib/upsertGlobalContentTypes.cjs.map +0 -1
- package/dist/lib/upsertGlobalContentTypes.d.ts +0 -12
- package/dist/lib/upsertGlobalContentTypes.js +0 -38
- package/dist/lib/upsertGlobalContentTypes.js.map +0 -1
- package/src/hooks/customType-asset-delete.ts +0 -18
- package/src/hooks/customType-asset-read.ts +0 -22
- package/src/hooks/customType-asset-update.ts +0 -20
- package/src/hooks/customType-create.ts +0 -45
- package/src/hooks/customType-delete.ts +0 -21
- package/src/hooks/customType-read.ts +0 -24
- package/src/hooks/customType-rename.ts +0 -3
- package/src/hooks/customType-update.ts +0 -3
- package/src/hooks/customTypeLibrary-read.ts +0 -58
- package/src/hooks/slice-asset-delete.ts +0 -21
- package/src/hooks/slice-asset-read.ts +0 -25
- package/src/hooks/slice-asset-update.ts +0 -23
- package/src/hooks/slice-delete.ts +0 -41
- package/src/hooks/slice-read.ts +0 -69
- package/src/hooks/slice-rename.ts +0 -46
- package/src/hooks/slice-update.ts +0 -19
- package/src/hooks/sliceLibrary-read.ts +0 -48
- package/src/lib/buildCustomTypeAssetPath.ts +0 -24
- package/src/lib/buildCustomTypeDirectoryPath.ts +0 -20
- package/src/lib/buildCustomTypeLibraryDirectoryPath.ts +0 -13
- package/src/lib/buildSliceAssetPath.ts +0 -32
- package/src/lib/buildSliceDirectoryPath.ts +0 -26
- package/src/lib/buildSliceLibraryDirectoryPath.ts +0 -14
- package/src/lib/checkPathExists.ts +0 -12
- package/src/lib/isSharedSliceModel.ts +0 -14
- package/src/lib/readJSONFile.ts +0 -7
- package/src/lib/updateSliceModelFile.ts +0 -33
- 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
|
|
53
|
-
if (!await
|
|
54
|
-
|
|
55
|
-
if (!await
|
|
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
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
|
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":"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"}
|
|
@@ -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
|
|
33
|
-
if (!await
|
|
34
|
-
|
|
35
|
-
if (!await
|
|
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
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
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":"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"}
|
|
@@ -1,76 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const fs = require("@slicemachine/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
|
-
|
|
14
|
-
|
|
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 ({
|
|
36
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
28
|
+
filename: "index.vue",
|
|
29
|
+
contents,
|
|
30
|
+
format: options.format,
|
|
31
|
+
actions,
|
|
32
|
+
helpers
|
|
61
33
|
});
|
|
62
|
-
|
|
34
|
+
};
|
|
35
|
+
const sliceCreate = async (data, context) => {
|
|
63
36
|
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
64
|
-
|
|
37
|
+
fs.writeSliceModel({
|
|
65
38
|
libraryID: data.libraryID,
|
|
66
39
|
model: data.model,
|
|
67
|
-
|
|
40
|
+
format: context.options.format,
|
|
41
|
+
helpers: context.helpers
|
|
68
42
|
}),
|
|
69
|
-
createComponentFile({
|
|
43
|
+
createComponentFile({ data, ...context })
|
|
70
44
|
]));
|
|
71
45
|
rejectIfNecessary.rejectIfNecessary(await Promise.allSettled([
|
|
72
|
-
|
|
73
|
-
|
|
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 {
|
|
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 ({
|
|
16
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
filename: "index.vue",
|
|
27
|
+
contents,
|
|
28
|
+
format: options.format,
|
|
29
|
+
actions,
|
|
30
|
+
helpers
|
|
41
31
|
});
|
|
42
|
-
|
|
32
|
+
};
|
|
33
|
+
const sliceCreate = async (data, context) => {
|
|
43
34
|
rejectIfNecessary(await Promise.allSettled([
|
|
44
|
-
|
|
35
|
+
writeSliceModel({
|
|
45
36
|
libraryID: data.libraryID,
|
|
46
37
|
model: data.model,
|
|
47
|
-
|
|
38
|
+
format: context.options.format,
|
|
39
|
+
helpers: context.helpers
|
|
48
40
|
}),
|
|
49
|
-
createComponentFile({
|
|
41
|
+
createComponentFile({ data, ...context })
|
|
50
42
|
]));
|
|
51
43
|
rejectIfNecessary(await Promise.allSettled([
|
|
52
|
-
|
|
53
|
-
|
|
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 {
|
|
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,\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":[],"mappings":";;;;;;;;;AAKA,IAAA,IAAA;AAkBA,MAAM,sBAAsB,OAAO,EAClC,MACA,SACA,SACA,cAC6B;AAC7B,QAAM,aAAa,WAAW,KAAK,MAAM,IAAI;AAEzC,MAAA;AAEE,QAAA,sBAAsB,MAAM,yBAAyB;AAAA,IAC1D;AAAA,IACA;AAAA,EAAA,CACA;AAED,MAAI,qBAAqB;AACb,eAAA,YAAA,OAAA,KAAW,gSAMkC,8OAUZ,gFAAA,GAhBtB,yRAMkC,8OAUZ,gFAAA,CAAA,IAVE,YAUf,KAAK,MAAM,EAAA;AAAA,EAAA,OAIpC;AACN,eAAW,YAAW,OAAA,KAAA,WAAA,CAAA,igBAAA,GAAA,CAAA,qgBAAA,CAAA,EAAA;AAAA,EAgBtB;AAED,QAAM,eAAe;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;AAEF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,gBAAgB;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;AAIF,oBAAA,MAAM,QAAQ,WAAW;AAAA,IACxB,4BAA4B;AAAA,MAC3B,WAAW,KAAK;AAAA,MAChB,GAAG;AAAA,IAAA,CACH;AAAA,IACD,4BAA4B;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,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const fs = require("@slicemachine/plugin-kit/fs");
|
|
4
4
|
async function checkHasSrcDirectory(args) {
|
|
5
|
-
return await
|
|
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\";\
|
|
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 {
|
|
1
|
+
import { checkHasProjectFile } from "@slicemachine/plugin-kit/fs";
|
|
2
2
|
async function checkHasSrcDirectory(args) {
|
|
3
|
-
return await
|
|
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\";\
|
|
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;"}
|