Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default (commandTree: Commands.Registrar, wsk) => {
if (!Capabilities.isHeadless()) {
registerListView('activations', renderActivationListView)
// for now, until we have updated the composer plugin
registerListView('session', renderActivationListView)
}
wsk.synonyms('activations').forEach(syn => {
commandTree.listen(`/wsk/${syn}/list`, doList(wsk), {
usage: usage(syn).available.find(({ command }) => command === 'list')
})
})
}
({ execOptions, tab }) => {
if (Capabilities.isHeadless()) {
throw new Error('beautify not supported in headless mode')
}
const selection = currentSelection(tab)
if (!selection) {
throw new Error('You have not yet selected an entity')
} else if (!(selection && selection.exec && selection.exec.code)) {
throw new Error('no action code selected')
} else {
// beautify
const beautify = require('js-beautify').js_beautify
selection.exec.code = beautify(selection.exec.code)
const code = getSidecar(tab).querySelector('.action-content .action-source') as HTMLElement
code.innerText = selection.exec.code
mode !== 'default' &&
!(
selection[mode] ||
(selection.exec && selection.exec[mode]) ||
(isActivationSpec(selection) && selection.response[mode])
)
) {
throw new Error(`The current entity does not support viewing ${mode}`)
} else {
showSidecar(tab)
return showEntity(tab, selection, { show: mode })
}
} else if (args.length === 3 || args.length === 4) {
// activation logs xxx or wsk activation logs xxx
const activation = await tab.REPL.qexec(`wsk ${entityType} get ${entityId}`)
if (Capabilities.isHeadless()) {
return activation[mode]
} else {
showEntity(tab, activation, { show: mode })
return true // make repl happy
}
} else {
const isVowel = c => c === 'a' || c === 'e' || c === 'i' || c === 'o' || c === 'u'
const startsWithVowel = s => isVowel(s.charAt(0))
throw new Error(
!entityType
? 'You have not selected an entity'
: `You have not yet selected ${startsWithVowel(entityType) ? 'an' : 'a'} ${entityType.replace(/s$/, '')}`
)
}
}
export const visualizeComposition = async (tab: UI.Tab, response, execOptions) => {
debug('Visualizing Composition', response)
const action = response.message || response
// const execOptions = opts.execOptions
debug('execOptions', execOptions)
if (hasAst(action) && !Capabilities.isHeadless()) {
const doVisualize = execOptions.override || !execOptions.nested
const options = execOptions.originalOptions || {}
// use require rather than import here to prevent from prequiring wskflow module in headless mode
const input = `/${response.namespace}/${response.name}`
const { content, subtext } = await decorateAsApp(tab, {
action,
input,
doVisualize,
options: Object.assign({}, execOptions, options)
})
if (doVisualize) {
debug('visualze composition')
return Object.assign(action, {
type: 'custom',
export default () => {
if (!Capabilities.isHeadless()) {
registerCLIEntityView('activations', async (
tab: UI.Tab,
response: Entity,
resultDom: Element,
parsedOptions: Object, // eslint-disable-line @typescript-eslint/ban-types
execOptions: Object // eslint-disable-line @typescript-eslint/ban-types
) => {
const showActivation = (await import('./lib/views/cli/activations/entity')).default as ViewHandler
return showActivation(tab, response, resultDom, parsedOptions, execOptions)
})
const doShow = async (
tab: UI.Tab,
entity: Object, // eslint-disable-line @typescript-eslint/ban-types
sidecar: Element,
options: ShowOptions
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest()
xhr.open(method, url)
xhr.addEventListener('error', () => {
console.error('error in xhr', xhr)
reject(xhr.response || 'Internal Error')
})
xhr.addEventListener('load', () => {
resolve({
statusCode: xhr.status,
body: xhr.response.response
})
})
xhr.send()
})
} else if (Capabilities.isHeadless()) {
debug('fetch via needle')
const needle = await import('needle')
return needle(method, url, { follow_max: 10 }).then(_ => ({ statusCode: _.statusCode, body: _.body }))
} else {
debug('fetch via electron.net')
const { net } = (await import('electron')).remote
return new Promise((resolve, reject) => {
const request = net.request({
method,
url,
redirect: 'follow'
})
request.on('response', response => {
const statusCode = response.statusCode
const clean = (command: Commands.Arguments, type: string, quiet?: boolean) => {
if (!quiet) {
if (Capabilities.isHeadless()) {
process.stdout.write('.'['random'])
} else {
debug(`Cleaning ${type}`)
}
}
return list(command, type).then(deleteAllUntilDone(command, type))
}
const addWskflow = (tab: UI.Tab) => opts => {
debug('addWskflow', opts)
if (Capabilities.isHeadless()) return opts
const { getEntity, editor, content, eventBus } = opts
const wskflowContainer = document.createElement('div')
const editorDom = content.querySelector('.monaco-editor-wrapper')
content.appendChild(wskflowContainer)
wskflowContainer.className = 'wskflow-container'
/** update the view to show the latest AST */
let lock
const updateView = async (_?, { event = 'init' } = {}) => {
if (lock) return
else lock = true
try {
const action = getEntity()
export const formatCompositionEntity = ({ REPL, execOptions }: Commands.Arguments) => response => {
return Capabilities.isHeadless()
? response
: REPL.qexec(`wsk app get "${response.name}"`, undefined, undefined, execOptions)
}