jscodeshift.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env node
  2. /*
  3. * Copyright (c) 2015-present, Facebook, Inc.
  4. * All rights reserved.
  5. *
  6. * This source code is licensed under the BSD-style license found in the
  7. * LICENSE file in the root directory of this source tree. An additional grant
  8. * of patent rights can be found in the PATENTS file in the same directory.
  9. *
  10. */
  11. 'use strict';
  12. const Runner = require('../src/Runner.js');
  13. const path = require('path');
  14. const pkg = require('../package.json');
  15. const opts = require('nomnom')
  16. .script('jscodeshift')
  17. .options({
  18. path: {
  19. position: 0,
  20. help: 'Files or directory to transform',
  21. list: true,
  22. metavar: 'FILE',
  23. required: true
  24. },
  25. transform: {
  26. abbr: 't',
  27. default: './transform.js',
  28. help: 'Path to the transform file. Can be either a local path or url',
  29. metavar: 'FILE'
  30. },
  31. cpus: {
  32. abbr: 'c',
  33. help: '(all by default) Determines the number of processes started.'
  34. },
  35. verbose: {
  36. abbr: 'v',
  37. choices: [0, 1, 2],
  38. default: 0,
  39. help: 'Show more information about the transform process'
  40. },
  41. dry: {
  42. abbr: 'd',
  43. flag: true,
  44. help: 'Dry run (no changes are made to files)'
  45. },
  46. print: {
  47. abbr: 'p',
  48. flag: true,
  49. help: 'Print output, useful for development'
  50. },
  51. babel: {
  52. flag: true,
  53. default: true,
  54. help: 'Apply Babel to transform files'
  55. },
  56. extensions: {
  57. default: 'js',
  58. help: 'File extensions the transform file should be applied to'
  59. },
  60. ignorePattern: {
  61. full: 'ignore-pattern',
  62. list: true,
  63. help: 'Ignore files that match a provided glob expression'
  64. },
  65. ignoreConfig: {
  66. full: 'ignore-config',
  67. list: true,
  68. help: 'Ignore files if they match patterns sourced from a configuration file (e.g., a .gitignore)',
  69. metavar: 'FILE'
  70. },
  71. runInBand: {
  72. flag: true,
  73. default: false,
  74. full: 'run-in-band',
  75. help: 'Run serially in the current process'
  76. },
  77. silent: {
  78. abbr: 's',
  79. flag: true,
  80. default: false,
  81. full: 'silent',
  82. help: 'No output'
  83. },
  84. parser: {
  85. choices: ['babel', 'babylon', 'flow'],
  86. default: 'babel',
  87. full: 'parser',
  88. help: 'The parser to use for parsing your source files (babel | babylon | flow)'
  89. },
  90. version: {
  91. flag: true,
  92. help: 'print version and exit',
  93. callback: function() {
  94. const requirePackage = require('../utils/requirePackage');
  95. return [
  96. `jscodeshift: ${pkg.version}`,
  97. ` - babel: ${require('babel-core').version}`,
  98. ` - babylon: ${requirePackage('babylon').version}`,
  99. ` - flow: ${requirePackage('flow-parser').version}`,
  100. ` - recast: ${requirePackage('recast').version}`,
  101. ].join('\n');
  102. },
  103. },
  104. })
  105. .parse();
  106. Runner.run(
  107. /^https?/.test(opts.transform) ? opts.transform : path.resolve(opts.transform),
  108. opts.path,
  109. opts
  110. );