當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript repl.start函數代碼示例

本文整理匯總了TypeScript中repl.start函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript start函數的具體用法?TypeScript start怎麽用?TypeScript start使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了start函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: openRepl

function openRepl(dangerContext: DangerContext): void {
  /**
   * Injects a read-only, global variable into the REPL
   *
   * @param {repl.REPLServer} repl The Node REPL created via `repl.start()`
   * @param {string} name The name of the global variable
   * @param {*} value The value of the global variable
   */
  function injectReadOnlyProperty(repl: repl.REPLServer, name: string, value: any) {
    Object.defineProperty(repl["context"], name, {
      configurable: false,
      enumerable: true,
      value,
    })
  }

  /**
   * Sets up the Danger REPL with `danger` and `results` global variables
   *
   * @param {repl.REPLServer} repl The Node REPL created via `repl.start()`
   */
  function setup(repl: repl.REPLServer) {
    injectReadOnlyProperty(repl, "danger", dangerContext.danger)
    injectReadOnlyProperty(repl, "results", dangerContext.results)
  }

  const dangerRepl = repl.start({ prompt: "> " })
  setup(dangerRepl)
  dangerRepl.on("exit", () => process.exit())
  // Called when `.clear` is executed in the Node REPL
  // This ensures that `danger` and `results` are not cleared from the REPL context
  dangerRepl.on("reset", () => setup(dangerRepl))
}
開發者ID:sapegin,項目名稱:danger-js,代碼行數:33,代碼來源:danger-pr.ts

示例2: function

	grunt.registerTask('repl', 'Bootstrap dojo-loader and start a Node.js REPL', function () {
		this.async(); // Ensure Grunt doesn't exit the process.

		const { baseUrl, packages, require: dojoRequire } = loadDojoLoader(packageJson);

		const nodeRequire = function (mid: string) {
			// Require relative to the baseUrl, not this module.
			return require(resolveFrom(baseUrl, mid));
		};
		Object.defineProperty(nodeRequire, 'resolve', {
			configurable: false,
			enumerable: true,
			value (mid: string) {
				return resolveFrom(baseUrl, mid);
			}
		});

		grunt.log.ok(`Available packages: ${packages.map(({ name }) => name).join(', ')}`);
		grunt.log.ok('require() is now powered by dojo-loader');
		grunt.log.ok('Node.js\' require() is available under nodeRequire()');

		const { context } = repl.start();
		Object.defineProperties(context, {
			nodeRequire: {
				configurable: false,
				enumerable: true,
				value: nodeRequire
			},
			require: {
				configurable: false,
				enumerable: true,
				value: dojoRequire
			}
		});
	});
開發者ID:vansimke,項目名稱:grunt-dojo2,代碼行數:35,代碼來源:repl.ts

示例3: prepareConsole

export async function prepareConsole(): Promise<any> {
    const connection = await db.connect()

    const consoleVars: {[key: string]: any} = { typeorm, db }

    // Expose all typeorm models
    for (const meta of connection.entityMetadatas) {
        consoleVars[meta.targetName] = meta.target
    }

    const r = repl.start({ prompt: 'owid> '})
    Object.assign(r.context, consoleVars)
}
開發者ID:OurWorldInData,項目名稱:owid-grapher,代碼行數:13,代碼來源:console.ts

示例4: startRepl

function startRepl () {
  if (process.platform === 'win32') {
    console.error('Electron REPL not currently supported on Windows')
    process.exit(1)
  }

  // prevent quitting
  app.on('window-all-closed', () => {})

  const repl = require('repl')
  repl.start('> ').on('exit', () => {
    process.exit(0)
  })
}
開發者ID:electron,項目名稱:electron,代碼行數:14,代碼來源:main.ts

示例5: repl

export default function repl(this:CmdLineConfig) {
	const envName = getCurrentDefault();
	const config = readEnvSync(envName);
	applyGlobalEnv(config);
	
	global.JsonEnv = config;
	console.log('config stored in glboal.JsonEnv');
	const repl = require('repl');
	
	repl.start({
		useGlobal: true,
		ignoreUndefined: false,
		replMode: repl.REPL_MODE_MAGIC,
		breakEvalOnSigint: true,
		prompt: '> '
	});
	
	return 999;
}
開發者ID:GongT,項目名稱:jenv,代碼行數:19,代碼來源:repl.ts

示例6: startRepl

/**
 * Start a CLI REPL.
 */
function startRepl () {
  const repl = start({
    prompt: '> ',
    input: process.stdin,
    output: process.stdout,
    terminal: process.stdout.isTTY,
    eval: replEval,
    useGlobal: true
  })

  // Bookmark the point where we should reset the REPL state.
  const resetEval = appendEval('')

  function reset () {
    resetEval()

    // Hard fix for TypeScript forcing `Object.defineProperty(exports, ...)`.
    exec('exports = module.exports', EVAL_FILENAME)
  }

  reset()
  repl.on('reset', reset)

  repl.defineCommand('type', {
    help: 'Check the type of a TypeScript identifier',
    action: function (identifier: string) {
      if (!identifier) {
        repl.displayPrompt()
        return
      }

      const undo = appendEval(identifier)
      const { name, comment } = service.getTypeInfo(EVAL_INSTANCE.input, EVAL_PATH, EVAL_INSTANCE.input.length)

      undo()

      repl.outputStream.write(`${name}\n${comment ? `${comment}\n` : ''}`)
      repl.displayPrompt()
    }
  })
}
開發者ID:santoshkanuri,項目名稱:ts-node,代碼行數:44,代碼來源:bin.ts

示例7: startRepl

/**
 * Start a CLI REPL.
 */
function startRepl () {
  const repl = start({
    prompt: '> ',
    input: process.stdin,
    output: process.stdout,
    eval: replEval,
    useGlobal: false
  })

  // Reset eval file information when repl is reset.
  repl.on('reset', () => {
    evalFile.input = ''
    evalFile.output = ''
    evalFile.version = 0
  })

  ;(repl as any).defineCommand('type', {
    help: 'Check the type of a TypeScript identifier',
    action: function (identifier: string) {
      if (!identifier) {
        ;(repl as any).displayPrompt()
        return
      }

      const undo = evalFile.input

      evalFile.input += identifier
      evalFile.version++

      const { name, comment } = service().getTypeInfo(EVAL_PATH, evalFile.input.length)

      ;(repl as any).outputStream.write(`${chalk.bold(name)}\n${comment ? `${comment}\n` : ''}`)
      ;(repl as any).displayPrompt()

      evalFile.input = undo
    }
  })
}
開發者ID:cartant,項目名稱:ts-node,代碼行數:41,代碼來源:_bin.ts

示例8: main

async function main(): Promise<void> {
  await getOpenExchangeAppId()

  const server = repl.start({
    prompt: '> ',

    eval(cmd: string, _context: any, _filename: string, callback: any) {
      calculate(cmd)
        .catch(err => {
          console.error('Error evaluating: ', err)
          callback(err)
        })
        .then(result => callback(null, result))
    },

    writer(output: string) {
      return '= ' + chalk.green(output) + '\n'
    }
  })
  ;(server as any).setupHistory(REPL_HISTORY_FILE, (err: Error) => {
    if (err != null) console.error('Error writing history', err)
  })
}
開發者ID:elentok,項目名稱:dotfiles,代碼行數:23,代碼來源:calc.ts

示例9:

import * as repl from "repl";
import { augurEmitter } from "./events";
import "./runServer";

const replServer = repl.start();
replServer.context.augurEmitter = augurEmitter;
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:6,代碼來源:repl.ts

示例10: require

if (jestProjectConfig.transform) {
  let transformerPath = null;
  for (let i = 0; i < jestProjectConfig.transform.length; i++) {
    if (new RegExp(jestProjectConfig.transform[i][0]).test('foobar.js')) {
      transformerPath = jestProjectConfig.transform[i][1];
      break;
    }
  }
  if (transformerPath) {
    transformer = require(transformerPath);
    if (typeof transformer.process !== 'function') {
      throw new TypeError(
        'Jest: a transformer must export a `process` function.',
      );
    }
  }
}

const replInstance: repl.REPLServer = repl.start({
  eval: evalCommand,
  prompt: '\u203A ',
  useGlobal: true,
});

replInstance.context.require = (moduleName: string) => {
  if (/(\/|\\|\.)/.test(moduleName)) {
    moduleName = path.resolve(process.cwd(), moduleName);
  }
  return require(moduleName);
};
開發者ID:Volune,項目名稱:jest,代碼行數:30,代碼來源:repl.ts


注:本文中的repl.start函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。