From 0863ade9d10badd95286a20dd11bd516d6b9ef11 Mon Sep 17 00:00:00 2001 From: Serhii Filonenko Date: Tue, 16 Jul 2024 15:45:48 +0300 Subject: [PATCH] HCK-7253: fix getting target script for documentation --- forward_engineering/api.js | 6 +----- .../azureCLIScriptHelpers/buildAzureCLIScript.js | 4 +++- .../helpers/azureCLIScriptHelpers/getCliShellName.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 forward_engineering/helpers/azureCLIScriptHelpers/getCliShellName.js diff --git a/forward_engineering/api.js b/forward_engineering/api.js index d0d6f23..ae06d99 100644 --- a/forward_engineering/api.js +++ b/forward_engineering/api.js @@ -18,10 +18,7 @@ module.exports = { (data.entityData[entityId] || [])[0] || {}, ), ); - if ( - data.options.targetScriptOptions && - data.options.targetScriptOptions.keyword === 'containerSettingsJson' - ) { + if (data.options?.targetScriptOptions?.keyword === 'containerSettingsJson') { const uniqueKeys = _.get(data.containerData, '[0].uniqueKey', []); const scriptData = { partitionKey: getPartitionKey(_)(data.containerData), @@ -43,7 +40,6 @@ module.exports = { const script = buildAzureCLIScript(_)({ ...data, - shellName: data.options.targetScriptOptions.keyword.split('azureCli')[1].toLowerCase(), }); if (withSamples || !insertSamplesOption.value) { diff --git a/forward_engineering/helpers/azureCLIScriptHelpers/buildAzureCLIScript.js b/forward_engineering/helpers/azureCLIScriptHelpers/buildAzureCLIScript.js index 2d5b8b0..6d14716 100644 --- a/forward_engineering/helpers/azureCLIScriptHelpers/buildAzureCLIScript.js +++ b/forward_engineering/helpers/azureCLIScriptHelpers/buildAzureCLIScript.js @@ -4,6 +4,7 @@ const { getUniqueKeyPolicyScript } = require('../getUniqueKeyPolicyScript'); const { getCliParamsDelimiter } = require('./getCliParamsDelimiter'); const getIndexPolicyScript = require('../getIndexPolicyScript'); const getPartitionKey = require('../getPartitionKey'); +const { getCliShellName } = require('./getCliShellName'); const { CLI, DATABASE, @@ -16,7 +17,8 @@ const { const buildAzureCLIScript = _ => - ({ modelData, containerData, shellName }) => { + ({ modelData, containerData, options }) => { + const shellName = getCliShellName(options?.targetScriptOptions); const cliParamsDelimiter = getCliParamsDelimiter(shellName); const escapeAndWrapInQuotes = string => wrapInSingleQuotes(escapeShellCommand(shellName, string)); diff --git a/forward_engineering/helpers/azureCLIScriptHelpers/getCliShellName.js b/forward_engineering/helpers/azureCLIScriptHelpers/getCliShellName.js new file mode 100644 index 0000000..85138b8 --- /dev/null +++ b/forward_engineering/helpers/azureCLIScriptHelpers/getCliShellName.js @@ -0,0 +1,12 @@ +/** + * @param {object} targetScriptOptions + * @returns {string} + */ +const getCliShellName = (targetScriptOptions = {}) => { + const keyword = targetScriptOptions.keyword ?? ''; + const [, shellName = ''] = keyword.split('azureCli'); + + return shellName.toLowerCase(); +}; + +module.exports = { getCliShellName };