@atlaskit/codemod-cli 0.8.1 → 0.8.5
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 +26 -0
- package/README.md +12 -2
- package/dist/cjs/cli.js +1 -1
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/main.js +6 -4
- package/dist/cjs/presets/index.js +4 -2
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +145 -0
- package/dist/cjs/presets/theme-to-design-tokens/types.js +5 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +88 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +19 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +59 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +348 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +83 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +8 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +38 -0
- package/dist/cjs/transforms.js +1 -1
- package/dist/cjs/types.js +5 -3
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/cli.js +1 -1
- package/dist/es2019/main.js +3 -1
- package/dist/es2019/presets/index.js +2 -1
- package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +100 -0
- package/dist/es2019/presets/theme-to-design-tokens/types.js +1 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +63 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast.js +10 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +35 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +336 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/legacy-colors.js +74 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/named-colors.js +1 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/tokens.js +12 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/cli.js +1 -1
- package/dist/esm/main.js +6 -4
- package/dist/esm/presets/index.js +3 -2
- package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +130 -0
- package/dist/esm/presets/theme-to-design-tokens/types.js +1 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +75 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/ast.js +10 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/color.js +39 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +340 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/legacy-colors.js +74 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/named-colors.js +1 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/tokens.js +24 -0
- package/dist/esm/types.js +3 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/presets/index.d.ts +1 -0
- package/dist/types/presets/theme-to-design-tokens/theme-to-design-tokens.d.ts +2 -0
- package/dist/types/presets/theme-to-design-tokens/utils/ast-meta.d.ts +3 -0
- package/dist/types/presets/theme-to-design-tokens/utils/ast.d.ts +3 -0
- package/dist/types/presets/theme-to-design-tokens/utils/color.d.ts +4 -0
- package/dist/types/presets/theme-to-design-tokens/utils/fuzzy-search.d.ts +5 -0
- package/dist/types/presets/theme-to-design-tokens/utils/legacy-colors.d.ts +3 -0
- package/dist/types/presets/theme-to-design-tokens/utils/named-colors.d.ts +1 -0
- package/dist/types/presets/theme-to-design-tokens/utils/tokens.d.ts +2 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @atlaskit/codemod-cli
|
|
2
2
|
|
|
3
|
+
## 0.8.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e4dd80187f5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e4dd80187f5) - Refactors theme-to-tokens codemod with new token names + simplifies logic
|
|
8
|
+
|
|
9
|
+
## 0.8.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`19d72473dfb`](https://bitbucket.org/atlassian/atlassian-frontend/commits/19d72473dfb) - Adds a new codemod preset `theme-to-design-tokens` that helps migrate from atlaskit theme to atlaskit tokens.
|
|
14
|
+
- [`19d72473dfb`](https://bitbucket.org/atlassian/atlassian-frontend/commits/19d72473dfb) - Theme preset is now picked up by the CLI.
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
17
|
+
## 0.8.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- [`f4d22b1c8af`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f4d22b1c8af) - Ignore directory filtering logic if filtering returns no paths
|
|
22
|
+
|
|
23
|
+
## 0.8.2
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- [`650aa20f6fe`](https://bitbucket.org/atlassian/atlassian-frontend/commits/650aa20f6fe) - Upgrade meow dependency
|
|
28
|
+
|
|
3
29
|
## 0.8.1
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Codemod CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Detailed docs and example usage can be found [here](../../../repo-docs/content/cloud/framework/atlassian-frontend/codemods/01-atlassian-codemods.md)
|
|
4
|
+
|
|
5
|
+
## Testing locally
|
|
6
|
+
|
|
7
|
+
When wanting to run the CLI before it has been published you can run the start command.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
yarn start [commands]
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a list of commands run it with `-h` or look at the [documentation](../../../repo-docs/content/cloud/framework/atlassian-frontend/codemods/01-atlassian-codemods.md).
|
package/dist/cjs/cli.js
CHANGED
|
@@ -30,7 +30,7 @@ function _run() {
|
|
|
30
30
|
while (1) {
|
|
31
31
|
switch (_context.prev = _context.next) {
|
|
32
32
|
case 0:
|
|
33
|
-
cli = (0, _meow.default)("\nUsage\n $ npx @atlaskit/codemod-cli [options] <file-paths>...\n\nOptions\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 --
|
|
33
|
+
cli = (0, _meow.default)("\nUsage\n $ npx @atlaskit/codemod-cli [options] <file-paths>...\n\nOptions\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
34
|
flags: {
|
|
35
35
|
transform: {
|
|
36
36
|
type: 'string',
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,10 +5,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
Object.defineProperty(exports, "
|
|
8
|
+
Object.defineProperty(exports, "NoTransformsExistError", {
|
|
9
9
|
enumerable: true,
|
|
10
10
|
get: function get() {
|
|
11
|
-
return
|
|
11
|
+
return _types.NoTransformsExistError;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
Object.defineProperty(exports, "ValidationError", {
|
|
@@ -17,10 +17,10 @@ Object.defineProperty(exports, "ValidationError", {
|
|
|
17
17
|
return _types.ValidationError;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
Object.defineProperty(exports, "
|
|
20
|
+
Object.defineProperty(exports, "default", {
|
|
21
21
|
enumerable: true,
|
|
22
22
|
get: function get() {
|
|
23
|
-
return
|
|
23
|
+
return _main.default;
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
|
package/dist/cjs/main.js
CHANGED
|
@@ -41,9 +41,9 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
41
41
|
|
|
42
42
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
43
43
|
|
|
44
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
44
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
45
45
|
|
|
46
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
46
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
47
47
|
|
|
48
48
|
var jscodeshift = require.resolve('.bin/jscodeshift');
|
|
49
49
|
|
|
@@ -179,7 +179,9 @@ var runTransform = /*#__PURE__*/function () {
|
|
|
179
179
|
codemodDirs = _context3.sent;
|
|
180
180
|
|
|
181
181
|
if (codemodDirs.length === 0) {
|
|
182
|
-
|
|
182
|
+
// Fallback to non-filter logic if filtering returns no directories
|
|
183
|
+
logger.log(_chalk.default.yellow("Could not filter source paths for ".concat(transform.module, ", falling back to running over all specified paths. (See --no-filter-paths flag)")));
|
|
184
|
+
codemodDirs = filePaths;
|
|
183
185
|
} else {
|
|
184
186
|
logger.log(_chalk.default.green("Running transform '".concat(_chalk.default.bold(transform.name), "' over filtered dirs ").concat(_chalk.default.bold(codemodDirs.join(', ')), "...")));
|
|
185
187
|
}
|
|
@@ -361,7 +363,7 @@ function _main() {
|
|
|
361
363
|
case 4:
|
|
362
364
|
_yield$parseArgs = _context5.sent;
|
|
363
365
|
packages = _yield$parseArgs.packages;
|
|
364
|
-
_process$env$_PACKAGE = "0.8.
|
|
366
|
+
_process$env$_PACKAGE = "0.8.5", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
|
|
365
367
|
logger.log(_chalk.default.bgBlue(_chalk.default.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
|
|
366
368
|
|
|
367
369
|
if (packages && packages.length > 0) {
|
|
@@ -11,12 +11,14 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
11
11
|
|
|
12
12
|
require("./styled-to-emotion/styled-to-emotion");
|
|
13
13
|
|
|
14
|
+
require("./theme-to-design-tokens/theme-to-design-tokens");
|
|
15
|
+
|
|
14
16
|
/**
|
|
15
17
|
* Manually import presets to make sure typescript includes them
|
|
16
18
|
* in the final bundle
|
|
17
19
|
*/
|
|
18
|
-
var presets = ['styled-to-emotion'].map(function (preset) {
|
|
19
|
-
return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js)"));
|
|
20
|
+
var presets = ['styled-to-emotion', 'theme-to-design-tokens'].map(function (preset) {
|
|
21
|
+
return _path.default.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
|
|
20
22
|
});
|
|
21
23
|
var _default = presets;
|
|
22
24
|
exports.default = _default;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = transformer;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
12
|
+
var _ast = require("./utils/ast");
|
|
13
|
+
|
|
14
|
+
var _astMeta = require("./utils/ast-meta");
|
|
15
|
+
|
|
16
|
+
var _color = require("./utils/color");
|
|
17
|
+
|
|
18
|
+
var _fuzzySearch = _interopRequireDefault(require("./utils/fuzzy-search"));
|
|
19
|
+
|
|
20
|
+
var _legacyColors = require("./utils/legacy-colors");
|
|
21
|
+
|
|
22
|
+
var _tokens = require("./utils/tokens");
|
|
23
|
+
|
|
24
|
+
/* eslint-disable no-console */
|
|
25
|
+
var search = (0, _fuzzySearch.default)(_tokens.tokens, false);
|
|
26
|
+
|
|
27
|
+
function hasImportDeclaration(j, source, sourcePath) {
|
|
28
|
+
return !!source.find(j.ImportDeclaration).filter(function (path) {
|
|
29
|
+
return path.node.source.value === sourcePath;
|
|
30
|
+
}).length;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function hasImportSpecifier(j, source, specifier, sourcePath) {
|
|
34
|
+
return !!source.find(j.ImportDeclaration).filter(function (path) {
|
|
35
|
+
return path.node.source.value === sourcePath;
|
|
36
|
+
}).find(j.ImportSpecifier, {
|
|
37
|
+
local: {
|
|
38
|
+
name: specifier
|
|
39
|
+
}
|
|
40
|
+
}).length;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function insertTokenImport(j, source) {
|
|
44
|
+
if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
49
|
+
source.get().node.program.body.unshift(newImport);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function buildToken(j, tokenId, node) {
|
|
53
|
+
var callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
|
|
54
|
+
return callExpr;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getTokenFromNode(j, path) {
|
|
58
|
+
var baseMeta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
59
|
+
var foundMeta = (0, _astMeta.getMetaFromAncestors)(j, path);
|
|
60
|
+
var meta = (0, _astMeta.cleanMeta)([].concat((0, _toConsumableArray2.default)(foundMeta), (0, _toConsumableArray2.default)(baseMeta)));
|
|
61
|
+
var results = search.get(meta.join(' '));
|
|
62
|
+
var tokenId = ['utility.UNSAFE_util.MISSING_TOKEN'];
|
|
63
|
+
|
|
64
|
+
if (results) {
|
|
65
|
+
tokenId = results.map(function (result) {
|
|
66
|
+
return result[1];
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return tokenId[0];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function transformer(file, api) {
|
|
74
|
+
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
75
|
+
var j = api.jscodeshift;
|
|
76
|
+
var source = j(file.source);
|
|
77
|
+
var transformed = false;
|
|
78
|
+
source // Handle colors.N100
|
|
79
|
+
.find(j.MemberExpression).filter(function (path) {
|
|
80
|
+
return path.value.object.type === 'Identifier' && path.value.object.name === 'colors' && path.value.property.type === 'Identifier' && (0, _color.isLegacyColor)(path.value.property.name);
|
|
81
|
+
}).filter(function (path) {
|
|
82
|
+
return !(0, _ast.isDecendantOfToken)(j, path);
|
|
83
|
+
}).forEach(function (path) {
|
|
84
|
+
debug && console.log('file:', file.path);
|
|
85
|
+
insertTokenImport(j, source);
|
|
86
|
+
var key = path.value.property.type === 'Identifier' ? path.value.property.name : undefined;
|
|
87
|
+
var colorMeta = _legacyColors.legacyColorMetaMap[key] || [];
|
|
88
|
+
var tokenId = getTokenFromNode(j, path, colorMeta);
|
|
89
|
+
j(path).replaceWith(buildToken(j, tokenId, path.value));
|
|
90
|
+
transformed = true;
|
|
91
|
+
});
|
|
92
|
+
source.find(j.ObjectProperty).filter(function (path) {
|
|
93
|
+
return path.value.value.type === 'Identifier' && ((0, _color.isLegacyColor)(path.value.value.name) || (0, _color.isLegacyNamedColor)(path.value.value.name));
|
|
94
|
+
}).filter(function (path) {
|
|
95
|
+
return hasImportSpecifier(j, source, path.value.value.type === 'Identifier' ? path.value.value.name : '', '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.value.type === 'Identifier' ? path.value.value.name : '', '@atlaskit/theme/colors');
|
|
96
|
+
}).filter(function (path) {
|
|
97
|
+
return !(0, _ast.isDecendantOfToken)(j, path.value.value);
|
|
98
|
+
}).forEach(function (path) {
|
|
99
|
+
var valuePath = path.get('value');
|
|
100
|
+
debug && console.log('file:', file.path);
|
|
101
|
+
insertTokenImport(j, source);
|
|
102
|
+
var colorMeta = _legacyColors.legacyColorMetaMap[valuePath.name] || [];
|
|
103
|
+
var tokenId = getTokenFromNode(j, valuePath, colorMeta);
|
|
104
|
+
j(path).replaceWith(j.objectProperty(path.value.key, buildToken(j, tokenId, valuePath.value)));
|
|
105
|
+
transformed = true;
|
|
106
|
+
});
|
|
107
|
+
source.find(j.Identifier).filter(function (path) {
|
|
108
|
+
return (0, _color.isLegacyColor)(path.value.name) || (0, _color.isLegacyNamedColor)(path.value.name);
|
|
109
|
+
}).filter(function (path) {
|
|
110
|
+
return hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme/colors');
|
|
111
|
+
}).filter(function (path) {
|
|
112
|
+
return !['ImportSpecifier', 'MemberExpression', 'ObjectProperty'].includes(path.parentPath.value.type);
|
|
113
|
+
}).filter(function (path) {
|
|
114
|
+
return !(0, _ast.isDecendantOfToken)(j, path);
|
|
115
|
+
}).forEach(function (path) {
|
|
116
|
+
debug && console.log('file:', file.path);
|
|
117
|
+
insertTokenImport(j, source);
|
|
118
|
+
var colorMeta = _legacyColors.legacyColorMetaMap[path.value.name] || [];
|
|
119
|
+
var tokenId = getTokenFromNode(j, path, colorMeta);
|
|
120
|
+
j(path).replaceWith(buildToken(j, tokenId, path.value));
|
|
121
|
+
transformed = true;
|
|
122
|
+
});
|
|
123
|
+
source.find(j.Literal).filter(function (path) {
|
|
124
|
+
return typeof path.value.value === 'string' && ((0, _color.includesHardCodedColor)(path.value.value) || (0, _color.isHardCodedColor)(path.value.value));
|
|
125
|
+
}).filter(function (path) {
|
|
126
|
+
return !(0, _ast.isDecendantOfToken)(j, path);
|
|
127
|
+
}).forEach(function (path) {
|
|
128
|
+
var _path$value, _path$value$value;
|
|
129
|
+
|
|
130
|
+
debug && console.log('file:', file.path);
|
|
131
|
+
insertTokenImport(j, source);
|
|
132
|
+
var value = path === null || path === void 0 ? void 0 : (_path$value = path.value) === null || _path$value === void 0 ? void 0 : (_path$value$value = _path$value.value) === null || _path$value$value === void 0 ? void 0 : _path$value$value.toString();
|
|
133
|
+
var colorMeta = _legacyColors.legacyColorMetaMap[value] || [];
|
|
134
|
+
var tokenId = getTokenFromNode(j, path, colorMeta);
|
|
135
|
+
var tokenNode = buildToken(j, tokenId, path.value);
|
|
136
|
+
j(path).replaceWith((0, _ast.isDecendantOfType)(j, path, j.JSXAttribute) ? j.jsxExpressionContainer(tokenNode) : tokenNode);
|
|
137
|
+
transformed = true;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (transformed) {
|
|
141
|
+
return source.toSource();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return file.source;
|
|
145
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.cleanMeta = cleanMeta;
|
|
9
|
+
exports.getMetaFromAncestors = getMetaFromAncestors;
|
|
10
|
+
|
|
11
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
|
+
|
|
13
|
+
var _tokens = require("./tokens");
|
|
14
|
+
|
|
15
|
+
function getMetaFromAncestors(j, path) {
|
|
16
|
+
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
17
|
+
var parent = path.parentPath;
|
|
18
|
+
var grandParent = parent && parent.parentPath;
|
|
19
|
+
|
|
20
|
+
if (parent && parent.value.type === 'ObjectProperty') {
|
|
21
|
+
var value = '';
|
|
22
|
+
|
|
23
|
+
if (parent.value.key.type === 'Literal' || parent.value.key.type === 'StringLiteral' || parent.value.key.type === 'NumericLiteral') {
|
|
24
|
+
value = parent.value.key.value.toString();
|
|
25
|
+
} else {
|
|
26
|
+
value = parent.value.key.name;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
meta.push(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
33
|
+
var expressionIndex = grandParent.value.expressions.findIndex(function (exp) {
|
|
34
|
+
return exp.name === path.value.name;
|
|
35
|
+
});
|
|
36
|
+
var quasi = grandParent.value.quasis[expressionIndex];
|
|
37
|
+
var propertyName = (quasi.value.cooked || quasi.value.raw || '').replace(/\n/g, '').split(/;|{|}/).filter(function (el) {
|
|
38
|
+
return !el.match(/\.|\@|\(|\)/);
|
|
39
|
+
}).pop().split(/:/g)[0].trim();
|
|
40
|
+
grandParent.value.quasis.slice(0, expressionIndex + 1).map(function (q) {
|
|
41
|
+
return q.value.cooked;
|
|
42
|
+
}) // We reverse so the most nested one is first which we're more likely than not interested in
|
|
43
|
+
.reverse().some(function (str) {
|
|
44
|
+
var result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
45
|
+
|
|
46
|
+
if (result) {
|
|
47
|
+
meta.push(result[0]);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
meta.push(propertyName);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (parent && parent.value.type === 'JSXAttribute') {
|
|
55
|
+
if (!['css', 'styles', 'style'].includes(parent.value.name.name)) {
|
|
56
|
+
meta.push(parent.value.name.name);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
61
|
+
meta.push(parent.value.id.name);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (parent) {
|
|
65
|
+
return getMetaFromAncestors(j, parent, meta);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return meta;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function cleanMeta(meta) {
|
|
72
|
+
return meta.reduce(function (accum, val) {
|
|
73
|
+
return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
|
|
74
|
+
return e.toLowerCase();
|
|
75
|
+
}) : []));
|
|
76
|
+
}, []).reduce(function (accum, val) {
|
|
77
|
+
accum.push(val.replace(/:/g, '').replace(/,/g, '').replace('grey', 'neutral').replace('skeleton', 'neutral').replace('texts', 'text').replace('red', 'danger').replace('error', 'danger').replace('invalid', 'danger').replace('removed', 'danger').replace('removal', 'danger').replace('remove', 'danger').replace('focus', 'focused').replace('valid', 'success').replace('successful', 'success').replace('risk', 'warning').replace('caution', 'warning').replace('warn', 'warning').replace('primary', 'bold').replace('info', 'bold').replace('secondary', 'subtle').replace('hyperlink', 'link').replace('anchor', 'link').replace('active', 'pressed').replace('hover', 'hovered').replace('dragged', 'overlay').replace('dragging', 'overlay').replace('drag', 'overlay').replace('background-color', 'background').replace('color', 'text').replace('icons', 'icon').replace('glyph', 'icon').replace('stroke', 'border').replace('border-left', 'border').replace('border-right', 'border').replace('border-top', 'border').replace('border-bottom', 'border').replace('box-shadow', 'shadow'));
|
|
78
|
+
return accum;
|
|
79
|
+
}, []).filter(function (val) {
|
|
80
|
+
return _tokens.getUniqueWordsFromTokens.includes(val);
|
|
81
|
+
}).reduce(function (accum, val) {
|
|
82
|
+
if (!accum.includes(val)) {
|
|
83
|
+
accum.push(val);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return accum;
|
|
87
|
+
}, []);
|
|
88
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isDecendantOfToken = isDecendantOfToken;
|
|
7
|
+
exports.isDecendantOfType = isDecendantOfType;
|
|
8
|
+
|
|
9
|
+
function isDecendantOfToken(j, path) {
|
|
10
|
+
return j(path).closest(j.CallExpression, {
|
|
11
|
+
callee: {
|
|
12
|
+
name: 'token'
|
|
13
|
+
}
|
|
14
|
+
}).length > 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isDecendantOfType(j, path, type) {
|
|
18
|
+
return j(path).closest(type).length > 0;
|
|
19
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = exports.includesHardCodedColor = void 0;
|
|
7
|
+
|
|
8
|
+
var _legacyColors = require("./legacy-colors");
|
|
9
|
+
|
|
10
|
+
var _namedColors = require("./named-colors");
|
|
11
|
+
|
|
12
|
+
var isLegacyColor = function isLegacyColor(value) {
|
|
13
|
+
return _legacyColors.legacyColors.includes(value);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.isLegacyColor = isLegacyColor;
|
|
17
|
+
|
|
18
|
+
var isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
19
|
+
return _legacyColors.legacyColorMixins.includes(value);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.isLegacyNamedColor = isLegacyNamedColor;
|
|
23
|
+
|
|
24
|
+
var includesHardCodedColor = function includesHardCodedColor(raw) {
|
|
25
|
+
var value = raw.toLowerCase();
|
|
26
|
+
|
|
27
|
+
if (/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|hsl)a?\([^\)]*\)/.exec(value.toLowerCase())) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (var i = 0; i < _namedColors.namedColors.length; i++) {
|
|
32
|
+
if (value.includes("".concat(_namedColors.namedColors[i], ";"))) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.includesHardCodedColor = includesHardCodedColor;
|
|
41
|
+
|
|
42
|
+
var isHardCodedColor = function isHardCodedColor(value) {
|
|
43
|
+
if (_namedColors.namedColors.includes(value.toLowerCase())) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (value.startsWith('rgb(') || value.startsWith('rgba(') || value.startsWith('hsl(') || value.startsWith('hsla(') || value.startsWith('lch(') || value.startsWith('lab(') || value.startsWith('color(')) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (value.startsWith('#') && ( // short hex, hex, or hex with alpha
|
|
52
|
+
value.length === 4 || value.length === 7 || value.length === 9)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.isHardCodedColor = isHardCodedColor;
|