@atlaskit/codemod-cli 0.14.0 → 0.16.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.
- package/CHANGELOG.md +72 -53
- package/dist/cjs/main.js +3 -3
- package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +52 -133
- package/dist/cjs/presets/css-to-design-tokens/lib/colors.js +49 -0
- package/dist/cjs/presets/css-to-design-tokens/lib/declaration.js +29 -0
- package/dist/cjs/presets/css-to-design-tokens/{utils → lib}/legacy-colors.js +13 -17
- package/dist/cjs/presets/css-to-design-tokens/lib/logger.js +18 -0
- package/dist/cjs/presets/css-to-design-tokens/lib/meta.js +157 -0
- package/dist/cjs/presets/css-to-design-tokens/lib/tokens.js +47 -0
- package/dist/cjs/presets/css-to-design-tokens/lib/value.js +80 -0
- package/dist/cjs/presets/index.js +3 -3
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +118 -0
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-split-imports.js +58 -0
- package/dist/cjs/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +45 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/constants.js +35 -0
- package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +1 -2
- package/dist/cjs/presets/theme-remove-deprecated-mixins/utils/replacements.js +2 -3
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +2 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +4 -8
- package/dist/cjs/presets/theme-to-design-tokens/utils/css-utils.js +2 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +1 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +4 -7
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/string-utils.js +1 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +3 -5
- package/dist/cjs/sinceRef.js +1 -2
- package/dist/cjs/transforms.js +6 -12
- package/dist/cjs/types.js +3 -5
- package/dist/cjs/utils.js +2 -3
- package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +52 -116
- package/dist/es2019/presets/css-to-design-tokens/lib/colors.js +34 -0
- package/dist/es2019/presets/css-to-design-tokens/lib/declaration.js +17 -0
- package/dist/es2019/presets/css-to-design-tokens/{utils → lib}/legacy-colors.js +9 -10
- package/dist/es2019/presets/css-to-design-tokens/lib/logger.js +11 -0
- package/dist/es2019/presets/css-to-design-tokens/lib/meta.js +133 -0
- package/dist/es2019/presets/css-to-design-tokens/lib/tokens.js +24 -0
- package/dist/es2019/presets/css-to-design-tokens/lib/value.js +68 -0
- package/dist/es2019/presets/index.js +2 -1
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +86 -0
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-split-imports.js +44 -0
- package/dist/es2019/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +19 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/constants.js +29 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/css-utils.js +2 -2
- package/dist/esm/main.js +3 -3
- package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +52 -132
- package/dist/esm/presets/css-to-design-tokens/lib/colors.js +38 -0
- package/dist/esm/presets/css-to-design-tokens/lib/declaration.js +19 -0
- package/dist/esm/presets/css-to-design-tokens/{utils → lib}/legacy-colors.js +9 -10
- package/dist/esm/presets/css-to-design-tokens/lib/logger.js +11 -0
- package/dist/esm/presets/css-to-design-tokens/lib/meta.js +146 -0
- package/dist/esm/presets/css-to-design-tokens/lib/tokens.js +40 -0
- package/dist/esm/presets/css-to-design-tokens/lib/value.js +73 -0
- package/dist/esm/presets/index.js +2 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +112 -0
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-split-imports.js +52 -0
- package/dist/esm/presets/migrate-to-new-buttons/migrate-to-new-buttons.js +38 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/constants.js +29 -0
- package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +2 -2
- package/dist/esm/presets/theme-to-design-tokens/utils/css-utils.js +2 -2
- package/dist/types/main.d.ts +0 -1
- package/dist/types/presets/css-to-design-tokens/css-to-design-tokens.d.ts +0 -1
- package/dist/types/presets/css-to-design-tokens/lib/colors.d.ts +6 -0
- package/dist/types/presets/css-to-design-tokens/lib/declaration.d.ts +5 -0
- package/dist/types/presets/css-to-design-tokens/{utils → lib}/legacy-colors.d.ts +1 -1
- package/dist/types/presets/css-to-design-tokens/lib/logger.d.ts +4 -0
- package/dist/types/presets/css-to-design-tokens/lib/meta.d.ts +6 -0
- package/dist/types/presets/css-to-design-tokens/lib/tokens.d.ts +7 -0
- package/dist/types/presets/css-to-design-tokens/lib/value.d.ts +6 -0
- package/dist/types/presets/index.d.ts +1 -0
- package/dist/types/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +3 -0
- package/dist/types/presets/migrate-to-new-buttons/codemods/next-split-imports.d.ts +3 -0
- package/dist/types/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/constants.d.ts +14 -0
- package/dist/types-ts4.5/main.d.ts +0 -1
- package/dist/types-ts4.5/presets/css-to-design-tokens/css-to-design-tokens.d.ts +0 -1
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/colors.d.ts +6 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/declaration.d.ts +5 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/{utils → lib}/legacy-colors.d.ts +1 -1
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/logger.d.ts +4 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/meta.d.ts +6 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/tokens.d.ts +7 -0
- package/dist/types-ts4.5/presets/css-to-design-tokens/lib/value.d.ts +6 -0
- package/dist/types-ts4.5/presets/index.d.ts +1 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/codemods/next-split-imports.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/migrate-to-new-buttons.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/constants.d.ts +14 -0
- package/package.json +3 -2
- package/report.api.md +0 -2
- package/tmp/api-report-tmp.d.ts +0 -2
- package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +0 -53
- package/dist/es2019/presets/css-to-design-tokens/utils/meta.js +0 -33
- package/dist/esm/presets/css-to-design-tokens/utils/meta.js +0 -46
- package/dist/types/presets/css-to-design-tokens/utils/meta.d.ts +0 -1
- package/dist/types-ts4.5/presets/css-to-design-tokens/utils/meta.d.ts +0 -1
package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PRINT_SETTINGS, NEW_BUTTON_VARIANTS, entryPointsMapping, NEW_BUTTON_ENTRY_POINT } from '../utils/constants';
|
|
2
|
+
const transformer = (file, api) => {
|
|
3
|
+
const j = api.jscodeshift;
|
|
4
|
+
const fileSource = j(file.source);
|
|
5
|
+
const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === entryPointsMapping.Button || path.node.source.value === NEW_BUTTON_ENTRY_POINT);
|
|
6
|
+
if (!buttonImports.length) {
|
|
7
|
+
return fileSource.toSource();
|
|
8
|
+
}
|
|
9
|
+
const defaultButtonImport = buttonImports.find(j.Specifier).filter(path => path.node.type === 'ImportDefaultSpecifier');
|
|
10
|
+
if (defaultButtonImport.length === 0) {
|
|
11
|
+
return fileSource.toSource();
|
|
12
|
+
}
|
|
13
|
+
const specifierIdentifier = defaultButtonImport.get(0).node.local.name;
|
|
14
|
+
const attributes = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier).find(j.JSXAttribute);
|
|
15
|
+
const hasCustomComponent = attributes.filter(attribute => attribute.node.name.name === 'component').length > 0;
|
|
16
|
+
const hasCssProp = attributes.filter(attribute => attribute.node.name.name === 'css').length > 0;
|
|
17
|
+
if (hasCustomComponent || hasCssProp) {
|
|
18
|
+
return fileSource.toSource(PRINT_SETTINGS);
|
|
19
|
+
}
|
|
20
|
+
const checkIfVariantAlreadyImported = variant => fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT).find(j.ImportSpecifier).filter(path => path.node.imported.name === variant).length > 0;
|
|
21
|
+
const generateNewElement = (variant, element) => {
|
|
22
|
+
const {
|
|
23
|
+
attributes
|
|
24
|
+
} = element.openingElement;
|
|
25
|
+
if (variant === NEW_BUTTON_VARIANTS.icon.as) {
|
|
26
|
+
const attr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter'));
|
|
27
|
+
if (attr !== null && attr !== void 0 && attr.length && attr[0].type === 'JSXAttribute') {
|
|
28
|
+
attr[0].name.name = 'icon';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// self closing if it's an icon button or icon link button
|
|
32
|
+
const isSelfClosing = variant === NEW_BUTTON_VARIANTS.icon.as || variant === NEW_BUTTON_VARIANTS.linkIcon.as;
|
|
33
|
+
return j.jsxElement(j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isSelfClosing), isSelfClosing ? null : j.jsxClosingElement(j.jsxIdentifier(variant)), element.children);
|
|
34
|
+
};
|
|
35
|
+
let hasLinkIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.linkIcon.import);
|
|
36
|
+
let hasLinkButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.link.import);
|
|
37
|
+
let hasIconButton = checkIfVariantAlreadyImported(NEW_BUTTON_VARIANTS.icon.import);
|
|
38
|
+
const allButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier);
|
|
39
|
+
allButtons.forEach(element => {
|
|
40
|
+
var _element$value$childr, _element$value$childr2;
|
|
41
|
+
const {
|
|
42
|
+
attributes
|
|
43
|
+
} = element.value.openingElement;
|
|
44
|
+
if (!attributes) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const buttonAttributes = attributes.map(node => node.type === 'JSXAttribute' && node.name.name);
|
|
48
|
+
const hasHref = buttonAttributes.includes('href');
|
|
49
|
+
const hasIcon = buttonAttributes.includes('iconBefore') || buttonAttributes.includes('iconAfter');
|
|
50
|
+
const isLinkIconButton = hasHref && hasIcon && ((_element$value$childr = element.value.children) === null || _element$value$childr === void 0 ? void 0 : _element$value$childr.length) === 0;
|
|
51
|
+
const isLinkButton = hasHref && !isLinkIconButton;
|
|
52
|
+
const isIconButton = !hasHref && hasIcon && ((_element$value$childr2 = element.value.children) === null || _element$value$childr2 === void 0 ? void 0 : _element$value$childr2.length) === 0;
|
|
53
|
+
if (isLinkIconButton) {
|
|
54
|
+
hasLinkIconButton = true;
|
|
55
|
+
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.linkIcon.as, element.value));
|
|
56
|
+
}
|
|
57
|
+
if (isIconButton) {
|
|
58
|
+
hasIconButton = true;
|
|
59
|
+
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.icon.as, element.value));
|
|
60
|
+
}
|
|
61
|
+
if (isLinkButton) {
|
|
62
|
+
hasLinkButton = true;
|
|
63
|
+
j(element).replaceWith(generateNewElement(NEW_BUTTON_VARIANTS.link.as, element.value));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const specifiers = [];
|
|
67
|
+
if (hasLinkButton) {
|
|
68
|
+
specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.link.import), j.identifier(NEW_BUTTON_VARIANTS.link.as)));
|
|
69
|
+
}
|
|
70
|
+
if (hasIconButton) {
|
|
71
|
+
specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.icon.import), j.identifier(NEW_BUTTON_VARIANTS.icon.as)));
|
|
72
|
+
}
|
|
73
|
+
if (hasLinkIconButton) {
|
|
74
|
+
specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.linkIcon.import), j.identifier(NEW_BUTTON_VARIANTS.linkIcon.as)));
|
|
75
|
+
}
|
|
76
|
+
const oldButtonImport = fileSource.find(j.ImportDeclaration).filter(path => path.node.source.value === NEW_BUTTON_ENTRY_POINT || path.node.source.value === entryPointsMapping.Button);
|
|
77
|
+
const leftButtons = fileSource.find(j.JSXElement).filter(path => path.value.openingElement.name.type === 'JSXIdentifier' && path.value.openingElement.name.name === specifierIdentifier).length > 0 || fileSource.find(j.CallExpression).filter(path => path.node.arguments.map(argument => argument.type === 'Identifier' && (argument === null || argument === void 0 ? void 0 : argument.name)).includes(specifierIdentifier)).length > 0;
|
|
78
|
+
if (specifiers.length || leftButtons) {
|
|
79
|
+
if (leftButtons) {
|
|
80
|
+
specifiers.push(j.importSpecifier(j.identifier(NEW_BUTTON_VARIANTS.default.import), j.identifier(specifierIdentifier)));
|
|
81
|
+
}
|
|
82
|
+
oldButtonImport.replaceWith(j.importDeclaration(specifiers, j.stringLiteral(NEW_BUTTON_ENTRY_POINT)));
|
|
83
|
+
}
|
|
84
|
+
return fileSource.toSource(PRINT_SETTINGS);
|
|
85
|
+
};
|
|
86
|
+
export default transformer;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { PRINT_SETTINGS, entryPointsMapping, BUTTON_TYPES } from '../utils/constants';
|
|
2
|
+
const transformer = (file, api) => {
|
|
3
|
+
const j = api.jscodeshift;
|
|
4
|
+
const fileSource = j(file.source);
|
|
5
|
+
const buttonImports = fileSource.find(j.ImportDeclaration).filter(path => {
|
|
6
|
+
var _path$node$source$val;
|
|
7
|
+
return (_path$node$source$val = path.node.source.value) === null || _path$node$source$val === void 0 ? void 0 : _path$node$source$val.includes('@atlaskit/button');
|
|
8
|
+
});
|
|
9
|
+
if (!buttonImports.length || buttonImports.every(node => node.node.source.value !== '@atlaskit/button')) {
|
|
10
|
+
return fileSource.toSource(PRINT_SETTINGS);
|
|
11
|
+
}
|
|
12
|
+
buttonImports.forEach(node => {
|
|
13
|
+
const {
|
|
14
|
+
specifiers
|
|
15
|
+
} = node.node;
|
|
16
|
+
const defaultSpecifier = specifiers === null || specifiers === void 0 ? void 0 : specifiers.find(specifier => specifier.type === 'ImportDefaultSpecifier');
|
|
17
|
+
if (defaultSpecifier && defaultSpecifier.local) {
|
|
18
|
+
const defaultButtonImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(defaultSpecifier.local.name))], j.stringLiteral(entryPointsMapping.Button));
|
|
19
|
+
j(node).insertAfter(defaultButtonImport);
|
|
20
|
+
}
|
|
21
|
+
const defaultTypeSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(specifier => specifier.importKind === 'type');
|
|
22
|
+
if (defaultTypeSpecifiers !== null && defaultTypeSpecifiers !== void 0 && defaultTypeSpecifiers.length) {
|
|
23
|
+
const typeImport = j.importDeclaration(defaultTypeSpecifiers, j.stringLiteral('@atlaskit/button/types'));
|
|
24
|
+
j(node).insertAfter(typeImport);
|
|
25
|
+
}
|
|
26
|
+
const valueSpecifiers = specifiers === null || specifiers === void 0 ? void 0 : specifiers.filter(specifier => specifier.type === 'ImportSpecifier');
|
|
27
|
+
const otherTypeSpecifiers = valueSpecifiers === null || valueSpecifiers === void 0 ? void 0 : valueSpecifiers.filter(specifier => BUTTON_TYPES.includes(specifier.imported.name));
|
|
28
|
+
if (otherTypeSpecifiers !== null && otherTypeSpecifiers !== void 0 && otherTypeSpecifiers.length) {
|
|
29
|
+
const typeImport = j.importDeclaration(otherTypeSpecifiers, j.stringLiteral('@atlaskit/button'));
|
|
30
|
+
j(node).insertAfter(typeImport);
|
|
31
|
+
}
|
|
32
|
+
if (valueSpecifiers !== null && valueSpecifiers !== void 0 && valueSpecifiers.length) {
|
|
33
|
+
valueSpecifiers.forEach(specifier => {
|
|
34
|
+
if (specifier.local && specifier.type === 'ImportSpecifier' && specifier.local.name && entryPointsMapping[specifier.imported.name]) {
|
|
35
|
+
const newImport = j.importDeclaration([j.importDefaultSpecifier(j.identifier(specifier.local.name))], j.stringLiteral(entryPointsMapping[specifier.imported.name]));
|
|
36
|
+
j(node).insertAfter(newImport);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
j(node).remove();
|
|
41
|
+
});
|
|
42
|
+
return fileSource.toSource(PRINT_SETTINGS);
|
|
43
|
+
};
|
|
44
|
+
export default transformer;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import splitImportsTransformer from './codemods/next-split-imports';
|
|
2
|
+
import migrateToNewButtonVariantsTransformer from './codemods/next-migrate-to-new-button-variants';
|
|
3
|
+
export default async function transformer(file, api) {
|
|
4
|
+
const transformers = [splitImportsTransformer, migrateToNewButtonVariantsTransformer];
|
|
5
|
+
let src = file.source;
|
|
6
|
+
transformers.forEach(transformer => {
|
|
7
|
+
if (typeof src === 'undefined') {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const nextSrc = transformer({
|
|
11
|
+
...file,
|
|
12
|
+
source: src
|
|
13
|
+
}, api);
|
|
14
|
+
if (nextSrc) {
|
|
15
|
+
src = nextSrc;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return src;
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const PRINT_SETTINGS = {
|
|
2
|
+
quote: 'single'
|
|
3
|
+
};
|
|
4
|
+
export const NEW_BUTTON_VARIANTS = {
|
|
5
|
+
default: {
|
|
6
|
+
import: 'UNSAFE_BUTTON',
|
|
7
|
+
as: 'Button'
|
|
8
|
+
},
|
|
9
|
+
link: {
|
|
10
|
+
import: 'UNSAFE_LINK_BUTTON',
|
|
11
|
+
as: 'LinkButton'
|
|
12
|
+
},
|
|
13
|
+
icon: {
|
|
14
|
+
import: 'UNSAFE_ICON_BUTTON',
|
|
15
|
+
as: 'IconButton'
|
|
16
|
+
},
|
|
17
|
+
linkIcon: {
|
|
18
|
+
import: 'UNSAFE_LINK_ICON_BUTTON',
|
|
19
|
+
as: 'LinkIconButton'
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
export const NEW_BUTTON_ENTRY_POINT = '@atlaskit/button/unsafe';
|
|
23
|
+
export const entryPointsMapping = {
|
|
24
|
+
Button: '@atlaskit/button/standard-button',
|
|
25
|
+
LoadingButton: '@atlaskit/button/loading-button',
|
|
26
|
+
ButtonGroup: '@atlaskit/button/button-group',
|
|
27
|
+
CustomThemeButton: '@atlaskit/button/custom-theme-button'
|
|
28
|
+
};
|
|
29
|
+
export const BUTTON_TYPES = ['Appearance', 'Spacing', 'BaseOwnProps', 'BaseProps', 'ButtonProps', 'LoadingButtonProps', 'LoadingButtonOwnProps', 'ThemeTokens', 'ThemeProps', 'InteractionState', 'CustomThemeButtonProps', 'CustomThemeButtonOwnProps'];
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isColorRelatedProperty } from '../../css-to-design-tokens/lib/declaration';
|
|
2
2
|
export function containsReplaceableCSSDeclarations(input) {
|
|
3
3
|
const cssPattern = /(\S+)\s*:/g;
|
|
4
4
|
let match;
|
|
5
5
|
while ((match = cssPattern.exec(input)) !== null) {
|
|
6
|
-
if (
|
|
6
|
+
if (isColorRelatedProperty(match[1])) {
|
|
7
7
|
return true;
|
|
8
8
|
}
|
|
9
9
|
}
|
package/dist/esm/main.js
CHANGED
|
@@ -5,8 +5,8 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
|
|
|
5
5
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
6
|
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; }
|
|
7
7
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
8
|
-
function ownKeys(
|
|
9
|
-
function _objectSpread(
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
10
|
import chalk from 'chalk';
|
|
11
11
|
import fs from 'fs';
|
|
12
12
|
import spawn from 'projector-spawn';
|
|
@@ -291,7 +291,7 @@ function _main() {
|
|
|
291
291
|
case 4:
|
|
292
292
|
_yield$parseArgs = _context5.sent;
|
|
293
293
|
packages = _yield$parseArgs.packages;
|
|
294
|
-
_process$env$_PACKAGE = "0.
|
|
294
|
+
_process$env$_PACKAGE = "0.16.0", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
|
|
295
295
|
logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
|
|
296
296
|
if (packages && packages.length > 0) {
|
|
297
297
|
logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
|
|
@@ -1,86 +1,17 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
3
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
4
|
import postcss from 'postcss';
|
|
6
5
|
// @ts-ignore
|
|
7
6
|
import lessSyntax from 'postcss-less';
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
var options = {
|
|
7
|
+
import { isColorRelatedProperty, isCssDeclaration, splitCssValue } from './lib/declaration';
|
|
8
|
+
import { getBaseDeclarationMeta } from './lib/meta';
|
|
9
|
+
import findToken from './lib/tokens';
|
|
10
|
+
import parseValue from './lib/value';
|
|
11
|
+
var POSTCSS_OPTIONS = {
|
|
14
12
|
syntax: lessSyntax,
|
|
15
13
|
from: undefined
|
|
16
14
|
};
|
|
17
|
-
var tokens = rawTokens.filter(function (t) {
|
|
18
|
-
return t.attributes.state === 'active';
|
|
19
|
-
}).map(function (t) {
|
|
20
|
-
return t.name.replace(/\.\[default\]/g, '');
|
|
21
|
-
}).filter(function (t) {
|
|
22
|
-
return !t.includes('UNSAFE') && !t.includes('interaction');
|
|
23
|
-
});
|
|
24
|
-
var search = Search(tokens, false);
|
|
25
|
-
function isRule(node) {
|
|
26
|
-
return node.type === 'rule';
|
|
27
|
-
}
|
|
28
|
-
function getParentSelectors(node) {
|
|
29
|
-
if (isRule(node)) {
|
|
30
|
-
// @ts-expect-error
|
|
31
|
-
return getParentSelectors(node.parent) + ' ' + node.selector;
|
|
32
|
-
}
|
|
33
|
-
if (node.parent) {
|
|
34
|
-
return getParentSelectors(node.parent);
|
|
35
|
-
}
|
|
36
|
-
return '';
|
|
37
|
-
}
|
|
38
|
-
function stripVar(prop) {
|
|
39
|
-
return prop.substring(prop.indexOf('(') + 1).split(/\,|\)/)[0];
|
|
40
|
-
}
|
|
41
|
-
function stripLessVar(prop) {
|
|
42
|
-
return prop.substring(1);
|
|
43
|
-
}
|
|
44
|
-
export function isColorProperty(prop) {
|
|
45
|
-
return prop === 'color' || prop === 'background' || prop === 'background-color' || prop === 'box-shadow' || prop === 'border' || prop === 'border-left' || prop === 'border-right' || prop === 'border-top' || prop === 'border-bottom' || prop === 'border-color' || prop === 'outline';
|
|
46
|
-
}
|
|
47
|
-
function getDeclarationMeta(decl) {
|
|
48
|
-
if (decl.prop === 'color') {
|
|
49
|
-
return 'text';
|
|
50
|
-
}
|
|
51
|
-
if (decl.prop.startsWith('background')) {
|
|
52
|
-
return 'background';
|
|
53
|
-
}
|
|
54
|
-
if (decl.prop.includes('shadow')) {
|
|
55
|
-
return 'shadow';
|
|
56
|
-
}
|
|
57
|
-
if (decl.prop.includes('border')) {
|
|
58
|
-
return 'border';
|
|
59
|
-
}
|
|
60
|
-
return '';
|
|
61
|
-
}
|
|
62
|
-
function isDesignToken(tokenName) {
|
|
63
|
-
return Boolean(Object.entries(designTokens).find(function (_ref) {
|
|
64
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
65
|
-
_ = _ref2[0],
|
|
66
|
-
value = _ref2[1];
|
|
67
|
-
return tokenName === value;
|
|
68
|
-
}));
|
|
69
|
-
}
|
|
70
|
-
function getMetaFromCssVar(tokenName) {
|
|
71
|
-
var meta = knownVariables[tokenName];
|
|
72
|
-
if (!meta || meta.length === 0) {
|
|
73
|
-
return tokenName.split('-');
|
|
74
|
-
}
|
|
75
|
-
return meta;
|
|
76
|
-
}
|
|
77
|
-
function getMetaFromRawColor(rawColor) {
|
|
78
|
-
var cleanColor = rawColor.toLowerCase();
|
|
79
|
-
if (cleanColor.length === 4) {
|
|
80
|
-
cleanColor = cleanColor + cleanColor.substring(cleanColor.indexOf('#') + 1);
|
|
81
|
-
}
|
|
82
|
-
return knownRawColors[cleanColor];
|
|
83
|
-
}
|
|
84
15
|
|
|
85
16
|
// https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
|
|
86
17
|
// https://astexplorer.net/#/2uBU1BLuJ1
|
|
@@ -88,73 +19,62 @@ var plugin = function plugin() {
|
|
|
88
19
|
var processed = Symbol('processed');
|
|
89
20
|
return {
|
|
90
21
|
postcssPlugin: 'UsingTokens',
|
|
91
|
-
|
|
22
|
+
AtRule: function AtRule(atRule, helper) {
|
|
92
23
|
// @ts-expect-error
|
|
93
|
-
if (
|
|
24
|
+
if (atRule[processed]) {
|
|
94
25
|
return;
|
|
95
26
|
}
|
|
96
|
-
|
|
27
|
+
|
|
28
|
+
// @ts-expect-error: The 'variable' property does not exist on 'AtRule' according to the TypeScript definitions.
|
|
29
|
+
// However, the 'postcss-less' library adds a 'variable' property to 'AtRule' when parsing LESS variables.
|
|
30
|
+
// This property indicates whether the 'AtRule' is a LESS variable.
|
|
31
|
+
if (atRule.variable) {
|
|
32
|
+
// TODO https://hello.atlassian.net/browse/DCA11Y-637
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
atRule[processed] = true;
|
|
37
|
+
},
|
|
38
|
+
Declaration: function Declaration(decl) {
|
|
39
|
+
// @ts-expect-error
|
|
40
|
+
if (decl[processed]) {
|
|
97
41
|
return;
|
|
98
42
|
}
|
|
99
43
|
if (decl.value === 'none') {
|
|
100
44
|
return;
|
|
101
45
|
}
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// CSS variables
|
|
111
|
-
var cssVarMatch = decl.value.match(cssVarRe);
|
|
112
|
-
if (cssVarMatch) {
|
|
113
|
-
var _getMetaFromCssVar;
|
|
114
|
-
match = cssVarMatch[0];
|
|
115
|
-
if (isDesignToken(stripVar(match))) {
|
|
46
|
+
var baseMeta = getBaseDeclarationMeta(decl);
|
|
47
|
+
if (isCssDeclaration(decl.prop)) {
|
|
48
|
+
// TODO https://hello.atlassian.net/browse/DCA11Y-637
|
|
49
|
+
}
|
|
50
|
+
if (isColorRelatedProperty(decl.prop)) {
|
|
51
|
+
var values = splitCssValue(decl.value);
|
|
52
|
+
if (!values) {
|
|
116
53
|
return;
|
|
117
54
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
searchTerms.push.apply(searchTerms, _toConsumableArray((_knownColors$decl$val = knownColors[decl.value.toLowerCase()]) !== null && _knownColors$decl$val !== void 0 ? _knownColors$decl$val : []));
|
|
142
|
-
}
|
|
143
|
-
if (!match) {
|
|
144
|
-
// eslint-disable-next-line no-console
|
|
145
|
-
console.warn("Unable to find match for declaration: ".concat(decl.prop, ": ").concat(decl.value));
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
var cleanSearchTerms = cleanMeta(searchTerms).join(' ');
|
|
149
|
-
var results = search.get(cleanSearchTerms);
|
|
150
|
-
var candidates = results.map(function (result) {
|
|
151
|
-
return result[1];
|
|
152
|
-
});
|
|
153
|
-
var replacement = candidates.length ? designTokens[candidates[0]] : 'MISSING_TOKEN';
|
|
154
|
-
if (decl.prop === 'box-shadow') {
|
|
155
|
-
decl.value = "var(".concat(replacement, ", ").concat(decl.value, ")");
|
|
156
|
-
} else {
|
|
157
|
-
decl.value = decl.value.split(match).join("var(".concat(replacement, ", ").concat(match, ")"));
|
|
55
|
+
switch (decl.prop) {
|
|
56
|
+
case 'box-shadow':
|
|
57
|
+
var meta = values.reduce(function (acc, curr) {
|
|
58
|
+
var parsedValue = parseValue(curr);
|
|
59
|
+
if (!parsedValue) {
|
|
60
|
+
return acc;
|
|
61
|
+
}
|
|
62
|
+
return [].concat(_toConsumableArray(acc), _toConsumableArray(parsedValue.getMeta()));
|
|
63
|
+
}, baseMeta);
|
|
64
|
+
var token = findToken(meta);
|
|
65
|
+
decl.value = "var(".concat(token, ", ").concat(decl.value, ")");
|
|
66
|
+
break;
|
|
67
|
+
default:
|
|
68
|
+
var replacedValues = values.map(function (value) {
|
|
69
|
+
var parsedValue = parseValue(value);
|
|
70
|
+
if (!parsedValue) {
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
return parsedValue.getReplacement(baseMeta);
|
|
74
|
+
});
|
|
75
|
+
decl.value = replacedValues.join(' ');
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
158
78
|
}
|
|
159
79
|
|
|
160
80
|
// @ts-expect-error
|
|
@@ -174,7 +94,7 @@ function _transformer() {
|
|
|
174
94
|
processor = postcss([plugin()]);
|
|
175
95
|
src = typeof file === 'string' ? file : file.source;
|
|
176
96
|
_context.next = 4;
|
|
177
|
-
return processor.process(src,
|
|
97
|
+
return processor.process(src, POSTCSS_OPTIONS);
|
|
178
98
|
case 4:
|
|
179
99
|
_yield$processor$proc = _context.sent;
|
|
180
100
|
css = _yield$processor$proc.css;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { knownNamedColors, knownVariables } from './legacy-colors';
|
|
2
|
+
var NAMED_COLORS = Object.keys(knownNamedColors);
|
|
3
|
+
var GRADIENT_TYPES = ['linear', 'radial', 'conic'];
|
|
4
|
+
var LESS_COLOR_FUNCTIONS = ['lighten', 'darken', 'saturate', 'desaturate', 'fadein', 'fadeout', 'fade', 'spin', 'mix', 'greyscale', 'contrast', 'multiply', 'screen', 'overlay', 'softlight', 'hardlight', 'difference', 'exclusion', 'average', 'negation', 'tint', 'shade', 'luma', 'hue', 'saturation', 'lightness', 'alpha', 'red', 'green', 'blue'];
|
|
5
|
+
var REGEXES = {
|
|
6
|
+
// The CSS regular expression matches CSS variable declarations.
|
|
7
|
+
// It looks for the string "var(" followed by any characters except a closing parenthesis, and ending with a closing parenthesis.
|
|
8
|
+
CSS: /var\([^\)]+\)/g,
|
|
9
|
+
// The RAW_COLOR regular expression matches various CSS color formats including hexadecimal, RGB(A), HSL(A), LAB, LCH, and HWB.
|
|
10
|
+
// It allows for optional leading and trailing white spaces.
|
|
11
|
+
// For RGBA and HSLA, it allows any number (including negative numbers and numbers greater than 1) for the alpha channel.
|
|
12
|
+
// For RGB, HSL, LAB, LCH, and HWB, it expects three comma-separated values.
|
|
13
|
+
// It also allows optional white spaces around the commas and the values.
|
|
14
|
+
RAW_COLOR: /^\s*(#([0-9a-f]{3}){1,2}|(rgba|hsla)\(\s*\d{1,3}%?\s*(,\s*\d{1,3}%?\s*){2},\s*-?\d*\.?\d+\s*\)|(rgb|hsl)\(\s*\d{1,3}%?\s*(,\s*\d{1,3}%?\s*){2}\)\s*|(lab|lch)\(\s*\d{1,3}%?\s+\d{1,3}%?\s+\d{1,3}%?\s*\)|hwb\(\s*\d{1,3}\s+\d{1,3}%?\s+\d{1,3}%?\s*\))\s*$/i
|
|
15
|
+
};
|
|
16
|
+
export function isKnownCssVariable(value) {
|
|
17
|
+
return value in knownVariables;
|
|
18
|
+
}
|
|
19
|
+
export function isRawColor(value) {
|
|
20
|
+
return REGEXES.RAW_COLOR.test(value);
|
|
21
|
+
}
|
|
22
|
+
export function isNamedColor(value) {
|
|
23
|
+
return NAMED_COLORS.includes(value);
|
|
24
|
+
}
|
|
25
|
+
export function isGradient(value) {
|
|
26
|
+
return GRADIENT_TYPES.some(function (gradient) {
|
|
27
|
+
return value.startsWith("".concat(gradient, "-gradient("));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function extractBetweenParentheses(value) {
|
|
31
|
+
var match = value.match(/\((.*?)\)/);
|
|
32
|
+
return match ? match[1] : '';
|
|
33
|
+
}
|
|
34
|
+
export function isLessFunction(value) {
|
|
35
|
+
return LESS_COLOR_FUNCTIONS.some(function (func) {
|
|
36
|
+
return value.startsWith("".concat(func, "("));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var COLOR_PROPERTIES = ['color', 'background', 'background-color', 'box-shadow', 'border', 'border-left', 'border-right', 'border-top', 'border-bottom', 'border-color', 'border-left-color', 'border-right-color', 'border-top-color', 'border-bottom-color', 'outline', 'outline-color', 'accent-color', 'caret-color', 'scrollbar-color', 'text-stroke'];
|
|
2
|
+
export function isColorRelatedProperty(prop) {
|
|
3
|
+
return COLOR_PROPERTIES.some(function (property) {
|
|
4
|
+
return property === prop;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
export function isCssDeclaration(prop) {
|
|
8
|
+
return prop.startsWith('--');
|
|
9
|
+
}
|
|
10
|
+
export function extractCssVarName(prop) {
|
|
11
|
+
return prop.substring(prop.indexOf('(') + 1).split(/\,|\)/)[0];
|
|
12
|
+
}
|
|
13
|
+
export function extractLessVarName(prop) {
|
|
14
|
+
return prop.substring(1);
|
|
15
|
+
}
|
|
16
|
+
export function splitCssValue(value) {
|
|
17
|
+
var regex = /(?:[^\s()]+|\((?:[^()]+|\([^()]*\))*\))+/g;
|
|
18
|
+
return value.match(regex);
|
|
19
|
+
}
|
|
@@ -163,7 +163,7 @@ export var knownVariables = {
|
|
|
163
163
|
'--jpo-border-default-color': ['border'],
|
|
164
164
|
'--jpo-border-secondary-color': ['border', 'subtle']
|
|
165
165
|
};
|
|
166
|
-
export var
|
|
166
|
+
export var knownNamedColors = {
|
|
167
167
|
aliceblue: ['blue'],
|
|
168
168
|
antiquewhite: [],
|
|
169
169
|
aqua: ['teal'],
|
|
@@ -183,7 +183,7 @@ export var knownColors = {
|
|
|
183
183
|
coral: [],
|
|
184
184
|
cornflowerblue: ['blue'],
|
|
185
185
|
cornsilk: [],
|
|
186
|
-
crimson: ['
|
|
186
|
+
crimson: ['red'],
|
|
187
187
|
cyan: ['accent', 'teal', 'subtle'],
|
|
188
188
|
darkblue: ['accent', 'blue', 'bold'],
|
|
189
189
|
darkcyan: ['accent', 'teal', 'bold'],
|
|
@@ -237,11 +237,11 @@ export var knownColors = {
|
|
|
237
237
|
lightgoldenrodyellow: [],
|
|
238
238
|
lightgray: [],
|
|
239
239
|
lightgrey: [],
|
|
240
|
-
lightgreen: ['green'],
|
|
240
|
+
lightgreen: ['green', 'accent'],
|
|
241
241
|
lightpink: ['magenta'],
|
|
242
242
|
lightsalmon: ['pink', 'subtler'],
|
|
243
243
|
lightseagreen: ['green'],
|
|
244
|
-
lightskyblue: ['blue'],
|
|
244
|
+
lightskyblue: ['blue', 'accent'],
|
|
245
245
|
lightslategray: [],
|
|
246
246
|
lightslategrey: [],
|
|
247
247
|
lightsteelblue: ['blue'],
|
|
@@ -283,7 +283,8 @@ export var knownColors = {
|
|
|
283
283
|
plum: [],
|
|
284
284
|
powderblue: ['blue', 'subtle'],
|
|
285
285
|
purple: ['purple'],
|
|
286
|
-
|
|
286
|
+
rebeccapurple: ['purple', 'accent'],
|
|
287
|
+
red: ['red', 'accent'],
|
|
287
288
|
rosybrown: [],
|
|
288
289
|
royalblue: [],
|
|
289
290
|
saddlebrown: [],
|
|
@@ -313,10 +314,9 @@ export var knownColors = {
|
|
|
313
314
|
yellowgreen: ['yellow']
|
|
314
315
|
};
|
|
315
316
|
export var knownRawColors = {
|
|
316
|
-
'#
|
|
317
|
-
'#
|
|
318
|
-
'#
|
|
319
|
-
'#bbbbbb': ['border'],
|
|
317
|
+
'#cccccc': ['gray'],
|
|
318
|
+
'#aaaaaa': ['gray', 'subtlest'],
|
|
319
|
+
'#bbbbbb': ['gray', 'subtle'],
|
|
320
320
|
'#ffffff': ['elevation', 'surface'],
|
|
321
321
|
'#f0f0f0': ['elevation', 'surface'],
|
|
322
322
|
'#eeeeee': ['elevation', 'surface', 'sunken'],
|
|
@@ -325,7 +325,6 @@ export var knownRawColors = {
|
|
|
325
325
|
'#c00c00': ['danger'],
|
|
326
326
|
'#5243aa': ['discovery'],
|
|
327
327
|
'#ffc712': ['warning'],
|
|
328
|
-
'#292929': ['text'],
|
|
329
328
|
'#00f00f': ['brand'],
|
|
330
329
|
'#3b73af': ['brand'],
|
|
331
330
|
'#326ca6': ['brand'],
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
export var logger = {
|
|
3
|
+
warn: function warn(message) {
|
|
4
|
+
// eslint-disable-next-line no-console
|
|
5
|
+
console.warn(chalk.yellow('WARNING'), message);
|
|
6
|
+
},
|
|
7
|
+
error: function error(message) {
|
|
8
|
+
// eslint-disable-next-line no-console
|
|
9
|
+
console.error(chalk.red('ERROR'), message);
|
|
10
|
+
}
|
|
11
|
+
};
|