How to use the @kui-shell/core.Util.findFile 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
if (extension === 'json' || extension === 'ast') {
      // we were given the AST directly
      debug('input is composer AST')
    } else if (extension === 'js' || extension === 'py') {
      debug('input is composer library client', extension)
    } else {
      return reject(
        new Errors.UsageError({
          message: messages.unknownInput,
          usage: create('create'),
          code: 497
        })
      )
    }

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

    return loadSourceCode(inputFile, localCodePath) // check inputfile extension and existence and then return the source code
      .then(sourceCode => loadComposition(inputFile, sourceCode)) // check before parse by composer and give users more freedom on source input
      .then(composition => resolve(compileComposition(composition, name))) // parse and compile composition and get {composition, ast, version} object
      .catch(reject)
  })
github IBM / kui / plugins / plugin-apache-composer / src / lib / controller / cmd / preview.ts View on Github external
new Promise((resolve, reject) => {
      const idx = argvNoOptions.indexOf(cmd)
      const inputFile = argvNoOptions[idx + 1]

      debug('cmd', cmd)
      debug('inputFile', inputFile)

      if (options.c) {
        // then the user wants to see the code and preview side-by-side
        debug('delegating to editor')
        return resolve(REPL.qexec(`compose ${basename(inputFile)} --simple --readOnly --template "${inputFile}"`))
      }

      const input = Util.findFile(Util.expandHomeDir(inputFile))

      /* if (currentSelection() && currentSelection().input === input) {
             debug('already showing', input)
             return resolve(true);
         } */

      const exists = () =>
        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 => {
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / actions / let.ts View on Github external
tmp.tmpName({ postfix: extension }, (err: Error, tmpFilePath: string) => {
          if (err) {
            reject(err)
          } else {
            writeFile(tmpFilePath, data, err => {
              if (err) {
                reject(err)
              } else {
                resolve({ location: tmpFilePath, removeWhenDone: true })
              }
            })
          }
        })
      })
    } else {
      lstat(Util.findFile(Util.expandHomeDir(locationWithoutQuotes)), (err, stats) => {
        if (stats) {
          // nothing to fetch, it's local!
          resolve({ location: locationWithoutQuotes, removeWhenDone: false })
        }
        if (err) {
          // we can't determine how to access the given url
          reject(new Error(`Unable to locate the given resource location ${locationWithoutQuotes}`))
        }
      })
    }
  })
github IBM / kui / plugins / plugin-k8s / src / lib / util / fetch-file.ts View on Github external
throw err
          }
        }

        // fetch with three retries
        return fetchOnce()
          .catch(retry(500))
          .catch(retry(1000))
          .catch(retry(5000))
      } else {
        debug('fetch local', url)

        // why the dynamic import? being browser friendly here
        const { readFile } = await import('fs-extra')

        return readFile(Util.findFile(Util.expandHomeDir(url)))
      }
    })
  )
github IBM / kui / plugins / plugin-openwhisk / src / lib / cmds / openwhisk-core.ts View on Github external
action: action
            }
          })
      }
    } else if (verb !== 'update' || argv[0]) {
      // for action create, or update and the user gave a
      // positional param... find the input file
      if (options.docker) {
        // blackbox action
        options.action.exec.kind = 'blackbox'
        options.action.exec.image = options.docker
      }

      if (argv[0]) {
        // find the file named by argv[0]
        const filepath = Util.findFile(Util.expandHomeDir(argv[0]))
        const isZip = argv[0].endsWith('.zip')
        const isJar = argv[0].endsWith('.jar')
        const isBinary = isZip || isJar
        const encoding = isBinary ? 'base64' : 'utf8'

        if (argv[0].charAt(0) === '!') {
          // read the file from execOptions
          const key = argv[0].slice(1)
          options.action.exec.code = execOptions && (execOptions.parameters[key] || execOptions.params[key])

          // remove traces of this from params
          if (execOptions.parameters) delete execOptions.parameters[key]
          if (execOptions.params) delete execOptions.params[key]
          options.action.parameters = options.action.parameters.filter(({ key: otherKey }) => key !== otherKey)

          debug('code passed programmatically', options.action, execOptions)
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / compose.ts View on Github external
const readViaImport = () => {
        debug(
          'readViaImport',
          Util.findFile(template),
          Util.findFile(template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')
        )
        resolve(
          require('raw-loader!@kui-shell/plugin-apache-composer/samples' +
            Util.findFile(template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')).default
        )
      }
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / compose.ts View on Github external
const compile = () =>
    type === 'compositions' && options.template
      ? Capabilities.inBrowser()
        ? import(
            '@kui-shell/plugin-apache-composer/samples' +
              Util.findFile(options.template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')
          )
        : generateAST(code, options.template)
      : Promise.resolve()
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())
          }
        })
      }
github IBM / kui / plugins / plugin-openwhisk-editor-extensions / src / lib / cmds / compose.ts View on Github external
const readViaImport = () => {
        debug(
          'readViaImport',
          Util.findFile(template),
          Util.findFile(template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')
        )
        resolve(
          require('raw-loader!@kui-shell/plugin-apache-composer/samples' +
            Util.findFile(template).replace(/^.*plugin-apache-composer\/samples(.*)$/, '$1')).default
        )
      }