From 5a10bc47609d5340eb395641ab22fdf2322c0bc2 Mon Sep 17 00:00:00 2001 From: i325261 Date: Fri, 13 Sep 2024 14:30:43 +0200 Subject: [PATCH] refactor run method --- lib/add.js | 26 +++++++++++++------------- test/add.test.js | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/add.js b/lib/add.js index e57998b..0d2162a 100644 --- a/lib/add.js +++ b/lib/add.js @@ -69,6 +69,8 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin { await rimraf('chart') } else if (cds.cli.options['with-configurable-templates'] && cds.cli.options['with-templates']) { throw new Error(`Option '--with-templates' cannot be used with '--with-configurable-templates' option.`) + } else if (!cds.cli.options['with-mta'] && cds.cli.options['with-mta-extensions']) { + throw new Error(`mta YAML not provided. Please pass the mta YAML via option '--with-mta'.`) } else if (exists('chart')) { const isCAPOpChart = isCAPOperatorChart('chart') const isConfigurableTempChart = isConfigurableTemplateChart('chart') @@ -114,19 +116,6 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin { console.log("`chart` folder generated.") - // Update xs-security.json - const { hasXsuaa } = project - if (hasXsuaa) { - await cds.add.merge(__dirname, '../files/xs-security.json.hbs').into('xs-security.json', { - project, - additions: [{ in: 'scopes', where: { name: '$XSAPPNAME.Callback' }}, - { in: 'scopes', where: { name: '$XSAPPNAME.mtcallback' }}] - }) - } - - if (!cds.cli.options['with-mta'] && cds.cli.options['with-mta-extensions']) - throw new Error(`mta YAML not provided. Please pass the mta YAML via option '--with-mta'.`) - if (cds.cli.options['with-mta']) { const { hasMta } = project if (!hasMta) throw new Error(`mta is not added to this project. Run 'cds add mta'.`) @@ -147,6 +136,17 @@ module.exports = class CapOperatorAddPlugin extends cds.add.Plugin { } else { console.log("Review and update the values.yaml file in the 'chart' folder as per your project's requirements.") } + + // Update xs-security.json + const { hasXsuaa } = project + if (hasXsuaa) { + await cds.add.merge(__dirname, '../files/xs-security.json.hbs').into('xs-security.json', { + project, + additions: [{ in: 'scopes', where: { name: '$XSAPPNAME.Callback' }}, + { in: 'scopes', where: { name: '$XSAPPNAME.mtcallback' }}] + }) + } + console.log("Once values.yaml is updated, run 'cds build' to generate the helm chart. You can find the generated chart in the 'gen' folder within your project directory.") } diff --git a/test/add.test.js b/test/add.test.js index 1819455..729b234 100644 --- a/test/add.test.js +++ b/test/add.test.js @@ -23,7 +23,7 @@ describe('cds add cap-operator', () => { }) afterEach(async () => { - execSync(`rm -r chart`, { cwd: bookshop }) + if (cds.utils.exists(join(bookshop, 'chart'))) execSync(`rm -r chart`, { cwd: bookshop }) }) after(async () => {