@prismicio/plugin-kit 0.0.1
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/_node_modules/lower-case/dist.es2015/index.js +7 -0
- package/dist/_node_modules/lower-case/dist.es2015/index.js.map +1 -0
- package/dist/_node_modules/no-case/dist.es2015/index.js +28 -0
- package/dist/_node_modules/no-case/dist.es2015/index.js.map +1 -0
- package/dist/_node_modules/p-limit/_node_modules/yocto-queue/index.js +68 -0
- package/dist/_node_modules/p-limit/_node_modules/yocto-queue/index.js.map +1 -0
- package/dist/_node_modules/p-limit/index.js +77 -0
- package/dist/_node_modules/p-limit/index.js.map +1 -0
- package/dist/_node_modules/pascal-case/dist.es2015/index.js +25 -0
- package/dist/_node_modules/pascal-case/dist.es2015/index.js.map +1 -0
- package/dist/_node_modules/tslib/tslib.es6.js +14 -0
- package/dist/_node_modules/tslib/tslib.es6.js.map +1 -0
- package/dist/createPluginHookSystem.d.ts +6 -0
- package/dist/createPluginHookSystem.js +8 -0
- package/dist/createPluginHookSystem.js.map +1 -0
- package/dist/createPluginSystemActions.d.ts +46 -0
- package/dist/createPluginSystemActions.js +96 -0
- package/dist/createPluginSystemActions.js.map +1 -0
- package/dist/createPluginSystemContext.d.ts +31 -0
- package/dist/createPluginSystemContext.js +12 -0
- package/dist/createPluginSystemContext.js.map +1 -0
- package/dist/createPluginSystemHelpers.d.ts +37 -0
- package/dist/createPluginSystemHelpers.js +72 -0
- package/dist/createPluginSystemHelpers.js.map +1 -0
- package/dist/createPluginSystemRunner.d.ts +58 -0
- package/dist/createPluginSystemRunner.js +128 -0
- package/dist/createPluginSystemRunner.js.map +1 -0
- package/dist/definePlugin.d.ts +30 -0
- package/dist/definePlugin.js +5 -0
- package/dist/definePlugin.js.map +1 -0
- package/dist/fs/buildCustomTypeDirectoryPath.d.ts +5 -0
- package/dist/fs/buildCustomTypeDirectoryPath.js +9 -0
- package/dist/fs/buildCustomTypeDirectoryPath.js.map +1 -0
- package/dist/fs/buildCustomTypeFilePath.d.ts +5 -0
- package/dist/fs/buildCustomTypeFilePath.js +9 -0
- package/dist/fs/buildCustomTypeFilePath.js.map +1 -0
- package/dist/fs/buildCustomTypeLibraryDirectoryPath.d.ts +6 -0
- package/dist/fs/buildCustomTypeLibraryDirectoryPath.js +8 -0
- package/dist/fs/buildCustomTypeLibraryDirectoryPath.js.map +1 -0
- package/dist/fs/buildSliceDirectoryPath.d.ts +4 -0
- package/dist/fs/buildSliceDirectoryPath.js +12 -0
- package/dist/fs/buildSliceDirectoryPath.js.map +1 -0
- package/dist/fs/buildSliceFilePath.d.ts +5 -0
- package/dist/fs/buildSliceFilePath.js +9 -0
- package/dist/fs/buildSliceFilePath.js.map +1 -0
- package/dist/fs/buildSliceLibraryDirectoryPath.d.ts +7 -0
- package/dist/fs/buildSliceLibraryDirectoryPath.js +8 -0
- package/dist/fs/buildSliceLibraryDirectoryPath.js.map +1 -0
- package/dist/fs/checkHasProjectFile.d.ts +6 -0
- package/dist/fs/checkHasProjectFile.js +9 -0
- package/dist/fs/checkHasProjectFile.js.map +1 -0
- package/dist/fs/checkIsTypeScriptProject.d.ts +4 -0
- package/dist/fs/checkIsTypeScriptProject.js +12 -0
- package/dist/fs/checkIsTypeScriptProject.js.map +1 -0
- package/dist/fs/constants.d.ts +9 -0
- package/dist/fs/constants.js +15 -0
- package/dist/fs/constants.js.map +1 -0
- package/dist/fs/deleteCustomTypeDirectory.d.ts +3 -0
- package/dist/fs/deleteCustomTypeDirectory.js +18 -0
- package/dist/fs/deleteCustomTypeDirectory.js.map +1 -0
- package/dist/fs/deleteProjectFile.d.ts +6 -0
- package/dist/fs/deleteProjectFile.js +10 -0
- package/dist/fs/deleteProjectFile.js.map +1 -0
- package/dist/fs/deleteSliceDirectory.d.ts +3 -0
- package/dist/fs/deleteSliceDirectory.js +18 -0
- package/dist/fs/deleteSliceDirectory.js.map +1 -0
- package/dist/fs/deleteSliceFile.d.ts +3 -0
- package/dist/fs/deleteSliceFile.js +18 -0
- package/dist/fs/deleteSliceFile.js.map +1 -0
- package/dist/fs/index.d.ts +49 -0
- package/dist/fs/index.js +53 -0
- package/dist/fs/index.js.map +1 -0
- package/dist/fs/lib/checkPathExists.d.ts +2 -0
- package/dist/fs/lib/checkPathExists.js +13 -0
- package/dist/fs/lib/checkPathExists.js.map +1 -0
- package/dist/fs/lib/fsLimit.d.ts +31 -0
- package/dist/fs/lib/fsLimit.js +23 -0
- package/dist/fs/lib/fsLimit.js.map +1 -0
- package/dist/fs/lib/isCustomTypeModel.d.ts +2 -0
- package/dist/fs/lib/isCustomTypeModel.js +7 -0
- package/dist/fs/lib/isCustomTypeModel.js.map +1 -0
- package/dist/fs/lib/isSharedSliceModel.d.ts +2 -0
- package/dist/fs/lib/isSharedSliceModel.js +7 -0
- package/dist/fs/lib/isSharedSliceModel.js.map +1 -0
- package/dist/fs/lib/pascalCase.d.ts +8 -0
- package/dist/fs/lib/pascalCase.js +10 -0
- package/dist/fs/lib/pascalCase.js.map +1 -0
- package/dist/fs/lib/readJSONFile.d.ts +1 -0
- package/dist/fs/lib/readJSONFile.js +9 -0
- package/dist/fs/lib/readJSONFile.js.map +1 -0
- package/dist/fs/lib/resolveSliceModel.d.ts +10 -0
- package/dist/fs/lib/resolveSliceModel.js +14 -0
- package/dist/fs/lib/resolveSliceModel.js.map +1 -0
- package/dist/fs/readCustomTypeFile.d.ts +8 -0
- package/dist/fs/readCustomTypeFile.js +14 -0
- package/dist/fs/readCustomTypeFile.js.map +1 -0
- package/dist/fs/readCustomTypeLibrary.d.ts +6 -0
- package/dist/fs/readCustomTypeLibrary.js +53 -0
- package/dist/fs/readCustomTypeLibrary.js.map +1 -0
- package/dist/fs/readCustomTypeModel.d.ts +7 -0
- package/dist/fs/readCustomTypeModel.js +16 -0
- package/dist/fs/readCustomTypeModel.js.map +1 -0
- package/dist/fs/readProjectFile.d.ts +12 -0
- package/dist/fs/readProjectFile.js +9 -0
- package/dist/fs/readProjectFile.js.map +1 -0
- package/dist/fs/readSliceFile.d.ts +8 -0
- package/dist/fs/readSliceFile.js +17 -0
- package/dist/fs/readSliceFile.js.map +1 -0
- package/dist/fs/readSliceLibrary.d.ts +7 -0
- package/dist/fs/readSliceLibrary.js +56 -0
- package/dist/fs/readSliceLibrary.js.map +1 -0
- package/dist/fs/readSliceModel.d.ts +11 -0
- package/dist/fs/readSliceModel.js +46 -0
- package/dist/fs/readSliceModel.js.map +1 -0
- package/dist/fs/renameCustomType.d.ts +3 -0
- package/dist/fs/renameCustomType.js +8 -0
- package/dist/fs/renameCustomType.js.map +1 -0
- package/dist/fs/renameSlice.d.ts +7 -0
- package/dist/fs/renameSlice.js +22 -0
- package/dist/fs/renameSlice.js.map +1 -0
- package/dist/fs/types.d.ts +3 -0
- package/dist/fs/upsertGlobalTypeScriptTypes.d.ts +16 -0
- package/dist/fs/upsertGlobalTypeScriptTypes.js +37 -0
- package/dist/fs/upsertGlobalTypeScriptTypes.js.map +1 -0
- package/dist/fs/writeCustomTypeFile.d.ts +9 -0
- package/dist/fs/writeCustomTypeFile.js +18 -0
- package/dist/fs/writeCustomTypeFile.js.map +1 -0
- package/dist/fs/writeCustomTypeModel.d.ts +12 -0
- package/dist/fs/writeCustomTypeModel.js +14 -0
- package/dist/fs/writeCustomTypeModel.js.map +1 -0
- package/dist/fs/writeProjectFile.d.ts +15 -0
- package/dist/fs/writeProjectFile.js +16 -0
- package/dist/fs/writeProjectFile.js.map +1 -0
- package/dist/fs/writeSliceFile.d.ts +9 -0
- package/dist/fs/writeSliceFile.js +18 -0
- package/dist/fs/writeSliceFile.js.map +1 -0
- package/dist/fs/writeSliceModel.d.ts +11 -0
- package/dist/fs/writeSliceModel.js +13 -0
- package/dist/fs/writeSliceModel.js.map +1 -0
- package/dist/hooks/customType-create.d.ts +28 -0
- package/dist/hooks/customType-delete.d.ts +26 -0
- package/dist/hooks/customType-read.d.ts +32 -0
- package/dist/hooks/customType-rename.d.ts +29 -0
- package/dist/hooks/customType-update.d.ts +29 -0
- package/dist/hooks/customTypeLibrary-read.d.ts +25 -0
- package/dist/hooks/debug.d.ts +22 -0
- package/dist/hooks/project-init.d.ts +35 -0
- package/dist/hooks/slice-create.d.ts +30 -0
- package/dist/hooks/slice-delete.d.ts +26 -0
- package/dist/hooks/slice-read.d.ts +32 -0
- package/dist/hooks/slice-rename.d.ts +26 -0
- package/dist/hooks/slice-update.d.ts +29 -0
- package/dist/hooks/sliceLibrary-read.d.ts +27 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/DecodeError.d.ts +13 -0
- package/dist/lib/DecodeError.js +21 -0
- package/dist/lib/DecodeError.js.map +1 -0
- package/dist/lib/HookSystem.d.ts +93 -0
- package/dist/lib/HookSystem.js +121 -0
- package/dist/lib/HookSystem.js.map +1 -0
- package/dist/lib/decode.d.ts +10 -0
- package/dist/lib/decode.js +16 -0
- package/dist/lib/decode.js.map +1 -0
- package/dist/lib/decodePrismicConfig.d.ts +3 -0
- package/dist/lib/decodePrismicConfig.js +22 -0
- package/dist/lib/decodePrismicConfig.js.map +1 -0
- package/dist/types.d.ts +129 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +90 -0
- package/src/createPluginHookSystem.ts +9 -0
- package/src/createPluginSystemActions.ts +188 -0
- package/src/createPluginSystemContext.ts +51 -0
- package/src/createPluginSystemHelpers.ts +129 -0
- package/src/createPluginSystemRunner.ts +216 -0
- package/src/definePlugin.ts +48 -0
- package/src/fs/buildCustomTypeDirectoryPath.ts +19 -0
- package/src/fs/buildCustomTypeFilePath.ts +16 -0
- package/src/fs/buildCustomTypeLibraryDirectoryPath.ts +16 -0
- package/src/fs/buildSliceDirectoryPath.ts +25 -0
- package/src/fs/buildSliceFilePath.ts +16 -0
- package/src/fs/buildSliceLibraryDirectoryPath.ts +17 -0
- package/src/fs/checkHasProjectFile.ts +16 -0
- package/src/fs/checkIsTypeScriptProject.ts +16 -0
- package/src/fs/constants.ts +15 -0
- package/src/fs/deleteCustomTypeDirectory.ts +24 -0
- package/src/fs/deleteProjectFile.ts +18 -0
- package/src/fs/deleteSliceDirectory.ts +24 -0
- package/src/fs/deleteSliceFile.ts +24 -0
- package/src/fs/index.ts +103 -0
- package/src/fs/lib/checkPathExists.ts +13 -0
- package/src/fs/lib/fsLimit.ts +72 -0
- package/src/fs/lib/isCustomTypeModel.ts +7 -0
- package/src/fs/lib/isSharedSliceModel.ts +14 -0
- package/src/fs/lib/pascalCase.ts +17 -0
- package/src/fs/lib/readJSONFile.ts +7 -0
- package/src/fs/lib/resolveSliceModel.ts +28 -0
- package/src/fs/readCustomTypeFile.ts +27 -0
- package/src/fs/readCustomTypeLibrary.ts +86 -0
- package/src/fs/readCustomTypeModel.ts +27 -0
- package/src/fs/readProjectFile.ts +24 -0
- package/src/fs/readSliceFile.ts +27 -0
- package/src/fs/readSliceLibrary.ts +91 -0
- package/src/fs/readSliceModel.ts +90 -0
- package/src/fs/renameCustomType.ts +12 -0
- package/src/fs/renameSlice.ts +35 -0
- package/src/fs/types.ts +5 -0
- package/src/fs/upsertGlobalTypeScriptTypes.ts +64 -0
- package/src/fs/writeCustomTypeFile.ts +30 -0
- package/src/fs/writeCustomTypeModel.ts +31 -0
- package/src/fs/writeProjectFile.ts +39 -0
- package/src/fs/writeSliceFile.ts +30 -0
- package/src/fs/writeSliceModel.ts +26 -0
- package/src/hooks/customType-create.ts +42 -0
- package/src/hooks/customType-delete.ts +40 -0
- package/src/hooks/customType-read.ts +46 -0
- package/src/hooks/customType-rename.ts +43 -0
- package/src/hooks/customType-update.ts +43 -0
- package/src/hooks/customTypeLibrary-read.ts +38 -0
- package/src/hooks/debug.ts +31 -0
- package/src/hooks/project-init.ts +48 -0
- package/src/hooks/slice-create.ts +44 -0
- package/src/hooks/slice-delete.ts +40 -0
- package/src/hooks/slice-read.ts +44 -0
- package/src/hooks/slice-rename.ts +40 -0
- package/src/hooks/slice-update.ts +43 -0
- package/src/hooks/sliceLibrary-read.ts +41 -0
- package/src/index.ts +141 -0
- package/src/lib/DecodeError.ts +31 -0
- package/src/lib/HookSystem.ts +277 -0
- package/src/lib/decode.ts +30 -0
- package/src/lib/decodePrismicConfig.ts +26 -0
- package/src/types.ts +175 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { buildSliceLibraryDirectoryPath } from "./buildSliceLibraryDirectoryPath.js";
|
|
3
|
+
import { SHARED_SLICE_MODEL_FILENAME } from "./constants.js";
|
|
4
|
+
import { checkPathExists } from "./lib/checkPathExists.js";
|
|
5
|
+
import { readdir } from "./lib/fsLimit.js";
|
|
6
|
+
import { isSharedSliceModel } from "./lib/isSharedSliceModel.js";
|
|
7
|
+
import { readJSONFile } from "./lib/readJSONFile.js";
|
|
8
|
+
const readSliceModel = async (args) => {
|
|
9
|
+
const libraryDir = buildSliceLibraryDirectoryPath({
|
|
10
|
+
libraryID: args.libraryID,
|
|
11
|
+
absolute: true,
|
|
12
|
+
helpers: args.helpers
|
|
13
|
+
});
|
|
14
|
+
if (await checkPathExists(libraryDir)) {
|
|
15
|
+
const childDirs = await readdir(libraryDir, { withFileTypes: true });
|
|
16
|
+
const unreadableModelPaths = [];
|
|
17
|
+
const models = await Promise.all(childDirs.map(async (childDir) => {
|
|
18
|
+
if (childDir.isDirectory()) {
|
|
19
|
+
const modelPath = path.join(libraryDir, childDir.name, SHARED_SLICE_MODEL_FILENAME);
|
|
20
|
+
try {
|
|
21
|
+
const modelContents = await readJSONFile(modelPath);
|
|
22
|
+
if (isSharedSliceModel(modelContents) && modelContents.id === args.sliceID) {
|
|
23
|
+
return modelContents;
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
unreadableModelPaths.push(modelPath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
const [model] = models.filter((model2) => isSharedSliceModel(model2));
|
|
31
|
+
if (model) {
|
|
32
|
+
return {
|
|
33
|
+
model
|
|
34
|
+
};
|
|
35
|
+
} else {
|
|
36
|
+
if (unreadableModelPaths.length > 0) {
|
|
37
|
+
throw new Error(`Did not find a Slice model with ID "${args.sliceID}" in the "${args.libraryID}" Slice Library. The following Slice models could not be read: [${unreadableModelPaths.join(", ")}]`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Did not find a Slice model with ID "${args.sliceID}" in the "${args.libraryID}" Slice Library.`);
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
readSliceModel
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=readSliceModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readSliceModel.js","sources":["../../../src/fs/readSliceModel.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport TypesInternal from \"@prismicio/types-internal/lib/customtypes/index.js\";\n\nimport { PluginSystemHelpers } from \"../createPluginSystemHelpers\";\n\nimport { buildSliceLibraryDirectoryPath } from \"./buildSliceLibraryDirectoryPath\";\nimport { SHARED_SLICE_MODEL_FILENAME } from \"./constants\";\nimport { checkPathExists } from \"./lib/checkPathExists\";\nimport * as fs from \"./lib/fsLimit\";\nimport { isSharedSliceModel } from \"./lib/isSharedSliceModel\";\nimport { readJSONFile } from \"./lib/readJSONFile\";\n\nexport type ReadSliceModelArgs = {\n\tlibraryID: string;\n\tsliceID: string;\n\thelpers: PluginSystemHelpers;\n};\n\nexport type ReadSliceModelReturnType = {\n\tmodel: TypesInternal.SharedSlice;\n};\n\nexport const readSliceModel = async (\n\targs: ReadSliceModelArgs,\n): Promise<ReadSliceModelReturnType> => {\n\tconst libraryDir = buildSliceLibraryDirectoryPath({\n\t\tlibraryID: args.libraryID,\n\t\tabsolute: true,\n\t\thelpers: args.helpers,\n\t});\n\n\tif (await checkPathExists(libraryDir)) {\n\t\tconst childDirs = await fs.readdir(libraryDir, { withFileTypes: true });\n\n\t\t/**\n\t\t * Paths to models that could not be read due to invalid JSON.\n\t\t */\n\t\tconst unreadableModelPaths: string[] = [];\n\n\t\t// Find the first matching model.\n\t\tconst models: (TypesInternal.SharedSlice | undefined)[] = await Promise.all(\n\t\t\tchildDirs.map(async (childDir) => {\n\t\t\t\tif (childDir.isDirectory()) {\n\t\t\t\t\tconst modelPath = path.join(\n\t\t\t\t\t\tlibraryDir,\n\t\t\t\t\t\tchildDir.name,\n\t\t\t\t\t\tSHARED_SLICE_MODEL_FILENAME,\n\t\t\t\t\t);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst modelContents = await readJSONFile(modelPath);\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tisSharedSliceModel(modelContents) &&\n\t\t\t\t\t\t\tmodelContents.id === args.sliceID\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn modelContents;\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tunreadableModelPaths.push(modelPath);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}),\n\t\t);\n\t\tconst [model] = models.filter((model): model is TypesInternal.SharedSlice =>\n\t\t\tisSharedSliceModel(model),\n\t\t);\n\n\t\tif (model) {\n\t\t\treturn {\n\t\t\t\tmodel,\n\t\t\t};\n\t\t} else {\n\t\t\tif (unreadableModelPaths.length > 0) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Did not find a Slice model with ID \"${args.sliceID}\" in the \"${\n\t\t\t\t\t\targs.libraryID\n\t\t\t\t\t}\" Slice Library. The following Slice models could not be read: [${unreadableModelPaths.join(\n\t\t\t\t\t\t\", \",\n\t\t\t\t\t)}]`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tthrow new Error(\n\t\t`Did not find a Slice model with ID \"${args.sliceID}\" in the \"${args.libraryID}\" Slice Library.`,\n\t);\n};\n"],"names":["fs.readdir","model"],"mappings":";;;;;;;AAuBO,MAAM,iBAAiB,OAC7B,SACsC;AACtC,QAAM,aAAa,+BAA+B;AAAA,IACjD,WAAW,KAAK;AAAA,IAChB,UAAU;AAAA,IACV,SAAS,KAAK;AAAA,EAAA,CACd;AAED,MAAI,MAAM,gBAAgB,UAAU,GAAG;AACtC,UAAM,YAAY,MAAMA,QAAW,YAAY,EAAE,eAAe,MAAM;AAKtE,UAAM,uBAAiC,CAAA;AAGvC,UAAM,SAAoD,MAAM,QAAQ,IACvE,UAAU,IAAI,OAAO,aAAY;AAChC,UAAI,SAAS,eAAe;AAC3B,cAAM,YAAY,KAAK,KACtB,YACA,SAAS,MACT,2BAA2B;AAG5B,YAAI;AACH,gBAAM,gBAAgB,MAAM,aAAa,SAAS;AAElD,cACC,mBAAmB,aAAa,KAChC,cAAc,OAAO,KAAK,SACzB;AACD,mBAAO;AAAA,UACR;AAAA,QACD,QAAQ;AACP,+BAAqB,KAAK,SAAS;AAAA,QACpC;AAAA,MACD;AAAA,IACD,CAAC,CAAC;AAEH,UAAM,CAAC,KAAK,IAAI,OAAO,OAAO,CAACC,WAC9B,mBAAmBA,MAAK,CAAC;AAG1B,QAAI,OAAO;AACV,aAAO;AAAA,QACN;AAAA,MAAA;AAAA,IAEF,OAAO;AACN,UAAI,qBAAqB,SAAS,GAAG;AACpC,cAAM,IAAI,MACT,uCAAuC,KAAK,OAAO,aAClD,KAAK,SACN,mEAAmE,qBAAqB,KACvF,IAAI,CACJ,GAAG;AAAA,MAEN;AAAA,IACD;AAAA,EACD;AAEA,QAAM,IAAI,MACT,uCAAuC,KAAK,OAAO,aAAa,KAAK,SAAS,kBAAkB;AAElG;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameCustomType.js","sources":["../../../src/fs/renameCustomType.ts"],"sourcesContent":["import {\n\twriteCustomTypeModel,\n\tWriteCustomTypeModelArgs,\n} from \"./writeCustomTypeModel\";\n\nexport type RenameCustomTypeArgs = WriteCustomTypeModelArgs;\n\nexport const renameCustomType = async (\n\targs: RenameCustomTypeArgs,\n): Promise<void> => {\n\tawait writeCustomTypeModel(args);\n};\n"],"names":[],"mappings":";AAOO,MAAM,mBAAmB,OAC/B,SACkB;AAClB,QAAM,qBAAqB,IAAI;AAChC;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PluginSystemActions } from "../createPluginSystemActions.js";
|
|
2
|
+
import { BuildSliceDirectoryPathArgs } from "./buildSliceDirectoryPath.js";
|
|
3
|
+
import { WriteSliceModelArgs } from "./writeSliceModel.js";
|
|
4
|
+
export type RenameSliceArgs = {
|
|
5
|
+
actions: PluginSystemActions;
|
|
6
|
+
} & Omit<BuildSliceDirectoryPathArgs, "sliceID"> & WriteSliceModelArgs;
|
|
7
|
+
export declare const renameSlice: (args: RenameSliceArgs) => Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as fse from "fs-extra";
|
|
2
|
+
import { buildSliceDirectoryPath } from "./buildSliceDirectoryPath.js";
|
|
3
|
+
import { writeSliceModel } from "./writeSliceModel.js";
|
|
4
|
+
const renameSlice = async (args) => {
|
|
5
|
+
const { model: existingModel } = await args.actions.readSliceModel({
|
|
6
|
+
libraryID: args.libraryID,
|
|
7
|
+
sliceID: args.model.id
|
|
8
|
+
});
|
|
9
|
+
await fse.move(await buildSliceDirectoryPath({
|
|
10
|
+
...args,
|
|
11
|
+
model: existingModel,
|
|
12
|
+
absolute: true
|
|
13
|
+
}), await buildSliceDirectoryPath({
|
|
14
|
+
...args,
|
|
15
|
+
absolute: true
|
|
16
|
+
}));
|
|
17
|
+
await writeSliceModel(args);
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
renameSlice
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=renameSlice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renameSlice.js","sources":["../../../src/fs/renameSlice.ts"],"sourcesContent":["import * as fse from \"fs-extra\";\n\nimport { PluginSystemActions } from \"../createPluginSystemActions\";\n\nimport {\n\tbuildSliceDirectoryPath,\n\tBuildSliceDirectoryPathArgs,\n} from \"./buildSliceDirectoryPath\";\nimport { writeSliceModel, WriteSliceModelArgs } from \"./writeSliceModel\";\n\nexport type RenameSliceArgs = {\n\tactions: PluginSystemActions;\n} & Omit<BuildSliceDirectoryPathArgs, \"sliceID\"> &\n\tWriteSliceModelArgs;\n\nexport const renameSlice = async (args: RenameSliceArgs): Promise<void> => {\n\tconst { model: existingModel } = await args.actions.readSliceModel({\n\t\tlibraryID: args.libraryID,\n\t\tsliceID: args.model.id,\n\t});\n\n\tawait fse.move(\n\t\tawait buildSliceDirectoryPath({\n\t\t\t...args,\n\t\t\tmodel: existingModel,\n\t\t\tabsolute: true,\n\t\t}),\n\t\tawait buildSliceDirectoryPath({\n\t\t\t...args,\n\t\t\tabsolute: true,\n\t\t}),\n\t);\n\n\tawait writeSliceModel(args);\n};\n"],"names":[],"mappings":";;;AAeO,MAAM,cAAc,OAAO,SAAwC;AACzE,QAAM,EAAE,OAAO,cAAA,IAAkB,MAAM,KAAK,QAAQ,eAAe;AAAA,IAClE,WAAW,KAAK;AAAA,IAChB,SAAS,KAAK,MAAM;AAAA,EAAA,CACpB;AAED,QAAM,IAAI,KACT,MAAM,wBAAwB;AAAA,IAC7B,GAAG;AAAA,IACH,OAAO;AAAA,IACP,UAAU;AAAA,EAAA,CACV,GACD,MAAM,wBAAwB;AAAA,IAC7B,GAAG;AAAA,IACH,UAAU;AAAA,EAAA,CACV,CAAC;AAGH,QAAM,gBAAgB,IAAI;AAC3B;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PluginSystemActions } from "../createPluginSystemActions.js";
|
|
2
|
+
import { WriteProjectFileArgs } from "./writeProjectFile.js";
|
|
3
|
+
/**
|
|
4
|
+
* Arguments for `upsertGlobalContentTypes()`.
|
|
5
|
+
*/
|
|
6
|
+
export type UpsertGlobalTypeScriptTypesArgs = {
|
|
7
|
+
filename?: string;
|
|
8
|
+
actions: PluginSystemActions;
|
|
9
|
+
} & Omit<WriteProjectFileArgs, "filename" | "contents">;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a globally accessible TypeScript file containing types representing
|
|
12
|
+
* the Prismic repository's content.
|
|
13
|
+
*
|
|
14
|
+
* @returns The file path to the written file.
|
|
15
|
+
*/
|
|
16
|
+
export declare const upsertGlobalTypeScriptTypes: (args: UpsertGlobalTypeScriptTypesArgs) => Promise<string>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { generateTypes, detectTypesProvider } from "prismic-ts-codegen";
|
|
2
|
+
import { GLOBAL_TYPESCRIPT_TYPES_FILENAME, NON_EDITABLE_FILE_BANNER } from "./constants.js";
|
|
3
|
+
import { writeProjectFile } from "./writeProjectFile.js";
|
|
4
|
+
const upsertGlobalTypeScriptTypes = async (args) => {
|
|
5
|
+
const project = await args.helpers.getProject();
|
|
6
|
+
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
7
|
+
args.actions.readAllCustomTypeModels(),
|
|
8
|
+
args.actions.readAllSliceModels()
|
|
9
|
+
]);
|
|
10
|
+
const customTypeModels = customTypeModelDescriptors.map((customTypeModelDescriptors2) => {
|
|
11
|
+
return customTypeModelDescriptors2.model;
|
|
12
|
+
});
|
|
13
|
+
const sharedSliceModels = sharedSliceModelDescriptors.map((sharedSliceModelDescriptors2) => {
|
|
14
|
+
return sharedSliceModelDescriptors2.model;
|
|
15
|
+
});
|
|
16
|
+
let contents = generateTypes({
|
|
17
|
+
customTypeModels,
|
|
18
|
+
sharedSliceModels,
|
|
19
|
+
clientIntegration: {
|
|
20
|
+
includeCreateClientInterface: true,
|
|
21
|
+
includeContentNamespace: true
|
|
22
|
+
},
|
|
23
|
+
typesProvider: await detectTypesProvider({ cwd: project.root })
|
|
24
|
+
});
|
|
25
|
+
contents = `${NON_EDITABLE_FILE_BANNER}
|
|
26
|
+
|
|
27
|
+
${contents}`;
|
|
28
|
+
return await writeProjectFile({
|
|
29
|
+
...args,
|
|
30
|
+
filename: args.filename || GLOBAL_TYPESCRIPT_TYPES_FILENAME,
|
|
31
|
+
contents
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export {
|
|
35
|
+
upsertGlobalTypeScriptTypes
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=upsertGlobalTypeScriptTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsertGlobalTypeScriptTypes.js","sources":["../../../src/fs/upsertGlobalTypeScriptTypes.ts"],"sourcesContent":["import { detectTypesProvider, generateTypes } from \"prismic-ts-codegen\";\n\nimport { PluginSystemActions } from \"../createPluginSystemActions\";\n\nimport {\n\tGLOBAL_TYPESCRIPT_TYPES_FILENAME,\n\tNON_EDITABLE_FILE_BANNER,\n} from \"./constants\";\nimport { writeProjectFile, WriteProjectFileArgs } from \"./writeProjectFile\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\nexport type UpsertGlobalTypeScriptTypesArgs = {\n\tfilename?: string;\n\tactions: PluginSystemActions;\n} & Omit<WriteProjectFileArgs, \"filename\" | \"contents\">;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n *\n * @returns The file path to the written file.\n */\nexport const upsertGlobalTypeScriptTypes = async (\n\targs: UpsertGlobalTypeScriptTypesArgs,\n): Promise<string> => {\n\tconst project = await args.helpers.getProject();\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\targs.actions.readAllCustomTypeModels(),\n\t\t\targs.actions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t\ttypesProvider: await detectTypesProvider({ cwd: project.root }),\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\treturn await writeProjectFile({\n\t\t...args,\n\t\tfilename: args.filename || GLOBAL_TYPESCRIPT_TYPES_FILENAME,\n\t\tcontents,\n\t});\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors"],"mappings":";;;AAwBO,MAAM,8BAA8B,OAC1C,SACoB;AACpB,QAAM,UAAU,MAAM,KAAK,QAAQ,WAAA;AAEnC,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,KAAK,QAAQ,wBAAA;AAAA,IACb,KAAK,QAAQ,mBAAA;AAAA,EAAkB,CAC/B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EACnC,CAAC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EACpC,CAAC;AAGF,MAAI,WAAW,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IAAA;AAAA,IAE1B,eAAe,MAAM,oBAAoB,EAAE,KAAK,QAAQ,MAAM;AAAA,EAAA,CAC9D;AAED,aAAW,GAAG,wBAAwB;AAAA;AAAA,EAAO,QAAQ;AAErD,SAAO,MAAM,iBAAiB;AAAA,IAC7B,GAAG;AAAA,IACH,UAAU,KAAK,YAAY;AAAA,IAC3B;AAAA,EAAA,CACA;AACF;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuildCustomTypeFilePathArgs } from "./buildCustomTypeFilePath.js";
|
|
2
|
+
import { WriteProjectFileArgs } from "./writeProjectFile.js";
|
|
3
|
+
export type WriteCustomTypeFileArgs = Omit<WriteProjectFileArgs, "filePath"> & BuildCustomTypeFilePathArgs;
|
|
4
|
+
/**
|
|
5
|
+
* Writes a custom type model to the file system.
|
|
6
|
+
*
|
|
7
|
+
* @returns The file path to the written file.
|
|
8
|
+
*/
|
|
9
|
+
export declare const writeCustomTypeFile: (args: WriteCustomTypeFileArgs) => Promise<string>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { buildCustomTypeFilePath } from "./buildCustomTypeFilePath.js";
|
|
2
|
+
import { writeProjectFile } from "./writeProjectFile.js";
|
|
3
|
+
const writeCustomTypeFile = async (args) => {
|
|
4
|
+
const filePath = buildCustomTypeFilePath(args);
|
|
5
|
+
const relativeFilePath = buildCustomTypeFilePath({
|
|
6
|
+
...args,
|
|
7
|
+
absolute: false
|
|
8
|
+
});
|
|
9
|
+
await writeProjectFile({
|
|
10
|
+
...args,
|
|
11
|
+
filename: relativeFilePath
|
|
12
|
+
});
|
|
13
|
+
return filePath;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
writeCustomTypeFile
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=writeCustomTypeFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeCustomTypeFile.js","sources":["../../../src/fs/writeCustomTypeFile.ts"],"sourcesContent":["import {\n\tbuildCustomTypeFilePath,\n\tBuildCustomTypeFilePathArgs,\n} from \"./buildCustomTypeFilePath\";\nimport { writeProjectFile, WriteProjectFileArgs } from \"./writeProjectFile\";\n\nexport type WriteCustomTypeFileArgs = Omit<WriteProjectFileArgs, \"filePath\"> &\n\tBuildCustomTypeFilePathArgs;\n\n/**\n * Writes a custom type model to the file system.\n *\n * @returns The file path to the written file.\n */\nexport const writeCustomTypeFile = async (\n\targs: WriteCustomTypeFileArgs,\n): Promise<string> => {\n\tconst filePath = buildCustomTypeFilePath(args);\n\tconst relativeFilePath = buildCustomTypeFilePath({\n\t\t...args,\n\t\tabsolute: false,\n\t});\n\n\tawait writeProjectFile({\n\t\t...args,\n\t\tfilename: relativeFilePath,\n\t});\n\n\treturn filePath;\n};\n"],"names":[],"mappings":";;AAcO,MAAM,sBAAsB,OAClC,SACoB;AACpB,QAAM,WAAW,wBAAwB,IAAI;AAC7C,QAAM,mBAAmB,wBAAwB;AAAA,IAChD,GAAG;AAAA,IACH,UAAU;AAAA,EAAA,CACV;AAED,QAAM,iBAAiB;AAAA,IACtB,GAAG;AAAA,IACH,UAAU;AAAA,EAAA,CACV;AAED,SAAO;AACR;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
|
|
2
|
+
import { WriteCustomTypeFileArgs } from "./writeCustomTypeFile.js";
|
|
3
|
+
export type WriteCustomTypeModelArgs = Omit<WriteCustomTypeFileArgs, "customTypeID" | "filename" | "contents"> & {
|
|
4
|
+
model: TypesInternal.CustomType;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Writes a CustomType model to the file system in the CustomType's CustomType
|
|
8
|
+
* library.
|
|
9
|
+
*
|
|
10
|
+
* @returns The file path to the written model.
|
|
11
|
+
*/
|
|
12
|
+
export declare const writeCustomTypeModel: (args: WriteCustomTypeModelArgs) => Promise<string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CUSTOM_TYPE_MODEL_FILENAME } from "./constants.js";
|
|
2
|
+
import { writeCustomTypeFile } from "./writeCustomTypeFile.js";
|
|
3
|
+
const writeCustomTypeModel = async (args) => {
|
|
4
|
+
return await writeCustomTypeFile({
|
|
5
|
+
...args,
|
|
6
|
+
customTypeID: args.model.id,
|
|
7
|
+
filename: CUSTOM_TYPE_MODEL_FILENAME,
|
|
8
|
+
contents: JSON.stringify(args.model, null, 2)
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
export {
|
|
12
|
+
writeCustomTypeModel
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=writeCustomTypeModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeCustomTypeModel.js","sources":["../../../src/fs/writeCustomTypeModel.ts"],"sourcesContent":["import TypesInternal from \"@prismicio/types-internal/lib/customtypes/index.js\";\n\nimport { CUSTOM_TYPE_MODEL_FILENAME } from \"./constants\";\nimport {\n\twriteCustomTypeFile,\n\tWriteCustomTypeFileArgs,\n} from \"./writeCustomTypeFile\";\n\nexport type WriteCustomTypeModelArgs = Omit<\n\tWriteCustomTypeFileArgs,\n\t\"customTypeID\" | \"filename\" | \"contents\"\n> & {\n\tmodel: TypesInternal.CustomType;\n};\n\n/**\n * Writes a CustomType model to the file system in the CustomType's CustomType\n * library.\n *\n * @returns The file path to the written model.\n */\nexport const writeCustomTypeModel = async (\n\targs: WriteCustomTypeModelArgs,\n): Promise<string> => {\n\treturn await writeCustomTypeFile({\n\t\t...args,\n\t\tcustomTypeID: args.model.id,\n\t\tfilename: CUSTOM_TYPE_MODEL_FILENAME,\n\t\tcontents: JSON.stringify(args.model, null, 2),\n\t});\n};\n"],"names":[],"mappings":";;AAqBO,MAAM,uBAAuB,OACnC,SACoB;AACpB,SAAO,MAAM,oBAAoB;AAAA,IAChC,GAAG;AAAA,IACH,cAAc,KAAK,MAAM;AAAA,IACzB,UAAU;AAAA,IACV,UAAU,KAAK,UAAU,KAAK,OAAO,MAAM,CAAC;AAAA,EAAA,CAC5C;AACF;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PluginSystemHelpers } from "../createPluginSystemHelpers.js";
|
|
2
|
+
import * as fs from "./lib/fsLimit.js";
|
|
3
|
+
export type WriteProjectFileArgs = {
|
|
4
|
+
filename: string;
|
|
5
|
+
contents: Parameters<typeof fs.writeFile>[1];
|
|
6
|
+
format?: boolean;
|
|
7
|
+
formatOptions?: Parameters<PluginSystemHelpers["format"]>[2];
|
|
8
|
+
helpers: PluginSystemHelpers;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Writes a file to the project with optional formatting.
|
|
12
|
+
*
|
|
13
|
+
* @returns The file path to the written file.
|
|
14
|
+
*/
|
|
15
|
+
export declare const writeProjectFile: (args: WriteProjectFileArgs) => Promise<string>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { mkdir, writeFile } from "./lib/fsLimit.js";
|
|
3
|
+
const writeProjectFile = async (args) => {
|
|
4
|
+
const filePath = args.helpers.joinPathFromRoot(args.filename);
|
|
5
|
+
let contents = args.contents;
|
|
6
|
+
if (args.format) {
|
|
7
|
+
contents = await args.helpers.format(contents.toString(), filePath, args.formatOptions);
|
|
8
|
+
}
|
|
9
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
10
|
+
await writeFile(filePath, contents);
|
|
11
|
+
return filePath;
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
writeProjectFile
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=writeProjectFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeProjectFile.js","sources":["../../../src/fs/writeProjectFile.ts"],"sourcesContent":["import * as path from \"node:path\";\n\nimport { PluginSystemHelpers } from \"../createPluginSystemHelpers\";\n\nimport * as fs from \"./lib/fsLimit\";\n\nexport type WriteProjectFileArgs = {\n\tfilename: string;\n\tcontents: Parameters<typeof fs.writeFile>[1];\n\tformat?: boolean;\n\tformatOptions?: Parameters<PluginSystemHelpers[\"format\"]>[2];\n\thelpers: PluginSystemHelpers;\n};\n\n/**\n * Writes a file to the project with optional formatting.\n *\n * @returns The file path to the written file.\n */\nexport const writeProjectFile = async (\n\targs: WriteProjectFileArgs,\n): Promise<string> => {\n\tconst filePath = args.helpers.joinPathFromRoot(args.filename);\n\n\tlet contents = args.contents;\n\n\tif (args.format) {\n\t\tcontents = await args.helpers.format(\n\t\t\tcontents.toString(),\n\t\t\tfilePath,\n\t\t\targs.formatOptions,\n\t\t);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n\n\treturn filePath;\n};\n"],"names":["fs.mkdir","fs.writeFile"],"mappings":";;AAmBO,MAAM,mBAAmB,OAC/B,SACoB;AACpB,QAAM,WAAW,KAAK,QAAQ,iBAAiB,KAAK,QAAQ;AAE5D,MAAI,WAAW,KAAK;AAEpB,MAAI,KAAK,QAAQ;AAChB,eAAW,MAAM,KAAK,QAAQ,OAC7B,SAAS,YACT,UACA,KAAK,aAAa;AAAA,EAEpB;AAEA,QAAMA,MAAS,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,MAAM;AAC1D,QAAMC,UAAa,UAAU,QAAQ;AAErC,SAAO;AACR;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuildSliceFilePathArgs } from "./buildSliceFilePath.js";
|
|
2
|
+
import { WriteProjectFileArgs } from "./writeProjectFile.js";
|
|
3
|
+
export type WriteSliceFileArgs = Omit<WriteProjectFileArgs, "filePath"> & BuildSliceFilePathArgs;
|
|
4
|
+
/**
|
|
5
|
+
* Writes a Slice model to the file system in the Slice's Slice library.
|
|
6
|
+
*
|
|
7
|
+
* @returns The file path to the written file.
|
|
8
|
+
*/
|
|
9
|
+
export declare const writeSliceFile: (args: WriteSliceFileArgs) => Promise<string>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { buildSliceFilePath } from "./buildSliceFilePath.js";
|
|
2
|
+
import { writeProjectFile } from "./writeProjectFile.js";
|
|
3
|
+
const writeSliceFile = async (args) => {
|
|
4
|
+
const filePath = await buildSliceFilePath(args);
|
|
5
|
+
const relativeFilePath = await buildSliceFilePath({
|
|
6
|
+
...args,
|
|
7
|
+
absolute: false
|
|
8
|
+
});
|
|
9
|
+
await writeProjectFile({
|
|
10
|
+
...args,
|
|
11
|
+
filename: relativeFilePath
|
|
12
|
+
});
|
|
13
|
+
return filePath;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
writeSliceFile
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=writeSliceFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeSliceFile.js","sources":["../../../src/fs/writeSliceFile.ts"],"sourcesContent":["import {\n\tbuildSliceFilePath,\n\tBuildSliceFilePathArgs,\n} from \"./buildSliceFilePath\";\nimport { writeProjectFile, WriteProjectFileArgs } from \"./writeProjectFile\";\n\nexport type WriteSliceFileArgs = Omit<WriteProjectFileArgs, \"filePath\"> &\n\tBuildSliceFilePathArgs;\n\n/**\n * Writes a Slice model to the file system in the Slice's Slice library.\n *\n * @returns The file path to the written file.\n */\nexport const writeSliceFile = async (\n\targs: WriteSliceFileArgs,\n): Promise<string> => {\n\tconst filePath = await buildSliceFilePath(args);\n\tconst relativeFilePath = await buildSliceFilePath({\n\t\t...args,\n\t\tabsolute: false,\n\t});\n\n\tawait writeProjectFile({\n\t\t...args,\n\t\tfilename: relativeFilePath,\n\t});\n\n\treturn filePath;\n};\n"],"names":[],"mappings":";;AAcO,MAAM,iBAAiB,OAC7B,SACoB;AACpB,QAAM,WAAW,MAAM,mBAAmB,IAAI;AAC9C,QAAM,mBAAmB,MAAM,mBAAmB;AAAA,IACjD,GAAG;AAAA,IACH,UAAU;AAAA,EAAA,CACV;AAED,QAAM,iBAAiB;AAAA,IACtB,GAAG;AAAA,IACH,UAAU;AAAA,EAAA,CACV;AAED,SAAO;AACR;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
|
|
2
|
+
import { WriteSliceFileArgs } from "./writeSliceFile.js";
|
|
3
|
+
export type WriteSliceModelArgs = Omit<WriteSliceFileArgs, "filename" | "contents" | "sliceID"> & {
|
|
4
|
+
model: TypesInternal.SharedSlice;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Writes a Slice model to the file system in the Slice's Slice library.
|
|
8
|
+
*
|
|
9
|
+
* @returns The file path to the written model.
|
|
10
|
+
*/
|
|
11
|
+
export declare const writeSliceModel: (args: WriteSliceModelArgs) => Promise<string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SHARED_SLICE_MODEL_FILENAME } from "./constants.js";
|
|
2
|
+
import { writeSliceFile } from "./writeSliceFile.js";
|
|
3
|
+
const writeSliceModel = async (args) => {
|
|
4
|
+
return await writeSliceFile({
|
|
5
|
+
...args,
|
|
6
|
+
filename: SHARED_SLICE_MODEL_FILENAME,
|
|
7
|
+
contents: JSON.stringify(args.model, null, 2)
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
writeSliceModel
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=writeSliceModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeSliceModel.js","sources":["../../../src/fs/writeSliceModel.ts"],"sourcesContent":["import TypesInternal from \"@prismicio/types-internal/lib/customtypes/index.js\";\n\nimport { SHARED_SLICE_MODEL_FILENAME } from \"./constants\";\nimport { writeSliceFile, WriteSliceFileArgs } from \"./writeSliceFile\";\n\nexport type WriteSliceModelArgs = Omit<\n\tWriteSliceFileArgs,\n\t\"filename\" | \"contents\" | \"sliceID\"\n> & {\n\tmodel: TypesInternal.SharedSlice;\n};\n\n/**\n * Writes a Slice model to the file system in the Slice's Slice library.\n *\n * @returns The file path to the written model.\n */\nexport const writeSliceModel = async (\n\targs: WriteSliceModelArgs,\n): Promise<string> => {\n\treturn await writeSliceFile({\n\t\t...args,\n\t\tfilename: SHARED_SLICE_MODEL_FILENAME,\n\t\tcontents: JSON.stringify(args.model, null, 2),\n\t});\n};\n"],"names":[],"mappings":";;AAiBO,MAAM,kBAAkB,OAC9B,SACoB;AACpB,SAAO,MAAM,eAAe;AAAA,IAC3B,GAAG;AAAA,IACH,UAAU;AAAA,IACV,UAAU,KAAK,UAAU,KAAK,OAAO,MAAM,CAAC;AAAA,EAAA,CAC5C;AACF;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
|
|
2
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Data provided to `custom-type:create` hook handlers.
|
|
5
|
+
*/
|
|
6
|
+
export type CustomTypeCreateHookData = {
|
|
7
|
+
model: TypesInternal.CustomType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Return value for `custom-type:create` hook handlers.
|
|
11
|
+
*/
|
|
12
|
+
export type CustomTypeCreateHookReturnType = void;
|
|
13
|
+
/**
|
|
14
|
+
* Base version of `custom-type:create` without plugin runner context.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type CustomTypeCreateHookBase = PluginHook<CustomTypeCreateHookData, CustomTypeCreateHookReturnType>;
|
|
19
|
+
/**
|
|
20
|
+
* Handler for the `custom-type:create` hook. The hook is called when a Custom
|
|
21
|
+
* Type is created.
|
|
22
|
+
*
|
|
23
|
+
* `custom-type:create` is only called the first time a Custom Type is saved.
|
|
24
|
+
* Subsequent saves will call the `custom-type:update` hook.
|
|
25
|
+
*
|
|
26
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
27
|
+
*/
|
|
28
|
+
export type CustomTypeCreateHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<CustomTypeCreateHookBase, TPluginOptions>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
|
|
2
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Data provided to `custom-type:delete` hook handlers.
|
|
5
|
+
*/
|
|
6
|
+
export type CustomTypeDeleteHookData = {
|
|
7
|
+
model: TypesInternal.CustomType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Return value for `custom-type:delete` hook handlers.
|
|
11
|
+
*/
|
|
12
|
+
export type CustomTypeDeleteHookReturnType = void;
|
|
13
|
+
/**
|
|
14
|
+
* Base version of a `custom-type:delete` hook handler without plugin runner
|
|
15
|
+
* context.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type CustomTypeDeleteHookBase = PluginHook<CustomTypeDeleteHookData, CustomTypeDeleteHookReturnType>;
|
|
20
|
+
/**
|
|
21
|
+
* Handler for the `custom-type:delete` hook. The hook is called when a Custom
|
|
22
|
+
* Type is deleted.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
25
|
+
*/
|
|
26
|
+
export type CustomTypeDeleteHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<CustomTypeDeleteHookBase, TPluginOptions>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
|
|
2
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Data provided to `custom-type:read` hook handlers.
|
|
5
|
+
*/
|
|
6
|
+
export type CustomTypeReadHookData = {
|
|
7
|
+
id: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Return value for `custom-type:read` hook handlers.
|
|
11
|
+
*/
|
|
12
|
+
export type CustomTypeReadHookReturnType = {
|
|
13
|
+
model: TypesInternal.CustomType;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Base version of a `custom-type:read` hook handler without plugin runner
|
|
17
|
+
* context.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export type CustomTypeReadHookBase = PluginHook<CustomTypeReadHookData, CustomTypeReadHookReturnType>;
|
|
22
|
+
/**
|
|
23
|
+
* Handler for the `custom-type:read` hook. The hook is called when a Custom
|
|
24
|
+
* Type's model is needed.
|
|
25
|
+
*
|
|
26
|
+
* This hook is **required** to be implemented by adapters.
|
|
27
|
+
*
|
|
28
|
+
* This hook will only be called in adapters.
|
|
29
|
+
*
|
|
30
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
31
|
+
*/
|
|
32
|
+
export type CustomTypeReadHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<CustomTypeReadHookBase, TPluginOptions>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
|
|
2
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Data provided to `custom-type:rename` hook handlers.
|
|
5
|
+
*/
|
|
6
|
+
export type CustomTypeRenameHookData = {
|
|
7
|
+
model: TypesInternal.CustomType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Return value for `custom-type:rename` hook handlers.
|
|
11
|
+
*/
|
|
12
|
+
export type CustomTypeRenameHookReturnType = void;
|
|
13
|
+
/**
|
|
14
|
+
* Base version of a `custom-type:rename` hook handler without plugin runner
|
|
15
|
+
* context.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type CustomTypeRenameHookBase = PluginHook<CustomTypeRenameHookData, CustomTypeRenameHookReturnType>;
|
|
20
|
+
/**
|
|
21
|
+
* Handler for the `custom-type:rename` hook. The hook is called when a Custom
|
|
22
|
+
* Type is renamed.
|
|
23
|
+
*
|
|
24
|
+
* `custom-type:rename` is not called the first time a Custom Type is saved. The
|
|
25
|
+
* `custom-type:create` hook is called instead.
|
|
26
|
+
*
|
|
27
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
28
|
+
*/
|
|
29
|
+
export type CustomTypeRenameHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<CustomTypeRenameHookBase, TPluginOptions>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
|
|
2
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Data provided to `custom-type:update` hook handlers.
|
|
5
|
+
*/
|
|
6
|
+
export type CustomTypeUpdateHookData = {
|
|
7
|
+
model: TypesInternal.CustomType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Return value for `custom-type:update` hook handlers.
|
|
11
|
+
*/
|
|
12
|
+
export type CustomTypeUpdateHookReturnType = void;
|
|
13
|
+
/**
|
|
14
|
+
* Base version of a `custom-type:update` hook handler without plugin runner
|
|
15
|
+
* context.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export type CustomTypeUpdateHookBase = PluginHook<CustomTypeUpdateHookData, CustomTypeUpdateHookReturnType>;
|
|
20
|
+
/**
|
|
21
|
+
* Handler for the `custom-type:update` hook. The hook is called when a Custom
|
|
22
|
+
* Type is updated.
|
|
23
|
+
*
|
|
24
|
+
* `custom-type:update` is not called the first time a Custom Type is saved. The
|
|
25
|
+
* `custom-type:create` hook is called instead.
|
|
26
|
+
*
|
|
27
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
28
|
+
*/
|
|
29
|
+
export type CustomTypeUpdateHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<CustomTypeUpdateHookBase, TPluginOptions>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Data provided to `custom-type-library:read` hook handlers.
|
|
4
|
+
*/
|
|
5
|
+
export type CustomTypeLibraryReadHookData = undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Return value for `custom-type-library:read` hook handlers.
|
|
8
|
+
*/
|
|
9
|
+
export type CustomTypeLibraryReadHookReturnType = {
|
|
10
|
+
ids: string[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Base version of a `custom-type-library:read` hook handler without plugin
|
|
14
|
+
* runner context.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export type CustomTypeLibraryReadHookBase = PluginHook<CustomTypeLibraryReadHookData, CustomTypeLibraryReadHookReturnType>;
|
|
19
|
+
/**
|
|
20
|
+
* Handler for the `custom-type-library:read` hook. The hook is called when a
|
|
21
|
+
* Custom Type Library's metadata is needed.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
24
|
+
*/
|
|
25
|
+
export type CustomTypeLibraryReadHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<CustomTypeLibraryReadHookBase, TPluginOptions>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Data provided to `debug` hook handlers.
|
|
4
|
+
*/
|
|
5
|
+
export type DebugHookData = unknown;
|
|
6
|
+
/**
|
|
7
|
+
* Return value for `debug` hook handlers.
|
|
8
|
+
*/
|
|
9
|
+
export type DebugHookReturnType = unknown;
|
|
10
|
+
/**
|
|
11
|
+
* Base version of a `debug` hook handler without plugin runner context.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export type DebugHookBase = PluginHook<DebugHookData, DebugHookReturnType>;
|
|
16
|
+
/**
|
|
17
|
+
* Handler for the `debug` hook. This hook is never called in a production app.
|
|
18
|
+
* It can be used for testing purposes.
|
|
19
|
+
*
|
|
20
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
21
|
+
*/
|
|
22
|
+
export type DebugHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<DebugHookBase, TPluginOptions>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Data provided to `project:init` hook handlers.
|
|
4
|
+
*/
|
|
5
|
+
export type ProjectInitHookData = {
|
|
6
|
+
/**
|
|
7
|
+
* Log messages. The message may be sent to the console or elsewhere.
|
|
8
|
+
*/
|
|
9
|
+
log: (message: string) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Install package dependencies. The correct package manager will
|
|
12
|
+
* automatically be used (npm/Yarn/pnpm/etc.).
|
|
13
|
+
*/
|
|
14
|
+
installDependencies: (args: {
|
|
15
|
+
dependencies: Record<string, string>;
|
|
16
|
+
dev?: boolean;
|
|
17
|
+
}) => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Return value for `project:init` hook handlers.
|
|
21
|
+
*/
|
|
22
|
+
export type ProjectInitHookReturnType = void;
|
|
23
|
+
/**
|
|
24
|
+
* Base version of `project:init` without plugin runner context.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export type ProjectInitHookBase = PluginHook<ProjectInitHookData, ProjectInitHookReturnType>;
|
|
29
|
+
/**
|
|
30
|
+
* Handler for the `project:init` hook. The hook is called during the init
|
|
31
|
+
* Project for plugins to init
|
|
32
|
+
*
|
|
33
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
34
|
+
*/
|
|
35
|
+
export type ProjectInitHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<ProjectInitHookBase, TPluginOptions>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import TypesInternal from "@prismicio/types-internal/lib/customtypes/index.js";
|
|
2
|
+
import type { ExtendPluginSystemHook, PluginOptions, PluginHook } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Data provided to `slice:create` hook handlers.
|
|
5
|
+
*/
|
|
6
|
+
export type SliceCreateHookData = {
|
|
7
|
+
libraryID: string;
|
|
8
|
+
model: TypesInternal.SharedSlice;
|
|
9
|
+
componentContents?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Return value for `slice:create` hook handlers.
|
|
13
|
+
*/
|
|
14
|
+
export type SliceCreateHookReturnType = void;
|
|
15
|
+
/**
|
|
16
|
+
* Base version of `slice:create` without plugin runner context.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type SliceCreateHookBase = PluginHook<SliceCreateHookData, SliceCreateHookReturnType>;
|
|
21
|
+
/**
|
|
22
|
+
* Handler for the `slice:create` hook. The hook is called when a Slice is
|
|
23
|
+
* created.
|
|
24
|
+
*
|
|
25
|
+
* `slice:create` is only called the first time a Slice is saved. Subsequent
|
|
26
|
+
* saves will call the `slice:update` hook.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam TPluginOptions - User-provided options for the hook's plugin.
|
|
29
|
+
*/
|
|
30
|
+
export type SliceCreateHook<TPluginOptions extends PluginOptions = PluginOptions> = ExtendPluginSystemHook<SliceCreateHookBase, TPluginOptions>;
|