From 69e8dcb2ac423291c759a737682912231d0ddff5 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 25 Sep 2023 16:00:54 +0530 Subject: [PATCH 1/4] Added the version info in generated types for both content type and global field. Version bump --- package-lock.json | 4 ++-- package.json | 2 +- src/lib/stack/schema.ts | 1 + src/lib/tsgen/factory.ts | 2 ++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3347c68..bc9e5fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "contentstack-cli-tsgen", - "version": "2.1.6", + "version": "2.1.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "contentstack-cli-tsgen", - "version": "2.1.6", + "version": "2.1.7", "license": "MIT", "dependencies": { "@contentstack/cli-command": "^1.2.9", diff --git a/package.json b/package.json index 4b3d351..fca5bc3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "contentstack-cli-tsgen", "description": "Generate TypeScript typings from a Stack.", - "version": "2.1.6", + "version": "2.1.7", "author": "Michael Davis", "bugs": "https://github.com/Contentstack-Solutions/contentstack-cli-tsgen/issues", "dependencies": { diff --git a/src/lib/stack/schema.ts b/src/lib/stack/schema.ts index 0fa18a4..e02e8a4 100644 --- a/src/lib/stack/schema.ts +++ b/src/lib/stack/schema.ts @@ -27,6 +27,7 @@ export type Block = { export type GlobalField = { reference_to: string; schema: Schema; + _version?: number } & FieldOptions; export type ReferenceField = { diff --git a/src/lib/tsgen/factory.ts b/src/lib/tsgen/factory.ts index e794d39..ee7ed6f 100644 --- a/src/lib/tsgen/factory.ts +++ b/src/lib/tsgen/factory.ts @@ -228,6 +228,8 @@ export default function (userOptions: TSGenOptions) { options.docgen.interface(contentType.description), define_interface(contentType), '{', + ['/**', "Version", '*/'].join(' '), + [`version: `,contentType._version].join(' '), visit_fields(contentType.schema), '}', ] From d8859e482842b3809dafda63f32c5b56c931ca4f Mon Sep 17 00:00:00 2001 From: raj pandey Date: Mon, 25 Sep 2023 17:37:40 +0530 Subject: [PATCH 2/4] Modified the test cases to include version information --- firstts.ts | 105 +++++++++++++++++++++++++++++ src/lib/tsgen/factory.ts | 2 +- tests/tsgen/boolean.test.ts | 2 + tests/tsgen/defaults.test.ts | 4 ++ tests/tsgen/global.fields.test.ts | 4 ++ tests/tsgen/group.test.ts | 2 + tests/tsgen/isodate.test.ts | 2 + tests/tsgen/jsdoc.test.ts | 2 + tests/tsgen/modular.blocks.test.ts | 2 + tests/tsgen/number.test.ts | 2 + tests/tsgen/options.test.ts | 2 + tests/tsgen/references.test.ts | 2 + tests/tsgen/select.test.ts | 2 + tests/tsgen/string.test.ts | 2 + 14 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 firstts.ts diff --git a/firstts.ts b/firstts.ts new file mode 100644 index 0000000..8d467b4 --- /dev/null +++ b/firstts.ts @@ -0,0 +1,105 @@ +export interface File { + uid: string; + created_at: string; + updated_at: string; + created_by: string; + updated_by: string; + content_type: string; + file_size: string; + tags: string[]; + filename: string; + url: string; + ACL: any[]; + is_dir: boolean; + parent_uid: string; + _version: number; + title: string; + publish_details: { + environment: string; + locale: string; + time: string; + user: string; + }; +} + +export interface Link { + title: string; + href: string; +} + +export interface Newglobalfield { + /** Version */ + version: 1; + /** Single Line Textbox */ + single_line?: string; +} + +export interface Fdsf { + /** Version */ + version: 3; + /** Rich Text Editor */ + rich_text_editor?: string; + /** JSON Rich Text Editor */ + json_rte?: any; + /** Markdown */ + markdown?: string; +} + +export interface C3 { + /** Version */ + version: 2; + /** Title */ + title: string; +} + +export interface C2 { + /** Version */ + version: 3; + /** Title */ + title: string; + /** Reference */ + reference?: C3[]; +} + +/** This is contentType for testing */ +export interface C1 { + /** Version */ + version: 6; + /** Title */ + title: string; + /** NumFeild */ + numfeild: number; + /** BoolField */ + boolfield?: boolean; + /** Date1 */ + date1?: string; + /** FileFeild */ + filefeild?: File; + /** SelectSingle */ + selectsingle?: "a" | "b"; + /** SelectMultiple */ + selectmultiple?: ("A:a" | "B:b" | "C:c" | "D:d")[]; + /** Modular Blocks Feild */ + modular_blocks_feild?: ( + | { + newblock1: { + /** Single Line Textbox */ single_line?: string; + }; + newblock2: undefined; + } + | { + newblock2: { + /** Single Line Textbox */ single_line?: string; + }; + newblock1: undefined; + } + )[]; + /** Rich Text Editor Feild */ + rich_text_editor_feild?: string; + /** JSON Rich Text Editor Field */ + json_rich_text_editor_field?: any; + /** File */ + file: File[]; + /** Reference */ + reference?: (C3 | C2 | C1)[]; +} diff --git a/src/lib/tsgen/factory.ts b/src/lib/tsgen/factory.ts index ee7ed6f..75929ee 100644 --- a/src/lib/tsgen/factory.ts +++ b/src/lib/tsgen/factory.ts @@ -229,7 +229,7 @@ export default function (userOptions: TSGenOptions) { define_interface(contentType), '{', ['/**', "Version", '*/'].join(' '), - [`version: `,contentType._version].join(' '), + [`version: `,contentType._version,';'].join(' '), visit_fields(contentType.schema), '}', ] diff --git a/tests/tsgen/boolean.test.ts b/tests/tsgen/boolean.test.ts index 985a32f..a49c0fc 100644 --- a/tests/tsgen/boolean.test.ts +++ b/tests/tsgen/boolean.test.ts @@ -24,6 +24,8 @@ describe('builtin boolean field', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IBoolean { + /** Version */ + version: 2 ; title: string; boolean?: boolean; }" diff --git a/tests/tsgen/defaults.test.ts b/tests/tsgen/defaults.test.ts index 6fdaf27..0fc5ba1 100644 --- a/tests/tsgen/defaults.test.ts +++ b/tests/tsgen/defaults.test.ts @@ -17,6 +17,8 @@ describe('default single content block', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IMetadataSingleContentBlock { + /** Version */ + version: 2 ; title: string; }" `) @@ -41,6 +43,8 @@ describe('default single webpage', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IMetadataSingleWebpage { + /** Version */ + version: 2 ; title: string; url: string; }" diff --git a/tests/tsgen/global.fields.test.ts b/tests/tsgen/global.fields.test.ts index c4a3632..4e78e7a 100644 --- a/tests/tsgen/global.fields.test.ts +++ b/tests/tsgen/global.fields.test.ts @@ -24,6 +24,8 @@ describe('global fields', () => { expect(globalField.definition).toMatchInlineSnapshot(` "export interface ISeo { + /** Version */ + version: ; keywords?: string; description?: string; }" @@ -34,6 +36,8 @@ describe('global fields', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IGlobalFields { + /** Version */ + version: 2 ; title: string; seo?: ISeo; }" diff --git a/tests/tsgen/group.test.ts b/tests/tsgen/group.test.ts index 52ca480..116591d 100644 --- a/tests/tsgen/group.test.ts +++ b/tests/tsgen/group.test.ts @@ -23,6 +23,8 @@ describe('group', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Group { + /** Version */ + version: 3 ; title: string; multiple_group_max_limit?: [{ number?: number; diff --git a/tests/tsgen/isodate.test.ts b/tests/tsgen/isodate.test.ts index d66b039..1ef533f 100644 --- a/tests/tsgen/isodate.test.ts +++ b/tests/tsgen/isodate.test.ts @@ -24,6 +24,8 @@ describe('builtin isodate field', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Isodate { + /** Version */ + version: 2 ; title: string; date?: string; date_required: string; diff --git a/tests/tsgen/jsdoc.test.ts b/tests/tsgen/jsdoc.test.ts index ca3f029..044bcd0 100644 --- a/tests/tsgen/jsdoc.test.ts +++ b/tests/tsgen/jsdoc.test.ts @@ -15,6 +15,8 @@ describe('jsdoc', () => { "/** Content Type Description */ export interface Jsdoc { + /** Version */ + version: 3 ; /** Name */ title: string; /** Age */ diff --git a/tests/tsgen/modular.blocks.test.ts b/tests/tsgen/modular.blocks.test.ts index 4f2d376..636286d 100644 --- a/tests/tsgen/modular.blocks.test.ts +++ b/tests/tsgen/modular.blocks.test.ts @@ -20,6 +20,8 @@ describe('modular blocks', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface ModularBlocks { + /** Version */ + version: 2 ; title: string; url: string; modular_blocks?: ({string_block: {single_line?: string; diff --git a/tests/tsgen/number.test.ts b/tests/tsgen/number.test.ts index 09d9dbd..ffa0114 100644 --- a/tests/tsgen/number.test.ts +++ b/tests/tsgen/number.test.ts @@ -21,6 +21,8 @@ describe('builtin number field', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Number { + /** Version */ + version: 2 ; title: string; url: string; number?: number; diff --git a/tests/tsgen/options.test.ts b/tests/tsgen/options.test.ts index 51a5b9c..4ff9df0 100644 --- a/tests/tsgen/options.test.ts +++ b/tests/tsgen/options.test.ts @@ -14,6 +14,8 @@ describe('all options', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Options { + /** Version */ + version: 4 ; title: string; url: string; single_line_textbox_not_required?: string; diff --git a/tests/tsgen/references.test.ts b/tests/tsgen/references.test.ts index 77698a2..0d70a5d 100644 --- a/tests/tsgen/references.test.ts +++ b/tests/tsgen/references.test.ts @@ -25,6 +25,8 @@ describe('references', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface IReferenceParent { + /** Version */ + version: 5 ; title: string; url: string; single_reference: (IReferenceChild)[]; diff --git a/tests/tsgen/select.test.ts b/tests/tsgen/select.test.ts index d5402a4..4894c4c 100644 --- a/tests/tsgen/select.test.ts +++ b/tests/tsgen/select.test.ts @@ -20,6 +20,8 @@ describe('select (dropdown)', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface Select { + /** Version */ + version: 5 ; title: string; select_single_value?: (\\"Option 1\\" | \\"Option 2\\" | \\"Option 3\\"); select_single_value_required: (\\"Test 1\\" | \\"Test 2\\" | \\"Test 3\\"); diff --git a/tests/tsgen/string.test.ts b/tests/tsgen/string.test.ts index 5d02b6c..16ff2c1 100644 --- a/tests/tsgen/string.test.ts +++ b/tests/tsgen/string.test.ts @@ -21,6 +21,8 @@ describe('builtin string fields', () => { expect(result.definition).toMatchInlineSnapshot(` "export interface BuiltinStrings { + /** Version */ + version: 4 ; title: string; single_line?: string; multi_line?: string; From 7fa68d2dc73bbac1c007c7b3a467e48d22fd6be3 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Tue, 26 Sep 2023 10:46:05 +0530 Subject: [PATCH 3/4] Removed the firstt.ts file as it was the generated --- firstts.ts | 105 ----------------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 firstts.ts diff --git a/firstts.ts b/firstts.ts deleted file mode 100644 index 8d467b4..0000000 --- a/firstts.ts +++ /dev/null @@ -1,105 +0,0 @@ -export interface File { - uid: string; - created_at: string; - updated_at: string; - created_by: string; - updated_by: string; - content_type: string; - file_size: string; - tags: string[]; - filename: string; - url: string; - ACL: any[]; - is_dir: boolean; - parent_uid: string; - _version: number; - title: string; - publish_details: { - environment: string; - locale: string; - time: string; - user: string; - }; -} - -export interface Link { - title: string; - href: string; -} - -export interface Newglobalfield { - /** Version */ - version: 1; - /** Single Line Textbox */ - single_line?: string; -} - -export interface Fdsf { - /** Version */ - version: 3; - /** Rich Text Editor */ - rich_text_editor?: string; - /** JSON Rich Text Editor */ - json_rte?: any; - /** Markdown */ - markdown?: string; -} - -export interface C3 { - /** Version */ - version: 2; - /** Title */ - title: string; -} - -export interface C2 { - /** Version */ - version: 3; - /** Title */ - title: string; - /** Reference */ - reference?: C3[]; -} - -/** This is contentType for testing */ -export interface C1 { - /** Version */ - version: 6; - /** Title */ - title: string; - /** NumFeild */ - numfeild: number; - /** BoolField */ - boolfield?: boolean; - /** Date1 */ - date1?: string; - /** FileFeild */ - filefeild?: File; - /** SelectSingle */ - selectsingle?: "a" | "b"; - /** SelectMultiple */ - selectmultiple?: ("A:a" | "B:b" | "C:c" | "D:d")[]; - /** Modular Blocks Feild */ - modular_blocks_feild?: ( - | { - newblock1: { - /** Single Line Textbox */ single_line?: string; - }; - newblock2: undefined; - } - | { - newblock2: { - /** Single Line Textbox */ single_line?: string; - }; - newblock1: undefined; - } - )[]; - /** Rich Text Editor Feild */ - rich_text_editor_feild?: string; - /** JSON Rich Text Editor Field */ - json_rich_text_editor_field?: any; - /** File */ - file: File[]; - /** Reference */ - reference?: (C3 | C2 | C1)[]; -} From 1dcd521ae7a43dc69d3dc3727280b5e7c7cdd9cf Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Wed, 27 Sep 2023 11:00:02 +0530 Subject: [PATCH 4/4] fix: added csdxConfig and bumped version --- package-lock.json | 4 ++-- package.json | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3347c68..bc9e5fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "contentstack-cli-tsgen", - "version": "2.1.6", + "version": "2.1.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "contentstack-cli-tsgen", - "version": "2.1.6", + "version": "2.1.7", "license": "MIT", "dependencies": { "@contentstack/cli-command": "^1.2.9", diff --git a/package.json b/package.json index 4b3d351..280593a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "contentstack-cli-tsgen", "description": "Generate TypeScript typings from a Stack.", - "version": "2.1.6", + "version": "2.1.7", "author": "Michael Davis", "bugs": "https://github.com/Contentstack-Solutions/contentstack-cli-tsgen/issues", "dependencies": { @@ -58,5 +58,10 @@ "prepack": "rm -rf lib && tsc -b && oclif manifest && oclif readme", "test": "jest", "version": "oclif readme && git add README.md" + }, + "csdxConfig": { + "shortCommandName": { + "tsgen": "TSGEN" + } } }