@atlaskit/codemod-cli 0.13.3 → 0.13.4
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.
- package/CHANGELOG.md +6 -0
- package/README.md +117 -3
- package/dist/cjs/cli.js +70 -75
- package/dist/cjs/filepath.js +65 -29
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/main.js +329 -167
- package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +72 -31
- package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +3 -3
- package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +19 -6
- package/dist/cjs/presets/index.js +3 -1
- package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +19 -12
- package/dist/cjs/presets/theme-remove-deprecated-mixins/theme-remove-deprecated-mixins.js +51 -36
- package/dist/cjs/presets/theme-remove-deprecated-mixins/utils/replacements.js +25 -25
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +66 -46
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +33 -18
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +11 -7
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +10 -6
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +3 -3
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -1
- package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +16 -2
- package/dist/cjs/sinceRef.js +69 -35
- package/dist/cjs/transforms.js +44 -26
- package/dist/cjs/types.js +27 -3
- package/dist/cjs/utils.js +6 -6
- package/dist/es2019/cli.js +4 -0
- package/dist/es2019/main.js +2 -0
- package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +1 -0
- package/dist/es2019/sinceRef.js +1 -0
- package/dist/esm/cli.js +4 -0
- package/dist/esm/main.js +3 -1
- package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +1 -0
- package/dist/esm/sinceRef.js +1 -0
- package/package.json +2 -2
- package/dist/cjs/version.json +0 -4
- package/dist/es2019/version.json +0 -4
- package/dist/esm/version.json +0 -4
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,114 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Codemods
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
To easily download and run codemods associated with atlassian-frontend components and services, we provide a CLI tool called `@atlaskit/codemod-cli`.
|
|
4
|
+
|
|
5
|
+
The idea is that upgrading major versions can be **assisted** by codemods, reducing upgrade-pain, improving adoption and giving component authors the flexibility to improve API and component design.
|
|
6
|
+
|
|
7
|
+
**Note:** Codemods will be designed to do the heavy lifting, but they'll often not be perfect so some manual work may still be required in order to successfully migrate.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
`$ npx @atlaskit/codemod-cli /project/src/file.js`
|
|
14
|
+
|
|
15
|
+
## Options
|
|
16
|
+
|
|
17
|
+
### --preset, -n
|
|
18
|
+
|
|
19
|
+
Select which transform to run from existing transform list by providing the preset name. This will allow you run the transfrom without any interaction.
|
|
20
|
+
|
|
21
|
+
**example:**
|
|
22
|
+
|
|
23
|
+
- `npx @atlaskit/codemod-cli -n theme-to-design-tokens --extensions tsx,ts,js --parser tsx /project/src`
|
|
24
|
+
|
|
25
|
+
### --transform, -t
|
|
26
|
+
|
|
27
|
+
The transform to run, transforms can be either a single file or directory with an index.
|
|
28
|
+
|
|
29
|
+
**example:**
|
|
30
|
+
|
|
31
|
+
- `npx @atlaskit/codemod-cli --transform codemods/my-special-mod /project/src/file.js`
|
|
32
|
+
- `npx @atlaskit/codemod-cli --transform codemods/my-special-mod/index.ts /project/src/file.js`
|
|
33
|
+
|
|
34
|
+
### --since-ref <git-ref>
|
|
35
|
+
|
|
36
|
+
Determines changed packages since the specified git ref and runs all codemods for them. The automatic version of `--packages`. The ref can be any valid git ref, e.g. a commit hash, HEAD etc.
|
|
37
|
+
|
|
38
|
+
**example:**
|
|
39
|
+
|
|
40
|
+
- `npx @atlaskit/codemod-cli --since-ref HEAD /project/src`
|
|
41
|
+
- `npx @atlaskit/codemod-cli --since-ref abcdef123 /project/src`
|
|
42
|
+
|
|
43
|
+
### --packages
|
|
44
|
+
|
|
45
|
+
Runs transforms for the specified comma separated list of packages, optionally include a version for each package to run all transforms since that version
|
|
46
|
+
|
|
47
|
+
**example:**
|
|
48
|
+
|
|
49
|
+
- `npx @atlaskit/codemod-cli --packages @atlaskit/button /project/src`
|
|
50
|
+
- `npx @atlaskit/codemod-cli --packages @atlaskit/button@3.0.0,@atlaskit/range@4.0.0 /project/src`
|
|
51
|
+
|
|
52
|
+
### --parser, -p
|
|
53
|
+
|
|
54
|
+
Parser to use for parsing the source files you are code modding.
|
|
55
|
+
|
|
56
|
+
**options:**
|
|
57
|
+
|
|
58
|
+
- babel (default)
|
|
59
|
+
- babylon
|
|
60
|
+
- flow
|
|
61
|
+
- ts
|
|
62
|
+
- tsx
|
|
63
|
+
|
|
64
|
+
**example:**
|
|
65
|
+
|
|
66
|
+
- `npx @atlaskit/codemod-cli --parser tsx /project/src/file.js`
|
|
67
|
+
- `npx @atlaskit/codemod-cli -p babel /project/src/file.js`
|
|
68
|
+
|
|
69
|
+
### --extensions, -e
|
|
70
|
+
|
|
71
|
+
Transform files with these file extensions (comma separated list) (default: js)
|
|
72
|
+
|
|
73
|
+
**example:**
|
|
74
|
+
|
|
75
|
+
- `npx @atlaskit/codemod-cli --extensions ts,tsx /project/src/file.js`
|
|
76
|
+
- `npx @atlaskit/codemod-cli -e js /project/src/file.js`
|
|
77
|
+
|
|
78
|
+
### --ignore-pattern
|
|
79
|
+
|
|
80
|
+
Ignore files that match a provided glob expression
|
|
81
|
+
|
|
82
|
+
**example:**
|
|
83
|
+
|
|
84
|
+
- `@atlaskit/codemod-cli --ignore-pattern node_modules /project/src/file.js`
|
|
85
|
+
|
|
86
|
+
### --no-filter-paths
|
|
87
|
+
|
|
88
|
+
The codemod CLI filters supplied file paths by default, improving runtime by preventing codemods from running in non-dependent packages. Add this flag if there are problems with the filtering logic.
|
|
89
|
+
|
|
90
|
+
**example:**
|
|
91
|
+
|
|
92
|
+
- `npx @atlaskit/codemod-cli --no-filter-paths ./packages`
|
|
93
|
+
|
|
94
|
+
### --version, -v
|
|
95
|
+
|
|
96
|
+
Get current version number
|
|
97
|
+
|
|
98
|
+
**example:**
|
|
99
|
+
|
|
100
|
+
- `@atlaskit/codemod-cli --version`
|
|
101
|
+
- `@atlaskit/codemod-cli -v`
|
|
102
|
+
|
|
103
|
+
### --help
|
|
104
|
+
|
|
105
|
+
Print all help text to the command line
|
|
106
|
+
|
|
107
|
+
**example:**
|
|
108
|
+
|
|
109
|
+
- `@atlaskit/codemod-cli --help`
|
|
110
|
+
|
|
111
|
+
---
|
|
4
112
|
|
|
5
113
|
## Testing locally
|
|
6
114
|
|
|
@@ -10,4 +118,10 @@ When wanting to run the CLI before it has been published you can run the start c
|
|
|
10
118
|
yarn start [commands]
|
|
11
119
|
```
|
|
12
120
|
|
|
13
|
-
For a list of commands run it with `-h` or
|
|
121
|
+
For a list of commands run it with `-h` or refer to the documentation above.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## For internal Atlassians
|
|
126
|
+
|
|
127
|
+
_Internal Atlassians can access [additional documentation on Confluence](https://hello.atlassian.net/wiki/spaces/AF/pages/2627171992/Codemods)._
|
package/dist/cjs/cli.js
CHANGED
|
@@ -5,84 +5,79 @@ 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"));
|
|
8
10
|
var _meow = _interopRequireDefault(require("meow"));
|
|
9
11
|
var _types = require("./types");
|
|
10
12
|
var _main = _interopRequireDefault(require("./main"));
|
|
11
13
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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) switch (_context.prev = _context.next) {
|
|
22
|
+
case 0:
|
|
23
|
+
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", {
|
|
24
|
+
flags: {
|
|
25
|
+
transform: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
alias: 't'
|
|
28
|
+
},
|
|
29
|
+
preset: {
|
|
30
|
+
type: 'string',
|
|
31
|
+
alias: 'n'
|
|
32
|
+
},
|
|
33
|
+
packages: {
|
|
34
|
+
type: 'string'
|
|
35
|
+
},
|
|
36
|
+
parser: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
alias: 'p'
|
|
39
|
+
},
|
|
40
|
+
extensions: {
|
|
41
|
+
type: 'string',
|
|
42
|
+
alias: 'e'
|
|
43
|
+
},
|
|
44
|
+
ignorePattern: {
|
|
45
|
+
type: 'string'
|
|
46
|
+
},
|
|
47
|
+
sinceRef: {
|
|
48
|
+
type: 'string'
|
|
49
|
+
},
|
|
50
|
+
failOnError: {
|
|
51
|
+
type: 'boolean'
|
|
52
|
+
},
|
|
53
|
+
filterPaths: {
|
|
54
|
+
type: 'boolean',
|
|
55
|
+
default: true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
(0, _main.default)(cli.input, cli.flags).catch(function (e) {
|
|
60
|
+
if (e instanceof _types.ValidationError) {
|
|
61
|
+
// eslint-disable-next-line no-console
|
|
62
|
+
console.error(cli.help);
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.error(_chalk.default.red(e.message));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
} else if (e instanceof _types.NoTransformsExistError) {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.warn(_chalk.default.yellow(e.message));
|
|
69
|
+
process.exit(0);
|
|
70
|
+
} else {
|
|
71
|
+
// eslint-disable-next-line no-console
|
|
72
|
+
console.error(_chalk.default.red(e));
|
|
73
|
+
process.exit(3);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
case 2:
|
|
77
|
+
case "end":
|
|
78
|
+
return _context.stop();
|
|
72
79
|
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
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
|
-
});
|
|
80
|
+
}, _callee);
|
|
81
|
+
}));
|
|
82
|
+
return _run.apply(this, arguments);
|
|
88
83
|
}
|
package/dist/cjs/filepath.js
CHANGED
|
@@ -1,40 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.findDependentPackagePaths = findDependentPackagePaths;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
7
10
|
var _glob = require("glob");
|
|
8
11
|
var _fs = require("fs");
|
|
9
|
-
|
|
10
|
-
readFile
|
|
11
|
-
} = _fs.promises;
|
|
12
|
+
var readFile = _fs.promises.readFile;
|
|
12
13
|
|
|
13
14
|
/** Return products packages filePaths for running codemods from specified dependent package */
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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) switch (_context2.prev = _context2.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
// Get file paths leading to package.jsons
|
|
25
|
+
searchStrings = crawlPaths.map(function (crawlPath) {
|
|
26
|
+
//Replace leading './' due to bug with node-glob not properly ignoring files https://github.com/isaacs/node-glob/issues/309
|
|
27
|
+
return "".concat(crawlPath.replace(/^\.\//, ''), "/**/package.json");
|
|
28
|
+
}); // Convert array into glob string
|
|
29
|
+
globString = searchStrings.length > 1 ? "{".concat(searchStrings.join(','), "}") : searchStrings[0];
|
|
30
|
+
packageJsonPaths = _glob.glob.sync(globString, {
|
|
31
|
+
ignore: '**/node_modules/**',
|
|
32
|
+
nodir: true
|
|
33
|
+
});
|
|
34
|
+
productPackageJsonPathPromises = packageJsonPaths.map( /*#__PURE__*/function () {
|
|
35
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(filePath) {
|
|
36
|
+
var fileContents, isMatch;
|
|
37
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
38
|
+
while (1) switch (_context.prev = _context.next) {
|
|
39
|
+
case 0:
|
|
40
|
+
fileContents = readFile(filePath, 'utf8'); // Grep for installedPackage
|
|
41
|
+
_context.next = 3;
|
|
42
|
+
return fileContents;
|
|
43
|
+
case 3:
|
|
44
|
+
isMatch = _context.sent.toString().split(/\n/).some(function (line) {
|
|
45
|
+
return line.match(dependencyPackage);
|
|
46
|
+
});
|
|
47
|
+
return _context.abrupt("return", isMatch && filePath);
|
|
48
|
+
case 5:
|
|
49
|
+
case "end":
|
|
50
|
+
return _context.stop();
|
|
51
|
+
}
|
|
52
|
+
}, _callee);
|
|
53
|
+
}));
|
|
54
|
+
return function (_x3) {
|
|
55
|
+
return _ref.apply(this, arguments);
|
|
56
|
+
};
|
|
57
|
+
}());
|
|
58
|
+
_context2.next = 6;
|
|
59
|
+
return Promise.all(productPackageJsonPathPromises);
|
|
60
|
+
case 6:
|
|
61
|
+
productPackageJsonPaths = _context2.sent.filter(function (path) {
|
|
62
|
+
return path !== false;
|
|
63
|
+
});
|
|
64
|
+
// Get directory
|
|
65
|
+
productPackagePaths = productPackageJsonPaths.map(function (line) {
|
|
66
|
+
return line.replace('/package.json', '');
|
|
67
|
+
});
|
|
68
|
+
return _context2.abrupt("return", productPackagePaths);
|
|
69
|
+
case 9:
|
|
70
|
+
case "end":
|
|
71
|
+
return _context2.stop();
|
|
72
|
+
}
|
|
73
|
+
}, _callee2);
|
|
74
|
+
}));
|
|
75
|
+
return _findDependentPackagePaths.apply(this, arguments);
|
|
40
76
|
}
|
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 () {
|
|
9
|
+
get: function get() {
|
|
10
10
|
return _types.NoTransformsExistError;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
13
|
Object.defineProperty(exports, "ValidationError", {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: function () {
|
|
15
|
+
get: function get() {
|
|
16
16
|
return _types.ValidationError;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "default", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () {
|
|
21
|
+
get: function get() {
|
|
22
22
|
return _main.default;
|
|
23
23
|
}
|
|
24
24
|
});
|