prismic-ts-codegen 0.1.30-pr.82.96148f3 → 0.1.30-pr.82.a4be5f3
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/cli/loadConfig.mjs +2 -5
- package/dist/cli/loadConfig.mjs.map +1 -1
- package/dist/cli/loadModels.mjs +1 -3
- package/dist/cli/loadModels.mjs.map +1 -1
- package/dist/lib/dedent.mjs +2 -3
- package/dist/lib/dedent.mjs.map +1 -1
- package/dist/package.mjs +1 -1
- package/package.json +1 -4
- package/src/cli/loadConfig.ts +2 -6
- package/src/cli/loadModels.ts +1 -4
- package/src/lib/dedent.ts +2 -6
package/dist/cli/loadConfig.mjs
CHANGED
|
@@ -3,15 +3,12 @@ import { resolve } from "path";
|
|
|
3
3
|
import { createJiti } from "jiti";
|
|
4
4
|
//#region src/cli/loadConfig.ts
|
|
5
5
|
const jiti = createJiti(process.cwd());
|
|
6
|
-
const loadModuleWithJiti = async (id) => {
|
|
7
|
-
return await jiti.import(id, { default: true });
|
|
8
|
-
};
|
|
9
6
|
const DEFAULT_CONFIG_PATHS = ["prismicCodegen.config.ts", "prismicCodegen.config.js"];
|
|
10
7
|
const loadConfig = async (config) => {
|
|
11
8
|
if (config.path) {
|
|
12
|
-
if (existsSync(config.path)) return await
|
|
9
|
+
if (existsSync(config.path)) return await jiti.import(resolve(config.path), { default: true });
|
|
13
10
|
else throw new Error(`Config file does not exist: ${config.path}`);
|
|
14
|
-
} else for (const configPath of DEFAULT_CONFIG_PATHS) if (existsSync(configPath)) return await
|
|
11
|
+
} else for (const configPath of DEFAULT_CONFIG_PATHS) if (existsSync(configPath)) return await jiti.import(resolve(configPath), { default: true });
|
|
15
12
|
return {};
|
|
16
13
|
};
|
|
17
14
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadConfig.mjs","names":["resolvePath"],"sources":["../../src/cli/loadConfig.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport { resolve as resolvePath } from \"path\";\n\nimport { createJiti } from \"jiti\";\n\nimport type { Config } from \"./configSchema\";\n\nconst jiti = createJiti(process.cwd());\n\nconst
|
|
1
|
+
{"version":3,"file":"loadConfig.mjs","names":["resolvePath"],"sources":["../../src/cli/loadConfig.ts"],"sourcesContent":["import { existsSync } from \"fs\";\nimport { resolve as resolvePath } from \"path\";\n\nimport { createJiti } from \"jiti\";\n\nimport type { Config } from \"./configSchema\";\n\nconst jiti = createJiti(process.cwd());\n\nconst DEFAULT_CONFIG_PATHS = [\"prismicCodegen.config.ts\", \"prismicCodegen.config.js\"];\n\ntype LoadConfigConfig = {\n\tpath?: string;\n};\n\nexport const loadConfig = async (config: LoadConfigConfig): Promise<Config> => {\n\tif (config.path) {\n\t\tif (existsSync(config.path)) {\n\t\t\treturn await jiti.import(resolvePath(config.path), { default: true });\n\t\t} else {\n\t\t\tthrow new Error(`Config file does not exist: ${config.path}`);\n\t\t}\n\t} else {\n\t\tfor (const configPath of DEFAULT_CONFIG_PATHS) {\n\t\t\tif (existsSync(configPath)) {\n\t\t\t\treturn await jiti.import(resolvePath(configPath), { default: true });\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no config file exists, an empty config is returned.\n\treturn {};\n};\n"],"mappings":";;;;AAOA,MAAM,OAAO,WAAW,QAAQ,IAAI,CAAC;AAErC,MAAM,uBAAuB,CAAC,4BAA4B,0BAA0B;AAMpF,MAAa,aAAa,OAAO,WAA8C;CAC9E,IAAI,OAAO,MAAM;EAChB,IAAI,WAAW,OAAO,IAAI,GACzB,OAAO,MAAM,KAAK,OAAOA,QAAY,OAAO,IAAI,GAAG,EAAE,SAAS,KAAK,CAAC;OAEpE,MAAM,IAAI,MAAM,+BAA+B,OAAO,MAAM;CAE9D,OACC,KAAK,MAAM,cAAc,sBACxB,IAAI,WAAW,UAAU,GACxB,OAAO,MAAM,KAAK,OAAOA,QAAY,UAAU,GAAG,EAAE,SAAS,KAAK,CAAC;CAMtE,OAAO,CAAC;AACT"}
|
package/dist/cli/loadModels.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
2
|
import { glob } from "tinyglobby";
|
|
3
3
|
//#region src/cli/loadModels.ts
|
|
4
|
-
const CUSTOM_TYPES_API_ENDPOINT = "https://customtypes.prismic.io/";
|
|
5
4
|
const isCustomTypeModel = (input) => {
|
|
6
5
|
return typeof input === "object" && input !== null && "json" in input;
|
|
7
6
|
};
|
|
@@ -15,8 +14,7 @@ const readJSONFromGlob = async (globs) => {
|
|
|
15
14
|
});
|
|
16
15
|
};
|
|
17
16
|
const fetchCustomTypesAPI = async (path, config) => {
|
|
18
|
-
const
|
|
19
|
-
const res = await fetch(url, { headers: {
|
|
17
|
+
const res = await fetch(new URL(path, "https://customtypes.prismic.io/"), { headers: {
|
|
20
18
|
repository: config.repositoryName,
|
|
21
19
|
Authorization: `Bearer ${config.customTypesAPIToken}`
|
|
22
20
|
} });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadModels.mjs","names":[],"sources":["../../src/cli/loadModels.ts"],"sourcesContent":["import { readFileSync } from \"fs\";\n\nimport type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { glob } from \"tinyglobby\";\n\nconst
|
|
1
|
+
{"version":3,"file":"loadModels.mjs","names":[],"sources":["../../src/cli/loadModels.ts"],"sourcesContent":["import { readFileSync } from \"fs\";\n\nimport type { CustomTypeModel, SharedSliceModel } from \"@prismicio/client\";\nimport { glob } from \"tinyglobby\";\n\nconst isCustomTypeModel = (input: unknown): input is CustomTypeModel => {\n\treturn typeof input === \"object\" && input !== null && \"json\" in input;\n};\n\nconst isSharedSliceModel = (input: unknown): input is SharedSliceModel => {\n\treturn typeof input === \"object\" && input !== null && \"variations\" in input;\n};\n\nconst readJSONFromGlob = async <T>(globs: string): Promise<T[]> => {\n\tconst paths = await glob(\n\t\tglobs.split(\",\").map((path) => path.trim()),\n\t\t{ expandDirectories: false },\n\t);\n\n\treturn paths.map((path) => {\n\t\tconst raw = readFileSync(path, \"utf8\");\n\n\t\treturn JSON.parse(raw);\n\t});\n};\n\nconst fetchCustomTypesAPI = async <T>(\n\tpath: string,\n\tconfig: { repositoryName: string; customTypesAPIToken: string },\n): Promise<T[]> => {\n\tconst res = await fetch(new URL(path, \"https://customtypes.prismic.io/\"), {\n\t\theaders: {\n\t\t\trepository: config.repositoryName,\n\t\t\tAuthorization: `Bearer ${config.customTypesAPIToken}`,\n\t\t},\n\t});\n\n\tif (!res.ok) {\n\t\tthrow new Error(\n\t\t\t`Failed to fetch models from the Custom Types API (${res.status}): ${await res.text()}`,\n\t\t);\n\t}\n\n\treturn await res.json();\n};\n\ntype LoadModelsConfig =\n\t| {\n\t\t\tlocalPaths?: string[];\n\t }\n\t| {\n\t\t\tlocalPaths?: string[];\n\t\t\trepositoryName: string;\n\t\t\tcustomTypesAPIToken: string;\n\t\t\tfetchFromRepository?: boolean;\n\t };\n\ntype LoadModelsReturnType = {\n\tcustomTypeModels: CustomTypeModel[];\n\tsharedSliceModels: SharedSliceModel[];\n};\n\nexport const loadModels = async (config: LoadModelsConfig): Promise<LoadModelsReturnType> => {\n\tconst customTypeModels: Record<string, CustomTypeModel> = {};\n\tconst sharedSliceModels: Record<string, SharedSliceModel> = {};\n\n\tif (\"customTypesAPIToken\" in config) {\n\t\tif (config.fetchFromRepository) {\n\t\t\tconst [remoteCustomTypeModels, remoteSharedSliceModels] = await Promise.all([\n\t\t\t\tfetchCustomTypesAPI<CustomTypeModel>(\"customtypes\", config),\n\t\t\t\tfetchCustomTypesAPI<SharedSliceModel>(\"slices\", config),\n\t\t\t]);\n\n\t\t\tfor (const customTypeModel of remoteCustomTypeModels) {\n\t\t\t\tcustomTypeModels[customTypeModel.id] = customTypeModel;\n\t\t\t}\n\t\t\tfor (const sharedSliceModel of remoteSharedSliceModels) {\n\t\t\t\tsharedSliceModels[sharedSliceModel.id] = sharedSliceModel;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (config.localPaths) {\n\t\tconst models = (\n\t\t\tawait Promise.all(config.localPaths.map((glob) => readJSONFromGlob(glob)))\n\t\t).flat();\n\n\t\tfor (const model of models) {\n\t\t\tif (isCustomTypeModel(model)) {\n\t\t\t\tcustomTypeModels[model.id] = model;\n\t\t\t} else if (isSharedSliceModel(model)) {\n\t\t\t\tsharedSliceModels[model.id] = model;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\tcustomTypeModels: Object.values(customTypeModels).sort((a, b) => {\n\t\t\treturn a.id.localeCompare(b.id);\n\t\t}),\n\t\tsharedSliceModels: Object.values(sharedSliceModels).sort((a, b) => {\n\t\t\treturn a.id.localeCompare(b.id);\n\t\t}),\n\t};\n};\n"],"mappings":";;;AAKA,MAAM,qBAAqB,UAA6C;CACvE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,UAAU;AACjE;AAEA,MAAM,sBAAsB,UAA8C;CACzE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,gBAAgB;AACvE;AAEA,MAAM,mBAAmB,OAAU,UAAgC;CAMlE,QAAO,MALa,KACnB,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,SAAS,KAAK,KAAK,CAAC,GAC1C,EAAE,mBAAmB,MAAM,CAC5B,EAAA,CAEa,KAAK,SAAS;EAC1B,MAAM,MAAM,aAAa,MAAM,MAAM;EAErC,OAAO,KAAK,MAAM,GAAG;CACtB,CAAC;AACF;AAEA,MAAM,sBAAsB,OAC3B,MACA,WACkB;CAClB,MAAM,MAAM,MAAM,MAAM,IAAI,IAAI,MAAM,iCAAiC,GAAG,EACzE,SAAS;EACR,YAAY,OAAO;EACnB,eAAe,UAAU,OAAO;CACjC,EACD,CAAC;CAED,IAAI,CAAC,IAAI,IACR,MAAM,IAAI,MACT,qDAAqD,IAAI,OAAO,KAAK,MAAM,IAAI,KAAK,GACrF;CAGD,OAAO,MAAM,IAAI,KAAK;AACvB;AAkBA,MAAa,aAAa,OAAO,WAA4D;CAC5F,MAAM,mBAAoD,CAAC;CAC3D,MAAM,oBAAsD,CAAC;CAE7D,IAAI,yBAAyB,QACxB;MAAA,OAAO,qBAAqB;GAC/B,MAAM,CAAC,wBAAwB,2BAA2B,MAAM,QAAQ,IAAI,CAC3E,oBAAqC,eAAe,MAAM,GAC1D,oBAAsC,UAAU,MAAM,CACvD,CAAC;GAED,KAAK,MAAM,mBAAmB,wBAC7B,iBAAiB,gBAAgB,MAAM;GAExC,KAAK,MAAM,oBAAoB,yBAC9B,kBAAkB,iBAAiB,MAAM;EAE3C;;CAGD,IAAI,OAAO,YAAY;EACtB,MAAM,UACL,MAAM,QAAQ,IAAI,OAAO,WAAW,KAAK,SAAS,iBAAiB,IAAI,CAAC,CAAC,EAAA,CACxE,KAAK;EAEP,KAAK,MAAM,SAAS,QACnB,IAAI,kBAAkB,KAAK,GAC1B,iBAAiB,MAAM,MAAM;OACvB,IAAI,mBAAmB,KAAK,GAClC,kBAAkB,MAAM,MAAM;CAGjC;CAEA,OAAO;EACN,kBAAkB,OAAO,OAAO,gBAAgB,CAAC,CAAC,MAAM,GAAG,MAAM;GAChE,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE;EAC/B,CAAC;EACD,mBAAmB,OAAO,OAAO,iBAAiB,CAAC,CAAC,MAAM,GAAG,MAAM;GAClE,OAAO,EAAE,GAAG,cAAc,EAAE,EAAE;EAC/B,CAAC;CACF;AACD"}
|
package/dist/lib/dedent.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import baseDedent from "dedent";
|
|
2
2
|
//#region src/lib/dedent.ts
|
|
3
3
|
const baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });
|
|
4
|
-
|
|
5
|
-
if (typeof strings === "string") return baseDedentWithOptions(strings);
|
|
4
|
+
const dedent = (strings, ...values) => {
|
|
6
5
|
const resolved = Array.from(strings);
|
|
7
6
|
return baseDedentWithOptions(Object.assign(resolved, { raw: resolved }), ...values);
|
|
8
|
-
}
|
|
7
|
+
};
|
|
9
8
|
//#endregion
|
|
10
9
|
export { dedent };
|
|
11
10
|
|
package/dist/lib/dedent.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dedent.mjs","names":[],"sources":["../../src/lib/dedent.ts"],"sourcesContent":["import baseDedent from \"dedent\";\n\nconst baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });\n\nexport
|
|
1
|
+
{"version":3,"file":"dedent.mjs","names":[],"sources":["../../src/lib/dedent.ts"],"sourcesContent":["import baseDedent from \"dedent\";\n\nconst baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });\n\nexport const dedent = (strings: TemplateStringsArray, ...values: unknown[]): string => {\n\t// dedent reads `strings.raw` by default, which keeps escapes in string literals. Point `raw` at\n\t// the regular string segments instead, where escapes are already resolved.\n\tconst resolved = Array.from(strings);\n\treturn baseDedentWithOptions(Object.assign(resolved, { raw: resolved }), ...values);\n};\n"],"mappings":";;AAEA,MAAM,wBAAwB,WAAW,YAAY,EAAE,aAAa,KAAK,CAAC;AAE1E,MAAa,UAAU,SAA+B,GAAG,WAA8B;CAGtF,MAAM,WAAW,MAAM,KAAK,OAAO;CACnC,OAAO,sBAAsB,OAAO,OAAO,UAAU,EAAE,KAAK,SAAS,CAAC,GAAG,GAAG,MAAM;AACnF"}
|
package/dist/package.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prismic-ts-codegen",
|
|
3
|
-
"version": "0.1.30-pr.82.
|
|
3
|
+
"version": "0.1.30-pr.82.a4be5f3",
|
|
4
4
|
"description": "An experimental Prismic model-to-TypeScript-type generator",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prismic",
|
|
@@ -66,9 +66,6 @@
|
|
|
66
66
|
"@prismicio/types": "^0.2.8"
|
|
67
67
|
},
|
|
68
68
|
"peerDependenciesMeta": {
|
|
69
|
-
"@prismicio/client": {
|
|
70
|
-
"optional": true
|
|
71
|
-
},
|
|
72
69
|
"@prismicio/types": {
|
|
73
70
|
"optional": true
|
|
74
71
|
}
|
package/src/cli/loadConfig.ts
CHANGED
|
@@ -7,10 +7,6 @@ import type { Config } from "./configSchema";
|
|
|
7
7
|
|
|
8
8
|
const jiti = createJiti(process.cwd());
|
|
9
9
|
|
|
10
|
-
const loadModuleWithJiti = async <TModule>(id: string): Promise<TModule> => {
|
|
11
|
-
return await jiti.import<TModule>(id, { default: true });
|
|
12
|
-
};
|
|
13
|
-
|
|
14
10
|
const DEFAULT_CONFIG_PATHS = ["prismicCodegen.config.ts", "prismicCodegen.config.js"];
|
|
15
11
|
|
|
16
12
|
type LoadConfigConfig = {
|
|
@@ -20,14 +16,14 @@ type LoadConfigConfig = {
|
|
|
20
16
|
export const loadConfig = async (config: LoadConfigConfig): Promise<Config> => {
|
|
21
17
|
if (config.path) {
|
|
22
18
|
if (existsSync(config.path)) {
|
|
23
|
-
return await
|
|
19
|
+
return await jiti.import(resolvePath(config.path), { default: true });
|
|
24
20
|
} else {
|
|
25
21
|
throw new Error(`Config file does not exist: ${config.path}`);
|
|
26
22
|
}
|
|
27
23
|
} else {
|
|
28
24
|
for (const configPath of DEFAULT_CONFIG_PATHS) {
|
|
29
25
|
if (existsSync(configPath)) {
|
|
30
|
-
return await
|
|
26
|
+
return await jiti.import(resolvePath(configPath), { default: true });
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
}
|
package/src/cli/loadModels.ts
CHANGED
|
@@ -3,8 +3,6 @@ import { readFileSync } from "fs";
|
|
|
3
3
|
import type { CustomTypeModel, SharedSliceModel } from "@prismicio/client";
|
|
4
4
|
import { glob } from "tinyglobby";
|
|
5
5
|
|
|
6
|
-
const CUSTOM_TYPES_API_ENDPOINT = "https://customtypes.prismic.io/";
|
|
7
|
-
|
|
8
6
|
const isCustomTypeModel = (input: unknown): input is CustomTypeModel => {
|
|
9
7
|
return typeof input === "object" && input !== null && "json" in input;
|
|
10
8
|
};
|
|
@@ -30,8 +28,7 @@ const fetchCustomTypesAPI = async <T>(
|
|
|
30
28
|
path: string,
|
|
31
29
|
config: { repositoryName: string; customTypesAPIToken: string },
|
|
32
30
|
): Promise<T[]> => {
|
|
33
|
-
const
|
|
34
|
-
const res = await fetch(url, {
|
|
31
|
+
const res = await fetch(new URL(path, "https://customtypes.prismic.io/"), {
|
|
35
32
|
headers: {
|
|
36
33
|
repository: config.repositoryName,
|
|
37
34
|
Authorization: `Bearer ${config.customTypesAPIToken}`,
|
package/src/lib/dedent.ts
CHANGED
|
@@ -2,13 +2,9 @@ import baseDedent from "dedent";
|
|
|
2
2
|
|
|
3
3
|
const baseDedentWithOptions = baseDedent.withOptions({ alignValues: true });
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
if (typeof strings === "string") {
|
|
7
|
-
return baseDedentWithOptions(strings);
|
|
8
|
-
}
|
|
9
|
-
|
|
5
|
+
export const dedent = (strings: TemplateStringsArray, ...values: unknown[]): string => {
|
|
10
6
|
// dedent reads `strings.raw` by default, which keeps escapes in string literals. Point `raw` at
|
|
11
7
|
// the regular string segments instead, where escapes are already resolved.
|
|
12
8
|
const resolved = Array.from(strings);
|
|
13
9
|
return baseDedentWithOptions(Object.assign(resolved, { raw: resolved }), ...values);
|
|
14
|
-
}
|
|
10
|
+
};
|