How to use the codemod-cli.getOptions function in codemod-cli

To help you get started, we’ve selected a few codemod-cli 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 ember-codemods / ember-native-class-codemod / transforms / ember-object / index.js View on Github external
module.exports = function transformer(file, api) {
  const extension = path.extname(file.path);

  if (!['.js', '.ts'].includes(extension.toLowerCase())) {
    // do nothing on non-js/ts files
    return;
  }

  const j = api.jscodeshift;
  const options = Object.assign({}, DEFAULT_OPTIONS, getOptions());
  let { source } = file;

  const root = j(source);

  const replaced = replaceEmberObjectExpressions(j, root, file.path, options);
  if (replaced) {
    source = root.toSource({
      quote: options.quotes || options.quote,
    });
  }
  return source;
};
github ember-codemods / ember-3x-codemods / transforms / deprecate-router-events / index.js View on Github external
module.exports = function transformer(file, api) {
  const j = getParser(api);
  const options = getOptions();

  const root = j(file.source);

  const createInit = (props, exp1, exp2) => {
    // First create the super call for init
    let superCall = j.expressionStatement(
      j.callExpression(j.memberExpression(j.thisExpression(), j.identifier("_super"), false), [
        j.identifier("...arguments")
      ])
    );

    let initProp = j.objectMethod("method", j.identifier("init"), [], j.blockStatement([superCall, exp1, exp2]));

    props.push(initProp);
  };
github ember-codemods / ember-3x-codemods / transforms / fpe-on / index.js View on Github external
module.exports = function transformer(file, api) {
  const j = getParser(api);
  const options = getOptions();
  const root = j(file.source);

  root
    .find(j.CallExpression, {
      callee: {
        type: "MemberExpression",
        object: { type: "FunctionExpression" },
        property: { name: "on" }
      }
    })
    //.forEach(p => console.log(p))
    .replaceWith(path => {
      let onImport = j.importDeclaration(
        [j.importSpecifier(j.identifier("on"))],
        j.literal("@ember/object/evented")
      );
github ember-codemods / ember-3x-codemods / transforms / fpe-computed / index.js View on Github external
module.exports = function transformer(file, api) {
  const j = getParser(api);
  const options = getOptions();
  const root = j(file.source);

  root
    .find(j.CallExpression, {
      callee: {
        type: "MemberExpression",
        object: { type: "FunctionExpression" },
        property: { name: "computed" }
      }
    })
    //.forEach(p => console.log(p))
    .replaceWith(path => {
      let computedImport = j.importDeclaration(
        [j.importSpecifier(j.identifier("computed"))],
        j.literal("@ember/object")
      );
github ember-codemods / ember-3x-codemods / transforms / cp-property / index.js View on Github external
module.exports = function transformer(file, api) {
  const j = getParser(api);
  const options = getOptions();
  const root = j(file.source);

  root
    .find(j.CallExpression, {
      callee: {
        type: "MemberExpression",
        object: { callee: { name: "computed" } },
        property: { name: "property" }
      }
    })
  //.forEach(p => console.log(p))
    .replaceWith(path => {
      let args = [...path.value.arguments].concat(path.value.callee.object.arguments);
      return j.callExpression(j.identifier("computed"), args);
    });
github ember-codemods / ember-angle-brackets-codemod / transforms / angle-brackets / index.js View on Github external
function getOptions() {
  let options = {};

  let cliOptions = getCLIOptions();
  if (cliOptions.config) {
    let filePath = path.join(process.cwd(), cliOptions.config);
    let config = JSON.parse(fs.readFileSync(filePath));

    if (config.helpers) {
      options.helpers = config.helpers;
    }

    if (config.skipAttributesThatMatchRegex) {
      options.skipAttributesThatMatchRegex = config.skipAttributesThatMatchRegex;
    }

    if (config.skipFilesThatMatchRegex) {
      options.skipFilesThatMatchRegex = new RegExp(config.skipFilesThatMatchRegex);
    }
github ember-codemods / ember-3x-codemods / transforms / jquery-apis / index.js View on Github external
module.exports = function transformer(file, api) {
  const j = getParser(api);
  const options = getOptions();
  const root = j(file.source);

  root
    .find(j.CallExpression, {
      callee: {
        object: {
          callee: {
            object: {
              type: "ThisExpression"
            },
            property: {
              name: "$"
            }
          }
        }
      }
github ember-codemods / ember-angle-brackets-codemod / transforms / -preset.js View on Github external
return function(file, api) {
    let src = file.source;
    let options = getOptions();
    let error;

    fs.readdirSync(transformPath).forEach(fileName => {
      let fix = require(path.join(transformPath, fileName));
      if (typeof src === 'undefined') {
        return;
      }
      try {
        src = fix(Object.assign({}, file, { source: src }), api, options);
      } catch (e) {
        error = new Error(
          `Transformation ${fileName} errored on file ${file.path}. Reason ${e}. Please report this in https://github.com/ember-codemods/ember-angle-brackets-codemod/issues\n\nStack trace:\n${e.stack}\n\nSource:\n${src}`
        );
      }
    });

codemod-cli

a command line tool for generating, testing, and publishing codemods

MIT
Latest version published 3 years ago

Package Health Score

45 / 100
Full package analysis