How to use the @kui-shell/core.Capabilities.inBrowser function in @kui-shell/core

To help you get started, we’ve selected a few @kui-shell/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IBM / kui / plugins / plugin-apache-composer / src / lib / utility / compile.ts View on Github external
export const loadComposition = (inputFile: string, originalCode?: string, localCodePath?: string) => {
  if (Capabilities.inBrowser() && originalCode) {
    debug('loadComposition for webpack', originalCode)
    return originalCode
  }

  const localSourcePath = localCodePath || Util.findFile(Util.expandHomeDir(inputFile))

  debug('load source code from', localSourcePath)

  try {
    let errorMessage = ''
    let logMessage = ''
    debug('using require to process composition', localSourcePath)
    // we'll override these temporarily
    const log = console.log
    const err = console.error
    const exit = process.exit
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / actions / let.ts View on Github external
const furlSequenceComponent = (parentActionName: string) => (component: string, idx: number): Promise => {
      const match = component.match(patterns.action.expr.inline)

      if (match && match.length === 3) {
        // then this component is an inline function
        debug('sequence component is inline function', match[0])
        const body = `let main = ${match[0]}`
        const candidateName = `${parentActionName}-${idx + 1}`
        return createWithRetryOnName(body, parentActionName, execOptions, idx, currentIter, candidateName)
      } else {
        if (!Capabilities.inBrowser() && existsSync(Util.expandHomeDir(component))) {
          debug('sequence component is local file', component)
          // then we assume that the component identifies a local file
          //    note: the first step reserves a name
          return createWithRetryOnName(
            'let main=x=>x',
            parentActionName,
            execOptions,
            idx,
            currentIter,
            basename(component.replace(/\..*$/, ''))
          )
            .then(reservedAction => reservedAction.name)
            .then(reservedName =>
              maybeComponentIsFile(reservedName, undefined, component, 'let', {}, args, { nested: true })
            )
        } else {
github IBM / kui / plugins / plugin-grid / src / lib / util.ts View on Github external
export const injectContent = () => {
  if (Capabilities.inBrowser()) {
    UI.injectCSS({
      css: require('@kui-shell/plugin-grid/web/css/table.css'),
      key: 'grid-visualization.table.css'
    })
  } else {
    const root = dirname(require.resolve('@kui-shell/plugin-grid/package.json'))
    UI.injectCSS(join(root, 'web/css/table.css'))
  }

  UI.injectCSS('https://cdnjs.cloudflare.com/ajax/libs/balloon-css/0.5.0/balloon.min.css') // tooltips
}
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / openwhisk-core.ts View on Github external
export const owOpts = (options = {}): WskOpts => {
  if (isLinux) {
    // options.forever = true
    options['timeout'] = 5000
    options['agent'] = agent()
  }

  if (Settings.theme.userAgent && !process.env.TEST_SPACE && !process.env.TRAVIS) {
    // install a User-Agent header, except when running tests
    debug('setting User-Agent', Settings.theme.userAgent)
    options['User-Agent'] = Settings.theme.userAgent
  }

  if (Capabilities.inBrowser()) {
    options['noUserAgent'] = true
  }

  return options
}
github IBM / kui / plugins / plugin-k8s / src / lib / util / fetch-file.ts View on Github external
async function needle(method: 'get', url: string): Promise<{ statusCode: number; body: string }> {
  if (Capabilities.inBrowser()) {
    debug('fetch via xhr')
    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()
    })
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / compose.ts View on Github external
}

      const readViaFilesystem = () => {
        debug('readViaFilesystem')
        require('fs').readFile(Util.findFile(template), (err, data) => {
          if (err) {
            reject(err)
          } else {
            resolve(data.toString())
          }
        })
      }

      try {
        debug('attempting to read template', template)
        if (Capabilities.inBrowser()) {
          if (template.indexOf('@') >= 0) {
            readViaImport()
          } else {
            reject(new Error('Unable to read the given template'))
          }
        } else {
          readViaFilesystem()
        }
      } catch (err) {
        console.error('error with readViaImport', err)
        readViaFilesystem()
      }
    })
  }
github IBM / kui / plugins / plugin-bash-like / src / lib / util / git-support.ts View on Github external
export const injectCSS = async () => {
  if (Capabilities.inBrowser()) {
    await Promise.all([
      UI.injectCSS({
        css: require('diff2html/dist/diff2html.min.css'),
        key: 'diff2html.css'
      }),
      UI.injectCSS({
        css: require('@kui-shell/plugin-bash-like/web/css/my-diff2html.css'),
        key: 'mydiff2html.css'
      })
    ])
  } else {
    const root = dirname(require.resolve('diff2html/package.json'))
    const ourRoot = dirname(require.resolve('@kui-shell/plugin-bash-like/package.json'))
    await Promise.all([
      UI.injectCSS(join(root, 'dist/diff2html.min.css')),
      UI.injectCSS(join(ourRoot, 'web/css/my-diff2html.css'))
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / auth.ts View on Github external
const updateLocalWskProps = (auth?: string, subject?: string): Promise => {
  if (!Capabilities.inBrowser()) {
    return readFromLocalWskProps(auth, subject).then(writeToLocalWskProps)
  } else {
    return Promise.resolve(auth)
  }
}
github IBM / kui / plugins / plugin-apache-composer / src / lib / controller / cmd / preview.ts View on Github external
new Promise((resolve, reject) => {
          const ENOENT = () => {
            const error = new Error('The specified file does not exist')
            error['code'] = 404
            return error
          }

          if (!Capabilities.inBrowser()) {
            stat(input, err => {
              if (err) {
                reject(ENOENT())
              } else {
                resolve()
              }
            })
          } else {
            if (input.indexOf('@') >= 0) {
              resolve()
            } else {
              reject(ENOENT())
            }
          }
        })
github IBM / kui / plugins / plugin-apache-composer / src / lib / utility / compile.ts View on Github external
new Promise(async (resolve, reject) => {
    if (!Capabilities.inBrowser()) {
      debug('readFile in headless mode or for electron')
      fs.readFile(localCodePath, (err, data) => {
        if (err) {
          reject(err)
        } else {
          resolve(data.toString())
        }
      })
    } else {
      debug('readFile for webpack', localCodePath)
      try {
        const data = await import(
          '@kui-shell/plugin-apache-composer/samples' +
            localCodePath.replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')
        )
        debug('readFile for webpack done', data)