Skip to content

Commit

Permalink
refactor run method
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhprasad-sap committed Sep 13, 2024
1 parent cca2381 commit 5a10bc4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions lib/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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'.`)
Expand All @@ -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.")
}

Expand Down
2 changes: 1 addition & 1 deletion test/add.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 5a10bc4

Please sign in to comment.