@vkontakte/vkui-codemods 1.1.0-beta.1 → 1.1.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/dist/autoDetectVKUIVersion.js +16 -24
- package/dist/cli.js +97 -160
- package/dist/codemod-helpers.js +41 -43
- package/dist/getAvailableCodemods.js +13 -14
- package/dist/helpers/logger.js +17 -17
- package/dist/index.js +76 -147
- package/dist/report.js +4 -4
- package/dist/testHelpers/testHelper.js +17 -88
- package/dist/transforms/v6/accordion.js +10 -10
- package/dist/transforms/v6/action-sheet-item.js +5 -5
- package/dist/transforms/v6/action-sheet.js +15 -15
- package/dist/transforms/v6/alert.js +14 -14
- package/dist/transforms/v6/appearance-provider.js +8 -10
- package/dist/transforms/v6/banner.js +10 -10
- package/dist/transforms/v6/calendar-range.js +6 -6
- package/dist/transforms/v6/calendar.js +6 -6
- package/dist/transforms/v6/card-scroll.js +5 -5
- package/dist/transforms/v6/chip.js +6 -6
- package/dist/transforms/v6/chips-input.js +6 -6
- package/dist/transforms/v6/config-provider.js +20 -20
- package/dist/transforms/v6/content-card.js +7 -7
- package/dist/transforms/v6/custom-scroll-view.js +11 -13
- package/dist/transforms/v6/date-input.js +6 -6
- package/dist/transforms/v6/date-range-input.js +6 -6
- package/dist/transforms/v6/fixed-layout.js +11 -11
- package/dist/transforms/v6/forbid-imports.js +8 -8
- package/dist/transforms/v6/form-item.js +9 -9
- package/dist/transforms/v6/form-layout.js +10 -10
- package/dist/transforms/v6/gallery.js +5 -5
- package/dist/transforms/v6/gradient-prop-change.js +12 -12
- package/dist/transforms/v6/horizontal-cell-show-more.js +7 -11
- package/dist/transforms/v6/image-base.js +7 -7
- package/dist/transforms/v6/modal-card.js +16 -18
- package/dist/transforms/v6/modal-page-header.js +11 -11
- package/dist/transforms/v6/pagination.js +12 -12
- package/dist/transforms/v6/panel-header-content.js +10 -10
- package/dist/transforms/v6/panel-header.js +11 -11
- package/dist/transforms/v6/placeholder.js +5 -5
- package/dist/transforms/v6/popout-wrapper.js +9 -9
- package/dist/transforms/v6/popover.js +45 -54
- package/dist/transforms/v6/popper.js +35 -44
- package/dist/transforms/v6/range-slider.js +14 -25
- package/dist/transforms/v6/rich-tooltip.js +10 -10
- package/dist/transforms/v6/search.js +6 -6
- package/dist/transforms/v6/select.js +7 -7
- package/dist/transforms/v6/simple-cell.js +13 -15
- package/dist/transforms/v6/split-col.js +9 -9
- package/dist/transforms/v6/tabbar.js +5 -5
- package/dist/transforms/v6/tappable.js +13 -15
- package/dist/transforms/v6/text-tooltip.js +47 -58
- package/dist/transforms/v6/tooltip-container.js +14 -14
- package/dist/transforms/v6/tooltip.js +63 -72
- package/dist/transforms/v6/typography.js +19 -21
- package/dist/transforms/v6/users-stack.js +13 -13
- package/dist/transforms/v6/visually-hidden-input.js +13 -24
- package/dist/transforms/v7/action-sheet.js +5 -5
- package/dist/transforms/v7/alert.js +5 -5
- package/dist/transforms/v7/appearance-provider.js +12 -12
- package/dist/transforms/v7/appearance.js +16 -16
- package/dist/transforms/v7/banner.js +13 -14
- package/dist/transforms/v7/calendar.js +5 -5
- package/dist/transforms/v7/card-grid.js +5 -5
- package/dist/transforms/v7/card-scroll.js +17 -18
- package/dist/transforms/v7/cell-button.js +13 -13
- package/dist/transforms/v7/cell.js +5 -5
- package/dist/transforms/v7/chips-select.js +8 -8
- package/dist/transforms/v7/common/moveFromChildrenToLabel.js +19 -21
- package/dist/transforms/v7/common/remapSizePropValue.js +14 -16
- package/dist/transforms/v7/common/removeChildrenFromComponent.js +6 -6
- package/dist/transforms/v7/common/swapGapPropElements.js +7 -7
- package/dist/transforms/v7/config-provider.js +32 -36
- package/dist/transforms/v7/content-card.js +5 -5
- package/dist/transforms/v7/counter.js +12 -12
- package/dist/transforms/v7/custom-scroll-view.js +8 -8
- package/dist/transforms/v7/custom-select.js +8 -8
- package/dist/transforms/v7/date-picker.js +8 -8
- package/dist/transforms/v7/flex.js +6 -6
- package/dist/transforms/v7/form-item.js +29 -35
- package/dist/transforms/v7/form-status.js +5 -5
- package/dist/transforms/v7/header.js +21 -21
- package/dist/transforms/v7/horizontal-cell-show-more.js +16 -19
- package/dist/transforms/v7/horizontal-cell.js +5 -5
- package/dist/transforms/v7/horizontal-scroll.js +12 -12
- package/dist/transforms/v7/image-overlay.js +30 -32
- package/dist/transforms/v7/mini-info-cell.js +5 -5
- package/dist/transforms/v7/modal-card.js +7 -7
- package/dist/transforms/v7/onboarding-tooltip.js +5 -5
- package/dist/transforms/v7/panel-header-back.js +6 -6
- package/dist/transforms/v7/panel-header-close.js +6 -6
- package/dist/transforms/v7/panel-header-content.js +5 -5
- package/dist/transforms/v7/panel-header-edit.js +6 -6
- package/dist/transforms/v7/panel-header-submit.js +6 -6
- package/dist/transforms/v7/panel-spinner.js +10 -10
- package/dist/transforms/v7/placeholder.js +5 -5
- package/dist/transforms/v7/rich-cell.js +5 -5
- package/dist/transforms/v7/screen-spinner.js +7 -7
- package/dist/transforms/v7/scroll-arrow.js +20 -23
- package/dist/transforms/v7/select.js +8 -8
- package/dist/transforms/v7/separator.js +6 -6
- package/dist/transforms/v7/simple-cell.js +5 -5
- package/dist/transforms/v7/simple-grid.js +6 -6
- package/dist/transforms/v7/spacing.js +9 -9
- package/dist/transforms/v7/spinner.js +9 -9
- package/dist/transforms/v7/subnavigation-bar.js +10 -10
- package/dist/transforms/v7/subnavigation-button.js +5 -5
- package/dist/transforms/v7/tabbar-item.js +5 -5
- package/dist/transforms/v7/tooltip.js +5 -5
- package/dist/transforms/v7/typography.js +16 -17
- package/dist/transforms/v7/users-stack.js +13 -13
- package/dist/transforms/v8/action-sheet.js +19 -0
- package/dist/transforms/v8/alert.js +5 -5
- package/dist/transforms/v8/checkbox.js +12 -12
- package/dist/transforms/v8/chips-input.js +7 -7
- package/dist/transforms/v8/chips-select.js +7 -7
- package/dist/transforms/v8/common/moveAllPropsIntoSlotProp.js +6 -16
- package/dist/transforms/v8/common/moveInputPropsIntoSlotProps.js +8 -8
- package/dist/transforms/v8/common/movePropIntoSlotProps.js +44 -63
- package/dist/transforms/v8/custom-select.js +7 -7
- package/dist/transforms/v8/file.js +7 -7
- package/dist/transforms/v8/input.js +8 -7
- package/dist/transforms/v8/native-select.js +7 -7
- package/dist/transforms/v8/popout-wrapper.js +12 -12
- package/dist/transforms/v8/radio.js +12 -12
- package/dist/transforms/v8/rich-cell.js +11 -11
- package/dist/transforms/v8/search.js +8 -7
- package/dist/transforms/v8/select.js +7 -7
- package/dist/transforms/v8/snackbar.js +6 -6
- package/dist/transforms/v8/split-layout.js +7 -7
- package/dist/transforms/v8/switch.js +7 -7
- package/dist/transforms/v8/text-area.js +7 -7
- package/dist/transforms/v8/write-bar.js +7 -7
- package/package.json +6 -5
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
3
|
if (k2 === undefined) k2 = k;
|
|
15
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -48,15 +37,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
48
37
|
};
|
|
49
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
39
|
exports.autoDetectVKUIVersion = autoDetectVKUIVersion;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
|
+
const semver = __importStar(require("semver"));
|
|
54
43
|
function findPackageJsonWithVKUI(startDir) {
|
|
55
|
-
|
|
44
|
+
let currentDir = startDir;
|
|
56
45
|
while (currentDir !== path.parse(currentDir).root) {
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
|
|
46
|
+
const packageJsonPath = path.join(currentDir, 'package.json');
|
|
47
|
+
if (node_fs_1.default.existsSync(packageJsonPath)) {
|
|
48
|
+
const vkuiVersion = getVKUIVersion(packageJsonPath);
|
|
60
49
|
if (vkuiVersion) {
|
|
61
50
|
return packageJsonPath;
|
|
62
51
|
}
|
|
@@ -66,19 +55,22 @@ function findPackageJsonWithVKUI(startDir) {
|
|
|
66
55
|
return null;
|
|
67
56
|
}
|
|
68
57
|
function getVKUIVersion(packageJsonPath) {
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
const packageJson = JSON.parse(node_fs_1.default.readFileSync(packageJsonPath, 'utf8'));
|
|
59
|
+
const dependencies = {
|
|
60
|
+
...packageJson.dependencies,
|
|
61
|
+
...packageJson.devDependencies,
|
|
62
|
+
};
|
|
71
63
|
return dependencies['@vkontakte/vkui'];
|
|
72
64
|
}
|
|
73
65
|
function getMajorVersion(version) {
|
|
74
|
-
|
|
66
|
+
const parsed = semver.valid(semver.coerce(version));
|
|
75
67
|
return parsed ? semver.major(parsed) : null;
|
|
76
68
|
}
|
|
77
69
|
function autoDetectVKUIVersion() {
|
|
78
|
-
|
|
79
|
-
|
|
70
|
+
const startDir = process.cwd();
|
|
71
|
+
const packageJsonPath = findPackageJsonWithVKUI(startDir);
|
|
80
72
|
if (packageJsonPath) {
|
|
81
|
-
|
|
73
|
+
const vkuiVersion = getVKUIVersion(packageJsonPath);
|
|
82
74
|
if (vkuiVersion) {
|
|
83
75
|
return String(getMajorVersion(vkuiVersion));
|
|
84
76
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,170 +1,107 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.runCli = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
onCancel: function () {
|
|
62
|
-
process.exit(1);
|
|
63
|
-
},
|
|
64
|
-
})];
|
|
65
|
-
case 1:
|
|
66
|
-
value = (_a.sent()).value;
|
|
67
|
-
if (value.length === 0) {
|
|
68
|
-
logger_js_1.default.error('No codemods picked.');
|
|
69
|
-
process.exit(1);
|
|
70
|
-
}
|
|
71
|
-
return [2 /*return*/, value];
|
|
72
|
-
}
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const commander_1 = require("commander");
|
|
10
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
11
|
+
const autoDetectVKUIVersion_1 = require("./autoDetectVKUIVersion");
|
|
12
|
+
const getAvailableCodemods_js_1 = __importDefault(require("./getAvailableCodemods.js"));
|
|
13
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
14
|
+
const logger_js_1 = __importDefault(require("./helpers/logger.js"));
|
|
15
|
+
const promptAvailableCodemods = async (codemods) => {
|
|
16
|
+
const { value } = await (0, prompts_1.default)({
|
|
17
|
+
type: 'multiselect',
|
|
18
|
+
name: 'value',
|
|
19
|
+
message: 'Pick codemods',
|
|
20
|
+
choices: codemods.map((name) => ({ title: name, value: name })),
|
|
21
|
+
}, {
|
|
22
|
+
onCancel: () => {
|
|
23
|
+
process.exit(1);
|
|
24
|
+
},
|
|
73
25
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
value = (_a.sent()).value;
|
|
95
|
-
return [2 /*return*/, value];
|
|
96
|
-
}
|
|
26
|
+
if (value.length === 0) {
|
|
27
|
+
logger_js_1.default.error('No codemods picked.');
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
};
|
|
32
|
+
const promptTransformVersions = async () => {
|
|
33
|
+
const { value } = await (0, prompts_1.default)({
|
|
34
|
+
type: 'select',
|
|
35
|
+
name: 'value',
|
|
36
|
+
message: 'Pick version',
|
|
37
|
+
choices: [
|
|
38
|
+
{ title: 'v6', value: '6' },
|
|
39
|
+
{ title: 'v7', value: '7' },
|
|
40
|
+
{ title: 'v8', value: '8' },
|
|
41
|
+
],
|
|
42
|
+
}, {
|
|
43
|
+
onCancel: () => {
|
|
44
|
+
process.exit(1);
|
|
45
|
+
},
|
|
97
46
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (codemods.length > 0) {
|
|
141
|
-
wrongCodemods = [];
|
|
142
|
-
for (_i = 0, codemods_1 = codemods; _i < codemods_1.length; _i++) {
|
|
143
|
-
codemodName = codemods_1[_i];
|
|
144
|
-
if (!availableCodemods.includes(codemodName)) {
|
|
145
|
-
wrongCodemods.push(codemodName);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (wrongCodemods.length > 0) {
|
|
149
|
-
logger_js_1.default.error("The following codemods doesn't exist: ".concat(wrongCodemods, ". Please check the available codemods by running with --list option"));
|
|
150
|
-
process.exit(1);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
if (!(codemods.length === 0 && !options.all)) return [3 /*break*/, 4];
|
|
154
|
-
return [4 /*yield*/, promptAvailableCodemods(availableCodemods)];
|
|
155
|
-
case 3:
|
|
156
|
-
codemods = _a.sent();
|
|
157
|
-
_a.label = 4;
|
|
158
|
-
case 4:
|
|
159
|
-
if (options.all) {
|
|
160
|
-
codemods = availableCodemods;
|
|
161
|
-
}
|
|
162
|
-
return [2 /*return*/, {
|
|
163
|
-
flags: options,
|
|
164
|
-
codemods: codemods,
|
|
165
|
-
transformsVersion: transformsVersion,
|
|
166
|
-
}];
|
|
47
|
+
return value;
|
|
48
|
+
};
|
|
49
|
+
const runCli = async () => {
|
|
50
|
+
const program = new commander_1.Command('@vkontakte/vkui-codemod')
|
|
51
|
+
.version(package_json_1.default.version || 'unknown')
|
|
52
|
+
.argument('[codemod-names...]', 'which codemods should be applied')
|
|
53
|
+
.usage(`${chalk_1.default.green('[codemod-names...]')}`)
|
|
54
|
+
.option('-l --list', 'list available codemods')
|
|
55
|
+
.option('--all', 'apply all available codemods')
|
|
56
|
+
.option('--tv, --transforms-version <transformsVersion>', 'vkui major version transforms (available versions: "6", "7", "8")')
|
|
57
|
+
.option('-p --path [paths...]', 'file paths where codemods need to apply (space separated list), default: current directory')
|
|
58
|
+
.option('--input-file <file>', 'apply codemods only to file/directory listed in the file')
|
|
59
|
+
.option('--log-file <file>', 'log migration instructions with required manual changes to the file instead of the console')
|
|
60
|
+
.option('--dry-run', 'no changes are made to files')
|
|
61
|
+
.option('--ignore-config <config>', 'ignore files if they match patterns sourced from a configuration file (e.g. a .gitignore)')
|
|
62
|
+
.option('--debug', `all logs are shown`)
|
|
63
|
+
.option('--alias <alias>', `in case you have adapter over original library`, '@vkontakte/vkui')
|
|
64
|
+
.configureOutput({
|
|
65
|
+
writeErr: (str) => logger_js_1.default.info(`${chalk_1.default.red(str)}`),
|
|
66
|
+
})
|
|
67
|
+
.parse(process.argv);
|
|
68
|
+
const options = program.opts();
|
|
69
|
+
let codemods = program.processedArgs[0];
|
|
70
|
+
let transformsVersion = options.transformsVersion || (0, autoDetectVKUIVersion_1.autoDetectVKUIVersion)();
|
|
71
|
+
if (!transformsVersion) {
|
|
72
|
+
transformsVersion = await promptTransformVersions();
|
|
73
|
+
}
|
|
74
|
+
const availableCodemods = (0, getAvailableCodemods_js_1.default)(transformsVersion);
|
|
75
|
+
if (options.list) {
|
|
76
|
+
logger_js_1.default.info(availableCodemods);
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
if (options.inputFile && !node_fs_1.default.existsSync(options.inputFile)) {
|
|
80
|
+
logger_js_1.default.error(`Input file ${options.inputFile} does not exist.`);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
if (codemods.length > 0) {
|
|
84
|
+
const wrongCodemods = [];
|
|
85
|
+
for (let codemodName of codemods) {
|
|
86
|
+
if (!availableCodemods.includes(codemodName)) {
|
|
87
|
+
wrongCodemods.push(codemodName);
|
|
88
|
+
}
|
|
167
89
|
}
|
|
168
|
-
|
|
169
|
-
});
|
|
90
|
+
if (wrongCodemods.length > 0) {
|
|
91
|
+
logger_js_1.default.error(`The following codemods doesn't exist: ${wrongCodemods}. Please check the available codemods by running with --list option`);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (codemods.length === 0 && !options.all) {
|
|
96
|
+
codemods = await promptAvailableCodemods(availableCodemods);
|
|
97
|
+
}
|
|
98
|
+
if (options.all) {
|
|
99
|
+
codemods = availableCodemods;
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
flags: options,
|
|
103
|
+
codemods,
|
|
104
|
+
transformsVersion,
|
|
105
|
+
};
|
|
106
|
+
};
|
|
170
107
|
exports.runCli = runCli;
|
package/dist/codemod-helpers.js
CHANGED
|
@@ -8,14 +8,14 @@ exports.renameTypeIdentifier = renameTypeIdentifier;
|
|
|
8
8
|
exports.renameProp = renameProp;
|
|
9
9
|
exports.renameSubComponent = renameSubComponent;
|
|
10
10
|
exports.swapBooleanValue = swapBooleanValue;
|
|
11
|
-
|
|
11
|
+
const report_1 = require("./report");
|
|
12
12
|
function getImportInfo(j, file, componentName, alias) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const source = j(file.source);
|
|
14
|
+
let localImportName = null;
|
|
15
15
|
source
|
|
16
16
|
.find(j.ImportDeclaration, { source: { value: alias } })
|
|
17
17
|
.find(j.ImportSpecifier, { imported: { name: componentName } })
|
|
18
|
-
.forEach(
|
|
18
|
+
.forEach((path) => {
|
|
19
19
|
if (path.node.local) {
|
|
20
20
|
localImportName = path.node.local.name;
|
|
21
21
|
}
|
|
@@ -26,37 +26,37 @@ function renameImportName(j, source, componentName, newName, alias, renameOnlyIm
|
|
|
26
26
|
source
|
|
27
27
|
.find(j.ImportDeclaration, { source: { value: alias } })
|
|
28
28
|
.find(j.ImportSpecifier, { local: { name: componentName } })
|
|
29
|
-
.forEach(
|
|
30
|
-
|
|
29
|
+
.forEach((path) => {
|
|
30
|
+
const newSpecifier = j.importSpecifier(j.identifier(newName), renameOnlyImportedName ? j.identifier(componentName) : j.identifier(newName));
|
|
31
31
|
newSpecifier.importKind = path.value.importKind;
|
|
32
32
|
j(path).replaceWith(newSpecifier);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
function renameIdentifier(j, source, oldName, newName) {
|
|
36
|
-
source.find(j.Identifier, { name: oldName }).forEach(
|
|
36
|
+
source.find(j.Identifier, { name: oldName }).forEach((path) => {
|
|
37
37
|
j(path).replaceWith(j.identifier(newName));
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
function renameTypeIdentifier(j, source, oldName, newName) {
|
|
41
41
|
source
|
|
42
42
|
.find(j.TSTypeReference, { typeName: { type: 'Identifier', name: oldName } })
|
|
43
|
-
.forEach(
|
|
43
|
+
.forEach((path) => {
|
|
44
44
|
if (path.node.typeName.type === 'Identifier') {
|
|
45
45
|
path.node.typeName.name = newName;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
function renameProp(j, source, componentName, renameMap) {
|
|
50
|
-
|
|
50
|
+
const from = Object.keys(renameMap);
|
|
51
51
|
return source
|
|
52
52
|
.find(j.JSXOpeningElement)
|
|
53
|
-
.filter(
|
|
53
|
+
.filter((path) => path.value.name.type === 'JSXIdentifier' && path.value.name.name === componentName)
|
|
54
54
|
.find(j.JSXAttribute)
|
|
55
|
-
.filter(
|
|
56
|
-
|
|
55
|
+
.filter((attribute) => {
|
|
56
|
+
const attributeName = attribute.node.name.name;
|
|
57
57
|
return typeof attributeName === 'string' ? from.includes(attributeName) : false;
|
|
58
58
|
})
|
|
59
|
-
.forEach(
|
|
59
|
+
.forEach((attribute) => {
|
|
60
60
|
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(renameMap[attribute.node.name.name]), attribute.node.value));
|
|
61
61
|
});
|
|
62
62
|
}
|
|
@@ -69,12 +69,12 @@ function renameSubComponent(j, source, componentName, prevSubcomponentName, newS
|
|
|
69
69
|
.replaceWith(j.memberExpression(j.identifier(componentName), j.identifier(newSubcomponentName)));
|
|
70
70
|
}
|
|
71
71
|
function swapBooleanValue(api, source, componentName, previousPropName, currentPropName) {
|
|
72
|
-
|
|
72
|
+
const j = api.jscodeshift;
|
|
73
73
|
source
|
|
74
|
-
.find(j.JSXOpeningElement,
|
|
75
|
-
.find(j.JSXAttribute,
|
|
76
|
-
.forEach(
|
|
77
|
-
|
|
74
|
+
.find(j.JSXOpeningElement, (element) => element.name.type === 'JSXIdentifier' && element.name.name === componentName)
|
|
75
|
+
.find(j.JSXAttribute, (attribute) => attribute.name.name === previousPropName)
|
|
76
|
+
.forEach((attribute) => {
|
|
77
|
+
const node = attribute.node;
|
|
78
78
|
if (!node.value) {
|
|
79
79
|
j(attribute).remove();
|
|
80
80
|
}
|
|
@@ -88,13 +88,12 @@ function swapBooleanValue(api, source, componentName, previousPropName, currentP
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
else {
|
|
91
|
-
(0, report_1.report)(api,
|
|
91
|
+
(0, report_1.report)(api, `Manual changes required for ${componentName}'s ${previousPropName} prop.`);
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
var needToShowReport = false;
|
|
95
|
+
const removeProps = (j, api, source, componentName, propsNames, createReportMessage = () => '') => {
|
|
96
|
+
let needToShowReport = false;
|
|
98
97
|
source
|
|
99
98
|
.find(j.JSXElement, {
|
|
100
99
|
openingElement: {
|
|
@@ -103,11 +102,11 @@ var removeProps = function (j, api, source, componentName, propsNames, createRep
|
|
|
103
102
|
},
|
|
104
103
|
},
|
|
105
104
|
})
|
|
106
|
-
.forEach(
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
.forEach((path) => {
|
|
106
|
+
const attributes = path.node.openingElement.attributes;
|
|
107
|
+
const newAttributes = attributes?.filter((attr) => {
|
|
109
108
|
if (attr.type === 'JSXAttribute') {
|
|
110
|
-
|
|
109
|
+
const attrName = attr.name ? attr.name.name : null;
|
|
111
110
|
if (typeof attrName === 'string') {
|
|
112
111
|
return !propsNames.includes(attrName);
|
|
113
112
|
}
|
|
@@ -120,24 +119,23 @@ var removeProps = function (j, api, source, componentName, propsNames, createRep
|
|
|
120
119
|
path.node.openingElement.attributes = newAttributes;
|
|
121
120
|
});
|
|
122
121
|
if (needToShowReport) {
|
|
123
|
-
(0, report_1.report)(api,
|
|
122
|
+
(0, report_1.report)(api, `: ${componentName} has been changed. Manual changes required: ${createReportMessage()}`);
|
|
124
123
|
}
|
|
125
124
|
};
|
|
126
125
|
exports.removeProps = removeProps;
|
|
127
|
-
|
|
128
|
-
attributes
|
|
126
|
+
const removeAttribute = (attributes, attribute) => {
|
|
127
|
+
attributes?.splice(attributes?.indexOf(attribute), 1);
|
|
129
128
|
};
|
|
130
129
|
exports.removeAttribute = removeAttribute;
|
|
131
130
|
/**
|
|
132
131
|
* @description Функция достает из атрибута строковое значение. Если вернулся null, значит значение не строковое
|
|
133
132
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
133
|
+
const getStringValueFromAttribute = (attribute) => {
|
|
134
|
+
if (attribute.value?.type === 'StringLiteral') {
|
|
137
135
|
return attribute.value.value;
|
|
138
136
|
}
|
|
139
|
-
if (
|
|
140
|
-
|
|
137
|
+
if (attribute.value?.type === 'JSXExpressionContainer') {
|
|
138
|
+
const expression = attribute.value.expression;
|
|
141
139
|
if (expression.type === 'StringLiteral') {
|
|
142
140
|
return expression.value;
|
|
143
141
|
}
|
|
@@ -145,22 +143,22 @@ var getStringValueFromAttribute = function (attribute) {
|
|
|
145
143
|
return null;
|
|
146
144
|
};
|
|
147
145
|
exports.getStringValueFromAttribute = getStringValueFromAttribute;
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
const createAttributeManipulator = (props, api) => {
|
|
147
|
+
const map = new Map(Object.entries(props));
|
|
150
148
|
return {
|
|
151
|
-
has
|
|
149
|
+
has(attributeKey) {
|
|
152
150
|
return typeof attributeKey === 'string' ? map.has(attributeKey) : false;
|
|
153
151
|
},
|
|
154
|
-
getReplacers
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
getReplacers(attributeKeyProp) {
|
|
153
|
+
const attributeKey = typeof attributeKeyProp === 'string' ? attributeKeyProp : '';
|
|
154
|
+
const found = map.get(attributeKey);
|
|
157
155
|
if (found && found.reportText) {
|
|
158
|
-
|
|
156
|
+
const text = typeof found.reportText === 'function' ? found.reportText() : found.reportText;
|
|
159
157
|
(0, report_1.report)(api, text);
|
|
160
158
|
}
|
|
161
159
|
return {
|
|
162
160
|
action: found && found.action,
|
|
163
|
-
keyTo
|
|
161
|
+
keyTo() {
|
|
164
162
|
if (!found || !found.keyTo) {
|
|
165
163
|
return attributeKey;
|
|
166
164
|
}
|
|
@@ -169,7 +167,7 @@ var createAttributeManipulator = function (props, api) {
|
|
|
169
167
|
}
|
|
170
168
|
return found.keyTo(attributeKey);
|
|
171
169
|
},
|
|
172
|
-
valueTo
|
|
170
|
+
valueTo(attributeKeyValue) {
|
|
173
171
|
if (!found || !found.valueTo) {
|
|
174
172
|
return attributeKeyValue;
|
|
175
173
|
}
|
|
@@ -38,29 +38,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.TRANSFORM_DIR = void 0;
|
|
40
40
|
exports.default = getAvailableCodemods;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
exports.TRANSFORM_DIR =
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
42
|
+
const path = __importStar(require("node:path"));
|
|
43
|
+
exports.TRANSFORM_DIR = `${__dirname}/transforms`;
|
|
44
|
+
let CODEMODS = [];
|
|
45
|
+
const swapElementsOfArray = (a, b, array) => {
|
|
46
46
|
if (a === -1 || b === -1) {
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
const valueA = array[a];
|
|
50
|
+
const valueB = array[b];
|
|
51
51
|
array[b] = valueA;
|
|
52
52
|
array[a] = valueB;
|
|
53
53
|
};
|
|
54
|
-
function getAvailableCodemods(version, dirname) {
|
|
55
|
-
if (dirname === void 0) { dirname = exports.TRANSFORM_DIR; }
|
|
54
|
+
function getAvailableCodemods(version, dirname = exports.TRANSFORM_DIR) {
|
|
56
55
|
if (CODEMODS.length === 0) {
|
|
57
|
-
|
|
58
|
-
CODEMODS =
|
|
56
|
+
const transformsPath = path.join(dirname, `v${version}`);
|
|
57
|
+
CODEMODS = node_fs_1.default
|
|
59
58
|
.readdirSync(transformsPath)
|
|
60
|
-
.filter(
|
|
61
|
-
.map(
|
|
59
|
+
.filter((fname) => fname.endsWith('.js') || fname.endsWith('.ts'))
|
|
60
|
+
.map((fname) => fname.slice(0, -3));
|
|
62
61
|
if (version === '6') {
|
|
63
|
-
swapElementsOfArray(CODEMODS.findIndex(
|
|
62
|
+
swapElementsOfArray(CODEMODS.findIndex((fname) => fname === 'text-tooltip'), CODEMODS.findIndex((fname) => fname === 'tooltip'), CODEMODS);
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
65
|
return CODEMODS;
|
package/dist/helpers/logger.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
class Logger {
|
|
4
|
+
quiet;
|
|
5
|
+
constructor() {
|
|
5
6
|
this.quiet = false;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
setQuietMode() {
|
|
8
9
|
this.quiet = true;
|
|
9
|
-
}
|
|
10
|
-
|
|
10
|
+
}
|
|
11
|
+
log(level, message) {
|
|
11
12
|
if (this.quiet) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
|
-
console.log(
|
|
15
|
-
}
|
|
16
|
-
|
|
15
|
+
console.log(`[${level}]: `, message, '\n');
|
|
16
|
+
}
|
|
17
|
+
debug(message) {
|
|
17
18
|
this.log('debug', message);
|
|
18
|
-
}
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
info(message) {
|
|
20
21
|
this.log('info', message);
|
|
21
|
-
}
|
|
22
|
-
|
|
22
|
+
}
|
|
23
|
+
warn(message) {
|
|
23
24
|
this.log('warn', message);
|
|
24
|
-
}
|
|
25
|
-
|
|
25
|
+
}
|
|
26
|
+
error(message) {
|
|
26
27
|
this.log('error', message);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
30
|
exports.default = new Logger();
|