@atlaskit/codemod-cli 0.11.5 → 0.12.1

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 (51) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/cli.js +75 -68
  3. package/dist/cjs/filepath.js +29 -69
  4. package/dist/cjs/index.js +3 -3
  5. package/dist/cjs/main.js +167 -337
  6. package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +31 -73
  7. package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +3 -3
  8. package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +6 -19
  9. package/dist/cjs/presets/index.js +1 -3
  10. package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +12 -19
  11. package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +32 -61
  12. package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +13 -26
  13. package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +7 -11
  14. package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +6 -10
  15. package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +3 -3
  16. package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -1
  17. package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +2 -16
  18. package/dist/cjs/sinceRef.js +35 -70
  19. package/dist/cjs/transforms.js +26 -44
  20. package/dist/cjs/types.js +3 -27
  21. package/dist/cjs/utils.js +6 -6
  22. package/dist/cjs/version.json +1 -1
  23. package/dist/es2019/version.json +1 -1
  24. package/dist/esm/cli.js +53 -55
  25. package/dist/esm/filepath.js +50 -54
  26. package/dist/esm/main.js +220 -230
  27. package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +11 -13
  28. package/dist/esm/sinceRef.js +48 -50
  29. package/dist/esm/version.json +1 -1
  30. package/dist/types-ts4.0/cli.d.ts +1 -0
  31. package/dist/types-ts4.0/filepath.d.ts +2 -0
  32. package/dist/types-ts4.0/index.d.ts +4 -0
  33. package/dist/types-ts4.0/main.d.ts +19 -0
  34. package/dist/types-ts4.0/presets/css-to-design-tokens/css-to-design-tokens.d.ts +2 -0
  35. package/dist/types-ts4.0/presets/css-to-design-tokens/utils/legacy-colors.d.ts +3 -0
  36. package/dist/types-ts4.0/presets/css-to-design-tokens/utils/meta.d.ts +1 -0
  37. package/dist/types-ts4.0/presets/index.d.ts +9 -0
  38. package/dist/types-ts4.0/presets/styled-to-emotion/styled-to-emotion.d.ts +6 -0
  39. package/dist/types-ts4.0/presets/theme-to-design-tokens/theme-to-design-tokens.d.ts +2 -0
  40. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/ast-meta.d.ts +3 -0
  41. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/ast.d.ts +3 -0
  42. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/color.d.ts +4 -0
  43. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/fuzzy-search.d.ts +5 -0
  44. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/legacy-colors.d.ts +3 -0
  45. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/named-colors.d.ts +1 -0
  46. package/dist/types-ts4.0/presets/theme-to-design-tokens/utils/tokens.d.ts +2 -0
  47. package/dist/types-ts4.0/sinceRef.d.ts +5 -0
  48. package/dist/types-ts4.0/transforms.d.ts +10 -0
  49. package/dist/types-ts4.0/types.d.ts +59 -0
  50. package/dist/types-ts4.0/utils.d.ts +1 -0
  51. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @atlaskit/codemod-cli
2
2
 
3
+ ## 0.12.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`07020547a93`](https://bitbucket.org/atlassian/atlassian-frontend/commits/07020547a93) - Safe direct migraiton to design token API. This change is not visible for those who aren't using design tokens
8
+
9
+ ## 0.12.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`56507598609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56507598609) - Skip minor dependency bump
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
3
19
  ## 0.11.5
4
20
 
5
21
  ### Patch Changes
package/dist/cjs/cli.js CHANGED
@@ -5,77 +5,84 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.run = run;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
8
  var _meow = _interopRequireDefault(require("meow"));
11
9
  var _types = require("./types");
12
10
  var _main = _interopRequireDefault(require("./main"));
13
11
  var _chalk = _interopRequireDefault(require("chalk"));
14
- function run() {
15
- return _run.apply(this, arguments);
16
- }
17
- function _run() {
18
- _run = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
19
- var cli;
20
- return _regenerator.default.wrap(function _callee$(_context) {
21
- while (1) {
22
- switch (_context.prev = _context.next) {
23
- case 0:
24
- 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", {
25
- flags: {
26
- transform: {
27
- type: 'string',
28
- alias: 't'
29
- },
30
- preset: {
31
- type: 'string',
32
- alias: 'n'
33
- },
34
- packages: {
35
- type: 'string'
36
- },
37
- parser: {
38
- type: 'string',
39
- alias: 'p'
40
- },
41
- extensions: {
42
- type: 'string',
43
- alias: 'e'
44
- },
45
- ignorePattern: {
46
- type: 'string'
47
- },
48
- sinceRef: {
49
- type: 'string'
50
- },
51
- failOnError: {
52
- type: 'boolean'
53
- },
54
- filterPaths: {
55
- type: 'boolean',
56
- default: true
57
- }
58
- }
59
- });
60
- (0, _main.default)(cli.input, cli.flags).catch(function (e) {
61
- if (e instanceof _types.ValidationError) {
62
- console.error(cli.help);
63
- console.error(_chalk.default.red(e.message));
64
- process.exit(1);
65
- } else if (e instanceof _types.NoTransformsExistError) {
66
- console.warn(_chalk.default.yellow(e.message));
67
- process.exit(0);
68
- } else {
69
- console.error(_chalk.default.red(e));
70
- process.exit(3);
71
- }
72
- });
73
- case 2:
74
- case "end":
75
- return _context.stop();
76
- }
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 😱
29
+
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
33
+
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
36
+
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
77
72
  }
78
- }, _callee);
79
- }));
80
- 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
+ });
81
88
  }
@@ -1,80 +1,40 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.findDependentPackagePaths = findDependentPackagePaths;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
7
  var _glob = require("glob");
11
8
  var _fs = require("fs");
12
- var readFile = _fs.promises.readFile;
9
+ const {
10
+ readFile
11
+ } = _fs.promises;
13
12
 
14
13
  /** Return products packages filePaths for running codemods from specified dependent package */
15
- function findDependentPackagePaths(_x, _x2) {
16
- return _findDependentPackagePaths.apply(this, arguments);
17
- }
18
- function _findDependentPackagePaths() {
19
- _findDependentPackagePaths = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(crawlPaths, dependencyPackage) {
20
- var searchStrings, globString, packageJsonPaths, productPackageJsonPathPromises, productPackageJsonPaths, productPackagePaths;
21
- return _regenerator.default.wrap(function _callee2$(_context2) {
22
- while (1) {
23
- switch (_context2.prev = _context2.next) {
24
- case 0:
25
- // Get file paths leading to package.jsons
26
- searchStrings = crawlPaths.map(function (crawlPath) {
27
- //Replace leading './' due to bug with node-glob not properly ignoring files https://github.com/isaacs/node-glob/issues/309
28
- return "".concat(crawlPath.replace(/^\.\//, ''), "/**/package.json");
29
- }); // Convert array into glob string
30
- globString = searchStrings.length > 1 ? "{".concat(searchStrings.join(','), "}") : searchStrings[0];
31
- packageJsonPaths = _glob.glob.sync(globString, {
32
- ignore: '**/node_modules/**',
33
- nodir: true
34
- });
35
- productPackageJsonPathPromises = packageJsonPaths.map( /*#__PURE__*/function () {
36
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(filePath) {
37
- var fileContents, isMatch;
38
- return _regenerator.default.wrap(function _callee$(_context) {
39
- while (1) {
40
- switch (_context.prev = _context.next) {
41
- case 0:
42
- fileContents = readFile(filePath, 'utf8'); // Grep for installedPackage
43
- _context.next = 3;
44
- return fileContents;
45
- case 3:
46
- isMatch = _context.sent.toString().split(/\n/).some(function (line) {
47
- return line.match(dependencyPackage);
48
- });
49
- return _context.abrupt("return", isMatch && filePath);
50
- case 5:
51
- case "end":
52
- return _context.stop();
53
- }
54
- }
55
- }, _callee);
56
- }));
57
- return function (_x3) {
58
- return _ref.apply(this, arguments);
59
- };
60
- }());
61
- _context2.next = 6;
62
- return Promise.all(productPackageJsonPathPromises);
63
- case 6:
64
- productPackageJsonPaths = _context2.sent.filter(function (path) {
65
- return path !== false;
66
- });
67
- // Get directory
68
- productPackagePaths = productPackageJsonPaths.map(function (line) {
69
- return line.replace('/package.json', '');
70
- });
71
- return _context2.abrupt("return", productPackagePaths);
72
- case 9:
73
- case "end":
74
- return _context2.stop();
75
- }
76
- }
77
- }, _callee2);
78
- }));
79
- 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;
80
40
  }
package/dist/cjs/index.js CHANGED
@@ -6,19 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  Object.defineProperty(exports, "NoTransformsExistError", {
8
8
  enumerable: true,
9
- get: function get() {
9
+ get: function () {
10
10
  return _types.NoTransformsExistError;
11
11
  }
12
12
  });
13
13
  Object.defineProperty(exports, "ValidationError", {
14
14
  enumerable: true,
15
- get: function get() {
15
+ get: function () {
16
16
  return _types.ValidationError;
17
17
  }
18
18
  });
19
19
  Object.defineProperty(exports, "default", {
20
20
  enumerable: true,
21
- get: function get() {
21
+ get: function () {
22
22
  return _main.default;
23
23
  }
24
24
  });