Skip to content

Commit

Permalink
Add debug flag to generate method and deploy command (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
tardieu authored and reggeenr committed Mar 12, 2021
1 parent ff01897 commit 1d9a239
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions bin/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const minimist = require('minimist')
const path = require('path')

const argv = minimist(process.argv.slice(2), {
string: ['apihost', 'auth', 'source', 'annotation', 'annotation-file'],
string: ['apihost', 'auth', 'source', 'annotation', 'annotation-file', 'debug'],
boolean: ['insecure', 'version', 'overwrite'],
alias: { auth: 'u', insecure: 'i', version: 'v', annotation: 'a', 'annotation-file': 'A', overwrite: 'w' }
})
Expand All @@ -46,6 +46,7 @@ if (argv._.length !== 2 || path.extname(argv._[1]) !== '.json') {
console.error(' -u, --auth KEY authorization KEY')
console.error(' -v, --version output the composer version')
console.error(' -w, --overwrite overwrite actions if already defined')
console.error(' --debug LIST comma-separated list of debug flags')
process.exit(1)
}
let composition
Expand Down Expand Up @@ -85,7 +86,7 @@ try {
console.error(error)
process.exit(400 - 256) // Bad Request
}
client(options).compositions.deploy(composition, argv.overwrite)
client(options).compositions.deploy(composition, argv.overwrite, argv.debug)
.then(actions => {
const names = actions.map(action => action.name)
console.log(`ok: created action${actions.length > 1 ? 's' : ''} ${names}`)
Expand Down
4 changes: 2 additions & 2 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class Compositions {
this.actions = wsk.actions
}

deploy (composition, overwrite) {
const actions = (composition.actions || []).concat(conductor.generate(composition))
deploy (composition, overwrite, debug) {
const actions = (composition.actions || []).concat(conductor.generate(composition, debug))
return actions.reduce((promise, action) => promise.then(() => overwrite && this.actions.delete(action).catch(() => { }))
.then(() => this.actions.create(action)), Promise.resolve())
.then(() => actions)
Expand Down
5 changes: 3 additions & 2 deletions conductor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const { minify } = require('terser')
const version = require('./package.json').version

// synthesize conductor action code from composition
function generate ({ name, composition, ast, version: composer, annotations = [] }) {
const code = `// generated by composer v${composer} and conductor v${version}\n\nconst composition = ${JSON.stringify(composition, null, 4)}\n\n// do not edit below this point\n\n` +
function generate ({ name, composition, ast, version: composer, annotations = [] }, debug) {
let code = `// generated by composer v${composer} and conductor v${version}\n\nconst composition = ${JSON.stringify(composition, null, 4)}\n\n// do not edit below this point\n\n` +
minify(`const main=(${main})(composition)`, { output: { max_line_len: 127 } }).code
if (debug) code = `process.env.DEBUG='${debug}'\n\n` + code
annotations = annotations.concat([{ key: 'conductor', value: ast }, { key: 'composerVersion', value: composer }, { key: 'conductorVersion', value: version }])
return { name, action: { exec: { kind: 'nodejs:default', code }, annotations } }
}
Expand Down

0 comments on commit 1d9a239

Please sign in to comment.