@slicemachine/adapter-nuxt 0.0.2-dev-plugins-m3.0
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/LICENSE +202 -0
- package/README.md +98 -0
- package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs +41 -0
- package/dist/_node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -0
- package/dist/_node_modules/data-uri-to-buffer/dist/index.js +41 -0
- package/dist/_node_modules/data-uri-to-buffer/dist/index.js.map +1 -0
- package/dist/_node_modules/fetch-blob/file.cjs +61 -0
- package/dist/_node_modules/fetch-blob/file.cjs.map +1 -0
- package/dist/_node_modules/fetch-blob/file.js +61 -0
- package/dist/_node_modules/fetch-blob/file.js.map +1 -0
- package/dist/_node_modules/fetch-blob/index.cjs +223 -0
- package/dist/_node_modules/fetch-blob/index.cjs.map +1 -0
- package/dist/_node_modules/fetch-blob/index.js +223 -0
- package/dist/_node_modules/fetch-blob/index.js.map +1 -0
- package/dist/_node_modules/fetch-blob/streams.cjs +43 -0
- package/dist/_node_modules/fetch-blob/streams.cjs.map +1 -0
- package/dist/_node_modules/fetch-blob/streams.js +42 -0
- package/dist/_node_modules/fetch-blob/streams.js.map +1 -0
- package/dist/_node_modules/formdata-polyfill/esm.min.cjs +116 -0
- package/dist/_node_modules/formdata-polyfill/esm.min.cjs.map +1 -0
- package/dist/_node_modules/formdata-polyfill/esm.min.js +116 -0
- package/dist/_node_modules/formdata-polyfill/esm.min.js.map +1 -0
- package/dist/_node_modules/node-domexception/index.cjs +11 -0
- package/dist/_node_modules/node-domexception/index.cjs.map +1 -0
- package/dist/_node_modules/node-domexception/index.js +10 -0
- package/dist/_node_modules/node-domexception/index.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/body.cjs +262 -0
- package/dist/_node_modules/node-fetch/src/body.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/body.js +262 -0
- package/dist/_node_modules/node-fetch/src/body.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs +10 -0
- package/dist/_node_modules/node-fetch/src/errors/abort-error.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/abort-error.js +10 -0
- package/dist/_node_modules/node-fetch/src/errors/abort-error.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/base.cjs +17 -0
- package/dist/_node_modules/node-fetch/src/errors/base.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/base.js +17 -0
- package/dist/_node_modules/node-fetch/src/errors/base.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs +19 -0
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.js +19 -0
- package/dist/_node_modules/node-fetch/src/errors/fetch-error.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/headers.cjs +190 -0
- package/dist/_node_modules/node-fetch/src/headers.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/headers.js +190 -0
- package/dist/_node_modules/node-fetch/src/headers.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/index.cjs +292 -0
- package/dist/_node_modules/node-fetch/src/index.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/index.js +292 -0
- package/dist/_node_modules/node-fetch/src/index.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/request.cjs +206 -0
- package/dist/_node_modules/node-fetch/src/request.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/request.js +206 -0
- package/dist/_node_modules/node-fetch/src/request.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/response.cjs +122 -0
- package/dist/_node_modules/node-fetch/src/response.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/response.js +123 -0
- package/dist/_node_modules/node-fetch/src/response.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/get-search.cjs +12 -0
- package/dist/_node_modules/node-fetch/src/utils/get-search.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/get-search.js +12 -0
- package/dist/_node_modules/node-fetch/src/utils/get-search.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs +8 -0
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.js +8 -0
- package/dist/_node_modules/node-fetch/src/utils/is-redirect.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/is.cjs +28 -0
- package/dist/_node_modules/node-fetch/src/utils/is.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/is.js +28 -0
- package/dist/_node_modules/node-fetch/src/utils/is.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs +356 -0
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js +356 -0
- package/dist/_node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/referrer.cjs +149 -0
- package/dist/_node_modules/node-fetch/src/utils/referrer.cjs.map +1 -0
- package/dist/_node_modules/node-fetch/src/utils/referrer.js +149 -0
- package/dist/_node_modules/node-fetch/src/utils/referrer.js.map +1 -0
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +3822 -0
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -0
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +3822 -0
- package/dist/_node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -0
- package/dist/_virtual/_commonjsHelpers.cjs +5 -0
- package/dist/_virtual/_commonjsHelpers.cjs.map +1 -0
- package/dist/_virtual/_commonjsHelpers.js +5 -0
- package/dist/_virtual/_commonjsHelpers.js.map +1 -0
- package/dist/_virtual/ponyfill.es2018.cjs +13 -0
- package/dist/_virtual/ponyfill.es2018.cjs.map +1 -0
- package/dist/_virtual/ponyfill.es2018.js +14 -0
- package/dist/_virtual/ponyfill.es2018.js.map +1 -0
- package/dist/constants.cjs +5 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +5 -0
- package/dist/constants.js.map +1 -0
- package/dist/hooks/customType-asset-delete.cjs +31 -0
- package/dist/hooks/customType-asset-delete.cjs.map +1 -0
- package/dist/hooks/customType-asset-delete.d.ts +3 -0
- package/dist/hooks/customType-asset-delete.js +14 -0
- package/dist/hooks/customType-asset-delete.js.map +1 -0
- package/dist/hooks/customType-asset-read.cjs +34 -0
- package/dist/hooks/customType-asset-read.cjs.map +1 -0
- package/dist/hooks/customType-asset-read.d.ts +3 -0
- package/dist/hooks/customType-asset-read.js +17 -0
- package/dist/hooks/customType-asset-read.js.map +1 -0
- package/dist/hooks/customType-asset-update.cjs +34 -0
- package/dist/hooks/customType-asset-update.cjs.map +1 -0
- package/dist/hooks/customType-asset-update.d.ts +3 -0
- package/dist/hooks/customType-asset-update.js +16 -0
- package/dist/hooks/customType-asset-update.js.map +1 -0
- package/dist/hooks/customType-create.cjs +43 -0
- package/dist/hooks/customType-create.cjs.map +1 -0
- package/dist/hooks/customType-create.d.ts +3 -0
- package/dist/hooks/customType-create.js +25 -0
- package/dist/hooks/customType-create.js.map +1 -0
- package/dist/hooks/customType-delete.cjs +32 -0
- package/dist/hooks/customType-delete.cjs.map +1 -0
- package/dist/hooks/customType-delete.d.ts +3 -0
- package/dist/hooks/customType-delete.js +15 -0
- package/dist/hooks/customType-delete.js.map +1 -0
- package/dist/hooks/customType-read.cjs +31 -0
- package/dist/hooks/customType-read.cjs.map +1 -0
- package/dist/hooks/customType-read.d.ts +3 -0
- package/dist/hooks/customType-read.js +14 -0
- package/dist/hooks/customType-read.js.map +1 -0
- package/dist/hooks/customType-rename.cjs +6 -0
- package/dist/hooks/customType-rename.cjs.map +1 -0
- package/dist/hooks/customType-rename.d.ts +1 -0
- package/dist/hooks/customType-rename.js +6 -0
- package/dist/hooks/customType-rename.js.map +1 -0
- package/dist/hooks/customType-update.cjs +6 -0
- package/dist/hooks/customType-update.cjs.map +1 -0
- package/dist/hooks/customType-update.d.ts +1 -0
- package/dist/hooks/customType-update.js +6 -0
- package/dist/hooks/customType-update.js.map +1 -0
- package/dist/hooks/customTypeLibrary-read.cjs +53 -0
- package/dist/hooks/customTypeLibrary-read.cjs.map +1 -0
- package/dist/hooks/customTypeLibrary-read.d.ts +3 -0
- package/dist/hooks/customTypeLibrary-read.js +35 -0
- package/dist/hooks/customTypeLibrary-read.js.map +1 -0
- package/dist/hooks/project-init.cjs +112 -0
- package/dist/hooks/project-init.cjs.map +1 -0
- package/dist/hooks/project-init.d.ts +3 -0
- package/dist/hooks/project-init.js +94 -0
- package/dist/hooks/project-init.js.map +1 -0
- package/dist/hooks/slice-asset-delete.cjs +33 -0
- package/dist/hooks/slice-asset-delete.cjs.map +1 -0
- package/dist/hooks/slice-asset-delete.d.ts +3 -0
- package/dist/hooks/slice-asset-delete.js +16 -0
- package/dist/hooks/slice-asset-delete.js.map +1 -0
- package/dist/hooks/slice-asset-read.cjs +36 -0
- package/dist/hooks/slice-asset-read.cjs.map +1 -0
- package/dist/hooks/slice-asset-read.d.ts +3 -0
- package/dist/hooks/slice-asset-read.js +19 -0
- package/dist/hooks/slice-asset-read.js.map +1 -0
- package/dist/hooks/slice-asset-update.cjs +36 -0
- package/dist/hooks/slice-asset-update.cjs.map +1 -0
- package/dist/hooks/slice-asset-update.d.ts +3 -0
- package/dist/hooks/slice-asset-update.js +18 -0
- package/dist/hooks/slice-asset-update.js.map +1 -0
- package/dist/hooks/slice-create.cjs +77 -0
- package/dist/hooks/slice-create.cjs.map +1 -0
- package/dist/hooks/slice-create.d.ts +3 -0
- package/dist/hooks/slice-create.js +59 -0
- package/dist/hooks/slice-create.js.map +1 -0
- package/dist/hooks/slice-delete.cjs +41 -0
- package/dist/hooks/slice-delete.cjs.map +1 -0
- package/dist/hooks/slice-delete.d.ts +3 -0
- package/dist/hooks/slice-delete.js +24 -0
- package/dist/hooks/slice-delete.js.map +1 -0
- package/dist/hooks/slice-read.cjs +62 -0
- package/dist/hooks/slice-read.cjs.map +1 -0
- package/dist/hooks/slice-read.d.ts +3 -0
- package/dist/hooks/slice-read.js +44 -0
- package/dist/hooks/slice-read.js.map +1 -0
- package/dist/hooks/slice-rename.cjs +51 -0
- package/dist/hooks/slice-rename.cjs.map +1 -0
- package/dist/hooks/slice-rename.d.ts +3 -0
- package/dist/hooks/slice-rename.js +34 -0
- package/dist/hooks/slice-rename.js.map +1 -0
- package/dist/hooks/slice-update.cjs +14 -0
- package/dist/hooks/slice-update.cjs.map +1 -0
- package/dist/hooks/slice-update.d.ts +3 -0
- package/dist/hooks/slice-update.js +14 -0
- package/dist/hooks/slice-update.js.map +1 -0
- package/dist/hooks/sliceLibrary-read.cjs +52 -0
- package/dist/hooks/sliceLibrary-read.cjs.map +1 -0
- package/dist/hooks/sliceLibrary-read.d.ts +3 -0
- package/dist/hooks/sliceLibrary-read.js +34 -0
- package/dist/hooks/sliceLibrary-read.js.map +1 -0
- package/dist/hooks/sliceSimulator-setup-read.cjs +150 -0
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -0
- package/dist/hooks/sliceSimulator-setup-read.d.ts +3 -0
- package/dist/hooks/sliceSimulator-setup-read.js +150 -0
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -0
- package/dist/hooks/snippet-read.cjs +101 -0
- package/dist/hooks/snippet-read.cjs.map +1 -0
- package/dist/hooks/snippet-read.d.ts +3 -0
- package/dist/hooks/snippet-read.js +101 -0
- package/dist/hooks/snippet-read.js.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/buildCustomTypeAssetPath.cjs +29 -0
- package/dist/lib/buildCustomTypeAssetPath.cjs.map +1 -0
- package/dist/lib/buildCustomTypeAssetPath.d.ts +9 -0
- package/dist/lib/buildCustomTypeAssetPath.js +12 -0
- package/dist/lib/buildCustomTypeAssetPath.js.map +1 -0
- package/dist/lib/buildCustomTypeDirectoryPath.cjs +26 -0
- package/dist/lib/buildCustomTypeDirectoryPath.cjs.map +1 -0
- package/dist/lib/buildCustomTypeDirectoryPath.d.ts +8 -0
- package/dist/lib/buildCustomTypeDirectoryPath.js +9 -0
- package/dist/lib/buildCustomTypeDirectoryPath.js.map +1 -0
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs +7 -0
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.cjs.map +1 -0
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.d.ts +7 -0
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.js +7 -0
- package/dist/lib/buildCustomTypeLibraryDirectoryPath.js.map +1 -0
- package/dist/lib/buildSliceAssetPath.cjs +34 -0
- package/dist/lib/buildSliceAssetPath.cjs.map +1 -0
- package/dist/lib/buildSliceAssetPath.d.ts +11 -0
- package/dist/lib/buildSliceAssetPath.js +17 -0
- package/dist/lib/buildSliceAssetPath.js.map +1 -0
- package/dist/lib/buildSliceDirectoryPath.cjs +30 -0
- package/dist/lib/buildSliceDirectoryPath.cjs.map +1 -0
- package/dist/lib/buildSliceDirectoryPath.d.ts +10 -0
- package/dist/lib/buildSliceDirectoryPath.js +13 -0
- package/dist/lib/buildSliceDirectoryPath.js.map +1 -0
- package/dist/lib/buildSliceLibraryDirectoryPath.cjs +7 -0
- package/dist/lib/buildSliceLibraryDirectoryPath.cjs.map +1 -0
- package/dist/lib/buildSliceLibraryDirectoryPath.d.ts +8 -0
- package/dist/lib/buildSliceLibraryDirectoryPath.js +7 -0
- package/dist/lib/buildSliceLibraryDirectoryPath.js.map +1 -0
- package/dist/lib/checkIsTypeScriptProject.cjs +9 -0
- package/dist/lib/checkIsTypeScriptProject.cjs.map +1 -0
- package/dist/lib/checkIsTypeScriptProject.d.ts +8 -0
- package/dist/lib/checkIsTypeScriptProject.js +9 -0
- package/dist/lib/checkIsTypeScriptProject.js.map +1 -0
- package/dist/lib/checkPathExists.cjs +30 -0
- package/dist/lib/checkPathExists.cjs.map +1 -0
- package/dist/lib/checkPathExists.d.ts +2 -0
- package/dist/lib/checkPathExists.js +13 -0
- package/dist/lib/checkPathExists.js.map +1 -0
- package/dist/lib/isSharedSliceModel.cjs +7 -0
- package/dist/lib/isSharedSliceModel.cjs.map +1 -0
- package/dist/lib/isSharedSliceModel.d.ts +335 -0
- package/dist/lib/isSharedSliceModel.js +7 -0
- package/dist/lib/isSharedSliceModel.js.map +1 -0
- package/dist/lib/pascalCase.cjs +8 -0
- package/dist/lib/pascalCase.cjs.map +1 -0
- package/dist/lib/pascalCase.d.ts +8 -0
- package/dist/lib/pascalCase.js +8 -0
- package/dist/lib/pascalCase.js.map +1 -0
- package/dist/lib/readJSONFile.cjs +26 -0
- package/dist/lib/readJSONFile.cjs.map +1 -0
- package/dist/lib/readJSONFile.d.ts +1 -0
- package/dist/lib/readJSONFile.js +9 -0
- package/dist/lib/readJSONFile.js.map +1 -0
- package/dist/lib/rejectIfNecessary.cjs +10 -0
- package/dist/lib/rejectIfNecessary.cjs.map +1 -0
- package/dist/lib/rejectIfNecessary.d.ts +1 -0
- package/dist/lib/rejectIfNecessary.js +10 -0
- package/dist/lib/rejectIfNecessary.js.map +1 -0
- package/dist/lib/updateSliceModelFile.cjs +33 -0
- package/dist/lib/updateSliceModelFile.cjs.map +1 -0
- package/dist/lib/updateSliceModelFile.d.ts +9 -0
- package/dist/lib/updateSliceModelFile.js +15 -0
- package/dist/lib/updateSliceModelFile.js.map +1 -0
- package/dist/lib/upsertGlobalContentTypes.cjs +55 -0
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -0
- package/dist/lib/upsertGlobalContentTypes.d.ts +12 -0
- package/dist/lib/upsertGlobalContentTypes.js +37 -0
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +83 -0
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -0
- package/dist/lib/upsertSliceLibraryIndexFile.d.ts +7 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js +65 -0
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -0
- package/dist/packages/adapter-nuxt/package.json.cjs +5 -0
- package/dist/packages/adapter-nuxt/package.json.cjs.map +1 -0
- package/dist/packages/adapter-nuxt/package.json.js +5 -0
- package/dist/packages/adapter-nuxt/package.json.js.map +1 -0
- package/dist/plugin.cjs +59 -0
- package/dist/plugin.cjs.map +1 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +59 -0
- package/dist/plugin.js.map +1 -0
- package/dist/simulator/SliceSimulator.cjs +79 -0
- package/dist/simulator/SliceSimulator.cjs.map +1 -0
- package/dist/simulator/SliceSimulator.d.ts +34 -0
- package/dist/simulator/SliceSimulator.js +79 -0
- package/dist/simulator/SliceSimulator.js.map +1 -0
- package/dist/simulator/index.d.ts +2 -0
- package/dist/simulator.cjs +5 -0
- package/dist/simulator.cjs.map +1 -0
- package/dist/simulator.js +5 -0
- package/dist/simulator.js.map +1 -0
- package/dist/types.d.ts +5 -0
- package/package.json +107 -0
- package/src/constants.ts +5 -0
- package/src/hooks/customType-asset-delete.ts +18 -0
- package/src/hooks/customType-asset-read.ts +22 -0
- package/src/hooks/customType-asset-update.ts +20 -0
- package/src/hooks/customType-create.ts +45 -0
- package/src/hooks/customType-delete.ts +21 -0
- package/src/hooks/customType-read.ts +24 -0
- package/src/hooks/customType-rename.ts +3 -0
- package/src/hooks/customType-update.ts +3 -0
- package/src/hooks/customTypeLibrary-read.ts +53 -0
- package/src/hooks/project-init.ts +163 -0
- package/src/hooks/slice-asset-delete.ts +21 -0
- package/src/hooks/slice-asset-read.ts +25 -0
- package/src/hooks/slice-asset-update.ts +23 -0
- package/src/hooks/slice-create.ts +115 -0
- package/src/hooks/slice-delete.ts +41 -0
- package/src/hooks/slice-read.ts +69 -0
- package/src/hooks/slice-rename.ts +46 -0
- package/src/hooks/slice-update.ts +19 -0
- package/src/hooks/sliceLibrary-read.ts +48 -0
- package/src/hooks/sliceSimulator-setup-read.ts +209 -0
- package/src/hooks/snippet-read.ts +145 -0
- package/src/index.ts +4 -0
- package/src/lib/buildCustomTypeAssetPath.ts +24 -0
- package/src/lib/buildCustomTypeDirectoryPath.ts +20 -0
- package/src/lib/buildCustomTypeLibraryDirectoryPath.ts +13 -0
- package/src/lib/buildSliceAssetPath.ts +32 -0
- package/src/lib/buildSliceDirectoryPath.ts +26 -0
- package/src/lib/buildSliceLibraryDirectoryPath.ts +14 -0
- package/src/lib/checkIsTypeScriptProject.ts +17 -0
- package/src/lib/checkPathExists.ts +12 -0
- package/src/lib/isSharedSliceModel.ts +14 -0
- package/src/lib/pascalCase.ts +12 -0
- package/src/lib/readJSONFile.ts +7 -0
- package/src/lib/rejectIfNecessary.ts +16 -0
- package/src/lib/updateSliceModelFile.ts +33 -0
- package/src/lib/upsertGlobalContentTypes.ts +62 -0
- package/src/lib/upsertSliceLibraryIndexFile.ts +90 -0
- package/src/plugin.ts +63 -0
- package/src/simulator/SliceSimulator.ts +157 -0
- package/src/simulator/index.ts +2 -0
- package/src/types.ts +5 -0
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@slicemachine/adapter-nuxt",
|
|
3
|
+
"version": "0.0.2-dev-plugins-m3.0",
|
|
4
|
+
"description": "Slice Machine adapter for Nuxt 3.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"prismic"
|
|
8
|
+
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "ssh://git@github.com/prismicio/slice-machine.git",
|
|
12
|
+
"directory": "packages/adapter-nuxt"
|
|
13
|
+
},
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"require": "./dist/index.cjs",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./simulator": {
|
|
23
|
+
"require": "./dist/simulator.cjs",
|
|
24
|
+
"import": "./dist/simulator.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"main": "dist/index.cjs",
|
|
29
|
+
"module": "dist/index.js",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"typesVersions": {
|
|
32
|
+
"*": {
|
|
33
|
+
"*": [
|
|
34
|
+
"dist/index.d.ts"
|
|
35
|
+
],
|
|
36
|
+
"simulator": [
|
|
37
|
+
"dist/simulator/index.d.ts"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"src"
|
|
44
|
+
],
|
|
45
|
+
"scripts": {
|
|
46
|
+
"build": "vite build",
|
|
47
|
+
"dev": "vite build --watch",
|
|
48
|
+
"format": "prettier --write .",
|
|
49
|
+
"lint": "eslint --ext .js,.ts .",
|
|
50
|
+
"prepublishOnly": "npm run build",
|
|
51
|
+
"size": "size-limit",
|
|
52
|
+
"test": "npm run lint && npm run types && npm run unit && npm run build && npm run size",
|
|
53
|
+
"types": "tsc --noEmit",
|
|
54
|
+
"unit": "vitest run --coverage",
|
|
55
|
+
"unit:watch": "vitest watch",
|
|
56
|
+
"depcheck": "depcheck --config=.depcheckrc",
|
|
57
|
+
"audit": "better-npm-audit audit -l high -p"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"@prismicio/slice-simulator-core": "^0.2.7",
|
|
61
|
+
"@prismicio/types-internal": "2.0.0-alpha.9",
|
|
62
|
+
"@slicemachine/plugin-kit": "0.1.8-dev-plugins-m3.0",
|
|
63
|
+
"common-tags": "^1.8.2",
|
|
64
|
+
"fs-extra": "^11.1.0",
|
|
65
|
+
"magicast": "^0.2.1",
|
|
66
|
+
"node-fetch": "^3.3.1",
|
|
67
|
+
"pascal-case": "^3.1.2",
|
|
68
|
+
"prismic-ts-codegen": "^0.1.5"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@prismicio/mock": "^0.2.0",
|
|
72
|
+
"@size-limit/preset-small-lib": "^8.2.4",
|
|
73
|
+
"@types/common-tags": "^1.8.1",
|
|
74
|
+
"@types/fs-extra": "^11.0.1",
|
|
75
|
+
"@types/prettier": "^2.7.2",
|
|
76
|
+
"@types/semver": "^7.3.13",
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
78
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
79
|
+
"@vitest/coverage-c8": "^0.27.3",
|
|
80
|
+
"better-npm-audit": "^3.7.3",
|
|
81
|
+
"depcheck": "^1.4.3",
|
|
82
|
+
"eslint": "^8.37.0",
|
|
83
|
+
"eslint-config-prettier": "^8.7.0",
|
|
84
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
85
|
+
"eslint-plugin-tsdoc": "^0.2.17",
|
|
86
|
+
"nuxt": "^3.3.3",
|
|
87
|
+
"prettier": "^2.8.4",
|
|
88
|
+
"prettier-plugin-jsdoc": "^0.4.2",
|
|
89
|
+
"size-limit": "^8.2.4",
|
|
90
|
+
"ts-morph": "^17.0.1",
|
|
91
|
+
"typescript": "^4.9.5",
|
|
92
|
+
"vite": "^4.1.4",
|
|
93
|
+
"vite-plugin-sdk": "^0.1.1",
|
|
94
|
+
"vitest": "^0.27.3",
|
|
95
|
+
"vue": "^3.2.47"
|
|
96
|
+
},
|
|
97
|
+
"peerDependencies": {
|
|
98
|
+
"nuxt": "^3.0.0"
|
|
99
|
+
},
|
|
100
|
+
"engines": {
|
|
101
|
+
"node": ">=14.15.0"
|
|
102
|
+
},
|
|
103
|
+
"publishConfig": {
|
|
104
|
+
"access": "public"
|
|
105
|
+
},
|
|
106
|
+
"gitHead": "9223acb43eebf3f0e1731090b48c44ebd96f4aae"
|
|
107
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CustomTypeAssetDeleteHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import { buildCustomTypeAssetPath } from "../lib/buildCustomTypeAssetPath";
|
|
5
|
+
|
|
6
|
+
import type { PluginOptions } from "../types";
|
|
7
|
+
|
|
8
|
+
export const customTypeAssetDelete: CustomTypeAssetDeleteHook<
|
|
9
|
+
PluginOptions
|
|
10
|
+
> = async (data, context) => {
|
|
11
|
+
const filePath = buildCustomTypeAssetPath({
|
|
12
|
+
customTypeID: data.customTypeID,
|
|
13
|
+
assetID: data.assetID,
|
|
14
|
+
helpers: context.helpers,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
await fs.rm(filePath);
|
|
18
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CustomTypeAssetReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import { buildCustomTypeAssetPath } from "../lib/buildCustomTypeAssetPath";
|
|
5
|
+
|
|
6
|
+
import type { PluginOptions } from "../types";
|
|
7
|
+
|
|
8
|
+
export const customTypeAssetRead: CustomTypeAssetReadHook<
|
|
9
|
+
PluginOptions
|
|
10
|
+
> = async (data, context) => {
|
|
11
|
+
const filePath = buildCustomTypeAssetPath({
|
|
12
|
+
customTypeID: data.customTypeID,
|
|
13
|
+
assetID: data.assetID,
|
|
14
|
+
helpers: context.helpers,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const assetData = await fs.readFile(filePath);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
data: assetData,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CustomTypeAssetUpdateHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { buildCustomTypeAssetPath } from "../lib/buildCustomTypeAssetPath";
|
|
6
|
+
|
|
7
|
+
import type { PluginOptions } from "../types";
|
|
8
|
+
|
|
9
|
+
export const customTypeAssetUpdate: CustomTypeAssetUpdateHook<
|
|
10
|
+
PluginOptions
|
|
11
|
+
> = async (data, context) => {
|
|
12
|
+
const filePath = buildCustomTypeAssetPath({
|
|
13
|
+
customTypeID: data.customTypeID,
|
|
14
|
+
assetID: data.asset.id,
|
|
15
|
+
helpers: context.helpers,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
19
|
+
await fs.writeFile(filePath, data.asset.data);
|
|
20
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CustomTypeCreateHook,
|
|
3
|
+
CustomTypeCreateHookData,
|
|
4
|
+
SliceMachineContext,
|
|
5
|
+
} from "@slicemachine/plugin-kit";
|
|
6
|
+
import * as fs from "node:fs/promises";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
|
|
9
|
+
import { buildCustomTypeDirectoryPath } from "../lib/buildCustomTypeDirectoryPath";
|
|
10
|
+
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
11
|
+
|
|
12
|
+
import type { PluginOptions } from "../types";
|
|
13
|
+
|
|
14
|
+
type Args = {
|
|
15
|
+
dir: string;
|
|
16
|
+
data: CustomTypeCreateHookData;
|
|
17
|
+
} & SliceMachineContext<PluginOptions>;
|
|
18
|
+
|
|
19
|
+
const createModelFile = async ({ dir, data, helpers, options }: Args) => {
|
|
20
|
+
const filePath = path.join(dir, "index.json");
|
|
21
|
+
|
|
22
|
+
let contents = JSON.stringify(data.model);
|
|
23
|
+
|
|
24
|
+
if (options.format) {
|
|
25
|
+
contents = await helpers.format(contents, filePath);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await fs.writeFile(filePath, contents);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const customTypeCreate: CustomTypeCreateHook<PluginOptions> = async (
|
|
32
|
+
data,
|
|
33
|
+
context,
|
|
34
|
+
) => {
|
|
35
|
+
const dir = buildCustomTypeDirectoryPath({
|
|
36
|
+
customTypeID: data.model.id,
|
|
37
|
+
helpers: context.helpers,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
await fs.mkdir(dir, { recursive: true });
|
|
41
|
+
|
|
42
|
+
await createModelFile({ dir, data, ...context });
|
|
43
|
+
|
|
44
|
+
await upsertGlobalContentTypes(context);
|
|
45
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CustomTypeDeleteHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import { buildCustomTypeDirectoryPath } from "../lib/buildCustomTypeDirectoryPath";
|
|
5
|
+
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
6
|
+
|
|
7
|
+
import type { PluginOptions } from "../types";
|
|
8
|
+
|
|
9
|
+
export const customTypeDelete: CustomTypeDeleteHook<PluginOptions> = async (
|
|
10
|
+
data,
|
|
11
|
+
context,
|
|
12
|
+
) => {
|
|
13
|
+
const dir = buildCustomTypeDirectoryPath({
|
|
14
|
+
customTypeID: data.model.id,
|
|
15
|
+
helpers: context.helpers,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
await fs.rm(dir, { recursive: true });
|
|
19
|
+
|
|
20
|
+
await upsertGlobalContentTypes(context);
|
|
21
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CustomTypeReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { buildCustomTypeDirectoryPath } from "../lib/buildCustomTypeDirectoryPath";
|
|
6
|
+
import { readJSONFile } from "../lib/readJSONFile";
|
|
7
|
+
|
|
8
|
+
import type { PluginOptions } from "../types";
|
|
9
|
+
|
|
10
|
+
export const customTypeRead: CustomTypeReadHook<PluginOptions> = async (
|
|
11
|
+
data,
|
|
12
|
+
{ helpers },
|
|
13
|
+
) => {
|
|
14
|
+
const filePath = path.join(
|
|
15
|
+
buildCustomTypeDirectoryPath({ customTypeID: data.id, helpers }),
|
|
16
|
+
"index.json",
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const model = await readJSONFile<CustomType>(filePath);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
model,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { CustomTypeLibraryReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
|
|
3
|
+
import * as fs from "node:fs/promises";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
|
|
6
|
+
import { buildCustomTypeLibraryDirectoryPath } from "../lib/buildCustomTypeLibraryDirectoryPath";
|
|
7
|
+
import { readJSONFile } from "../lib/readJSONFile";
|
|
8
|
+
|
|
9
|
+
import type { PluginOptions } from "../types";
|
|
10
|
+
|
|
11
|
+
const isCustomTypeModel = (
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
input: any,
|
|
14
|
+
): input is CustomType => {
|
|
15
|
+
return typeof input === "object" && input !== null && "json" in input;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const customTypeLibraryRead: CustomTypeLibraryReadHook<
|
|
19
|
+
PluginOptions
|
|
20
|
+
> = async (_data, { helpers }) => {
|
|
21
|
+
const dirPath = buildCustomTypeLibraryDirectoryPath({ helpers });
|
|
22
|
+
|
|
23
|
+
// Ensure the directory exists.
|
|
24
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
25
|
+
|
|
26
|
+
const childDirs = await fs.readdir(dirPath);
|
|
27
|
+
|
|
28
|
+
const ids: string[] = [];
|
|
29
|
+
await Promise.all(
|
|
30
|
+
childDirs.map(async (childDir) => {
|
|
31
|
+
const childDirContents = await fs.readdir(path.join(dirPath, childDir), {
|
|
32
|
+
withFileTypes: true,
|
|
33
|
+
});
|
|
34
|
+
const isCustomTypeDir = childDirContents.some((entry) => {
|
|
35
|
+
return entry.isFile() && entry.name === "index.json";
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (isCustomTypeDir) {
|
|
39
|
+
const modelPath = path.join(dirPath, childDir, "index.json");
|
|
40
|
+
|
|
41
|
+
const modelContents = await readJSONFile(modelPath);
|
|
42
|
+
|
|
43
|
+
if (isCustomTypeModel(modelContents)) {
|
|
44
|
+
ids.push(modelContents.id);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
ids: ids.sort(),
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import type {
|
|
4
|
+
ProjectInitHook,
|
|
5
|
+
ProjectInitHookData,
|
|
6
|
+
SliceMachineContext,
|
|
7
|
+
} from "@slicemachine/plugin-kit";
|
|
8
|
+
import { stripIndent } from "common-tags";
|
|
9
|
+
import { loadFile, writeFile, type ASTNode } from "magicast";
|
|
10
|
+
|
|
11
|
+
import { checkPathExists } from "../lib/checkPathExists";
|
|
12
|
+
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
13
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
14
|
+
|
|
15
|
+
import type { PluginOptions } from "../types";
|
|
16
|
+
|
|
17
|
+
const NUXT_PRISMIC = "@nuxtjs/prismic";
|
|
18
|
+
|
|
19
|
+
type InstallDependenciesArgs = {
|
|
20
|
+
installDependencies: ProjectInitHookData["installDependencies"];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const installDependencies = async ({
|
|
24
|
+
installDependencies,
|
|
25
|
+
}: InstallDependenciesArgs) => {
|
|
26
|
+
try {
|
|
27
|
+
await installDependencies({
|
|
28
|
+
dependencies: {
|
|
29
|
+
[NUXT_PRISMIC]: "^3.0.0",
|
|
30
|
+
},
|
|
31
|
+
dev: true,
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
// TODO: Remove when latest is published and documented
|
|
35
|
+
// Fallback to RC if latest is still not available
|
|
36
|
+
await installDependencies({
|
|
37
|
+
dependencies: {
|
|
38
|
+
[NUXT_PRISMIC]: "rc",
|
|
39
|
+
},
|
|
40
|
+
dev: true,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type ConfigurePrismicModuleArgs = SliceMachineContext<PluginOptions>;
|
|
46
|
+
|
|
47
|
+
const configurePrismicModule = async ({
|
|
48
|
+
helpers,
|
|
49
|
+
project,
|
|
50
|
+
}: ConfigurePrismicModuleArgs) => {
|
|
51
|
+
let nuxtConfigPath = helpers.joinPathFromRoot("nuxt.config.js");
|
|
52
|
+
|
|
53
|
+
if (!(await checkPathExists(nuxtConfigPath))) {
|
|
54
|
+
nuxtConfigPath = helpers.joinPathFromRoot("nuxt.config.ts");
|
|
55
|
+
|
|
56
|
+
// nuxt.config.* not found
|
|
57
|
+
if (!(await checkPathExists(nuxtConfigPath))) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const mod = await loadFile(nuxtConfigPath);
|
|
63
|
+
const config =
|
|
64
|
+
mod.exports.default.$type === "function-call"
|
|
65
|
+
? mod.exports.default.$args[0]
|
|
66
|
+
: mod.exports.default;
|
|
67
|
+
|
|
68
|
+
// Register Prismic module
|
|
69
|
+
let hasInlinedConfiguration = false;
|
|
70
|
+
const hasPrismicModuleRegistered = (config.modules || []).find(
|
|
71
|
+
(registration: string | [string, unknown]) => {
|
|
72
|
+
if (typeof registration === "string") {
|
|
73
|
+
return registration === NUXT_PRISMIC;
|
|
74
|
+
} else if (Array.isArray(registration)) {
|
|
75
|
+
hasInlinedConfiguration = !!registration[1];
|
|
76
|
+
|
|
77
|
+
return registration[0] === NUXT_PRISMIC;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return false;
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (!hasPrismicModuleRegistered) {
|
|
85
|
+
config.modules ||= [];
|
|
86
|
+
config.modules.push(NUXT_PRISMIC);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Append Prismic module configuration
|
|
90
|
+
const endpoint = project.config.repositoryName;
|
|
91
|
+
if (!hasInlinedConfiguration) {
|
|
92
|
+
config.prismic ||= {};
|
|
93
|
+
config.prismic.endpoint = endpoint;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
await writeFile(mod as unknown as ASTNode, nuxtConfigPath);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
type CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;
|
|
100
|
+
|
|
101
|
+
const createSliceSimulatorPage = async ({
|
|
102
|
+
helpers,
|
|
103
|
+
options,
|
|
104
|
+
}: CreateSliceSimulatorPageArgs) => {
|
|
105
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
106
|
+
helpers,
|
|
107
|
+
options,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const srcPagesDirectoryExists = await checkPathExists(
|
|
111
|
+
helpers.joinPathFromRoot("src/pages"),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const filePath = helpers.joinPathFromRoot(
|
|
115
|
+
srcPagesDirectoryExists ? "src/pages" : "pages",
|
|
116
|
+
"slice-simulator.vue",
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
if (await checkPathExists(filePath)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
124
|
+
|
|
125
|
+
const scriptAttributes = ["setup"];
|
|
126
|
+
if (isTypeScriptProject) {
|
|
127
|
+
scriptAttributes.push('lang="ts"');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let contents = stripIndent`
|
|
131
|
+
<template>
|
|
132
|
+
<SliceSimulator #default="{ slices }">
|
|
133
|
+
<SliceZone :slices="slices" :components="components" />
|
|
134
|
+
</SliceSimulator>
|
|
135
|
+
</template>
|
|
136
|
+
|
|
137
|
+
<script ${scriptAttributes.join(" ")}>
|
|
138
|
+
import { SliceSimulator } from "@slicemachine/adapter-nuxt/simulator";
|
|
139
|
+
import { components } from "~/slices";
|
|
140
|
+
</script>
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
if (options.format) {
|
|
144
|
+
contents = await helpers.format(contents, filePath, {
|
|
145
|
+
prettier: { parser: "vue" },
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
await fs.writeFile(filePath, contents);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const projectInit: ProjectInitHook<PluginOptions> = async (
|
|
153
|
+
{ installDependencies: _installDependencies },
|
|
154
|
+
context,
|
|
155
|
+
) => {
|
|
156
|
+
rejectIfNecessary(
|
|
157
|
+
await Promise.allSettled([
|
|
158
|
+
await installDependencies({ installDependencies: _installDependencies }),
|
|
159
|
+
await configurePrismicModule(context),
|
|
160
|
+
await createSliceSimulatorPage(context),
|
|
161
|
+
]),
|
|
162
|
+
);
|
|
163
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SliceAssetDeleteHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import { buildSliceAssetPath } from "../lib/buildSliceAssetPath";
|
|
5
|
+
|
|
6
|
+
import type { PluginOptions } from "../types";
|
|
7
|
+
|
|
8
|
+
export const sliceAssetDelete: SliceAssetDeleteHook<PluginOptions> = async (
|
|
9
|
+
data,
|
|
10
|
+
context,
|
|
11
|
+
) => {
|
|
12
|
+
const filePath = await buildSliceAssetPath({
|
|
13
|
+
libraryID: data.libraryID,
|
|
14
|
+
sliceID: data.sliceID,
|
|
15
|
+
assetID: data.assetID,
|
|
16
|
+
helpers: context.helpers,
|
|
17
|
+
actions: context.actions,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await fs.rm(filePath);
|
|
21
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SliceAssetReadHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import { buildSliceAssetPath } from "../lib/buildSliceAssetPath";
|
|
5
|
+
|
|
6
|
+
import type { PluginOptions } from "../types";
|
|
7
|
+
|
|
8
|
+
export const sliceAssetRead: SliceAssetReadHook<PluginOptions> = async (
|
|
9
|
+
data,
|
|
10
|
+
context,
|
|
11
|
+
) => {
|
|
12
|
+
const filePath = await buildSliceAssetPath({
|
|
13
|
+
libraryID: data.libraryID,
|
|
14
|
+
sliceID: data.sliceID,
|
|
15
|
+
assetID: data.assetID,
|
|
16
|
+
helpers: context.helpers,
|
|
17
|
+
actions: context.actions,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const assetData = await fs.readFile(filePath);
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
data: assetData,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SliceAssetUpdateHook } from "@slicemachine/plugin-kit";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { buildSliceAssetPath } from "../lib/buildSliceAssetPath";
|
|
6
|
+
|
|
7
|
+
import type { PluginOptions } from "../types";
|
|
8
|
+
|
|
9
|
+
export const sliceAssetUpdate: SliceAssetUpdateHook<PluginOptions> = async (
|
|
10
|
+
data,
|
|
11
|
+
context,
|
|
12
|
+
) => {
|
|
13
|
+
const filePath = await buildSliceAssetPath({
|
|
14
|
+
libraryID: data.libraryID,
|
|
15
|
+
sliceID: data.sliceID,
|
|
16
|
+
assetID: data.asset.id,
|
|
17
|
+
helpers: context.helpers,
|
|
18
|
+
actions: context.actions,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
22
|
+
await fs.writeFile(filePath, data.asset.data);
|
|
23
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SliceCreateHook,
|
|
3
|
+
SliceCreateHookData,
|
|
4
|
+
SliceMachineContext,
|
|
5
|
+
} from "@slicemachine/plugin-kit";
|
|
6
|
+
import { stripIndent } from "common-tags";
|
|
7
|
+
import * as fs from "node:fs/promises";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
|
|
10
|
+
import { buildSliceDirectoryPath } from "../lib/buildSliceDirectoryPath";
|
|
11
|
+
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
12
|
+
import { updateSliceModelFile } from "../lib/updateSliceModelFile";
|
|
13
|
+
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
14
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
|
|
15
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
16
|
+
import { pascalCase } from "../lib/pascalCase";
|
|
17
|
+
|
|
18
|
+
import type { PluginOptions } from "../types";
|
|
19
|
+
|
|
20
|
+
type Args = {
|
|
21
|
+
dir: string;
|
|
22
|
+
data: SliceCreateHookData;
|
|
23
|
+
} & SliceMachineContext<PluginOptions>;
|
|
24
|
+
|
|
25
|
+
const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
26
|
+
const filePath = path.join(dir, "index.vue");
|
|
27
|
+
const model = data.model;
|
|
28
|
+
const pascalName = pascalCase(model.name);
|
|
29
|
+
|
|
30
|
+
let contents: string;
|
|
31
|
+
|
|
32
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
33
|
+
helpers,
|
|
34
|
+
options,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (isTypeScriptProject) {
|
|
38
|
+
contents = stripIndent`
|
|
39
|
+
<template>
|
|
40
|
+
<section
|
|
41
|
+
:data-slice-type="slice.slice_type"
|
|
42
|
+
:data-slice-variation="slice.variation"
|
|
43
|
+
>
|
|
44
|
+
Placeholder component for ${model.id} (variation: {{ slice.variation }}) Slices
|
|
45
|
+
</section>
|
|
46
|
+
</template>
|
|
47
|
+
|
|
48
|
+
<script setup lang="ts">
|
|
49
|
+
import { Content } from "@prismicio/client";
|
|
50
|
+
|
|
51
|
+
// The array passed to \`getSliceComponentProps\` is purely optional.
|
|
52
|
+
// Consider it as a visual hint for you when templating your slice.
|
|
53
|
+
defineProps(getSliceComponentProps<Content.${pascalName}Slice>(
|
|
54
|
+
["slice", "index", "slices", "context"]
|
|
55
|
+
));
|
|
56
|
+
</script>
|
|
57
|
+
`;
|
|
58
|
+
} else {
|
|
59
|
+
contents = stripIndent`
|
|
60
|
+
<template>
|
|
61
|
+
<section
|
|
62
|
+
:data-slice-type="slice.slice_type"
|
|
63
|
+
:data-slice-variation="slice.variation"
|
|
64
|
+
>
|
|
65
|
+
Placeholder component for {{ model.id }} (variation: {{ slice.variation }}) Slices
|
|
66
|
+
</section>
|
|
67
|
+
</template>
|
|
68
|
+
|
|
69
|
+
<script setup>
|
|
70
|
+
// The array passed to \`getSliceComponentProps\` is purely optional.
|
|
71
|
+
// Consider it as a visual hint for you when templating your slice.
|
|
72
|
+
defineProps(getSliceComponentProps(["slice", "index", "slices", "context"]));
|
|
73
|
+
</script>
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (options.format) {
|
|
78
|
+
contents = await helpers.format(contents, filePath, {
|
|
79
|
+
prettier: { parser: "vue" },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
await fs.writeFile(filePath, contents);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const sliceCreate: SliceCreateHook<PluginOptions> = async (
|
|
87
|
+
data,
|
|
88
|
+
context,
|
|
89
|
+
) => {
|
|
90
|
+
const dir = buildSliceDirectoryPath({
|
|
91
|
+
libraryID: data.libraryID,
|
|
92
|
+
model: data.model,
|
|
93
|
+
helpers: context.helpers,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
await fs.mkdir(dir, { recursive: true });
|
|
97
|
+
|
|
98
|
+
rejectIfNecessary(
|
|
99
|
+
await Promise.allSettled([
|
|
100
|
+
updateSliceModelFile({
|
|
101
|
+
libraryID: data.libraryID,
|
|
102
|
+
model: data.model,
|
|
103
|
+
...context,
|
|
104
|
+
}),
|
|
105
|
+
createComponentFile({ dir, data, ...context }),
|
|
106
|
+
]),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
rejectIfNecessary(
|
|
110
|
+
await Promise.allSettled([
|
|
111
|
+
upsertGlobalContentTypes(context),
|
|
112
|
+
upsertSliceLibraryIndexFile({ libraryID: data.libraryID, ...context }),
|
|
113
|
+
]),
|
|
114
|
+
);
|
|
115
|
+
};
|