@jungvonmatt/contentful-typings 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -5
- package/dist/cli.js +4 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -7
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/cli.ts +9 -0
- package/src/index.ts +9 -9
package/README.md
CHANGED
|
@@ -32,11 +32,13 @@ npx contentful-typings generate [options]
|
|
|
32
32
|
#### options
|
|
33
33
|
|
|
34
34
|
```
|
|
35
|
-
-o, --output <filepath>
|
|
36
|
-
-l, --localized
|
|
37
|
-
-d, --jsdoc
|
|
38
|
-
-g, --typeguard
|
|
39
|
-
|
|
35
|
+
-o, --output <filepath> Specify output file (default: "@types/contentful.d.ts")
|
|
36
|
+
-l, --localized Add localized types
|
|
37
|
+
-d, --jsdoc Add JSDoc comments
|
|
38
|
+
-g, --typeguard Add type guards
|
|
39
|
+
--config <configuration file> Use this configuration, overriding other config options if present
|
|
40
|
+
--cwd <directory> Working directory. Defaults to process.cwd()
|
|
41
|
+
-h, --help display help for command
|
|
40
42
|
```
|
|
41
43
|
|
|
42
44
|
[npm-url]: https://www.npmjs.com/package/@jungvonmatt/contentful-typings
|
package/dist/cli.js
CHANGED
|
@@ -26,6 +26,8 @@ const program = new Command();
|
|
|
26
26
|
program
|
|
27
27
|
.command('generate')
|
|
28
28
|
.description('Generate typescript definitions for contentful content types.')
|
|
29
|
+
.option('--config <configFile>', 'Use this configuration, overriding other config options if present')
|
|
30
|
+
.option('--cwd <directory>', 'Working directory. Defaults to process.cwd()')
|
|
29
31
|
.option('-o, --output <filepath>', 'Specify output file', '@types/contentful.ts')
|
|
30
32
|
.option('-l, --localized', 'Add localized types')
|
|
31
33
|
.option('-d, --jsdoc', 'Add JSDoc comments')
|
|
@@ -38,6 +40,8 @@ program
|
|
|
38
40
|
jsdoc: cmd.jsdoc,
|
|
39
41
|
localized: cmd.localized,
|
|
40
42
|
legacy: cmd.legacy,
|
|
43
|
+
cwd: cmd?.cwd || process.cwd(),
|
|
44
|
+
configFile: cmd?.config || undefined,
|
|
41
45
|
});
|
|
42
46
|
await outputFile(output, typings);
|
|
43
47
|
console.log(pico.green(` added: ${output}`));
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;AAC5B,MAAM,CAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAA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KAAK,EAAE,GAAgB,EAAE,EAAE;IACtC,MAAM,MAAM,GAAW,GAAG,EAAE,MAAM,IAAI,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;QACpC,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;QAC9B,UAAU,EAAE,GAAG,EAAE,MAAM,IAAI,SAAS;KACrC,CAAC,CAAC;IAEH,MAAM,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC,CAAC;AAChD,CAAC,CAAC,CACH,CAAC;AAEJ,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { loadContentfulConfig } from '@jungvonmatt/contentful-config';
|
|
3
3
|
import { getEnvironment, pagedGet } from '@jungvonmatt/contentful-ssg/lib/contentful';
|
|
4
|
-
import { askMissing } from '@jungvonmatt/contentful-ssg/lib/ui';
|
|
5
4
|
import { CFDefinitionsBuilder } from 'cf-content-types-generator';
|
|
6
5
|
import { readPackageUp } from 'read-pkg-up';
|
|
7
6
|
import semiver from 'semiver';
|
|
@@ -19,11 +18,12 @@ const isLegacyVersion = async (dir) => {
|
|
|
19
18
|
return false;
|
|
20
19
|
};
|
|
21
20
|
export const generateTypings = async (options = {}) => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const loaderResult = await loadContentfulConfig('contentful', {
|
|
22
|
+
configFile: options?.configFile,
|
|
23
|
+
cwd: options?.cwd,
|
|
24
|
+
required: ['managementToken', 'environmentId', 'spaceId'],
|
|
25
|
+
});
|
|
26
|
+
const client = await getEnvironment(loaderResult.config);
|
|
27
27
|
const { items: contentTypes } = await pagedGet(client, {
|
|
28
28
|
method: 'getContentTypes',
|
|
29
29
|
});
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAA4B,MAAM,4BAA4B,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACpB,aAAa,EACb,4BAA4B,EAC5B,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAW7B,MAAM,eAAe,GAAG,KAAK,EAAE,GAAY,EAAE,EAAE;IAC7C,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;QAC1E,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,aAAa,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAErD,IACE,WAAW,CAAC,IAAI,KAAK,YAAY;YAEjC,OAAO,CAAC,WAA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a,CAAC,CAAC,CAAC,IAAI,iBAAiB,EAAE,CAAC,CAAC,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAEpD,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE,CAAC;QACjC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,OAAO,CAAC,QAAQ,EAAE,CAAC;AAC5B,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungvonmatt/contentful-typings",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"homepage": "https://github.com/jungvonmatt/contentful-ssg#readme",
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@faker-js/faker": "^8.3.1",
|
|
41
|
-
"@jungvonmatt/contentful-ssg": "^
|
|
41
|
+
"@jungvonmatt/contentful-ssg": "^3.0.0",
|
|
42
42
|
"cf-content-types-generator": "^2.13.1",
|
|
43
43
|
"change-case": "^5.4.2",
|
|
44
44
|
"commander": "^11.1.0",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"@types/chance": "^1.1.6",
|
|
58
58
|
"ts-morph": "^19.0.0"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "31f9f440b9e48364b7e11372ca0accf55c8ff368"
|
|
61
61
|
}
|
package/src/cli.ts
CHANGED
|
@@ -19,6 +19,8 @@ type CommandArgs = {
|
|
|
19
19
|
jsdoc?: boolean;
|
|
20
20
|
localized?: boolean;
|
|
21
21
|
legacy?: boolean;
|
|
22
|
+
cwd?: string;
|
|
23
|
+
config?: string;
|
|
22
24
|
};
|
|
23
25
|
|
|
24
26
|
type CommandError = Error & {
|
|
@@ -49,6 +51,11 @@ const program = new Command();
|
|
|
49
51
|
program
|
|
50
52
|
.command('generate')
|
|
51
53
|
.description('Generate typescript definitions for contentful content types.')
|
|
54
|
+
.option(
|
|
55
|
+
'--config <configFile>',
|
|
56
|
+
'Use this configuration, overriding other config options if present',
|
|
57
|
+
)
|
|
58
|
+
.option('--cwd <directory>', 'Working directory. Defaults to process.cwd()')
|
|
52
59
|
.option('-o, --output <filepath>', 'Specify output file', '@types/contentful.ts')
|
|
53
60
|
.option('-l, --localized', 'Add localized types')
|
|
54
61
|
.option('-d, --jsdoc', 'Add JSDoc comments')
|
|
@@ -62,6 +69,8 @@ program
|
|
|
62
69
|
jsdoc: cmd.jsdoc,
|
|
63
70
|
localized: cmd.localized,
|
|
64
71
|
legacy: cmd.legacy,
|
|
72
|
+
cwd: cmd?.cwd || process.cwd(),
|
|
73
|
+
configFile: cmd?.config || undefined,
|
|
65
74
|
});
|
|
66
75
|
|
|
67
76
|
await outputFile(output, typings);
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/* _eslint-disable @typescript-eslint/no-unsafe-call */
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { type ContentfulConfig, type ContentType } from '@jungvonmatt/contentful-ssg';
|
|
4
|
-
import {
|
|
4
|
+
import { loadContentfulConfig } from '@jungvonmatt/contentful-config';
|
|
5
5
|
import { getEnvironment, pagedGet } from '@jungvonmatt/contentful-ssg/lib/contentful';
|
|
6
|
-
import { askMissing } from '@jungvonmatt/contentful-ssg/lib/ui';
|
|
7
6
|
import { CFDefinitionsBuilder, type ContentTypeRenderer } from 'cf-content-types-generator';
|
|
8
7
|
import { readPackageUp } from 'read-pkg-up';
|
|
9
8
|
import semiver from 'semiver';
|
|
@@ -22,6 +21,8 @@ type Options = {
|
|
|
22
21
|
jsdoc?: boolean;
|
|
23
22
|
typeguard?: boolean;
|
|
24
23
|
legacy?: boolean;
|
|
24
|
+
cwd?: string;
|
|
25
|
+
configFile?: string;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
28
|
const isLegacyVersion = async (dir?: string) => {
|
|
@@ -42,14 +43,13 @@ const isLegacyVersion = async (dir?: string) => {
|
|
|
42
43
|
};
|
|
43
44
|
|
|
44
45
|
export const generateTypings = async (options: Options = {}) => {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
);
|
|
46
|
+
const loaderResult = await loadContentfulConfig<ContentfulConfig>('contentful', {
|
|
47
|
+
configFile: options?.configFile,
|
|
48
|
+
cwd: options?.cwd,
|
|
49
|
+
required: ['managementToken', 'environmentId', 'spaceId'],
|
|
50
|
+
});
|
|
51
51
|
|
|
52
|
-
const client = await getEnvironment(
|
|
52
|
+
const client = await getEnvironment(loaderResult.config);
|
|
53
53
|
|
|
54
54
|
const { items: contentTypes } = await pagedGet<ContentType>(client, {
|
|
55
55
|
method: 'getContentTypes',
|