@slicemachine/adapter-next 0.0.9 → 0.0.11
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/command-init.cjs +196 -0
- package/dist/hooks/command-init.cjs.map +1 -0
- package/dist/hooks/command-init.d.ts +3 -0
- package/dist/hooks/command-init.js +178 -0
- package/dist/hooks/command-init.js.map +1 -0
- package/dist/hooks/slice-create.cjs +8 -3
- package/dist/hooks/slice-create.cjs.map +1 -1
- package/dist/hooks/slice-create.js +8 -3
- package/dist/hooks/slice-create.js.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.cjs +12 -2
- package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
- package/dist/hooks/sliceSimulator-setup-read.js +12 -2
- package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
- 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/getJSOrTSXFileExtension.cjs +8 -3
- package/dist/lib/getJSOrTSXFileExtension.cjs.map +1 -1
- package/dist/lib/getJSOrTSXFileExtension.d.ts +7 -1
- package/dist/lib/getJSOrTSXFileExtension.js +8 -3
- package/dist/lib/getJSOrTSXFileExtension.js.map +1 -1
- package/dist/lib/rejectIfNecessary.cjs.map +1 -1
- package/dist/lib/rejectIfNecessary.js.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.cjs +37 -11
- package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
- package/dist/lib/upsertSliceLibraryIndexFile.js +37 -11
- package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
- package/dist/node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -1
- package/dist/node_modules/data-uri-to-buffer/dist/index.js.map +1 -1
- package/dist/node_modules/fetch-blob/file.cjs +6 -0
- package/dist/node_modules/fetch-blob/file.cjs.map +1 -1
- package/dist/node_modules/fetch-blob/file.js +6 -0
- package/dist/node_modules/fetch-blob/file.js.map +1 -1
- package/dist/node_modules/fetch-blob/index.cjs +48 -2
- package/dist/node_modules/fetch-blob/index.cjs.map +1 -1
- package/dist/node_modules/fetch-blob/index.js +48 -2
- package/dist/node_modules/fetch-blob/index.js.map +1 -1
- package/dist/node_modules/fetch-blob/streams.cjs.map +1 -1
- package/dist/node_modules/fetch-blob/streams.js.map +1 -1
- package/dist/node_modules/formdata-polyfill/esm.min.cjs.map +1 -1
- package/dist/node_modules/formdata-polyfill/esm.min.js.map +1 -1
- package/dist/node_modules/node-domexception/index.cjs.map +1 -1
- package/dist/node_modules/node-domexception/index.js.map +1 -1
- package/dist/node_modules/node-fetch/src/body.cjs +25 -0
- package/dist/node_modules/node-fetch/src/body.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/body.js +25 -0
- package/dist/node_modules/node-fetch/src/body.js.map +1 -1
- package/dist/node_modules/node-fetch/src/errors/base.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/errors/base.js.map +1 -1
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs +5 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js +5 -0
- package/dist/node_modules/node-fetch/src/errors/fetch-error.js.map +1 -1
- package/dist/node_modules/node-fetch/src/headers.cjs +17 -0
- package/dist/node_modules/node-fetch/src/headers.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/headers.js +17 -0
- package/dist/node_modules/node-fetch/src/headers.js.map +1 -1
- package/dist/node_modules/node-fetch/src/index.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/index.js.map +1 -1
- package/dist/node_modules/node-fetch/src/request.cjs +13 -0
- package/dist/node_modules/node-fetch/src/request.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/request.js +13 -0
- package/dist/node_modules/node-fetch/src/request.js.map +1 -1
- package/dist/node_modules/node-fetch/src/response.cjs +13 -0
- package/dist/node_modules/node-fetch/src/response.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/response.js +13 -0
- package/dist/node_modules/node-fetch/src/response.js.map +1 -1
- package/dist/node_modules/node-fetch/src/utils/get-search.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/utils/get-search.js.map +1 -1
- package/dist/node_modules/node-fetch/src/utils/is.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/utils/is.js.map +1 -1
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs +6 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -1
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js +6 -0
- package/dist/node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -1
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +223 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -1
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +223 -0
- package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -1
- package/dist/plugin.cjs +4 -1
- package/dist/plugin.cjs.map +1 -1
- package/dist/plugin.js +4 -1
- package/dist/plugin.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +15 -15
- package/src/hooks/command-init.ts +227 -0
- package/src/hooks/slice-create.ts +12 -3
- package/src/hooks/sliceSimulator-setup-read.ts +11 -2
- package/src/lib/checkIsTypeScriptProject.ts +17 -0
- package/src/lib/checkPathExists.ts +12 -0
- package/src/lib/getJSOrTSXFileExtension.ts +18 -5
- package/src/lib/upsertSliceLibraryIndexFile.ts +44 -10
- package/src/plugin.ts +4 -0
- package/src/types.ts +1 -0
package/dist/plugin.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const pluginKit = require("@slicemachine/plugin-kit");
|
|
4
4
|
const _package = require("./package.json.cjs");
|
|
5
|
+
const commandInit = require("./hooks/command-init.cjs");
|
|
5
6
|
const customTypeAssetDelete = require("./hooks/customType-asset-delete.cjs");
|
|
6
7
|
const customTypeAssetRead = require("./hooks/customType-asset-read.cjs");
|
|
7
8
|
const customTypeAssetUpdate = require("./hooks/customType-asset-update.cjs");
|
|
@@ -27,9 +28,11 @@ const plugin = pluginKit.defineSliceMachinePlugin({
|
|
|
27
28
|
name: _package.name
|
|
28
29
|
},
|
|
29
30
|
defaultOptions: {
|
|
30
|
-
format: true
|
|
31
|
+
format: true,
|
|
32
|
+
lazyLoadSlices: true
|
|
31
33
|
},
|
|
32
34
|
setup({ hook }) {
|
|
35
|
+
hook("command:init", commandInit.commandInit);
|
|
33
36
|
hook("slice:create", sliceCreate.sliceCreate);
|
|
34
37
|
hook("slice:update", sliceUpdate.sliceUpdate);
|
|
35
38
|
hook("slice:rename", sliceRename.sliceRename);
|
package/dist/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import { defineSliceMachinePlugin } from \"@slicemachine/plugin-kit\";\n\nimport { name as pkgName } from \"../package.json\";\nimport { PluginOptions } from \"./types\";\n\nimport { customTypeAssetDelete } from \"./hooks/customType-asset-delete\";\nimport { customTypeAssetRead } from \"./hooks/customType-asset-read\";\nimport { customTypeAssetUpdate } from \"./hooks/customType-asset-update\";\nimport { customTypeCreate } from \"./hooks/customType-create\";\nimport { customTypeDelete } from \"./hooks/customType-delete\";\nimport { customTypeLibraryRead } from \"./hooks/customTypeLibrary-read\";\nimport { customTypeRead } from \"./hooks/customType-read\";\nimport { customTypeRename } from \"./hooks/customType-rename\";\nimport { customTypeUpdate } from \"./hooks/customType-update\";\nimport { sliceAssetDelete } from \"./hooks/slice-asset-delete\";\nimport { sliceAssetRead } from \"./hooks/slice-asset-read\";\nimport { sliceAssetUpdate } from \"./hooks/slice-asset-update\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { sliceDelete } from \"./hooks/slice-delete\";\nimport { sliceLibraryRead } from \"./hooks/sliceLibrary-read\";\nimport { sliceRead } from \"./hooks/slice-read\";\nimport { sliceRename } from \"./hooks/slice-rename\";\nimport { sliceSimulatorSetupRead } from \"./hooks/sliceSimulator-setup-read\";\nimport { sliceUpdate } from \"./hooks/slice-update\";\nimport { snippetRead } from \"./hooks/snippet-read\";\n\nexport const plugin = defineSliceMachinePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t},\n\tsetup({ hook }) {\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", sliceUpdate);\n\t\thook(\"slice:rename\", sliceRename);\n\t\thook(\"slice:delete\", sliceDelete);\n\t\thook(\"slice:read\", sliceRead);\n\t\thook(\"slice:asset:update\", sliceAssetUpdate);\n\t\thook(\"slice:asset:delete\", sliceAssetDelete);\n\t\thook(\"slice:asset:read\", sliceAssetRead);\n\t\thook(\"slice-library:read\", sliceLibraryRead);\n\n\t\thook(\"custom-type:create\", customTypeCreate);\n\t\thook(\"custom-type:update\", customTypeUpdate);\n\t\thook(\"custom-type:rename\", customTypeRename);\n\t\thook(\"custom-type:delete\", customTypeDelete);\n\t\thook(\"custom-type:read\", customTypeRead);\n\t\thook(\"custom-type:asset:update\", customTypeAssetUpdate);\n\t\thook(\"custom-type:asset:delete\", customTypeAssetDelete);\n\t\thook(\"custom-type:asset:read\", customTypeAssetRead);\n\t\thook(\"custom-type-library:read\", customTypeLibraryRead);\n\n\t\thook(\"snippet:read\", snippetRead);\n\n\t\thook(\"slice-simulator:setup:read\", sliceSimulatorSetupRead);\n\t},\n});\n"],"names":["defineSliceMachinePlugin","pkgName","sliceCreate","sliceUpdate","sliceRename","sliceDelete","sliceRead","sliceAssetUpdate","sliceAssetDelete","sliceAssetRead","sliceLibraryRead","customTypeCreate","customTypeUpdate","customTypeRename","customTypeDelete","customTypeRead","customTypeAssetUpdate","customTypeAssetDelete","customTypeAssetRead","customTypeLibraryRead","snippetRead","sliceSimulatorSetupRead"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import { defineSliceMachinePlugin } from \"@slicemachine/plugin-kit\";\n\nimport { name as pkgName } from \"../package.json\";\nimport { PluginOptions } from \"./types\";\n\nimport { commandInit } from \"./hooks/command-init\";\nimport { customTypeAssetDelete } from \"./hooks/customType-asset-delete\";\nimport { customTypeAssetRead } from \"./hooks/customType-asset-read\";\nimport { customTypeAssetUpdate } from \"./hooks/customType-asset-update\";\nimport { customTypeCreate } from \"./hooks/customType-create\";\nimport { customTypeDelete } from \"./hooks/customType-delete\";\nimport { customTypeLibraryRead } from \"./hooks/customTypeLibrary-read\";\nimport { customTypeRead } from \"./hooks/customType-read\";\nimport { customTypeRename } from \"./hooks/customType-rename\";\nimport { customTypeUpdate } from \"./hooks/customType-update\";\nimport { sliceAssetDelete } from \"./hooks/slice-asset-delete\";\nimport { sliceAssetRead } from \"./hooks/slice-asset-read\";\nimport { sliceAssetUpdate } from \"./hooks/slice-asset-update\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { sliceDelete } from \"./hooks/slice-delete\";\nimport { sliceLibraryRead } from \"./hooks/sliceLibrary-read\";\nimport { sliceRead } from \"./hooks/slice-read\";\nimport { sliceRename } from \"./hooks/slice-rename\";\nimport { sliceSimulatorSetupRead } from \"./hooks/sliceSimulator-setup-read\";\nimport { sliceUpdate } from \"./hooks/slice-update\";\nimport { snippetRead } from \"./hooks/snippet-read\";\n\nexport const plugin = defineSliceMachinePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t\tlazyLoadSlices: true,\n\t},\n\tsetup({ hook }) {\n\t\thook(\"command:init\", commandInit);\n\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", sliceUpdate);\n\t\thook(\"slice:rename\", sliceRename);\n\t\thook(\"slice:delete\", sliceDelete);\n\t\thook(\"slice:read\", sliceRead);\n\t\thook(\"slice:asset:update\", sliceAssetUpdate);\n\t\thook(\"slice:asset:delete\", sliceAssetDelete);\n\t\thook(\"slice:asset:read\", sliceAssetRead);\n\t\thook(\"slice-library:read\", sliceLibraryRead);\n\n\t\thook(\"custom-type:create\", customTypeCreate);\n\t\thook(\"custom-type:update\", customTypeUpdate);\n\t\thook(\"custom-type:rename\", customTypeRename);\n\t\thook(\"custom-type:delete\", customTypeDelete);\n\t\thook(\"custom-type:read\", customTypeRead);\n\t\thook(\"custom-type:asset:update\", customTypeAssetUpdate);\n\t\thook(\"custom-type:asset:delete\", customTypeAssetDelete);\n\t\thook(\"custom-type:asset:read\", customTypeAssetRead);\n\t\thook(\"custom-type-library:read\", customTypeLibraryRead);\n\n\t\thook(\"snippet:read\", snippetRead);\n\n\t\thook(\"slice-simulator:setup:read\", sliceSimulatorSetupRead);\n\t},\n});\n"],"names":["defineSliceMachinePlugin","pkgName","commandInit","sliceCreate","sliceUpdate","sliceRename","sliceDelete","sliceRead","sliceAssetUpdate","sliceAssetDelete","sliceAssetRead","sliceLibraryRead","customTypeCreate","customTypeUpdate","customTypeRename","customTypeDelete","customTypeRead","customTypeAssetUpdate","customTypeAssetDelete","customTypeAssetRead","customTypeLibraryRead","snippetRead","sliceSimulatorSetupRead"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2BO,MAAM,SAASA,UAAAA,yBAAwC;AAAA,EAC7D,MAAM;AAAA,IACL,MAAMC,SAAA;AAAA,EACN;AAAA,EACD,gBAAgB;AAAA,IACf,QAAQ;AAAA,IACR,gBAAgB;AAAA,EAChB;AAAA,EACD,MAAM,EAAE,QAAM;AACb,SAAK,gBAAgBC,YAAAA,WAAW;AAEhC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,cAAcC,UAAAA,SAAS;AAC5B,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,oBAAoBC,eAAAA,cAAc;AACvC,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAE3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,oBAAoBC,eAAAA,cAAc;AACvC,SAAK,4BAA4BC,sBAAAA,qBAAqB;AACtD,SAAK,4BAA4BC,sBAAAA,qBAAqB;AACtD,SAAK,0BAA0BC,oBAAAA,mBAAmB;AAClD,SAAK,4BAA4BC,sBAAAA,qBAAqB;AAEtD,SAAK,gBAAgBC,YAAAA,WAAW;AAEhC,SAAK,8BAA8BC,wBAAAA,uBAAuB;AAAA,EAC3D;AACA,CAAA;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineSliceMachinePlugin } from "@slicemachine/plugin-kit";
|
|
2
2
|
import { name } from "./package.json.js";
|
|
3
|
+
import { commandInit } from "./hooks/command-init.js";
|
|
3
4
|
import { customTypeAssetDelete } from "./hooks/customType-asset-delete.js";
|
|
4
5
|
import { customTypeAssetRead } from "./hooks/customType-asset-read.js";
|
|
5
6
|
import { customTypeAssetUpdate } from "./hooks/customType-asset-update.js";
|
|
@@ -25,9 +26,11 @@ const plugin = defineSliceMachinePlugin({
|
|
|
25
26
|
name
|
|
26
27
|
},
|
|
27
28
|
defaultOptions: {
|
|
28
|
-
format: true
|
|
29
|
+
format: true,
|
|
30
|
+
lazyLoadSlices: true
|
|
29
31
|
},
|
|
30
32
|
setup({ hook }) {
|
|
33
|
+
hook("command:init", commandInit);
|
|
31
34
|
hook("slice:create", sliceCreate);
|
|
32
35
|
hook("slice:update", sliceUpdate);
|
|
33
36
|
hook("slice:rename", sliceRename);
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import { defineSliceMachinePlugin } from \"@slicemachine/plugin-kit\";\n\nimport { name as pkgName } from \"../package.json\";\nimport { PluginOptions } from \"./types\";\n\nimport { customTypeAssetDelete } from \"./hooks/customType-asset-delete\";\nimport { customTypeAssetRead } from \"./hooks/customType-asset-read\";\nimport { customTypeAssetUpdate } from \"./hooks/customType-asset-update\";\nimport { customTypeCreate } from \"./hooks/customType-create\";\nimport { customTypeDelete } from \"./hooks/customType-delete\";\nimport { customTypeLibraryRead } from \"./hooks/customTypeLibrary-read\";\nimport { customTypeRead } from \"./hooks/customType-read\";\nimport { customTypeRename } from \"./hooks/customType-rename\";\nimport { customTypeUpdate } from \"./hooks/customType-update\";\nimport { sliceAssetDelete } from \"./hooks/slice-asset-delete\";\nimport { sliceAssetRead } from \"./hooks/slice-asset-read\";\nimport { sliceAssetUpdate } from \"./hooks/slice-asset-update\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { sliceDelete } from \"./hooks/slice-delete\";\nimport { sliceLibraryRead } from \"./hooks/sliceLibrary-read\";\nimport { sliceRead } from \"./hooks/slice-read\";\nimport { sliceRename } from \"./hooks/slice-rename\";\nimport { sliceSimulatorSetupRead } from \"./hooks/sliceSimulator-setup-read\";\nimport { sliceUpdate } from \"./hooks/slice-update\";\nimport { snippetRead } from \"./hooks/snippet-read\";\n\nexport const plugin = defineSliceMachinePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t},\n\tsetup({ hook }) {\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", sliceUpdate);\n\t\thook(\"slice:rename\", sliceRename);\n\t\thook(\"slice:delete\", sliceDelete);\n\t\thook(\"slice:read\", sliceRead);\n\t\thook(\"slice:asset:update\", sliceAssetUpdate);\n\t\thook(\"slice:asset:delete\", sliceAssetDelete);\n\t\thook(\"slice:asset:read\", sliceAssetRead);\n\t\thook(\"slice-library:read\", sliceLibraryRead);\n\n\t\thook(\"custom-type:create\", customTypeCreate);\n\t\thook(\"custom-type:update\", customTypeUpdate);\n\t\thook(\"custom-type:rename\", customTypeRename);\n\t\thook(\"custom-type:delete\", customTypeDelete);\n\t\thook(\"custom-type:read\", customTypeRead);\n\t\thook(\"custom-type:asset:update\", customTypeAssetUpdate);\n\t\thook(\"custom-type:asset:delete\", customTypeAssetDelete);\n\t\thook(\"custom-type:asset:read\", customTypeAssetRead);\n\t\thook(\"custom-type-library:read\", customTypeLibraryRead);\n\n\t\thook(\"snippet:read\", snippetRead);\n\n\t\thook(\"slice-simulator:setup:read\", sliceSimulatorSetupRead);\n\t},\n});\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import { defineSliceMachinePlugin } from \"@slicemachine/plugin-kit\";\n\nimport { name as pkgName } from \"../package.json\";\nimport { PluginOptions } from \"./types\";\n\nimport { commandInit } from \"./hooks/command-init\";\nimport { customTypeAssetDelete } from \"./hooks/customType-asset-delete\";\nimport { customTypeAssetRead } from \"./hooks/customType-asset-read\";\nimport { customTypeAssetUpdate } from \"./hooks/customType-asset-update\";\nimport { customTypeCreate } from \"./hooks/customType-create\";\nimport { customTypeDelete } from \"./hooks/customType-delete\";\nimport { customTypeLibraryRead } from \"./hooks/customTypeLibrary-read\";\nimport { customTypeRead } from \"./hooks/customType-read\";\nimport { customTypeRename } from \"./hooks/customType-rename\";\nimport { customTypeUpdate } from \"./hooks/customType-update\";\nimport { sliceAssetDelete } from \"./hooks/slice-asset-delete\";\nimport { sliceAssetRead } from \"./hooks/slice-asset-read\";\nimport { sliceAssetUpdate } from \"./hooks/slice-asset-update\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { sliceDelete } from \"./hooks/slice-delete\";\nimport { sliceLibraryRead } from \"./hooks/sliceLibrary-read\";\nimport { sliceRead } from \"./hooks/slice-read\";\nimport { sliceRename } from \"./hooks/slice-rename\";\nimport { sliceSimulatorSetupRead } from \"./hooks/sliceSimulator-setup-read\";\nimport { sliceUpdate } from \"./hooks/slice-update\";\nimport { snippetRead } from \"./hooks/snippet-read\";\n\nexport const plugin = defineSliceMachinePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t\tlazyLoadSlices: true,\n\t},\n\tsetup({ hook }) {\n\t\thook(\"command:init\", commandInit);\n\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", sliceUpdate);\n\t\thook(\"slice:rename\", sliceRename);\n\t\thook(\"slice:delete\", sliceDelete);\n\t\thook(\"slice:read\", sliceRead);\n\t\thook(\"slice:asset:update\", sliceAssetUpdate);\n\t\thook(\"slice:asset:delete\", sliceAssetDelete);\n\t\thook(\"slice:asset:read\", sliceAssetRead);\n\t\thook(\"slice-library:read\", sliceLibraryRead);\n\n\t\thook(\"custom-type:create\", customTypeCreate);\n\t\thook(\"custom-type:update\", customTypeUpdate);\n\t\thook(\"custom-type:rename\", customTypeRename);\n\t\thook(\"custom-type:delete\", customTypeDelete);\n\t\thook(\"custom-type:read\", customTypeRead);\n\t\thook(\"custom-type:asset:update\", customTypeAssetUpdate);\n\t\thook(\"custom-type:asset:delete\", customTypeAssetDelete);\n\t\thook(\"custom-type:asset:read\", customTypeAssetRead);\n\t\thook(\"custom-type-library:read\", customTypeLibraryRead);\n\n\t\thook(\"snippet:read\", snippetRead);\n\n\t\thook(\"slice-simulator:setup:read\", sliceSimulatorSetupRead);\n\t},\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BO,MAAM,SAAS,yBAAwC;AAAA,EAC7D,MAAM;AAAA,IACL;AAAA,EACA;AAAA,EACD,gBAAgB;AAAA,IACf,QAAQ;AAAA,IACR,gBAAgB;AAAA,EAChB;AAAA,EACD,MAAM,EAAE,QAAM;AACb,SAAK,gBAAgB,WAAW;AAEhC,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,cAAc,SAAS;AAC5B,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,oBAAoB,cAAc;AACvC,SAAK,sBAAsB,gBAAgB;AAE3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,oBAAoB,cAAc;AACvC,SAAK,4BAA4B,qBAAqB;AACtD,SAAK,4BAA4B,qBAAqB;AACtD,SAAK,0BAA0B,mBAAmB;AAClD,SAAK,4BAA4B,qBAAqB;AAEtD,SAAK,gBAAgB,WAAW;AAEhC,SAAK,8BAA8B,uBAAuB;AAAA,EAC3D;AACA,CAAA;"}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slicemachine/adapter-next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Slice Machine adapter for Next.js.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@prismicio/slice-simulator-core": "^0.2.7",
|
|
61
61
|
"@prismicio/types": "^0.2.7",
|
|
62
|
-
"@slicemachine/plugin-kit": "
|
|
62
|
+
"@slicemachine/plugin-kit": "0.1.8-dev-plugins.12",
|
|
63
63
|
"common-tags": "^1.8.2",
|
|
64
64
|
"fs-extra": "^11.1.0",
|
|
65
65
|
"node-fetch": "^3.3.0",
|
|
@@ -68,31 +68,31 @@
|
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@prismicio/mock": "^0.2.0",
|
|
71
|
-
"@size-limit/preset-small-lib": "^8.
|
|
71
|
+
"@size-limit/preset-small-lib": "^8.2.4",
|
|
72
72
|
"@types/common-tags": "^1.8.1",
|
|
73
|
-
"@types/fs-extra": "^11.0.
|
|
73
|
+
"@types/fs-extra": "^11.0.1",
|
|
74
74
|
"@types/prettier": "^2.7.2",
|
|
75
|
-
"@types/react": "^18.0.
|
|
75
|
+
"@types/react": "^18.0.28",
|
|
76
76
|
"@types/semver": "^7.3.13",
|
|
77
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
78
|
-
"@typescript-eslint/parser": "^5.
|
|
79
|
-
"@vitejs/plugin-react": "^3.0
|
|
80
|
-
"@vitest/coverage-c8": "^0.
|
|
81
|
-
"eslint": "^8.
|
|
77
|
+
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
78
|
+
"@typescript-eslint/parser": "^5.54.0",
|
|
79
|
+
"@vitejs/plugin-react": "^3.1.0",
|
|
80
|
+
"@vitest/coverage-c8": "^0.29.1",
|
|
81
|
+
"eslint": "^8.35.0",
|
|
82
82
|
"eslint-config-prettier": "^8.6.0",
|
|
83
83
|
"eslint-plugin-prettier": "^4.2.1",
|
|
84
84
|
"eslint-plugin-tsdoc": "^0.2.17",
|
|
85
85
|
"npm-run-all": "^4.1.5",
|
|
86
|
-
"prettier": "^2.8.
|
|
86
|
+
"prettier": "^2.8.4",
|
|
87
87
|
"prettier-plugin-jsdoc": "^0.4.2",
|
|
88
88
|
"react": "^18.2.0",
|
|
89
|
-
"size-limit": "^8.
|
|
89
|
+
"size-limit": "^8.2.4",
|
|
90
90
|
"standard-version": "^9.5.0",
|
|
91
91
|
"ts-morph": "^17.0.1",
|
|
92
|
-
"typescript": "^4.9.
|
|
93
|
-
"vite": "^4.
|
|
92
|
+
"typescript": "^4.9.5",
|
|
93
|
+
"vite": "^4.1.4",
|
|
94
94
|
"vite-plugin-sdk": "^0.1.0",
|
|
95
|
-
"vitest": "^0.
|
|
95
|
+
"vitest": "^0.29.1"
|
|
96
96
|
},
|
|
97
97
|
"peerDependencies": {
|
|
98
98
|
"next": "^11 || ^12 || ^13",
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import type {
|
|
4
|
+
CommandInitHook,
|
|
5
|
+
CommandInitHookData,
|
|
6
|
+
SliceMachineContext,
|
|
7
|
+
} from "@slicemachine/plugin-kit";
|
|
8
|
+
import { stripIndent } from "common-tags";
|
|
9
|
+
|
|
10
|
+
import { checkPathExists } from "../lib/checkPathExists";
|
|
11
|
+
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
|
|
12
|
+
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
13
|
+
|
|
14
|
+
import type { PluginOptions } from "../types";
|
|
15
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
16
|
+
|
|
17
|
+
type InstallDependenciesArgs = {
|
|
18
|
+
installDependencies: CommandInitHookData["installDependencies"];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const installDependencies = async ({
|
|
22
|
+
installDependencies,
|
|
23
|
+
}: InstallDependenciesArgs) => {
|
|
24
|
+
await installDependencies({
|
|
25
|
+
dependencies: {
|
|
26
|
+
"@prismicio/client": "latest",
|
|
27
|
+
"@prismicio/next": "latest",
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
await installDependencies({
|
|
32
|
+
dependencies: {
|
|
33
|
+
"@prismicio/types": "latest",
|
|
34
|
+
},
|
|
35
|
+
dev: true,
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;
|
|
40
|
+
|
|
41
|
+
const createPrismicIOFile = async ({
|
|
42
|
+
helpers,
|
|
43
|
+
options,
|
|
44
|
+
}: CreatePrismicIOFileArgs) => {
|
|
45
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
46
|
+
helpers,
|
|
47
|
+
options,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const filePath = helpers.joinPathFromRoot(
|
|
51
|
+
isTypeScriptProject ? "prismicio.ts" : "prismicio.js",
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (await checkPathExists(filePath)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let contents: string;
|
|
59
|
+
|
|
60
|
+
if (isTypeScriptProject) {
|
|
61
|
+
contents = stripIndent`
|
|
62
|
+
import * as prismic from "@prismicio/client";
|
|
63
|
+
import * as prismicNext from "@prismicio/next";
|
|
64
|
+
import config from "./slicemachine.config.json";
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The project's Prismic repository name.
|
|
68
|
+
*/
|
|
69
|
+
export const repositoryName = config.repositoryName;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A list of Route Resolver objects that define how a document's \`url\` field
|
|
73
|
+
* is resolved.
|
|
74
|
+
*
|
|
75
|
+
* {@link https://prismic.io/docs/route-resolver#route-resolver}
|
|
76
|
+
*/
|
|
77
|
+
// TODO: Update the routes array to match your project's route structure.
|
|
78
|
+
const routes: prismic.ClientConfig["routes"] = [
|
|
79
|
+
{
|
|
80
|
+
type: "homepage",
|
|
81
|
+
path: "/",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: "page",
|
|
85
|
+
path: "/:uid",
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
91
|
+
* query content from the Prismic API.
|
|
92
|
+
*
|
|
93
|
+
* @param config - Configuration for the Prismic client.
|
|
94
|
+
*/
|
|
95
|
+
export const createClient = (config: prismicNext.CreateClientConfig = {}) => {
|
|
96
|
+
const client = prismic.createClient(repositoryName, {
|
|
97
|
+
routes,
|
|
98
|
+
...config,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
prismicNext.enableAutoPreviews({
|
|
102
|
+
client,
|
|
103
|
+
previewData: config.previewData,
|
|
104
|
+
req: config.req,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return client;
|
|
108
|
+
};
|
|
109
|
+
`;
|
|
110
|
+
} else {
|
|
111
|
+
contents = stripIndent`
|
|
112
|
+
import * as prismic from "@prismicio/client";
|
|
113
|
+
import * as prismicNext from "@prismicio/next";
|
|
114
|
+
import config from "./slicemachine.config.json";
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The project's Prismic repository name.
|
|
118
|
+
*/
|
|
119
|
+
export const repositoryName = config.repositoryName;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A list of Route Resolver objects that define how a document's \`url\` field
|
|
123
|
+
* is resolved.
|
|
124
|
+
*
|
|
125
|
+
* {@link https://prismic.io/docs/route-resolver#route-resolver}
|
|
126
|
+
*
|
|
127
|
+
* @type {prismic.ClientConfig["routes"]}
|
|
128
|
+
*/
|
|
129
|
+
// TODO: Update the routes array to match your project's route structure.
|
|
130
|
+
const routes = [
|
|
131
|
+
{
|
|
132
|
+
type: "homepage",
|
|
133
|
+
path: "/",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: "page",
|
|
137
|
+
path: "/:uid",
|
|
138
|
+
},
|
|
139
|
+
];
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Creates a Prismic client for the project's repository. The client is used to
|
|
143
|
+
* query content from the Prismic API.
|
|
144
|
+
*
|
|
145
|
+
* @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.
|
|
146
|
+
*/
|
|
147
|
+
export const createClient = (config = {}) => {
|
|
148
|
+
const client = prismic.createClient(repositoryName, {
|
|
149
|
+
routes,
|
|
150
|
+
...config,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
prismicNext.enableAutoPreviews({
|
|
154
|
+
client,
|
|
155
|
+
previewData: config.previewData,
|
|
156
|
+
req: config.req,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
return client;
|
|
160
|
+
};
|
|
161
|
+
`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (options.format) {
|
|
165
|
+
contents = await helpers.format(contents, filePath);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
await fs.writeFile(filePath, contents);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
type CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;
|
|
172
|
+
|
|
173
|
+
const createSliceSimulatorPage = async ({
|
|
174
|
+
helpers,
|
|
175
|
+
options,
|
|
176
|
+
}: CreateSliceSimulatorPageArgs) => {
|
|
177
|
+
const srcDirectoryExists = await checkPathExists(
|
|
178
|
+
helpers.joinPathFromRoot("src"),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
const filePath = helpers.joinPathFromRoot(
|
|
182
|
+
srcDirectoryExists ? "src/pages" : "pages",
|
|
183
|
+
`slice-simulator.${await getJSOrTSXFileExtension({ helpers, options })}`,
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
if (await checkPathExists(filePath)) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
191
|
+
|
|
192
|
+
let contents = stripIndent`
|
|
193
|
+
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
194
|
+
import { SliceZone } from "@prismicio/react";
|
|
195
|
+
|
|
196
|
+
import { components } from "../slices";
|
|
197
|
+
|
|
198
|
+
const SliceSimulatorPage = () => {
|
|
199
|
+
return (
|
|
200
|
+
<SliceSimulator
|
|
201
|
+
sliceZone={(props) => <SliceZone {...props} components={components} />}
|
|
202
|
+
/>
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export default SliceSimulatorPage;
|
|
207
|
+
`;
|
|
208
|
+
|
|
209
|
+
if (options.format) {
|
|
210
|
+
contents = await helpers.format(contents, filePath);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
await fs.writeFile(filePath, contents);
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export const commandInit: CommandInitHook<PluginOptions> = async (
|
|
217
|
+
{ installDependencies: _installDependencies },
|
|
218
|
+
context,
|
|
219
|
+
) => {
|
|
220
|
+
rejectIfNecessary(
|
|
221
|
+
await Promise.allSettled([
|
|
222
|
+
await installDependencies({ installDependencies: _installDependencies }),
|
|
223
|
+
await createPrismicIOFile(context),
|
|
224
|
+
await createSliceSimulatorPage(context),
|
|
225
|
+
]),
|
|
226
|
+
);
|
|
227
|
+
};
|
|
@@ -7,11 +7,12 @@ import { stripIndent } from "common-tags";
|
|
|
7
7
|
import * as fs from "node:fs/promises";
|
|
8
8
|
import * as path from "node:path";
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
11
11
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
|
|
12
12
|
import { pascalCase } from "../lib/pascalCase";
|
|
13
13
|
import { rejectIfNecessary } from "../lib/rejectIfNecessary";
|
|
14
14
|
import { upsertGlobalContentTypes } from "../lib/upsertGlobalContentTypes";
|
|
15
|
+
import { upsertSliceLibraryIndexFile } from "../lib/upsertSliceLibraryIndexFile";
|
|
15
16
|
|
|
16
17
|
import type { PluginOptions } from "../types";
|
|
17
18
|
|
|
@@ -33,13 +34,21 @@ const createModelFile = async ({ dir, data, helpers, options }: Args) => {
|
|
|
33
34
|
};
|
|
34
35
|
|
|
35
36
|
const createComponentFile = async ({ dir, data, helpers, options }: Args) => {
|
|
36
|
-
const filePath = path.join(
|
|
37
|
+
const filePath = path.join(
|
|
38
|
+
dir,
|
|
39
|
+
`index.${await getJSOrTSXFileExtension({ helpers, options })}`,
|
|
40
|
+
);
|
|
37
41
|
const model = data.model;
|
|
38
42
|
const pascalName = pascalCase(model.name);
|
|
39
43
|
|
|
40
44
|
let contents: string;
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
47
|
+
helpers,
|
|
48
|
+
options,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (isTypeScriptProject) {
|
|
43
52
|
contents = stripIndent`
|
|
44
53
|
import { Content } from "@prismicio/client";
|
|
45
54
|
import { SliceComponentProps } from "@prismicio/react";
|
|
@@ -7,6 +7,7 @@ import { source } from "common-tags";
|
|
|
7
7
|
import { createRequire } from "node:module";
|
|
8
8
|
import fetch from "node-fetch";
|
|
9
9
|
|
|
10
|
+
import { checkIsTypeScriptProject } from "../lib/checkIsTypeScriptProject";
|
|
10
11
|
import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
|
|
11
12
|
|
|
12
13
|
import type { PluginOptions } from "../types";
|
|
@@ -83,12 +84,20 @@ const createStep2 = async ({
|
|
|
83
84
|
helpers,
|
|
84
85
|
options,
|
|
85
86
|
}: Args): Promise<SliceSimulatorSetupStep> => {
|
|
86
|
-
const fileName = `slice-simulator.${getJSOrTSXFileExtension(
|
|
87
|
+
const fileName = `slice-simulator.${await getJSOrTSXFileExtension({
|
|
88
|
+
helpers,
|
|
89
|
+
options,
|
|
90
|
+
})}`;
|
|
87
91
|
const filePath = helpers.joinPathFromRoot("pages", fileName);
|
|
88
92
|
|
|
89
93
|
let fileContents: string;
|
|
90
94
|
|
|
91
|
-
|
|
95
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
96
|
+
helpers,
|
|
97
|
+
options,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (isTypeScriptProject) {
|
|
92
101
|
fileContents = await helpers.format(
|
|
93
102
|
source`
|
|
94
103
|
import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
|
|
3
|
+
import { PluginOptions } from "../types";
|
|
4
|
+
import { checkPathExists } from "./checkPathExists";
|
|
5
|
+
|
|
6
|
+
type CheckIsTypeScriptProjectArgs = {
|
|
7
|
+
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
8
|
+
options: SliceMachineContext<PluginOptions>["options"];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const checkIsTypeScriptProject = async (
|
|
12
|
+
args: CheckIsTypeScriptProjectArgs,
|
|
13
|
+
): Promise<boolean> => {
|
|
14
|
+
const tsConfigPath = args.helpers.joinPathFromRoot("tsconfig.json");
|
|
15
|
+
|
|
16
|
+
return args.options.typescript ?? (await checkPathExists(tsConfigPath));
|
|
17
|
+
};
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
import { SliceMachineContext } from "@slicemachine/plugin-kit";
|
|
2
|
+
|
|
1
3
|
import type { PluginOptions } from "../types";
|
|
4
|
+
import { checkIsTypeScriptProject } from "./checkIsTypeScriptProject";
|
|
5
|
+
|
|
6
|
+
type GetJSOrTSXFileExtensionArgs = {
|
|
7
|
+
helpers: SliceMachineContext<PluginOptions>["helpers"];
|
|
8
|
+
options: SliceMachineContext<PluginOptions>["options"];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const getJSOrTSXFileExtension = async (
|
|
12
|
+
args: GetJSOrTSXFileExtensionArgs,
|
|
13
|
+
): Promise<string> => {
|
|
14
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
15
|
+
helpers: args.helpers,
|
|
16
|
+
options: args.options,
|
|
17
|
+
});
|
|
2
18
|
|
|
3
|
-
|
|
4
|
-
pluginOptions: PluginOptions,
|
|
5
|
-
): string => {
|
|
6
|
-
if (pluginOptions.typescript) {
|
|
19
|
+
if (isTypeScriptProject) {
|
|
7
20
|
return "tsx";
|
|
8
|
-
} else if (
|
|
21
|
+
} else if (args.options.jsxExtension) {
|
|
9
22
|
return "jsx";
|
|
10
23
|
} else {
|
|
11
24
|
return "js";
|
|
@@ -5,6 +5,7 @@ import { NON_EDITABLE_FILE_BANNER } from "../constants";
|
|
|
5
5
|
|
|
6
6
|
import { PluginOptions } from "../types";
|
|
7
7
|
|
|
8
|
+
import { checkIsTypeScriptProject } from "./checkIsTypeScriptProject";
|
|
8
9
|
import { pascalCase } from "./pascalCase";
|
|
9
10
|
|
|
10
11
|
type UpsertSliceLibraryIndexFileArgs = {
|
|
@@ -14,31 +15,64 @@ type UpsertSliceLibraryIndexFileArgs = {
|
|
|
14
15
|
export const upsertSliceLibraryIndexFile = async (
|
|
15
16
|
args: UpsertSliceLibraryIndexFileArgs,
|
|
16
17
|
): Promise<void> => {
|
|
18
|
+
const isTypeScriptProject = await checkIsTypeScriptProject({
|
|
19
|
+
helpers: args.helpers,
|
|
20
|
+
options: args.options,
|
|
21
|
+
});
|
|
22
|
+
|
|
17
23
|
const filePath = args.helpers.joinPathFromRoot(
|
|
18
24
|
args.libraryID,
|
|
19
|
-
|
|
25
|
+
isTypeScriptProject ? "index.ts" : "index.js",
|
|
20
26
|
);
|
|
21
27
|
|
|
22
28
|
const slices = await args.actions.readAllSliceModelsForLibrary({
|
|
23
29
|
libraryID: args.libraryID,
|
|
24
30
|
});
|
|
25
31
|
|
|
26
|
-
let contents
|
|
27
|
-
|
|
32
|
+
let contents: string;
|
|
33
|
+
|
|
34
|
+
if (args.options.lazyLoadSlices) {
|
|
35
|
+
contents = stripIndent`
|
|
36
|
+
${NON_EDITABLE_FILE_BANNER}
|
|
37
|
+
|
|
38
|
+
import dynamic from 'next/dynamic'
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
export const components = {
|
|
41
|
+
${slices
|
|
42
|
+
.map((slice) => {
|
|
43
|
+
const id = slice.model.id;
|
|
44
|
+
const dirName = pascalCase(slice.model.name);
|
|
45
|
+
|
|
46
|
+
return `${id}: dynamic(() => import('./${dirName}'))`;
|
|
47
|
+
})
|
|
48
|
+
.join(",\n")}
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
} else {
|
|
52
|
+
contents = stripIndent`
|
|
53
|
+
${NON_EDITABLE_FILE_BANNER}
|
|
30
54
|
|
|
31
|
-
export const components = {
|
|
32
55
|
${slices
|
|
33
56
|
.map((slice) => {
|
|
34
|
-
const
|
|
57
|
+
const componentName = pascalCase(slice.model.name);
|
|
35
58
|
const dirName = pascalCase(slice.model.name);
|
|
36
59
|
|
|
37
|
-
return
|
|
60
|
+
return `import ${componentName} from "./${dirName}";`;
|
|
38
61
|
})
|
|
39
|
-
.join("
|
|
40
|
-
|
|
41
|
-
|
|
62
|
+
.join("\n")}
|
|
63
|
+
|
|
64
|
+
export const components = {
|
|
65
|
+
${slices
|
|
66
|
+
.map((slice) => {
|
|
67
|
+
const id = slice.model.id;
|
|
68
|
+
const componentName = pascalCase(slice.model.name);
|
|
69
|
+
|
|
70
|
+
return `${id}: ${componentName},`;
|
|
71
|
+
})
|
|
72
|
+
.join("\n")}
|
|
73
|
+
}
|
|
74
|
+
`;
|
|
75
|
+
}
|
|
42
76
|
|
|
43
77
|
if (args.options.format) {
|
|
44
78
|
contents = await args.helpers.format(contents, filePath);
|
package/src/plugin.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { defineSliceMachinePlugin } from "@slicemachine/plugin-kit";
|
|
|
3
3
|
import { name as pkgName } from "../package.json";
|
|
4
4
|
import { PluginOptions } from "./types";
|
|
5
5
|
|
|
6
|
+
import { commandInit } from "./hooks/command-init";
|
|
6
7
|
import { customTypeAssetDelete } from "./hooks/customType-asset-delete";
|
|
7
8
|
import { customTypeAssetRead } from "./hooks/customType-asset-read";
|
|
8
9
|
import { customTypeAssetUpdate } from "./hooks/customType-asset-update";
|
|
@@ -30,8 +31,11 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
|
|
|
30
31
|
},
|
|
31
32
|
defaultOptions: {
|
|
32
33
|
format: true,
|
|
34
|
+
lazyLoadSlices: true,
|
|
33
35
|
},
|
|
34
36
|
setup({ hook }) {
|
|
37
|
+
hook("command:init", commandInit);
|
|
38
|
+
|
|
35
39
|
hook("slice:create", sliceCreate);
|
|
36
40
|
hook("slice:update", sliceUpdate);
|
|
37
41
|
hook("slice:rename", sliceRename);
|