Skip to content

Commit

Permalink
Merge pull request #73 from Contentstack-Solutions/staging
Browse files Browse the repository at this point in the history
Merge staging to main
  • Loading branch information
aman19K authored Dec 18, 2023
2 parents a6bbf20 + d45d075 commit c825c9a
Show file tree
Hide file tree
Showing 18 changed files with 438 additions and 370 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Node.js CI

on:
push:
branches: [ master ]
branches: [ master, development, staging ]
pull_request:
branches: [ master ]
branches: [ master, development, staging ]

jobs:
build:
Expand Down
249 changes: 158 additions & 91 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "contentstack-cli-tsgen",
"description": "Generate TypeScript typings from a Stack.",
"version": "2.2.0",
"version": "2.2.1",
"author": "Michael Davis",
"bugs": "https://github.com/Contentstack-Solutions/contentstack-cli-tsgen/issues",
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/lib/stack/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type FieldOptions = {
multiple: boolean;
non_localizable: boolean;
max_instance: boolean | undefined;
display_type: string;
} & Identifier;

export type Block = {
Expand Down
5 changes: 2 additions & 3 deletions src/lib/tsgen/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ export default function (userOptions: TSGenOptions) {
fieldType += "[]";
}
}

return [
field.uid + op_required(field.mandatory) + ':',
fieldType || visit_field_type(field) + ';',
fieldType || visit_field_type(field), (['isodate','file','number'].includes(field.data_type) || ['radio','dropdown'].includes(field.display_type))?field.mandatory?'':'| null':'', ';'
].join(' ')
}

Expand Down Expand Up @@ -272,7 +271,7 @@ export default function (userOptions: TSGenOptions) {
}

function type_text() {
return 'string'
return 'string'
}

function type_number() {
Expand Down
38 changes: 19 additions & 19 deletions tests/tsgen/boolean.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
const testData = require('./boolean.ct')
const testData = require("./boolean.ct");

import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc'
import tsgenFactory from '../../src/lib/tsgen/factory'
import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc";
import tsgenFactory from "../../src/lib/tsgen/factory";

const tsgen = tsgenFactory({
docgen: new NullDocumentationGenerator(),
naming: {
prefix: 'I',
prefix: "I",
},
})
});

describe('builtin boolean field', () => {
const result = tsgen(testData.builtinBoolean)
describe("builtin boolean field", () => {
const result = tsgen(testData.builtinBoolean);

test('metadata', () => {
const types = result.metadata.types
expect([...types.contentstack]).toHaveLength(0)
expect([...types.globalFields]).toHaveLength(0)
expect(types.javascript).toContain('boolean')
})
test("metadata", () => {
const types = result.metadata.types;
expect([...types.contentstack]).toHaveLength(0);
expect([...types.globalFields]).toHaveLength(0);
expect(types.javascript).toContain("boolean");
});

test('definition', () => {
test("definition", () => {
expect(result.definition).toMatchInlineSnapshot(`
"export interface IBoolean
{
/** Version */
version: 2 ;
title: string;
boolean?: boolean;
title: string ;
boolean?: boolean ;
}"
`)
})
})
`);
});
});
58 changes: 29 additions & 29 deletions tests/tsgen/defaults.test.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
const testData = require('./defaults.ct')
const testData = require("./defaults.ct");

import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc'
import tsgenFactory from '../../src/lib/tsgen/factory'
import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc";
import tsgenFactory from "../../src/lib/tsgen/factory";

const tsgen = tsgenFactory({
docgen: new NullDocumentationGenerator(),
naming: {
prefix: 'I',
prefix: "I",
},
})
});

describe('default single content block', () => {
const result = tsgen(testData.defaultSingleContentBlock)
describe("default single content block", () => {
const result = tsgen(testData.defaultSingleContentBlock);

test('definition', () => {
test("definition", () => {
expect(result.definition).toMatchInlineSnapshot(`
"export interface IMetadataSingleContentBlock
{
/** Version */
version: 2 ;
title: string;
title: string ;
}"
`)
})
})
`);
});
});

describe('default single webpage', () => {
const result = tsgen(testData.defaultSingleWebpage)
describe("default single webpage", () => {
const result = tsgen(testData.defaultSingleWebpage);

test('types', () => {
const types = result.metadata.types
expect([...types.contentstack]).toHaveLength(0)
expect([...types.globalFields]).toHaveLength(0)
expect(types.javascript).toContain('string')
})
test("types", () => {
const types = result.metadata.types;
expect([...types.contentstack]).toHaveLength(0);
expect([...types.globalFields]).toHaveLength(0);
expect(types.javascript).toContain("string");
});

test('dependencies', () => {
expect(result.metadata.dependencies.globalFields).toEqual({})
})
test("dependencies", () => {
expect(result.metadata.dependencies.globalFields).toEqual({});
});

test('definition', () => {
test("definition", () => {
expect(result.definition).toMatchInlineSnapshot(`
"export interface IMetadataSingleWebpage
{
/** Version */
version: 2 ;
title: string;
url: string;
title: string ;
url: string ;
}"
`)
})
})
`);
});
});
46 changes: 23 additions & 23 deletions tests/tsgen/global.fields.test.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
const testData = require('./global.fields.ct')
const testData = require("./global.fields.ct");

import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc'
import tsgenFactory from '../../src/lib/tsgen/factory'
import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc";
import tsgenFactory from "../../src/lib/tsgen/factory";

const tsgen = tsgenFactory({
docgen: new NullDocumentationGenerator(),
naming: {
prefix: 'I',
prefix: "I",
},
})
});

describe('global fields', () => {
const result = tsgen(testData.globalFields)
describe("global fields", () => {
const result = tsgen(testData.globalFields);

test('metadata', () => {
const types = result.metadata.types
test("metadata", () => {
const types = result.metadata.types;

expect([...types.globalFields]).toEqual(expect.arrayContaining(['ISeo']))
})
expect([...types.globalFields]).toEqual(expect.arrayContaining(["ISeo"]));
});

test('global field definition', () => {
const globalField = result.metadata.dependencies.globalFields.ISeo
test("global field definition", () => {
const globalField = result.metadata.dependencies.globalFields.ISeo;
expect(globalField.definition).toMatchInlineSnapshot(`
"export interface ISeo
{
/** Version */
version: ;
keywords?: string;
description?: string;
keywords?: string ;
description?: string ;
}"
`)
})
`);
});

test('content type definition', () => {
test("content type definition", () => {
expect(result.definition).toMatchInlineSnapshot(`
"export interface IGlobalFields
{
/** Version */
version: 2 ;
title: string;
seo?: ISeo;
title: string ;
seo?: ISeo ;
}"
`)
})
})
`);
});
});
68 changes: 34 additions & 34 deletions tests/tsgen/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
const testData = require('./group.ct')
const testData = require("./group.ct");

import NullDocumentationGenerator from '../../src/lib/tsgen/docgen/nulldoc'
import tsgenFactory from '../../src/lib/tsgen/factory'
import NullDocumentationGenerator from "../../src/lib/tsgen/docgen/nulldoc";
import tsgenFactory from "../../src/lib/tsgen/factory";

const tsgen = tsgenFactory({
docgen: new NullDocumentationGenerator(),
})
});

describe('group', () => {
const result = tsgen(testData.group)
describe("group", () => {
const result = tsgen(testData.group);

test('metadata', () => {
const types = result.metadata.types
expect([...types.contentstack]).toHaveLength(0)
expect([...types.globalFields]).toHaveLength(0)
test("metadata", () => {
const types = result.metadata.types;
expect([...types.contentstack]).toHaveLength(0);
expect([...types.globalFields]).toHaveLength(0);
expect([...types.javascript]).toEqual(
expect.arrayContaining(['string', 'number', 'boolean'])
)
})
expect.arrayContaining(["string", "number", "boolean"])
);
});

test('definition', () => {
test("definition", () => {
expect(result.definition).toMatchInlineSnapshot(`
"export interface Group
{
/** Version */
version: 3 ;
title: string;
title: string ;
multiple_group_max_limit?: [{
number?: number;
number?: number | null ;
}, {
number?: number;
number?: number | null ;
}, {
number?: number;
number?: number | null ;
}, {
number?: number;
number?: number | null ;
}, {
number?: number;
}];
number?: number | null ;
}] ;
multiple_group?: {
single_line?: string;
}[];
single_line?: string ;
}[] ;
parent_group?: {
rich_text_editor?: string;
multi_line?: string;
single_line?: string;
rich_text_editor?: string ;
multi_line?: string ;
single_line?: string ;
child_group?: {
number?: number;
boolean?: boolean;
date?: string;
};
};
number?: number | null ;
boolean?: boolean ;
date?: string | null ;
} ;
} ;
}"
`)
})
})
`);
});
});
Loading

0 comments on commit c825c9a

Please sign in to comment.