Skip to content

Commit df0a6a9

Browse files
committed
fix(render): move imports
1 parent 0ccb2c6 commit df0a6a9

File tree

4 files changed

+746
-542
lines changed

4 files changed

+746
-542
lines changed

src/contentful-typescript-codegen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const cli = meow(
4848
type: "string",
4949
alias: "n",
5050
required: false,
51-
}
51+
},
5252
},
5353
},
5454
)

src/renderers/render.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ import renderUnion from "./typescript/renderUnion"
88
import renderAllLocales from "./contentful/renderAllLocales"
99
import renderDefaultLocale from "./contentful/renderDefaultLocale"
1010

11-
export default async function render(contentTypes: ContentType[], locales: Locale[], namespace: string | null) {
11+
export default async function render(
12+
contentTypes: ContentType[],
13+
locales: Locale[],
14+
namespace: string | null,
15+
) {
1216
const sortedContentTypes = contentTypes.sort((a, b) => a.sys.id.localeCompare(b.sys.id))
1317
const sortedLocales = locales.sort((a, b) => a.code.localeCompare(b.code))
1418

15-
const source = wrapInNamespace([
16-
renderContentfulImports(),
19+
const typings = [
1720
renderAllContentTypes(sortedContentTypes),
1821
renderAllContentTypeIds(sortedContentTypes),
1922
renderAllLocales(sortedLocales),
2023
renderDefaultLocale(sortedLocales),
21-
].join("\n\n"), namespace)
24+
].join("\n\n")
25+
26+
const source = [renderContentfulImports(), wrapInNamespace(typings, namespace)].join("\n\n")
2227

2328
const prettierConfig = await resolveConfig(process.cwd())
2429
return format(source, { ...prettierConfig, parser: "typescript" })

test/renderers/render.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ describe("render()", () => {
8989
`)
9090

9191
expect(await render(contentTypes, locales, "Codegen")).toMatchInlineSnapshot(`
92-
"declare namespace Codegen {
93-
// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
92+
"// THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY IT.
9493
95-
import { Asset, Entry } from \\"contentful\\"
96-
import { Document } from \\"@contentful/rich-text-types\\"
94+
import { Asset, Entry } from \\"contentful\\"
95+
import { Document } from \\"@contentful/rich-text-types\\"
9796
97+
declare namespace Codegen {
9898
export interface IMyContentTypeFields {
9999
/** Array field */
100100
arrayField: (\\"one\\" | \\"of\\" | \\"the\\" | \\"above\\")[]
@@ -117,11 +117,11 @@ describe("render()", () => {
117117
}
118118
}
119119
120-
export type CONTENT_TYPE = \\"myContentType\\"
120+
type CONTENT_TYPE = \\"myContentType\\"
121121
122-
export type LOCALE_CODE = \\"en-US\\" | \\"pt-BR\\"
122+
type LOCALE_CODE = \\"en-US\\" | \\"pt-BR\\"
123123
124-
export type CONTENTFUL_DEFAULT_LOCALE_CODE = \\"en-US\\"
124+
type CONTENTFUL_DEFAULT_LOCALE_CODE = \\"en-US\\"
125125
}
126126
127127
export as namespace Codegen

0 commit comments

Comments
 (0)