Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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: 4 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ fileignoreconfig:
- filename: lib/commands/tsgen.js
checksum: 02bab20fef5508565dbf38b5c12192c48ec27249b89d48c70303abaae17984ce
- filename: src/commands/tsgen.ts
checksum: b797eacb07acbf02dc0092c2453a6e13360f3b4c5fb54dc7f9a762cdd092fd0a
checksum: 5817a6320d368fb82354709962cdb9d357c6dcba870ba53bf21eade9708505ba
- filename: package-lock.json
checksum: 5e3bffdfa9849c876b60bfae8bb6b4d4f47673f834f3480e99efd8aa98d2f65f
checksum: 881e3bb4855315648df324c3f01fd610ee6e1997ea7af8afe6cc7b3ed517d1e5
- filename: src/lib/helper.ts
checksum: b271817a4a666edea15429e1a5b79c074ee7e525e26dc1e68904f003853ed7e2
version: "1.0"
150 changes: 75 additions & 75 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,7 +1,7 @@
{
"name": "contentstack-cli-tsgen",
"description": "Generate TypeScript typings from a Stack.",
"version": "4.4.0",
"version": "4.5.0",
"author": "Michael Davis",
"bugs": "https://github.com/Contentstack-Solutions/contentstack-cli-tsgen/issues",
"dependencies": {
Expand Down
53 changes: 35 additions & 18 deletions src/commands/tsgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { Command } from "@contentstack/cli-command";
import { flags, FlagInput } from "@contentstack/cli-utilities";
import * as path from "path";
import * as fs from "fs";
import { cliux } from "@contentstack/cli-utilities";
import { generateTS, graphqlTS } from "@contentstack/types-generator";
import { sanitizePath } from "../lib/helper";
import { sanitizePath, printFormattedError } from "../lib/helper";
import { StackConnectionConfig } from "../types";

function createOutputPath(outputFile: string) {
Expand Down Expand Up @@ -184,11 +185,8 @@ export default class TypeScriptCodeGeneratorCommand extends Command {
`Successfully added the GraphQL schema type definitions to '${outputPath}'.`,
);
} catch (error: any) {
const errorMessage =
error?.error_message ||
error?.message ||
"An error occurred while generating GraphQL types";
this.error(errorMessage, { exit: 1 });
printFormattedError(error, error?.context || "graphql");
process.exit(1);
}
} else {
// Generate the Content Types TypeScript definitions
Expand All @@ -204,24 +202,43 @@ export default class TypeScriptCodeGeneratorCommand extends Command {

fs.writeFileSync(outputPath, result || "");

// -- TODO : Add count support for the number of Content Types generated
this.log(`Successfully added the Content Types to '${outputPath}'.`);
// Check if we have any skipped content types and show summary
if (
result &&
typeof result === "string" &&
result.includes(
"Generation completed successfully with partial schema",
)
) {
cliux.print("", {});
cliux.print(
"Type generation completed successfully with partial schema!",
{ color: "green", bold: true },
);
cliux.print(
"Some content types were skipped due to validation issues, but types were generated for valid content types.",
{ color: "yellow" },
);
cliux.print(
"Check the output above for details on what was skipped and suggestions for fixing issues.",
{ color: "cyan" },
);
} else {
cliux.print(
`Successfully added the Content Types to '${outputPath}'.`,
{ color: "green" },
);
}

// this.log(`Wrote ${outputPath} Content Types to '${result.outputPath}'.`)
} catch (error: any) {
const errorMessage =
error?.error_message ||
error?.message ||
"An error occurred while generating TypeScript types";
this.error(errorMessage, { exit: 1 });
printFormattedError(error, error?.context || "tsgen");
process.exit(1);
}
}
} catch (error: any) {
const errorMessage =
error?.error_message ||
error?.message ||
"An unexpected error occurred";
this.error(errorMessage, { exit: 1 });
printFormattedError(error, error?.context || "tsgen");
process.exit(1);
}
}
}
Loading
Loading