Skip to content

[DX-2968], added support for CSLP tags #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ fileignoreconfig:
checksum: 7ca77c023135dd0b7cf06a754dac82689f5a024141e444eadc04c840169bb4d1
- filename: .husky/pre-commit
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
- filename: src/generateTS/factory.ts
checksum: 0a693ed8cc35d373f3c88d2ca6b538648d2594e83c495e841546c161e419c8fe
- filename: tests/integration/generateTS/generateTS.test.ts
checksum: 328090da57e8cb2dd616091f3336b6da77a253f97ddfd47e3e1dd683260e58eb
- filename: src/generateTS/shared/cslp-helpers.ts
checksum: 55aa5c0c9ec0cd6c6139d4e9e4f1666abc7bc083313ccc2bf410c56935f35ef2
version: "1.0"
270 changes: 2 additions & 268 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/types-generator",
"version": "3.2.0",
"version": "3.3.0",
"description": "Contentstack type definition generation library",
"private": false,
"author": "Contentstack",
Expand Down
34 changes: 27 additions & 7 deletions src/generateTS/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { DocumentationGenerator } from "./docgen/doc";
import NullDocumentationGenerator from "./docgen/nulldoc";
import * as ContentstackTypes from "../types/schema";
import * as _ from "lodash";
import { CSLP_HELPERS } from "./shared/cslp-helpers";

export type TSGenOptions = {
docgen: DocumentationGenerator;
naming?: {
prefix: string;
};
systemFields?: boolean;
isEditableTags?: boolean;
};

export type TSGenResult = {
Expand Down Expand Up @@ -60,6 +62,7 @@ const defaultOptions: TSGenOptions = {
prefix: "",
},
systemFields: false,
isEditableTags: false,
};

export default function (userOptions: TSGenOptions) {
Expand Down Expand Up @@ -251,13 +254,30 @@ export default function (userOptions: TSGenOptions) {
}

function visit_fields(schema: ContentstackTypes.Schema) {
return schema
.map((v) => {
return [options.docgen.field(v.display_name), visit_field(v)]
.filter((v) => v)
.join("\n");
})
.join("\n");
const fieldLines: string[] = [];
const dollarKeys: string[] = [];

for (const field of schema) {
const line = [
options.docgen.field(field.display_name),
visit_field(field),
]
.filter((v) => v)
.join("\n");

fieldLines.push(line);
dollarKeys.push(CSLP_HELPERS.createFieldMapping(field.uid));
}

// If editableTags is enabled, add the $ field
if (options.isEditableTags) {
fieldLines.push(
`\n${CSLP_HELPERS.FIELD_COMMENT}`,
CSLP_HELPERS.createMappingBlock(dollarKeys)
);
}

return fieldLines.join("\n");
}

function visit_content_type(
Expand Down
Loading