@jackdbd/zod-to-doc
Advanced tools
Comparing version 1.0.6-canary.2 to 1.0.6-canary.3
# CHANGELOG | ||
## [1.0.6-canary.3](https://github.com/jackdbd/zod-to-doc/compare/v1.0.6-canary.2...v1.0.6-canary.3) (2024-02-06) | ||
### Bug Fixes | ||
* avoid throwing exceptions, better error messages ([d454274](https://github.com/jackdbd/zod-to-doc/commit/d4542740ffbfe3de20df8be9e00651990d600486)) | ||
## [1.0.6-canary.2](https://github.com/jackdbd/zod-to-doc/compare/v1.0.6-canary.1...v1.0.6-canary.2) (2024-02-06) | ||
@@ -4,0 +11,0 @@ |
@@ -7,6 +7,7 @@ #!/usr/bin/env node | ||
import { markdownTableFromZodSchema } from './lib.js'; | ||
import { CLI_NAME, DEBUG_PREFIX } from './constants.js'; | ||
import { CLI_NAME, DEBUG_PREFIX, INFO_PREFIX, LINK_ISSUE_BUG, LINK_ISSUE_ENHANCEMENT } from './constants.js'; | ||
import { couldNotGenerateTable, documentNotFound, esModuleNotFound, placeholderNotFound, schemaNotFound } from './error-messages.js'; | ||
const debug = defDebug(`${DEBUG_PREFIX}:cli`); | ||
const argv = await yargs(process.argv.slice(2)) | ||
.usage('./$0 - Generate a markdown table from a Zod schema and write it to a file') | ||
.usage(`$0 - Generate a markdown table from a Zod schema and write it to a file`) | ||
.option('module', { | ||
@@ -49,16 +50,23 @@ alias: 'm', | ||
.wrap(80) | ||
.epilogue('For more information, see https://github.com/jackdbd/zod-to-doc') | ||
.argv; | ||
.epilogue([ | ||
`Documenation:\nhttps://github.com/jackdbd/zod-to-doc`, | ||
`Found a bug? Please submit it here:\n${LINK_ISSUE_BUG}`, | ||
`Feature requests & suggestions:\n${LINK_ISSUE_ENHANCEMENT}` | ||
].join('\n\n')).argv; | ||
const module_filepath = path.join(process.env.PWD, argv.module); | ||
if (!fs.existsSync(module_filepath)) { | ||
throw new Error(`Module containing Zod schemas not found: ${module_filepath}`); | ||
console.error(esModuleNotFound(module_filepath)); | ||
process.exit(1); | ||
} | ||
const es_module = await import(module_filepath); | ||
const schema = es_module[argv.schema]; | ||
if (!schema) { | ||
console.error(schemaNotFound(argv.schema, module_filepath)); | ||
process.exit(1); | ||
} | ||
debug(`import { ${argv.schema} } from '${module_filepath}'`); | ||
const { error, value: table } = markdownTableFromZodSchema(schema); | ||
if (error) { | ||
const message = `Could not generate table from Zod schema: ${error.message}`; | ||
console.error(error); | ||
throw new Error(message); | ||
console.error(couldNotGenerateTable(error)); | ||
process.exit(1); | ||
} | ||
@@ -69,3 +77,4 @@ debug(`table generated from Zod schema`); | ||
if (!fs.existsSync(doc_filepath)) { | ||
throw new Error(`Document file not found: ${doc_filepath}`); | ||
console.error(documentNotFound(doc_filepath)); | ||
process.exit(1); | ||
} | ||
@@ -84,4 +93,4 @@ debug(`read ${doc_filepath}`); | ||
if (i_begin === -1) { | ||
const detail = `Please make sure to put both ${placeholder_begin} and ${placeholder_end} in ${doc_filepath}`; | ||
throw new Error(`Placeholder not found\n${detail}`); | ||
console.error(placeholderNotFound(argv.placeholder, doc_filepath)); | ||
process.exit(1); | ||
} | ||
@@ -103,3 +112,3 @@ const before = str.substring(0, i_begin).trimEnd(); | ||
if (argv['dry-run']) { | ||
console.log(`${doc_filepath} not modified because of --dry-run. Here is how it would look like:`); | ||
console.info(`${INFO_PREFIX} ${doc_filepath} not modified because of --dry-run. Here is how it would look like:`); | ||
console.log(`=== BEGIN ${doc_filepath} ===`); | ||
@@ -111,4 +120,4 @@ console.log(md); | ||
fs.writeFileSync(doc_filepath, md); | ||
console.log(`${doc_filepath} updated`); | ||
console.info(`${INFO_PREFIX} ${doc_filepath} updated`); | ||
} | ||
//# sourceMappingURL=cli.js.map |
export declare const CLI_NAME = "ztd"; | ||
export declare const DEBUG_PREFIX = "ztd"; | ||
export declare const ERROR_PREFIX = "\u274C"; | ||
export declare const INFO_PREFIX = "\uD83D\uDEC8"; | ||
export declare const LINK_ISSUE_BUG = "https://github.com/jackdbd/zod-to-doc/labels/bug"; | ||
export declare const LINK_ISSUE_ENHANCEMENT = "https://github.com/jackdbd/zod-to-doc/labels/enhancement"; | ||
//# sourceMappingURL=constants.d.ts.map |
export const CLI_NAME = 'ztd'; | ||
export const DEBUG_PREFIX = 'ztd'; | ||
export const ERROR_PREFIX = '❌'; | ||
export const INFO_PREFIX = '🛈'; | ||
export const LINK_ISSUE_BUG = `https://github.com/jackdbd/zod-to-doc/labels/bug`; | ||
export const LINK_ISSUE_ENHANCEMENT = `https://github.com/jackdbd/zod-to-doc/labels/enhancement`; | ||
//# sourceMappingURL=constants.js.map |
{ | ||
"name": "@jackdbd/zod-to-doc", | ||
"version": "1.0.6-canary.2", | ||
"version": "1.0.6-canary.3", | ||
"description": "Inject your [Zod](https://github.com/colinhacks/zod) schemas into your docs.", | ||
@@ -5,0 +5,0 @@ "author": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43971
21
569