@atlaskit/codemod-cli 0.11.4 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/cli.js +72 -75
  3. package/dist/cjs/filepath.js +29 -83
  4. package/dist/cjs/index.js +3 -6
  5. package/dist/cjs/main.js +165 -441
  6. package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +44 -135
  7. package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +3 -4
  8. package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +6 -29
  9. package/dist/cjs/presets/index.js +2 -9
  10. package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +13 -25
  11. package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +34 -82
  12. package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +14 -41
  13. package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +0 -2
  14. package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +9 -28
  15. package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +44 -106
  16. package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +3 -3
  17. package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -1
  18. package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +2 -22
  19. package/dist/cjs/sinceRef.js +36 -92
  20. package/dist/cjs/transforms.js +27 -72
  21. package/dist/cjs/types.js +2 -45
  22. package/dist/cjs/utils.js +7 -20
  23. package/dist/cjs/version.json +1 -1
  24. package/dist/es2019/filepath.js +7 -5
  25. package/dist/es2019/main.js +17 -51
  26. package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +19 -51
  27. package/dist/es2019/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
  28. package/dist/es2019/presets/css-to-design-tokens/utils/meta.js +0 -6
  29. package/dist/es2019/presets/index.js +1 -1
  30. package/dist/es2019/presets/styled-to-emotion/styled-to-emotion.js +1 -4
  31. package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -14
  32. package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
  33. package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +2 -7
  34. package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
  35. package/dist/es2019/presets/theme-to-design-tokens/utils/tokens.js +0 -1
  36. package/dist/es2019/sinceRef.js +2 -11
  37. package/dist/es2019/transforms.js +3 -13
  38. package/dist/es2019/types.js +1 -0
  39. package/dist/es2019/utils.js +1 -12
  40. package/dist/es2019/version.json +1 -1
  41. package/dist/esm/cli.js +53 -57
  42. package/dist/esm/filepath.js +51 -63
  43. package/dist/esm/main.js +221 -322
  44. package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +33 -71
  45. package/dist/esm/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
  46. package/dist/esm/presets/css-to-design-tokens/utils/meta.js +0 -6
  47. package/dist/esm/presets/index.js +1 -1
  48. package/dist/esm/presets/styled-to-emotion/styled-to-emotion.js +1 -4
  49. package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -15
  50. package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
  51. package/dist/esm/presets/theme-to-design-tokens/utils/color.js +2 -7
  52. package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
  53. package/dist/esm/presets/theme-to-design-tokens/utils/tokens.js +0 -1
  54. package/dist/esm/sinceRef.js +49 -65
  55. package/dist/esm/transforms.js +4 -14
  56. package/dist/esm/types.js +1 -11
  57. package/dist/esm/utils.js +1 -12
  58. package/dist/esm/version.json +1 -1
  59. package/package.json +2 -2
  60. package/tmp/api-report-tmp.d.ts +0 -66
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`56507598609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56507598609) - Skip minor dependency bump
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
13
+ ## 0.11.5
14
+
15
+ ### Patch Changes
16
+
17
+ - [`cc84a1ed227`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cc84a1ed227) - Updates default behaviour of codemods when a suggested token cannot be found
18
+ - Updated dependencies
19
+
3
20
  ## 0.11.4
4
21
 
5
22
  ### Patch Changes
package/dist/cjs/cli.js CHANGED
@@ -1,91 +1,88 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.run = run;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
8
  var _meow = _interopRequireDefault(require("meow"));
15
-
16
9
  var _types = require("./types");
17
-
18
10
  var _main = _interopRequireDefault(require("./main"));
19
-
20
11
  var _chalk = _interopRequireDefault(require("chalk"));
12
+ async function run() {
13
+ const cli = (0, _meow.default)(`
14
+ Usage
15
+ $ npx @atlaskit/codemod-cli [options] <file-paths>...
16
+
17
+ Options
18
+ --preset, -n select transform by preset name, avoid user interaction
19
+ --transform, -t the transform to run, will prompt for a transform if not provided and no module is passed
20
+ --since-ref, runs transforms for all packages that have been upgraded since the specified git ref
21
+ --packages, runs transforms for the specified comma separated list of packages, optionally include a version for each package to run all transforms since that version
22
+ --parser, -p babel|babylon|flow|ts|tsx parser to use for parsing the source files (default: babel)
23
+ --extensions, -e transform files with these file extensions (comma separated list) (default: js)
24
+ --ignore-pattern, ignore files that match a provided glob expression
25
+ --fail-on-error, return a 1 exit code when errors were found during execution of codemods
26
+ --version, -v version number
27
+ --no-filter-paths disables dependant package file path filtering logic
28
+ --help Help me 😱
21
29
 
22
- function run() {
23
- return _run.apply(this, arguments);
24
- }
30
+ Examples
31
+ # Run a codemod over the /project/src directory, will be prompted for which codemod to run
32
+ $ npx @atlaskit/codemod-cli /project/src
25
33
 
26
- function _run() {
27
- _run = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
28
- var cli;
29
- return _regenerator.default.wrap(function _callee$(_context) {
30
- while (1) {
31
- switch (_context.prev = _context.next) {
32
- case 0:
33
- cli = (0, _meow.default)("\nUsage\n $ npx @atlaskit/codemod-cli [options] <file-paths>...\n\nOptions\n --preset, -n select transform by preset name, avoid user interaction\n --transform, -t the transform to run, will prompt for a transform if not provided and no module is passed\n --since-ref, runs transforms for all packages that have been upgraded since the specified git ref\n --packages, runs transforms for the specified comma separated list of packages, optionally include a version for each package to run all transforms since that version\n --parser, -p babel|babylon|flow|ts|tsx parser to use for parsing the source files (default: babel)\n --extensions, -e transform files with these file extensions (comma separated list) (default: js)\n --ignore-pattern, ignore files that match a provided glob expression\n --fail-on-error, return a 1 exit code when errors were found during execution of codemods\n --version, -v version number\n --no-filter-paths disables dependant package file path filtering logic \n --help Help me \uD83D\uDE31\n\nExamples\n # Run a codemod over the /project/src directory, will be prompted for which codemod to run\n $ npx @atlaskit/codemod-cli /project/src\n\n # Run the \"4.0.0-remove-appearance-prop\" transform of the \"button\" package\n $ npx @atlaskit/codemod-cli -t button@4.0.0-remove-appearance-prop /project/src\n\n # Run all transforms for \"@atlaskit/button\" greater than version 3.0.0 and @atlaskit/range greater than 4.0.0\n $ npx @atlaskit/codemod-cli --packages @atlaskit/button@3.0.0,@atlaskit/range@4.0.0 /project/src\n", {
34
- flags: {
35
- transform: {
36
- type: 'string',
37
- alias: 't'
38
- },
39
- preset: {
40
- type: 'string',
41
- alias: 'n'
42
- },
43
- packages: {
44
- type: 'string'
45
- },
46
- parser: {
47
- type: 'string',
48
- alias: 'p'
49
- },
50
- extensions: {
51
- type: 'string',
52
- alias: 'e'
53
- },
54
- ignorePattern: {
55
- type: 'string'
56
- },
57
- sinceRef: {
58
- type: 'string'
59
- },
60
- failOnError: {
61
- type: 'boolean'
62
- },
63
- filterPaths: {
64
- type: 'boolean',
65
- default: true
66
- }
67
- }
68
- });
69
- (0, _main.default)(cli.input, cli.flags).catch(function (e) {
70
- if (e instanceof _types.ValidationError) {
71
- console.error(cli.help);
72
- console.error(_chalk.default.red(e.message));
73
- process.exit(1);
74
- } else if (e instanceof _types.NoTransformsExistError) {
75
- console.warn(_chalk.default.yellow(e.message));
76
- process.exit(0);
77
- } else {
78
- console.error(_chalk.default.red(e));
79
- process.exit(3);
80
- }
81
- });
34
+ # Run the "4.0.0-remove-appearance-prop" transform of the "button" package
35
+ $ npx @atlaskit/codemod-cli -t button@4.0.0-remove-appearance-prop /project/src
82
36
 
83
- case 2:
84
- case "end":
85
- return _context.stop();
86
- }
37
+ # Run all transforms for "@atlaskit/button" greater than version 3.0.0 and @atlaskit/range greater than 4.0.0
38
+ $ npx @atlaskit/codemod-cli --packages @atlaskit/button@3.0.0,@atlaskit/range@4.0.0 /project/src
39
+ `, {
40
+ flags: {
41
+ transform: {
42
+ type: 'string',
43
+ alias: 't'
44
+ },
45
+ preset: {
46
+ type: 'string',
47
+ alias: 'n'
48
+ },
49
+ packages: {
50
+ type: 'string'
51
+ },
52
+ parser: {
53
+ type: 'string',
54
+ alias: 'p'
55
+ },
56
+ extensions: {
57
+ type: 'string',
58
+ alias: 'e'
59
+ },
60
+ ignorePattern: {
61
+ type: 'string'
62
+ },
63
+ sinceRef: {
64
+ type: 'string'
65
+ },
66
+ failOnError: {
67
+ type: 'boolean'
68
+ },
69
+ filterPaths: {
70
+ type: 'boolean',
71
+ default: true
87
72
  }
88
- }, _callee);
89
- }));
90
- return _run.apply(this, arguments);
73
+ }
74
+ });
75
+ (0, _main.default)(cli.input, cli.flags).catch(e => {
76
+ if (e instanceof _types.ValidationError) {
77
+ console.error(cli.help);
78
+ console.error(_chalk.default.red(e.message));
79
+ process.exit(1);
80
+ } else if (e instanceof _types.NoTransformsExistError) {
81
+ console.warn(_chalk.default.yellow(e.message));
82
+ process.exit(0);
83
+ } else {
84
+ console.error(_chalk.default.red(e));
85
+ process.exit(3);
86
+ }
87
+ });
91
88
  }
@@ -1,94 +1,40 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.findDependentPackagePaths = findDependentPackagePaths;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
7
  var _glob = require("glob");
15
-
16
8
  var _fs = require("fs");
9
+ const {
10
+ readFile
11
+ } = _fs.promises;
17
12
 
18
- var readFile = _fs.promises.readFile;
19
13
  /** Return products packages filePaths for running codemods from specified dependent package */
20
-
21
- function findDependentPackagePaths(_x, _x2) {
22
- return _findDependentPackagePaths.apply(this, arguments);
23
- }
24
-
25
- function _findDependentPackagePaths() {
26
- _findDependentPackagePaths = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(crawlPaths, dependencyPackage) {
27
- var searchStrings, globString, packageJsonPaths, productPackageJsonPathPromises, productPackageJsonPaths, productPackagePaths;
28
- return _regenerator.default.wrap(function _callee2$(_context2) {
29
- while (1) {
30
- switch (_context2.prev = _context2.next) {
31
- case 0:
32
- // Get file paths leading to package.jsons
33
- searchStrings = crawlPaths.map(function (crawlPath) {
34
- //Replace leading './' due to bug with node-glob not properly ignoring files https://github.com/isaacs/node-glob/issues/309
35
- return "".concat(crawlPath.replace(/^\.\//, ''), "/**/package.json");
36
- }); // Convert array into glob string
37
-
38
- globString = searchStrings.length > 1 ? "{".concat(searchStrings.join(','), "}") : searchStrings[0];
39
- packageJsonPaths = _glob.glob.sync(globString, {
40
- ignore: '**/node_modules/**',
41
- nodir: true
42
- });
43
- productPackageJsonPathPromises = packageJsonPaths.map( /*#__PURE__*/function () {
44
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(filePath) {
45
- var fileContents, isMatch;
46
- return _regenerator.default.wrap(function _callee$(_context) {
47
- while (1) {
48
- switch (_context.prev = _context.next) {
49
- case 0:
50
- fileContents = readFile(filePath, 'utf8'); // Grep for installedPackage
51
-
52
- _context.next = 3;
53
- return fileContents;
54
-
55
- case 3:
56
- isMatch = _context.sent.toString().split(/\n/).some(function (line) {
57
- return line.match(dependencyPackage);
58
- });
59
- return _context.abrupt("return", isMatch && filePath);
60
-
61
- case 5:
62
- case "end":
63
- return _context.stop();
64
- }
65
- }
66
- }, _callee);
67
- }));
68
-
69
- return function (_x3) {
70
- return _ref.apply(this, arguments);
71
- };
72
- }());
73
- _context2.next = 6;
74
- return Promise.all(productPackageJsonPathPromises);
75
-
76
- case 6:
77
- productPackageJsonPaths = _context2.sent.filter(function (path) {
78
- return path !== false;
79
- });
80
- // Get directory
81
- productPackagePaths = productPackageJsonPaths.map(function (line) {
82
- return line.replace('/package.json', '');
83
- });
84
- return _context2.abrupt("return", productPackagePaths);
85
-
86
- case 9:
87
- case "end":
88
- return _context2.stop();
89
- }
90
- }
91
- }, _callee2);
92
- }));
93
- return _findDependentPackagePaths.apply(this, arguments);
14
+ async function findDependentPackagePaths(crawlPaths, dependencyPackage) {
15
+ // Get file paths leading to package.jsons
16
+ const searchStrings = crawlPaths.map(crawlPath => {
17
+ //Replace leading './' due to bug with node-glob not properly ignoring files https://github.com/isaacs/node-glob/issues/309
18
+ return `${crawlPath.replace(/^\.\//, '')}/**/package.json`;
19
+ });
20
+
21
+ // Convert array into glob string
22
+ const globString = searchStrings.length > 1 ? `{${searchStrings.join(',')}}` : searchStrings[0];
23
+ const packageJsonPaths = _glob.glob.sync(globString, {
24
+ ignore: '**/node_modules/**',
25
+ nodir: true
26
+ });
27
+ let productPackageJsonPathPromises = packageJsonPaths.map(async filePath => {
28
+ const fileContents = readFile(filePath, 'utf8');
29
+ // Grep for installedPackage
30
+ const isMatch = (await fileContents).toString().split(/\n/).some(function (line) {
31
+ return line.match(dependencyPackage);
32
+ });
33
+ return isMatch && filePath;
34
+ });
35
+ const productPackageJsonPaths = (await Promise.all(productPackageJsonPathPromises)).filter(path => path !== false);
36
+
37
+ // Get directory
38
+ const productPackagePaths = productPackageJsonPaths.map(line => line.replace('/package.json', ''));
39
+ return productPackagePaths;
94
40
  }
package/dist/cjs/index.js CHANGED
@@ -1,29 +1,26 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  Object.defineProperty(exports, "NoTransformsExistError", {
9
8
  enumerable: true,
10
- get: function get() {
9
+ get: function () {
11
10
  return _types.NoTransformsExistError;
12
11
  }
13
12
  });
14
13
  Object.defineProperty(exports, "ValidationError", {
15
14
  enumerable: true,
16
- get: function get() {
15
+ get: function () {
17
16
  return _types.ValidationError;
18
17
  }
19
18
  });
20
19
  Object.defineProperty(exports, "default", {
21
20
  enumerable: true,
22
- get: function get() {
21
+ get: function () {
23
22
  return _main.default;
24
23
  }
25
24
  });
26
-
27
25
  var _main = _interopRequireDefault(require("./main"));
28
-
29
26
  var _types = require("./types");