Javascript 如何从节点api运行jscodeshift?

Javascript 如何从节点api运行jscodeshift?,javascript,jscodeshift,Javascript,Jscodeshift,我看到一些开发人员想知道如何在没有CLI的情况下运行jscodeshift,虽然有一些问题,但它们非常简单,所以如果有人想使用选项有效地运行它,下面是一个示例 const path = require('path'); const Runner = require('jscodeshift/src/Runner'); // just the paths of the files to apply the transformation const paths = ['path/to/exampl

我看到一些开发人员想知道如何在没有CLI的情况下运行jscodeshift,虽然有一些问题,但它们非常简单,所以如果有人想使用选项有效地运行它,下面是一个示例

const path = require('path');
const Runner = require('jscodeshift/src/Runner');

// just the paths of the files to apply the transformation
const paths = ['path/to/example1.js', 'path/to/example2.js'];

/**
 * taken from
 * @link https://github.com/facebook/jscodeshift/blob/48f5d6d6e5e769639b958f1a955c83c68157a5fa/bin/jscodeshift.js#L18
 */
const options = {
  transform: 'path/to/transformerFile.js',
  verbose: 0,
  dry: false,
  print: true,
  babel: true,
  extensions: 'js',
  ignorePattern: [],
  ignoreConfig: [],
  runInBand: false,
  silent: false,
  parser: 'babel',
  stdin: false
}

/**
 * taken from
 * @link https://github.com/facebook/jscodeshift/blob/48f5d6d6e5e769639b958f1a955c83c68157a5fa/bin/jscodeshift.js#L135
 */
Runner.run(
  /^https?/.test(options.transform) ? options.transform : path.resolve(options.transform),
  paths,
  options
);