@atlaskit/codemod-cli 0.34.9 → 1.0.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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/cli.js +4 -3
- package/dist/cjs/get-transform-module.js +14 -0
- package/dist/cjs/get-transform-path.js +11 -0
- package/dist/cjs/get-transform-version.js +16 -0
- package/dist/cjs/{transforms.js → get-transforms.js} +19 -45
- package/dist/cjs/has-transform.js +10 -0
- package/dist/cjs/index.js +1 -14
- package/dist/cjs/main.js +18 -13
- package/dist/cjs/no-transforms-exist-error.js +23 -0
- package/dist/cjs/parse-transform-path.js +11 -0
- package/dist/cjs/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.js +22 -0
- package/dist/cjs/presets/migrate-deprecated-icon/utils/{mock.js → mock-metadata.js} +1 -17
- package/dist/cjs/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +6 -4
- package/dist/cjs/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.js +12 -0
- package/dist/cjs/presets/migrate-icon-object-to-object/utils/get-new-import-info.js +28 -0
- package/dist/cjs/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.js +13 -0
- package/dist/cjs/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.js +29 -0
- package/dist/cjs/presets/migrate-to-link/codemods/migrate-to-link.js +4 -2
- package/dist/cjs/presets/migrate-to-link/utils/comments.js +2 -13
- package/dist/cjs/presets/migrate-to-link/utils/generic-unsupported-migration-comment.js +11 -0
- package/dist/cjs/presets/migrate-to-link/utils/style-prop-comment.js +12 -0
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +2 -2
- package/dist/cjs/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +18 -16
- package/dist/cjs/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.js +11 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.js → find-variant-already-imported.js} +1 -5
- package/dist/cjs/presets/migrate-to-new-buttons/utils/{generate-link-element.js → generate-link-component.js} +3 -12
- package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-element.js +47 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/get-icon-attributes.js +15 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/get-icon-element.js +13 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/handle-icon-attributes.js +81 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +4 -3
- package/dist/cjs/presets/migrate-to-new-buttons/utils/modify-button-attributes.js +18 -0
- package/dist/cjs/presets/migrate-to-new-buttons/utils/modify-link-attributes.js +16 -0
- package/dist/cjs/presets/remove-token-fallbacks/after-all.js +337 -0
- package/dist/cjs/presets/remove-token-fallbacks/before-all.js +33 -0
- package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +4 -360
- package/dist/cjs/presets/remove-token-fallbacks/utils/clear-folder.js +68 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/{color-utils.js → color-to-hex.js} +0 -37
- package/dist/cjs/presets/remove-token-fallbacks/utils/{reporter.js → combine-reports.js} +59 -182
- package/dist/cjs/presets/remove-token-fallbacks/utils/compare-hex.js +25 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/is-valid-color.js +41 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/normalize-values.js +8 -6
- package/dist/cjs/presets/remove-token-fallbacks/utils/write-reports.js +83 -0
- package/dist/cjs/sinceRef.js +2 -2
- package/dist/cjs/types.js +1 -31
- package/dist/cjs/validation-error.js +23 -0
- package/dist/es2019/cli.js +2 -1
- package/dist/es2019/get-transform-module.js +7 -0
- package/dist/es2019/get-transform-path.js +4 -0
- package/dist/es2019/get-transform-version.js +9 -0
- package/dist/es2019/{transforms.js → get-transforms.js} +10 -31
- package/dist/es2019/has-transform.js +2 -0
- package/dist/es2019/index.js +1 -2
- package/dist/es2019/main.js +7 -2
- package/dist/es2019/no-transforms-exist-error.js +1 -0
- package/dist/es2019/parse-transform-path.js +2 -0
- package/dist/es2019/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.js +16 -0
- package/dist/es2019/presets/migrate-deprecated-icon/utils/{mock.js → mock-metadata.js} +0 -16
- package/dist/es2019/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +3 -1
- package/dist/es2019/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.js +6 -0
- package/dist/es2019/presets/migrate-icon-object-to-object/utils/get-new-import-info.js +22 -0
- package/dist/es2019/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.js +5 -0
- package/dist/es2019/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.js +19 -0
- package/dist/es2019/presets/migrate-to-link/codemods/migrate-to-link.js +3 -1
- package/dist/es2019/presets/migrate-to-link/utils/comments.js +1 -11
- package/dist/es2019/presets/migrate-to-link/utils/generic-unsupported-migration-comment.js +4 -0
- package/dist/es2019/presets/migrate-to-link/utils/style-prop-comment.js +6 -0
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +1 -1
- package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -3
- package/dist/es2019/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.js +4 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.js → find-variant-already-imported.js} +0 -3
- package/dist/es2019/presets/migrate-to-new-buttons/utils/{generate-link-element.js → generate-link-component.js} +1 -10
- package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-element.js +39 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/get-icon-attributes.js +7 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/get-icon-element.js +7 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/handle-icon-attributes.js +68 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +2 -1
- package/dist/es2019/presets/migrate-to-new-buttons/utils/modify-button-attributes.js +12 -0
- package/dist/es2019/presets/migrate-to-new-buttons/utils/modify-link-attributes.js +10 -0
- package/dist/es2019/presets/remove-token-fallbacks/after-all.js +139 -0
- package/dist/es2019/presets/remove-token-fallbacks/before-all.js +8 -0
- package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +2 -150
- package/dist/es2019/presets/remove-token-fallbacks/utils/clear-folder.js +15 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/{color-utils.js → color-to-hex.js} +0 -34
- package/dist/es2019/presets/remove-token-fallbacks/utils/{reporter.js → combine-reports.js} +1 -50
- package/dist/es2019/presets/remove-token-fallbacks/utils/compare-hex.js +17 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/is-valid-color.js +35 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/normalize-values.js +3 -1
- package/dist/es2019/presets/remove-token-fallbacks/utils/write-reports.js +41 -0
- package/dist/es2019/sinceRef.js +1 -1
- package/dist/es2019/types.js +1 -7
- package/dist/es2019/validation-error.js +1 -0
- package/dist/esm/cli.js +2 -1
- package/dist/esm/get-transform-module.js +7 -0
- package/dist/esm/get-transform-path.js +5 -0
- package/dist/esm/get-transform-version.js +9 -0
- package/dist/esm/{transforms.js → get-transforms.js} +16 -42
- package/dist/esm/has-transform.js +4 -0
- package/dist/esm/index.js +1 -2
- package/dist/esm/main.js +8 -3
- package/dist/esm/no-transforms-exist-error.js +16 -0
- package/dist/esm/parse-transform-path.js +4 -0
- package/dist/esm/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.js +16 -0
- package/dist/esm/presets/migrate-deprecated-icon/utils/{mock.js → mock-metadata.js} +0 -16
- package/dist/esm/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js +3 -1
- package/dist/esm/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.js +6 -0
- package/dist/esm/presets/migrate-icon-object-to-object/utils/get-new-import-info.js +22 -0
- package/dist/esm/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.js +7 -0
- package/dist/esm/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.js +22 -0
- package/dist/esm/presets/migrate-to-link/codemods/migrate-to-link.js +3 -1
- package/dist/esm/presets/migrate-to-link/utils/comments.js +1 -12
- package/dist/esm/presets/migrate-to-link/utils/generic-unsupported-migration-comment.js +5 -0
- package/dist/esm/presets/migrate-to-link/utils/style-prop-comment.js +6 -0
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js +1 -1
- package/dist/esm/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js +5 -3
- package/dist/esm/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.js +5 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.js → find-variant-already-imported.js} +0 -4
- package/dist/esm/presets/migrate-to-new-buttons/utils/{generate-link-element.js → generate-link-component.js} +1 -10
- package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-element.js +41 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/get-icon-attributes.js +9 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/get-icon-element.js +7 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/handle-icon-attributes.js +75 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js +2 -1
- package/dist/esm/presets/migrate-to-new-buttons/utils/modify-button-attributes.js +12 -0
- package/dist/esm/presets/migrate-to-new-buttons/utils/modify-link-attributes.js +10 -0
- package/dist/esm/presets/remove-token-fallbacks/after-all.js +331 -0
- package/dist/esm/presets/remove-token-fallbacks/before-all.js +27 -0
- package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +2 -357
- package/dist/esm/presets/remove-token-fallbacks/utils/clear-folder.js +62 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/{color-utils.js → color-to-hex.js} +0 -36
- package/dist/esm/presets/remove-token-fallbacks/utils/{reporter.js → combine-reports.js} +57 -180
- package/dist/esm/presets/remove-token-fallbacks/utils/compare-hex.js +19 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/is-valid-color.js +35 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/normalize-values.js +3 -1
- package/dist/esm/presets/remove-token-fallbacks/utils/write-reports.js +75 -0
- package/dist/esm/sinceRef.js +1 -1
- package/dist/esm/types.js +1 -29
- package/dist/esm/validation-error.js +16 -0
- package/dist/types/get-transform-module.d.ts +2 -0
- package/dist/types/get-transform-path.d.ts +2 -0
- package/dist/types/get-transform-version.d.ts +2 -0
- package/dist/types/get-transforms.d.ts +3 -0
- package/dist/types/has-transform.d.ts +1 -0
- package/dist/types/index.d.ts +0 -1
- package/dist/types/main.d.ts +1 -1
- package/dist/types/no-transforms-exist-error.d.ts +2 -0
- package/dist/types/parse-transform-path.d.ts +2 -0
- package/dist/types/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.d.ts +16 -0
- package/dist/types/presets/migrate-deprecated-icon/utils/{mock.d.ts → mock-metadata.d.ts} +0 -16
- package/dist/types/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.d.ts +1 -0
- package/dist/types/presets/migrate-icon-object-to-object/utils/get-new-import-info.d.ts +4 -0
- package/dist/types/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.d.ts +1 -0
- package/dist/types/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.d.ts +4 -0
- package/dist/types/presets/migrate-to-link/utils/comments.d.ts +0 -5
- package/dist/types/presets/migrate-to-link/utils/generic-unsupported-migration-comment.d.ts +1 -0
- package/dist/types/presets/migrate-to-link/utils/style-prop-comment.d.ts +4 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.d.ts → find-variant-already-imported.d.ts} +0 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/{generate-link-element.d.ts → generate-link-component.d.ts} +0 -1
- package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-element.d.ts +3 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/get-icon-attributes.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/get-icon-element.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/handle-icon-attributes.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/modify-button-attributes.d.ts +2 -0
- package/dist/types/presets/migrate-to-new-buttons/utils/modify-link-attributes.d.ts +2 -0
- package/dist/types/presets/remove-token-fallbacks/after-all.d.ts +2 -0
- package/dist/types/presets/remove-token-fallbacks/before-all.d.ts +2 -0
- package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +0 -9
- package/dist/types/presets/remove-token-fallbacks/utils/clear-folder.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/utils/color-to-hex.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/utils/combine-reports.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/utils/compare-hex.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/utils/is-valid-color.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/utils/{reporter.d.ts → write-reports.d.ts} +0 -2
- package/dist/types/sinceRef.d.ts +1 -1
- package/dist/types/types.d.ts +0 -4
- package/dist/types/validation-error.d.ts +2 -0
- package/dist/types-ts4.5/get-transform-module.d.ts +2 -0
- package/dist/types-ts4.5/get-transform-path.d.ts +2 -0
- package/dist/types-ts4.5/get-transform-version.d.ts +2 -0
- package/dist/types-ts4.5/get-transforms.d.ts +3 -0
- package/dist/types-ts4.5/has-transform.d.ts +1 -0
- package/dist/types-ts4.5/index.d.ts +0 -1
- package/dist/types-ts4.5/main.d.ts +1 -1
- package/dist/types-ts4.5/no-transforms-exist-error.d.ts +2 -0
- package/dist/types-ts4.5/parse-transform-path.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-deprecated-icon/utils/mock-deprecated-icons.d.ts +16 -0
- package/dist/types-ts4.5/presets/migrate-deprecated-icon/utils/{mock.d.ts → mock-metadata.d.ts} +0 -16
- package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.d.ts +1 -0
- package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/get-new-import-info.d.ts +4 -0
- package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/kebab-to-pascal-case.d.ts +1 -0
- package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/parse-icon-object-import.d.ts +4 -0
- package/dist/types-ts4.5/presets/migrate-to-link/utils/comments.d.ts +0 -5
- package/dist/types-ts4.5/presets/migrate-to-link/utils/generic-unsupported-migration-comment.d.ts +1 -0
- package/dist/types-ts4.5/presets/migrate-to-link/utils/style-prop-comment.d.ts +4 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/check-if-variant-already-imported.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/{if-variant-already-imported.d.ts → find-variant-already-imported.d.ts} +0 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/{generate-link-element.d.ts → generate-link-component.d.ts} +0 -1
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-element.d.ts +3 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/get-icon-attributes.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/get-icon-element.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/handle-icon-attributes.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/modify-button-attributes.d.ts +2 -0
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/modify-link-attributes.d.ts +2 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/after-all.d.ts +2 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/before-all.d.ts +2 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +0 -9
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/clear-folder.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/color-to-hex.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/combine-reports.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/compare-hex.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/is-valid-color.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/{reporter.d.ts → write-reports.d.ts} +0 -2
- package/dist/types-ts4.5/sinceRef.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +0 -4
- package/dist/types-ts4.5/validation-error.d.ts +2 -0
- package/package.json +3 -3
- package/dist/cjs/presets/migrate-icon-object-to-object/utils/icon-mappings.js +0 -81
- package/dist/cjs/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +0 -160
- package/dist/es2019/presets/migrate-icon-object-to-object/utils/icon-mappings.js +0 -67
- package/dist/es2019/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +0 -143
- package/dist/esm/presets/migrate-icon-object-to-object/utils/icon-mappings.js +0 -72
- package/dist/esm/presets/migrate-to-new-buttons/utils/generate-new-button-element.js +0 -154
- package/dist/types/presets/migrate-icon-object-to-object/utils/icon-mappings.d.ts +0 -29
- package/dist/types/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +0 -20
- package/dist/types/presets/remove-token-fallbacks/utils/color-utils.d.ts +0 -3
- package/dist/types/transforms.d.ts +0 -11
- package/dist/types-ts4.5/presets/migrate-icon-object-to-object/utils/icon-mappings.d.ts +0 -29
- package/dist/types-ts4.5/presets/migrate-to-new-buttons/utils/generate-new-button-element.d.ts +0 -20
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/color-utils.d.ts +0 -3
- package/dist/types-ts4.5/transforms.d.ts +0 -11
- package/transforms/package.json +0 -14
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
export const getTransformVersion = transform => {
|
|
3
|
+
let transformName = transform.base;
|
|
4
|
+
if (transformName.startsWith('index.')) {
|
|
5
|
+
const pathSegments = transform.dir.split(path.sep);
|
|
6
|
+
transformName = pathSegments[pathSegments.length - 1];
|
|
7
|
+
}
|
|
8
|
+
return transformName.split('-')[0];
|
|
9
|
+
};
|
|
@@ -1,42 +1,14 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { globSync } from 'glob';
|
|
3
3
|
import semver from 'semver';
|
|
4
|
+
import { getTransformModule } from './get-transform-module';
|
|
5
|
+
import { getTransformVersion } from './get-transform-version';
|
|
6
|
+
import { parseTransformPath } from './parse-transform-path';
|
|
4
7
|
import presets from './presets';
|
|
5
8
|
const basePath = packages => {
|
|
6
9
|
const packageDirectory = packages && packages.length > 0 ? [`{${packages.map(pkg => pkg.name).join(',')},}`] : ['@{atlaskit,atlassian,atlassiansox}', '*'];
|
|
7
10
|
return path.join(process.cwd(), 'node_modules', ...packageDirectory, 'codemods');
|
|
8
11
|
};
|
|
9
|
-
export const hasTransform = transformPath => globSync(transformPath).length > 0;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Retrieves transforms for `packages` if provided, otherwise all transforms including presets
|
|
13
|
-
*/
|
|
14
|
-
export const getTransforms = packages => {
|
|
15
|
-
const transforms = [path.join(basePath(packages), '*.@(ts|tsx|js)'), path.join(basePath(packages), '*', 'index.@(ts|tsx|js)')];
|
|
16
|
-
if (!packages) {
|
|
17
|
-
transforms.unshift(...presets);
|
|
18
|
-
}
|
|
19
|
-
return transforms.map(transform => globSync(transform)).reduce((acc, val) => acc.concat(val), []).map(transform => parseTransformPath(transform)).filter(filterTransforms(packages)).sort();
|
|
20
|
-
};
|
|
21
|
-
export const parseTransformPath = transformPath => path.parse(transformPath);
|
|
22
|
-
export const getTransformPath = ({
|
|
23
|
-
dir,
|
|
24
|
-
base
|
|
25
|
-
}) => `${dir}/${base}`;
|
|
26
|
-
export const getTransformModule = transform => {
|
|
27
|
-
const pathSegments = transform.dir.split(path.sep);
|
|
28
|
-
const nodeModulesIdx = pathSegments.indexOf('node_modules');
|
|
29
|
-
// pathSegments will be of the form [node_modules, '@atlaskit', 'avatar', 'codemods']
|
|
30
|
-
return pathSegments.slice(nodeModulesIdx + 1, nodeModulesIdx + 3).join('/');
|
|
31
|
-
};
|
|
32
|
-
export const getTransformVersion = transform => {
|
|
33
|
-
let transformName = transform.base;
|
|
34
|
-
if (transformName.startsWith('index.')) {
|
|
35
|
-
const pathSegments = transform.dir.split(path.sep);
|
|
36
|
-
transformName = pathSegments[pathSegments.length - 1];
|
|
37
|
-
}
|
|
38
|
-
return transformName.split('-')[0];
|
|
39
|
-
};
|
|
40
12
|
const filterTransforms = packages => {
|
|
41
13
|
if (!packages || packages.length === 0) {
|
|
42
14
|
return () => true;
|
|
@@ -56,4 +28,11 @@ const filterTransforms = packages => {
|
|
|
56
28
|
return false;
|
|
57
29
|
}
|
|
58
30
|
};
|
|
31
|
+
};
|
|
32
|
+
export const getTransforms = packages => {
|
|
33
|
+
const transforms = [path.join(basePath(packages), '*.@(ts|tsx|js)'), path.join(basePath(packages), '*', 'index.@(ts|tsx|js)')];
|
|
34
|
+
if (!packages) {
|
|
35
|
+
transforms.unshift(...presets);
|
|
36
|
+
}
|
|
37
|
+
return transforms.map(transform => globSync(transform)).reduce((acc, val) => acc.concat(val), []).map(transform => parseTransformPath(transform)).filter(filterTransforms(packages)).sort();
|
|
59
38
|
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { default } from './main';
|
|
2
|
-
export { ValidationError, NoTransformsExistError } from './types';
|
|
1
|
+
export { default } from './main';
|
package/dist/es2019/main.js
CHANGED
|
@@ -5,10 +5,15 @@ import spawn from 'projector-spawn';
|
|
|
5
5
|
import semver from 'semver';
|
|
6
6
|
const jscodeshift = require.resolve('.bin/jscodeshift');
|
|
7
7
|
import { findDependentPackagePaths } from './filepath';
|
|
8
|
+
import { getTransformModule } from './get-transform-module';
|
|
9
|
+
import { getTransformPath } from './get-transform-path';
|
|
10
|
+
import { getTransforms } from './get-transforms';
|
|
11
|
+
import { hasTransform } from './has-transform';
|
|
12
|
+
import { NoTransformsExistError } from './no-transforms-exist-error';
|
|
13
|
+
import { parseTransformPath } from './parse-transform-path';
|
|
8
14
|
import { getPackagesSinceRef } from './sinceRef';
|
|
9
|
-
import { getTransformModule, getTransformPath, getTransforms, hasTransform, parseTransformPath } from './transforms';
|
|
10
|
-
import { NoTransformsExistError, ValidationError } from './types';
|
|
11
15
|
import { fixLineEnding } from './utils';
|
|
16
|
+
import { ValidationError } from './validation-error';
|
|
12
17
|
const applyTransformMeta = transforms => transforms.map(transform => {
|
|
13
18
|
const moduleMatch = transform.dir.match(/\/@atlaskit\/[^\/]+\//);
|
|
14
19
|
if (moduleMatch) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export class NoTransformsExistError extends Error {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const mockDeprecatedIcons = {
|
|
2
|
+
deprecatedCore: {
|
|
3
|
+
'@atlaskit/icon/core/capture': {
|
|
4
|
+
message: 'The icon "capture" is deprecated in favour of "focus-area" from "@atlaskit/icon/core"'
|
|
5
|
+
},
|
|
6
|
+
'@atlaskit/icon/core/chart-matrix': {
|
|
7
|
+
message: 'The icon "chart-matrix" is deprecated in favour of "chart-bubble" from "@atlaskit/icon/core"'
|
|
8
|
+
},
|
|
9
|
+
'@atlaskit/icon/core/close': {
|
|
10
|
+
message: 'The icon "close" is deprecated in favour of "cross" from "@atlaskit/icon/core"'
|
|
11
|
+
},
|
|
12
|
+
'@atlaskit/icon/core/error': {
|
|
13
|
+
message: 'The icon "error" is deprecated in favour of "status-error" from "@atlaskit/icon/core"'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
@@ -56,20 +56,4 @@ export const mockMetadata = {
|
|
|
56
56
|
status: 'deprecated'
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
};
|
|
60
|
-
export const mockDeprecatedIcons = {
|
|
61
|
-
deprecatedCore: {
|
|
62
|
-
'@atlaskit/icon/core/capture': {
|
|
63
|
-
message: 'The icon "capture" is deprecated in favour of "focus-area" from "@atlaskit/icon/core"'
|
|
64
|
-
},
|
|
65
|
-
'@atlaskit/icon/core/chart-matrix': {
|
|
66
|
-
message: 'The icon "chart-matrix" is deprecated in favour of "chart-bubble" from "@atlaskit/icon/core"'
|
|
67
|
-
},
|
|
68
|
-
'@atlaskit/icon/core/close': {
|
|
69
|
-
message: 'The icon "close" is deprecated in favour of "cross" from "@atlaskit/icon/core"'
|
|
70
|
-
},
|
|
71
|
-
'@atlaskit/icon/core/error': {
|
|
72
|
-
message: 'The icon "error" is deprecated in favour of "status-error" from "@atlaskit/icon/core"'
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
59
|
};
|
package/dist/es2019/presets/migrate-icon-object-to-object/codemods/migrate-icon-object-to-object.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
2
|
|
|
3
3
|
import { OLD_ICON_OBJECT_ENTRY_POINT, PRINT_SETTINGS } from '../utils/constants';
|
|
4
|
-
import { createDefaultImportDeclaration
|
|
4
|
+
import { createDefaultImportDeclaration } from '../utils/create-default-import-declaration';
|
|
5
|
+
import { getNewImportInfo } from '../utils/get-new-import-info';
|
|
6
|
+
import { parseIconObjectImport } from '../utils/parse-icon-object-import';
|
|
5
7
|
const transformer = (file, api) => {
|
|
6
8
|
const j = api.jscodeshift;
|
|
7
9
|
const fileSource = j(file.source);
|
package/dist/es2019/presets/migrate-icon-object-to-object/utils/create-default-import-declaration.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
|
+
|
|
3
|
+
export function createDefaultImportDeclaration(j, componentName, importPath) {
|
|
4
|
+
const defaultSpecifier = j.importDefaultSpecifier(j.identifier(componentName));
|
|
5
|
+
return j.importDeclaration([defaultSpecifier], j.stringLiteral(importPath));
|
|
6
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
|
+
|
|
3
|
+
import { ICON_TO_OBJECT_NAME_MAPPINGS } from './constants';
|
|
4
|
+
import { kebabToPascalCase } from './kebab-to-pascal-case';
|
|
5
|
+
export function getNewImportInfo(iconName, size) {
|
|
6
|
+
// Check if this icon name needs to be mapped to a different object name
|
|
7
|
+
const objectName = ICON_TO_OBJECT_NAME_MAPPINGS[iconName] || iconName;
|
|
8
|
+
|
|
9
|
+
// Convert the object name to PascalCase
|
|
10
|
+
const pascalCaseName = kebabToPascalCase(objectName);
|
|
11
|
+
if (size === '16') {
|
|
12
|
+
return {
|
|
13
|
+
importPath: `@atlaskit/object/${objectName}`,
|
|
14
|
+
componentName: `${pascalCaseName}Object`
|
|
15
|
+
};
|
|
16
|
+
} else {
|
|
17
|
+
return {
|
|
18
|
+
importPath: `@atlaskit/object/tile/${objectName}`,
|
|
19
|
+
componentName: `${pascalCaseName}ObjectTile`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
|
+
|
|
3
|
+
import { AVAILABLE_ICON_NAMES } from './constants';
|
|
4
|
+
export function parseIconObjectImport(importPath) {
|
|
5
|
+
const match = importPath.match(/^@atlaskit\/icon-object\/glyph\/([^/]+)\/(16|24)$/);
|
|
6
|
+
if (!match) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const [, iconName, size] = match;
|
|
10
|
+
|
|
11
|
+
// Check if this is a valid icon name we support
|
|
12
|
+
if (!AVAILABLE_ICON_NAMES.includes(iconName)) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
iconName,
|
|
17
|
+
size: size
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/* eslint-disable @repo/internal/fs/filename-pattern-match */
|
|
2
2
|
import { getImportDeclaration } from '@hypermod/utils';
|
|
3
3
|
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
|
-
import {
|
|
4
|
+
import { spreadPropsComment } from '../utils/comments';
|
|
5
5
|
import { LINK_ENTRY_POINT, LINK_EXPORT_NAME, PRINT_SETTINGS, UNSUPPORTED_STYLE_PROPS } from '../utils/constants';
|
|
6
6
|
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
7
|
+
import { genericUnsupportedMigrationComment } from '../utils/generic-unsupported-migration-comment';
|
|
8
|
+
import { stylePropComment } from '../utils/style-prop-comment';
|
|
7
9
|
export default function transformer(file, api) {
|
|
8
10
|
const j = api.jscodeshift;
|
|
9
11
|
const source = j(file.source);
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export const stylePropComment = ({
|
|
3
|
-
propName,
|
|
4
|
-
prefix = ''
|
|
5
|
-
}) => {
|
|
6
|
-
return `${prefix}This link could not be migrated due to custom styles in \`${propName}\` prop.`;
|
|
7
|
-
};
|
|
8
|
-
export const spreadPropsComment = `This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.`;
|
|
9
|
-
export const genericUnsupportedMigrationComment = (prefix = '') => `${prefix}- If this is a simple text-based link, replace with \`${LINK_ENTRY_POINT}\`.
|
|
10
|
-
${prefix}- If this is a button-like link style, replace with a link button from \`@atlaskit/button\`.
|
|
11
|
-
${prefix}- If this needs to retain custom styles, use the \`Anchor\` primitive from \`@atlaskit/primitives\`.`;
|
|
1
|
+
export const spreadPropsComment = `This link could not be migrated due to usage of spread props. The codemod cannot determine the props being spread. Please manually migrate.`;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { LINK_ENTRY_POINT } from './constants';
|
|
2
|
+
export const genericUnsupportedMigrationComment = (prefix = '') => `${prefix}- If this is a simple text-based link, replace with \`${LINK_ENTRY_POINT}\`.
|
|
3
|
+
${prefix}- If this is a button-like link style, replace with a link button from \`@atlaskit/button\`.
|
|
4
|
+
${prefix}- If this needs to retain custom styles, use the \`Anchor\` primitive from \`@atlaskit/primitives\`.`;
|
package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-link-button-to-link.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getImportDeclaration } from '@hypermod/utils';
|
|
|
3
3
|
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
4
|
import { migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, PRINT_SETTINGS } from '../utils/constants';
|
|
5
5
|
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
6
|
-
import { modifyLinkAttributes } from '../utils/
|
|
6
|
+
import { modifyLinkAttributes } from '../utils/modify-link-attributes';
|
|
7
7
|
import moveIconValueFromLinkButtonPropsToLinkChildren from '../utils/move-icon-value-from-link-button-to-link-children';
|
|
8
8
|
function transformer(file, api) {
|
|
9
9
|
const j = api.jscodeshift;
|
package/dist/es2019/presets/migrate-to-new-buttons/codemods/next-migrate-to-new-button-variants.js
CHANGED
|
@@ -3,16 +3,18 @@ import { getDefaultImportSpecifierName } from '@hypermod/utils';
|
|
|
3
3
|
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
4
4
|
import { addCommentForCustomThemeButtons } from '../utils/add-comment-for-custom-theme-buttons';
|
|
5
5
|
import { addCommentForOverlayProp } from '../utils/add-comment-for-overlay-prop';
|
|
6
|
+
import { checkIfVariantAlreadyImported } from '../utils/check-if-variant-already-imported';
|
|
6
7
|
import { buttonPropsNoLongerSupportedComment, entryPointsMapping, linkButtonMissingHrefComment, loadingButtonComment, migrateButtonToSubtleLinkButton, migrateSubtleButtonToSubtleLinkButton, NEW_BUTTON_ENTRY_POINT, NEW_BUTTON_VARIANTS, noSpacinglinkButtonMissingHrefComment, OLD_BUTTON_ENTRY_POINT, OLD_BUTTON_VARIANTS, PRINT_SETTINGS, unsupportedProps } from '../utils/constants';
|
|
7
8
|
import { findJSXAttributeWithValue } from '../utils/find-attribute-with-value';
|
|
8
|
-
import { generateLinkComponent } from '../utils/generate-link-
|
|
9
|
-
import { generateNewElement
|
|
9
|
+
import { generateLinkComponent } from '../utils/generate-link-component';
|
|
10
|
+
import { generateNewElement } from '../utils/generate-new-element';
|
|
10
11
|
import getDefaultImports from '../utils/get-default-imports';
|
|
11
12
|
import getSpecifierNames from '../utils/get-specifier-names';
|
|
13
|
+
import { handleIconAttributes } from '../utils/handle-icon-attributes';
|
|
12
14
|
import { ifHasUnsupportedProps } from '../utils/has-unsupported-props';
|
|
13
|
-
import { checkIfVariantAlreadyImported } from '../utils/if-variant-already-imported';
|
|
14
15
|
import { importTypesFromNewEntryPoint } from '../utils/import-types-from-new-entry-point';
|
|
15
16
|
import { migrateFitContainerIconButton } from '../utils/migrate-fit-container-icon-button';
|
|
17
|
+
import { modifyButtonAttributes } from '../utils/modify-button-attributes';
|
|
16
18
|
import { renameDefaultButtonToLegacyButtonImport } from '../utils/rename-default-button-to-legacy-button';
|
|
17
19
|
const transformer = (file, api) => {
|
|
18
20
|
const j = api.jscodeshift;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { findVariantAlreadyImported } from './find-variant-already-imported';
|
|
2
|
+
export const checkIfVariantAlreadyImported = (variant, entryPoint, fileSource, j, isDefaultSpecifier = false) => {
|
|
3
|
+
return findVariantAlreadyImported(variant, entryPoint, fileSource, j, isDefaultSpecifier).length > 0;
|
|
4
|
+
};
|
|
@@ -4,7 +4,4 @@ export const findVariantAlreadyImported = (variant, entryPoint, fileSource, j, i
|
|
|
4
4
|
return imports.find(j.ImportDefaultSpecifier);
|
|
5
5
|
}
|
|
6
6
|
return imports.find(j.ImportSpecifier).filter(path => path.node.imported.name === variant);
|
|
7
|
-
};
|
|
8
|
-
export const checkIfVariantAlreadyImported = (variant, entryPoint, fileSource, j, isDefaultSpecifier = false) => {
|
|
9
|
-
return findVariantAlreadyImported(variant, entryPoint, fileSource, j, isDefaultSpecifier).length > 0;
|
|
10
7
|
};
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
j(element).find(j.JSXAttribute).filter(path => {
|
|
3
|
-
var _path$node$value, _path$node$value2;
|
|
4
|
-
return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && path.node.value.value === 'link' || path.node.name.name === 'spacing' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && path.node.value.value === 'none';
|
|
5
|
-
}).remove();
|
|
6
|
-
j(element).find(j.JSXAttribute).filter(path => {
|
|
7
|
-
var _path$node$value3;
|
|
8
|
-
return path.node.name.name === 'appearance' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'subtle-link';
|
|
9
|
-
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
10
|
-
};
|
|
1
|
+
import { modifyLinkAttributes } from './modify-link-attributes';
|
|
11
2
|
export const generateLinkComponent = (element, j) => {
|
|
12
3
|
const {
|
|
13
4
|
attributes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NEW_BUTTON_VARIANTS } from './constants';
|
|
2
|
+
import { getIconAttributes } from './get-icon-attributes';
|
|
3
|
+
import { handleIconAttributes } from './handle-icon-attributes';
|
|
4
|
+
export const generateNewElement = (variant, element, j) => {
|
|
5
|
+
const {
|
|
6
|
+
attributes
|
|
7
|
+
} = element.openingElement;
|
|
8
|
+
const iconAttrs = attributes && getIconAttributes(attributes);
|
|
9
|
+
const isIconOrLinkIcon = variant === NEW_BUTTON_VARIANTS.icon || variant === NEW_BUTTON_VARIANTS.linkIcon;
|
|
10
|
+
if (variant === NEW_BUTTON_VARIANTS.link) {
|
|
11
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
12
|
+
var _path$node$value;
|
|
13
|
+
return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'subtle-link' || path.node.value.value === 'link');
|
|
14
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
15
|
+
}
|
|
16
|
+
if (isIconOrLinkIcon && iconAttrs !== null && iconAttrs !== void 0 && iconAttrs.length) {
|
|
17
|
+
handleIconAttributes(element, j, true);
|
|
18
|
+
|
|
19
|
+
// rename iconBefore/iconAfter to icon
|
|
20
|
+
iconAttrs[0].name.name = 'icon';
|
|
21
|
+
const ariaLabelAttr = j(element.openingElement).find(j.JSXAttribute).filter(attribute => attribute.node.name.name === 'aria-label');
|
|
22
|
+
if (ariaLabelAttr.length) {
|
|
23
|
+
const hasNoLabelProp = !(attributes !== null && attributes !== void 0 && attributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label'));
|
|
24
|
+
if (hasNoLabelProp && attributes) {
|
|
25
|
+
attributes.unshift(j.jsxAttribute.from({
|
|
26
|
+
name: j.jsxIdentifier('label'),
|
|
27
|
+
value: j.literal(ariaLabelAttr.get().value.value.value)
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
ariaLabelAttr.remove();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return j.jsxElement.from({
|
|
34
|
+
openingElement: j.jsxOpeningElement(j.jsxIdentifier(variant), attributes, isIconOrLinkIcon),
|
|
35
|
+
// self closing if it's an icon button or icon link button
|
|
36
|
+
closingElement: isIconOrLinkIcon ? null : j.jsxClosingElement(j.jsxIdentifier(variant)),
|
|
37
|
+
children: element.children
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const getIconAttributes = attributes => {
|
|
2
|
+
const iconAttr = attributes === null || attributes === void 0 ? void 0 : attributes.filter(attribute => attribute.type === 'JSXAttribute' && (attribute.name.name === 'iconBefore' || attribute.name.name === 'iconAfter'));
|
|
3
|
+
if (iconAttr !== null && iconAttr !== void 0 && iconAttr.length) {
|
|
4
|
+
return iconAttr;
|
|
5
|
+
}
|
|
6
|
+
return null;
|
|
7
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const getIconElement = iconAttr => {
|
|
2
|
+
var _iconAttr$value;
|
|
3
|
+
if (iconAttr && ((_iconAttr$value = iconAttr.value) === null || _iconAttr$value === void 0 ? void 0 : _iconAttr$value.type) === 'JSXExpressionContainer' && iconAttr.value.expression.type === 'JSXElement') {
|
|
4
|
+
return iconAttr.value.expression;
|
|
5
|
+
}
|
|
6
|
+
return null;
|
|
7
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { getIconAttributes } from './get-icon-attributes';
|
|
2
|
+
import { getIconElement } from './get-icon-element';
|
|
3
|
+
export const handleIconAttributes = (element, j, iconRenamed = false) => {
|
|
4
|
+
const {
|
|
5
|
+
attributes: buttonAttributes
|
|
6
|
+
} = element.openingElement;
|
|
7
|
+
// Get iconBefore and iconAfter attributes
|
|
8
|
+
const buttonIconAttributes = buttonAttributes && getIconAttributes(buttonAttributes);
|
|
9
|
+
buttonIconAttributes === null || buttonIconAttributes === void 0 ? void 0 : buttonIconAttributes.forEach(iconAttribute => {
|
|
10
|
+
let iconElement = getIconElement(iconAttribute);
|
|
11
|
+
if (!iconElement) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const iconAttributes = iconElement.openingElement.attributes;
|
|
15
|
+
if (!Array.isArray(iconAttributes)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 1. Move label to root button element, only if label doesn't exist already. Button label
|
|
20
|
+
// takes precedence over icon label.
|
|
21
|
+
|
|
22
|
+
const buttonAlreadyHasLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(buttonAttribute => buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'label');
|
|
23
|
+
const buttonAlreadyHasAriaLabelProp = buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.find(buttonAttribute => buttonAttribute.type === 'JSXAttribute' && buttonAttribute.name.name === 'aria-label');
|
|
24
|
+
if (!buttonAlreadyHasLabelProp && !buttonAlreadyHasAriaLabelProp) {
|
|
25
|
+
const labelAttribute = iconAttributes.find(attribute => attribute.type === 'JSXAttribute' && attribute.name.name === 'label');
|
|
26
|
+
if (labelAttribute && labelAttribute.type === 'JSXAttribute' && iconRenamed) {
|
|
27
|
+
buttonAttributes === null || buttonAttributes === void 0 ? void 0 : buttonAttributes.unshift(labelAttribute);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 2. If there are any other props on icon, move to render prop
|
|
32
|
+
const attributesOtherThanLabelOrMediumSize = iconAttributes.filter(iconAttribute => {
|
|
33
|
+
var _iconAttribute$value, _iconAttribute$value2;
|
|
34
|
+
// Exclude size="medium"
|
|
35
|
+
if (iconAttribute.type === 'JSXAttribute' && iconAttribute.name.name === 'size' && ((_iconAttribute$value = iconAttribute.value) === null || _iconAttribute$value === void 0 ? void 0 : _iconAttribute$value.type) === 'StringLiteral' && ((_iconAttribute$value2 = iconAttribute.value) === null || _iconAttribute$value2 === void 0 ? void 0 : _iconAttribute$value2.value) === 'medium') {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Exclude label
|
|
40
|
+
if (iconAttribute.type === 'JSXAttribute' && iconAttribute.name.name === 'label') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
});
|
|
45
|
+
if (attributesOtherThanLabelOrMediumSize.length > 0) {
|
|
46
|
+
// Move to render prop: `<MoreIcon primaryColor />` -> `(props) => <MoreIcon {...props} primaryColor />`
|
|
47
|
+
|
|
48
|
+
// Remove label and size="medium" attributes
|
|
49
|
+
j(iconElement.openingElement).find(j.JSXAttribute).filter(attribute => attribute.value.name.name === 'label' || attribute.value.type === 'JSXAttribute' && attribute.value.name.name === 'size' && attribute.value.value && attribute.value.value.type === 'StringLiteral' && attribute.value.value.value === 'medium' || false).remove();
|
|
50
|
+
|
|
51
|
+
// Add spread props
|
|
52
|
+
iconAttributes.unshift(j.jsxSpreadAttribute(j.identifier('iconProps')));
|
|
53
|
+
|
|
54
|
+
// Create new arrow function (renderProp)
|
|
55
|
+
iconAttribute.value = j.jsxExpressionContainer(j.arrowFunctionExpression.from({
|
|
56
|
+
params: [j.identifier('iconProps')],
|
|
57
|
+
body: iconElement,
|
|
58
|
+
expression: true
|
|
59
|
+
}));
|
|
60
|
+
} else {
|
|
61
|
+
var _iconAttribute$value3;
|
|
62
|
+
// Move to bounded API: {<MoreIcon />} => {MoreIcon}
|
|
63
|
+
if (iconElement.openingElement.name.type === 'JSXIdentifier' && ((_iconAttribute$value3 = iconAttribute.value) === null || _iconAttribute$value3 === void 0 ? void 0 : _iconAttribute$value3.type) === 'JSXExpressionContainer') {
|
|
64
|
+
iconAttribute.value.expression = j.identifier(iconElement.openingElement.name.name);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
package/dist/es2019/presets/migrate-to-new-buttons/utils/migrate-fit-container-icon-button.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { addCommentBefore } from '@atlaskit/codemod-utils';
|
|
2
|
-
import { getIconAttributes, getIconElement } from '../utils/generate-new-button-element';
|
|
3
2
|
import { migrateFitContainerButtonToDefaultButtonComment, migrateFitContainerButtonToIconButtonComment, NEW_BUTTON_VARIANTS } from './constants';
|
|
3
|
+
import { getIconAttributes } from './get-icon-attributes';
|
|
4
|
+
import { getIconElement } from './get-icon-element';
|
|
4
5
|
export const migrateFitContainerIconButton = (element, j) => {
|
|
5
6
|
var _iconElement$openingE, _labelAttribute$value;
|
|
6
7
|
const {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const modifyButtonAttributes = (element, j, hasSpacingNone) => {
|
|
2
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
3
|
+
var _path$node$value;
|
|
4
|
+
return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && (path.node.value.value === 'link' || path.node.value.value === 'subtle-link');
|
|
5
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
6
|
+
if (hasSpacingNone) {
|
|
7
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
8
|
+
var _path$node$value2;
|
|
9
|
+
return path.node.name.name === 'spacing' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && path.node.value.value === 'none';
|
|
10
|
+
}).remove();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const modifyLinkAttributes = (element, j) => {
|
|
2
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
3
|
+
var _path$node$value, _path$node$value2;
|
|
4
|
+
return path.node.name.name === 'appearance' && ((_path$node$value = path.node.value) === null || _path$node$value === void 0 ? void 0 : _path$node$value.type) === 'StringLiteral' && path.node.value.value === 'link' || path.node.name.name === 'spacing' && ((_path$node$value2 = path.node.value) === null || _path$node$value2 === void 0 ? void 0 : _path$node$value2.type) === 'StringLiteral' && path.node.value.value === 'none';
|
|
5
|
+
}).remove();
|
|
6
|
+
j(element).find(j.JSXAttribute).filter(path => {
|
|
7
|
+
var _path$node$value3;
|
|
8
|
+
return path.node.name.name === 'appearance' && ((_path$node$value3 = path.node.value) === null || _path$node$value3 === void 0 ? void 0 : _path$node$value3.type) === 'StringLiteral' && path.node.value.value === 'subtle-link';
|
|
9
|
+
}).replaceWith(j.jsxAttribute(j.jsxIdentifier('appearance'), j.stringLiteral('subtle')));
|
|
10
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import { findRoot } from '@manypkg/find-root';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import { chunkArray } from './utils/chunk';
|
|
9
|
+
import { combineReports } from './utils/combine-reports';
|
|
10
|
+
const execAsync = promisify(exec);
|
|
11
|
+
async function gitStage(filePaths, cwd) {
|
|
12
|
+
const gitAddCommand = `git add ${filePaths.join(' ')}`;
|
|
13
|
+
console.log(`Executing command: ${gitAddCommand}`);
|
|
14
|
+
const {
|
|
15
|
+
stdout: gitAddStdout,
|
|
16
|
+
stderr: gitAddStderr
|
|
17
|
+
} = await execAsync(gitAddCommand, {
|
|
18
|
+
cwd
|
|
19
|
+
});
|
|
20
|
+
if (gitAddStdout) {
|
|
21
|
+
console.log(chalk.blue(`Git add output:\n${gitAddStdout}`));
|
|
22
|
+
}
|
|
23
|
+
if (gitAddStderr) {
|
|
24
|
+
console.error(chalk.yellow(`Git add errors:\n${gitAddStderr}`));
|
|
25
|
+
}
|
|
26
|
+
console.log(chalk.green(`All changes have been staged.`));
|
|
27
|
+
}
|
|
28
|
+
async function runPrettier(filePaths, cwd) {
|
|
29
|
+
const prettierCommand = `yarn prettier --write ${filePaths.join(' ')}`;
|
|
30
|
+
console.log(`Executing command: ${prettierCommand}`);
|
|
31
|
+
const {
|
|
32
|
+
stdout: prettierStdout,
|
|
33
|
+
stderr: prettierStderr
|
|
34
|
+
} = await execAsync(prettierCommand, {
|
|
35
|
+
cwd
|
|
36
|
+
});
|
|
37
|
+
if (prettierStdout) {
|
|
38
|
+
console.log(chalk.blue(`Prettier output:\n${prettierStdout}`));
|
|
39
|
+
}
|
|
40
|
+
if (prettierStderr) {
|
|
41
|
+
console.error(chalk.yellow(`Prettier errors:\n${prettierStderr}`));
|
|
42
|
+
}
|
|
43
|
+
console.log(chalk.green(`Prettier was run successfully`));
|
|
44
|
+
}
|
|
45
|
+
async function runEslint(filePaths, cwd) {
|
|
46
|
+
const fileChunks = chunkArray(filePaths, 20);
|
|
47
|
+
const totalChunks = fileChunks.length;
|
|
48
|
+
for (const [chunkIndex, fileChunk] of fileChunks.entries()) {
|
|
49
|
+
const eslintCommand = `yarn eslint ${fileChunk.join(' ')} --report-unused-disable-directives --fix`;
|
|
50
|
+
console.log(`Executing command for chunk ${chunkIndex + 1} of ${totalChunks}: ${eslintCommand}`);
|
|
51
|
+
try {
|
|
52
|
+
const result = await execAsync(eslintCommand, {
|
|
53
|
+
cwd
|
|
54
|
+
});
|
|
55
|
+
const {
|
|
56
|
+
stdout,
|
|
57
|
+
stderr
|
|
58
|
+
} = result;
|
|
59
|
+
if (stdout) {
|
|
60
|
+
console.log(chalk.blue(`ESLint output for chunk ${chunkIndex + 1} of ${totalChunks}:\n${stdout}`));
|
|
61
|
+
}
|
|
62
|
+
if (stderr) {
|
|
63
|
+
console.error(chalk.yellow(`ESLint errors for chunk ${chunkIndex + 1} of ${totalChunks}:\n${stderr}`));
|
|
64
|
+
}
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(chalk.red(`Error running ESLint on chunk ${chunkIndex + 1} of ${totalChunks}: ${error}`));
|
|
67
|
+
|
|
68
|
+
// Retry each file individually
|
|
69
|
+
console.log(chalk.yellow(`Retrying each file in chunk ${chunkIndex + 1} of ${totalChunks} individually...`));
|
|
70
|
+
|
|
71
|
+
// Chunk the files into smaller groups of 5 for parallel retry
|
|
72
|
+
const smallerChunks = chunkArray(fileChunk, 5);
|
|
73
|
+
const totalSmallerChunks = smallerChunks.length;
|
|
74
|
+
for (const [smallChunkIndex, smallerChunk] of smallerChunks.entries()) {
|
|
75
|
+
await Promise.all(smallerChunk.map(async file => {
|
|
76
|
+
try {
|
|
77
|
+
const individualEslintCommand = `yarn eslint ${file} --report-unused-disable-directives --fix`;
|
|
78
|
+
console.log(`Executing command for file in small chunk ${smallChunkIndex + 1} of ${totalSmallerChunks}: ${individualEslintCommand}`);
|
|
79
|
+
const result = await execAsync(individualEslintCommand, {
|
|
80
|
+
cwd
|
|
81
|
+
});
|
|
82
|
+
const {
|
|
83
|
+
stdout,
|
|
84
|
+
stderr
|
|
85
|
+
} = result;
|
|
86
|
+
if (stdout) {
|
|
87
|
+
console.log(chalk.blue(`ESLint output for file ${file} in small chunk ${smallChunkIndex + 1} of ${totalSmallerChunks}:\n${stdout}`));
|
|
88
|
+
}
|
|
89
|
+
if (stderr) {
|
|
90
|
+
console.error(chalk.yellow(`ESLint errors for file ${file} in small chunk ${smallChunkIndex + 1} of ${totalSmallerChunks}:\n${stderr}`));
|
|
91
|
+
}
|
|
92
|
+
} catch (fileError) {
|
|
93
|
+
console.error(chalk.red(`Error running ESLint on file ${file} in small chunk ${smallChunkIndex + 1} of ${totalSmallerChunks}: ${fileError}`));
|
|
94
|
+
}
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
console.log(chalk.green(`Finished running ESLint for chunk ${chunkIndex + 1} of ${totalChunks}.`));
|
|
99
|
+
}
|
|
100
|
+
console.log(chalk.green(`ESLint was run on all files successfully`));
|
|
101
|
+
}
|
|
102
|
+
export async function afterAll(options) {
|
|
103
|
+
if (options.reportFolder) {
|
|
104
|
+
await combineReports(options.reportFolder);
|
|
105
|
+
}
|
|
106
|
+
if (options.reportFolder && !options.dry) {
|
|
107
|
+
try {
|
|
108
|
+
const filesTxtPath = path.join(options.reportFolder, 'files.txt');
|
|
109
|
+
const fileContent = await fs.readFile(filesTxtPath, 'utf-8');
|
|
110
|
+
if (fileContent.length > 0) {
|
|
111
|
+
const filePaths = fileContent.split(/\r?\n/).filter(Boolean);
|
|
112
|
+
|
|
113
|
+
// Get the first file path and strip any quotes
|
|
114
|
+
const firstFilePath = filePaths[0].replace(/^['"]|['"]$/g, '');
|
|
115
|
+
|
|
116
|
+
// Determine the root directory using findRoot
|
|
117
|
+
const rootDir = await findRoot(path.dirname(firstFilePath));
|
|
118
|
+
console.log('Root directory:', rootDir);
|
|
119
|
+
await gitStage(filePaths, rootDir);
|
|
120
|
+
if (!options.skipEslint) {
|
|
121
|
+
await runEslint(filePaths, rootDir);
|
|
122
|
+
} else if (options.verbose) {
|
|
123
|
+
console.log(chalk.blue('Skipping ESLint post-processing as requested.'));
|
|
124
|
+
}
|
|
125
|
+
if (!options.skipPrettier) {
|
|
126
|
+
await runPrettier(filePaths, rootDir);
|
|
127
|
+
} else if (options.verbose) {
|
|
128
|
+
console.log(chalk.blue('Skipping Prettier post-processing as requested.'));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error instanceof Error) {
|
|
133
|
+
console.error(chalk.red(`Unexpected error: ${error.message}`));
|
|
134
|
+
} else {
|
|
135
|
+
console.error(chalk.red('An unknown error occurred.'));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|