From 37ef0349205d51fe6dfe7283839af737faf1fc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Sat, 4 Mar 2023 10:40:17 +0100 Subject: [PATCH] #780: add --format param to generic document methods --- docs/dist/documentation.md | 10 ++++++---- lib/cli.js | 8 ++++++-- lib/index.js | 5 +++-- lib/metadataTypes/MetadataType.js | 3 ++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/docs/dist/documentation.md b/docs/dist/documentation.md index 706cc1955..21758eed5 100644 --- a/docs/dist/documentation.md +++ b/docs/dist/documentation.md @@ -482,7 +482,7 @@ main class * [.initProject([credentialsName])](#Mcdev.initProject) ⇒ Promise.<void> * [.joinProject()](#Mcdev.joinProject) ⇒ Promise.<void> * [.findBUs(credentialsName)](#Mcdev.findBUs) ⇒ Promise.<void> - * [.document(businessUnit, type)](#Mcdev.document) ⇒ Promise.<void> + * [.document(businessUnit, type, [format])](#Mcdev.document) ⇒ Promise.<void> * [.deleteByKey(businessUnit, type, customerKey)](#Mcdev.deleteByKey) ⇒ Promise.<void> * [.refresh(businessUnit, type, [keyArr])](#Mcdev.refresh) ⇒ Promise.<void> * [.badKeys(businessUnit)](#Mcdev.badKeys) ⇒ Promise.<void> @@ -609,7 +609,7 @@ Refreshes BU names and ID's from MC instance -### Mcdev.document(businessUnit, type) ⇒ Promise.<void> +### Mcdev.document(businessUnit, type, [format]) ⇒ Promise.<void> Creates docs for supported metadata types in Markdown and/or HTML format **Kind**: static method of [Mcdev](#Mcdev) @@ -619,6 +619,7 @@ Creates docs for supported metadata types in Markdown and/or HTML format | --- | --- | --- | | businessUnit | string | references credentials from properties.json | | type | string | metadata type | +| [format] | 'md' \| 'html' \| 'csv' | output format | @@ -3276,7 +3277,7 @@ Provides default functionality that can be overwritten by child metadata type cl * [.readSecondaryFolder(templateDir, typeDirArr, templateName, fileName, ex)](#MetadataType.readSecondaryFolder) ⇒ object * [.buildDefinition(templateDir, targetDir, templateName, variables)](#MetadataType.buildDefinition) ⇒ Promise.<TYPE.MetadataTypeMapObj> * [.checkForErrors(ex)](#MetadataType.checkForErrors) ⇒ Array.<string> \| void - * [.document([metadata], [isDeploy])](#MetadataType.document) ⇒ void + * [.document([metadata], [isDeploy], [format])](#MetadataType.document) ⇒ void * [.deleteByKey(customerKey)](#MetadataType.deleteByKey) ⇒ boolean * [.postDeleteTasks(customerKey, [additionalExtensions])](#MetadataType.postDeleteTasks) ⇒ Promise.<void> * [.deleteByKeySOAP(customerKey, [overrideKeyField], [handleOutside])](#MetadataType.deleteByKeySOAP) ⇒ boolean @@ -3906,7 +3907,7 @@ Standardizes a check for multiple messages -### MetadataType.document([metadata], [isDeploy]) ⇒ void +### MetadataType.document([metadata], [isDeploy], [format]) ⇒ void Gets metadata cache with limited fields and does not store value to disk **Kind**: static method of [MetadataType](#MetadataType) @@ -3915,6 +3916,7 @@ Gets metadata cache with limited fields and does not store value to disk | --- | --- | --- | | [metadata] | TYPE.MetadataTypeMap | a list of type definitions | | [isDeploy] | boolean | used to skip non-supported message during deploy | +| [format] | 'md' \| 'html' \| 'csv' | output format | diff --git a/lib/cli.js b/lib/cli.js index 4b34ae9b1..c2d9a75e5 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -125,7 +125,7 @@ yargs }, }) .command({ - command: 'document ', + command: 'document [--format]', aliases: ['doc'], desc: 'Creates Markdown or HTML documentation for the selected type', builder: (yargs) => { @@ -139,12 +139,16 @@ yargs type: 'string', describe: 'metadata type to generate docs for; currently supported: dataExtension, role', + }) + .option('format', { + type: 'string', + describe: 'md, html, csv: defaults to md if not specified', }); }, handler: (argv) => { Mcdev.setSkipInteraction(argv.skipInteraction); Mcdev.setLoggingLevel(argv); - Mcdev.document(argv.BU, argv.TYPE); + Mcdev.document(argv.BU, argv.TYPE, argv.format); }, }) .command({ diff --git a/lib/index.js b/lib/index.js index 029ed1357..4f937c516 100644 --- a/lib/index.js +++ b/lib/index.js @@ -331,9 +331,10 @@ class Mcdev { * * @param {string} businessUnit references credentials from properties.json * @param {string} type metadata type + * @param {'md'|'html'|'csv'} [format] output format * @returns {Promise.} - */ - static async document(businessUnit, type) { + static async document(businessUnit, type, format) { Util.logger.info('mcdev:: Document'); const properties = await config.getProperties(); if (!(await config.checkProperties(properties))) { @@ -353,7 +354,7 @@ class Mcdev { if (buObject !== null) { MetadataTypeInfo[type].properties = properties; MetadataTypeInfo[type].buObject = buObject; - MetadataTypeInfo[type].document(); + MetadataTypeInfo[type].document(null, null, format); } } catch (ex) { Util.logger.error('mcdev.document ' + ex.message); diff --git a/lib/metadataTypes/MetadataType.js b/lib/metadataTypes/MetadataType.js index 24a3c9f82..e39db288d 100644 --- a/lib/metadataTypes/MetadataType.js +++ b/lib/metadataTypes/MetadataType.js @@ -1572,9 +1572,10 @@ class MetadataType { * * @param {TYPE.MetadataTypeMap} [metadata] a list of type definitions * @param {boolean} [isDeploy] used to skip non-supported message during deploy + * @param {'md'|'html'|'csv'} [format] output format * @returns {void} */ - static document(metadata, isDeploy) { + static document(metadata, isDeploy, format) { if (!isDeploy) { Util.logger.error(`Documenting type ${this.definition.type} is not supported.`); }