本文整理汇总了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;未经允许,请勿转载。 |
请发表评论