How to use codemod-cli - 10 common examples

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-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-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-angle-brackets-codemod / bin / cli.js View on Github external
(async () => {
  await gatherTelemetryForUrl(process.argv[2], analyzeEmberObject);

  require('codemod-cli').runTransform(
    __dirname,
    'angle-brackets' /* transform name */,
    process.argv.slice(2) /* paths or globs */,
    'hbs'
  );
})();
github ember-codemods / ember-native-class-codemod / bin / cli.js View on Github external
(async () => {
  await gatherTelemetryForUrl(process.argv[2], analyzeEmberObject);

  require('codemod-cli').runTransform(
    __dirname,
    'ember-object',
    process.argv.slice(2) /* paths or globs */
  );
})();
github ember-codemods / ember-test-helpers-codemod / transforms / acceptance / transforms / click.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
    .find(j.CallExpression)
    .filter(({ node }) => isGlobalHelperExpression(j, node))
    ;

  if (replacements.length > 0) {
    makeAwait(j, replacements);
    dropAndThen(j, root);
    addImportStatement(['click']);
  }

  writeImportStatements(j, root);
  return root.toSource({ quote: 'single' });
github ember-codemods / ember-test-helpers-codemod / transforms / acceptance / transforms / visit.js View on Github external
function transform(file, api) {
  let source = file.source;
  let j = getParser(api);

  let root = j(source);

  let replacements = root
    .find(j.CallExpression)
    .filter(({ node }) => isGlobalHelperExpression(j, node))
    ;

  if (replacements.length > 0) {
    makeAwait(j, replacements);
    dropAndThen(j, root);
    addImportStatement(['visit']);
  }

  writeImportStatements(j, root);
  return root.toSource({ quote: 'single' });
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / text.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { createFindExpression, isJQuerySelectExpression, addImportStatement, writeImportStatements } = require('../../utils');

/**
 * Creates a `find(selector).textContent` expression
 *
 * @param j
 * @param findArgs
 * @returns {*}
 */
function createExpression(j, findArgs) {
  return j.memberExpression(
    createFindExpression(j, findArgs),
    j.identifier('textContent')
  );
}
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / attr.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const { createFindExpression, createPropExpression, isJQuerySelectExpression, addImportStatement, writeImportStatements } = require('../../utils');

/**
 * Creates a `find(selector).getAttribute(attr)` expression
 *
 * @param j
 * @param findArgs
 * @param attr
 * @returns {*}
 */
function createAttributeExpression(j, findArgs, attr) {
  return j.callExpression(
    j.memberExpression(
      createFindExpression(j, findArgs),
      j.identifier('getAttribute')
    ), [attr]
github ember-codemods / ember-test-helpers-codemod / transforms / integration / transforms / get.js View on Github external
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;
const {
  createFindAllExpression,
  isJQuerySelectExpression,
  addImportStatement,
  writeImportStatements,
} = require('../../utils');

/**
 * Creates a `findAll(selector)[0]` expression
 *
 * @param j
 * @param findArgs
 * @param indexArg
 * @returns {*}
 */
function createExpression(j, findArgs, indexArg) {

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