@vkontakte/vkui-codemods 1.0.0-beta.0 → 1.0.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/README.md +62 -19
- package/dist/autoDetectVKUIVersion.js +17 -7
- package/dist/cli.js +80 -32
- package/dist/codemod-helpers.js +86 -1
- package/dist/getAvailableCodemods.js +17 -7
- package/dist/index.js +45 -57
- package/dist/transforms/v7/action-sheet.js +16 -0
- package/dist/transforms/v7/alert.js +16 -0
- package/dist/transforms/v7/appearance-provider.js +35 -0
- package/dist/transforms/v7/appearance.js +45 -0
- package/dist/transforms/v7/banner.js +47 -0
- package/dist/transforms/v7/calendar.js +17 -0
- package/dist/transforms/v7/card-grid.js +16 -0
- package/dist/transforms/v7/card-scroll.js +59 -0
- package/dist/transforms/v7/cell-button.js +3 -15
- package/dist/transforms/v7/cell.js +19 -0
- package/dist/transforms/v7/chips-select.js +20 -0
- package/dist/transforms/v7/common/moveFromChildrenToLabel.js +68 -0
- package/dist/transforms/v7/common/remapSizePropValue.js +10 -5
- package/dist/transforms/v7/common/removeChildrenFromComponent.js +17 -0
- package/dist/transforms/v7/config-provider.js +136 -0
- package/dist/transforms/v7/content-card.js +21 -0
- package/dist/transforms/v7/counter.js +60 -0
- package/dist/transforms/v7/custom-scroll-view.js +21 -0
- package/dist/transforms/v7/custom-select.js +20 -0
- package/dist/transforms/v7/date-picker.js +26 -0
- package/dist/transforms/v7/form-item.js +2 -2
- package/dist/transforms/v7/form-status.js +18 -0
- package/dist/transforms/v7/header.js +47 -0
- package/dist/transforms/v7/horizontal-cell-show-more.js +33 -13
- package/dist/transforms/v7/horizontal-cell.js +16 -0
- package/dist/transforms/v7/image-overlay.js +10 -10
- package/dist/transforms/v7/mini-info-cell.js +18 -0
- package/dist/transforms/v7/modal-card.js +29 -0
- package/dist/transforms/v7/onboarding-tooltip.js +16 -0
- package/dist/transforms/v7/panel-header-back.js +18 -0
- package/dist/transforms/v7/panel-header-close.js +18 -0
- package/dist/transforms/v7/panel-header-content.js +16 -0
- package/dist/transforms/v7/panel-header-edit.js +19 -0
- package/dist/transforms/v7/panel-header-submit.js +18 -0
- package/dist/transforms/v7/panel-spinner.js +30 -0
- package/dist/transforms/v7/placeholder.js +19 -0
- package/dist/transforms/v7/rich-cell.js +20 -0
- package/dist/transforms/v7/screen-spinner.js +25 -2
- package/dist/transforms/v7/scroll-arrow.js +52 -0
- package/dist/transforms/v7/select.js +20 -0
- package/dist/transforms/v7/separator.js +1 -0
- package/dist/transforms/v7/simple-cell.js +19 -0
- package/dist/transforms/v7/subnavigation-bar.js +46 -0
- package/dist/transforms/v7/subnavigation-button.js +18 -0
- package/dist/transforms/v7/tabbar-item.js +16 -0
- package/dist/transforms/v7/tooltip.js +16 -0
- package/dist/transforms/v7/users-stack.js +2 -15
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Чтобы упростить переход на новую мажорную версию, можно воспользоваться инструментом по автоматической миграции ваших компонентов.
|
|
4
4
|
|
|
5
|
-
> Для начала обновите ваше приложение до необходимой мажорной версии (например, **v7**) в соответствии с требованиями вашего пакетного менеджера и
|
|
5
|
+
> Для начала обновите ваше приложение до необходимой мажорной версии (например, **v7**) в соответствии с требованиями вашего пакетного менеджера и среды.
|
|
6
6
|
|
|
7
|
-
> Обратите внимание, минимальная поддерживаемая версия **React** `v18.2.0
|
|
7
|
+
> Обратите внимание, минимальная поддерживаемая версия **React** `v18.2.0`.
|
|
8
8
|
|
|
9
|
-
> Пока для перевода доступны только `Typescript`-файлы (_.ts/_.tsx)
|
|
9
|
+
> Пока для перевода доступны только `Typescript`-файлы (_.ts/_.tsx).
|
|
10
10
|
|
|
11
11
|
> Из-за особенностей работы `jscodeshift` после применения миграции у вас могут появиться лишние скобки вокруг `JSX`-элементов, пожалуйста, запустите `prettier`, чтобы отформатировать код в соответствии с вашими настройками.
|
|
12
12
|
|
|
@@ -25,34 +25,47 @@ npx @vkontakte/vkui-codemods
|
|
|
25
25
|
```console
|
|
26
26
|
$ npx @vkontakte/vkui-codemods --help
|
|
27
27
|
|
|
28
|
-
Usage: @vkontakte/vkui-codemod [codemod-
|
|
28
|
+
Usage: @vkontakte/vkui-codemod [codemod-names...]
|
|
29
29
|
|
|
30
30
|
Arguments:
|
|
31
|
-
|
|
31
|
+
codemod-names which codemods should be applied
|
|
32
32
|
|
|
33
33
|
Options:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
-V, --version output the version number
|
|
35
|
+
-l --list list available codemods
|
|
36
|
+
--all apply all available codemods
|
|
37
|
+
-tv --transforms-version <transformsVersion> vkui major version transforms (available versions: "6", "7")
|
|
38
|
+
-p --path [paths...] file paths where codemods need to apply (space separated list), default: current
|
|
39
|
+
directory
|
|
40
|
+
--input-file <file> apply codemods only to file/directory listed in the file
|
|
41
|
+
--log-file <file> log migration instructions with required manual changes to the file instead of
|
|
42
|
+
the console
|
|
43
|
+
--dry-run no changes are made to files
|
|
44
|
+
--ignore-config <config> ignore files if they match patterns sourced from a configuration file (e.g. a
|
|
45
|
+
.gitignore)
|
|
46
|
+
--debug all logs are shown
|
|
47
|
+
--alias <alias> in case you have adapter over original library (default: "@vkontakte/vkui")
|
|
48
|
+
-h, --help display help for command
|
|
44
49
|
```
|
|
45
50
|
|
|
46
|
-
|
|
51
|
+
### `-tv (--transforms-version)`
|
|
52
|
+
|
|
53
|
+
Если приложение запустить без опции `-tv (--transforms-version)`, скрипт попытается автоматически определить версию, на которую необходимо мигрировать. Если этого сделать не удалось - нужно будет выбрать версию из предложенного списка.
|
|
54
|
+
|
|
55
|
+
### `--all`
|
|
56
|
+
|
|
57
|
+
При запуске приложения без аргументов будет предложено выбрать одну или несколько имеющихся миграций (их название отражает название компонента, к которому будет применено изменение). Если вам необходимо применить все имеющиеся миграции, запустите команду с опцией `--all`:
|
|
47
58
|
|
|
48
59
|
```shell
|
|
49
60
|
npx @vkontakte/vkui-codemods --all
|
|
50
61
|
```
|
|
51
62
|
|
|
52
|
-
|
|
63
|
+
### `--ignore-config <file>`
|
|
64
|
+
|
|
65
|
+
Если вы хотите исключить некоторые файлы или директории из обработки, то временно создайте файл (по примеру .gitignore) с перечисленными исключениями в папке:
|
|
53
66
|
|
|
54
67
|
```shell
|
|
55
|
-
npx @vkontakte/vkui-codemods --all --path
|
|
68
|
+
npx @vkontakte/vkui-codemods --all --path src --ignore-config "./.codemodignore"
|
|
56
69
|
```
|
|
57
70
|
|
|
58
71
|
```
|
|
@@ -61,10 +74,40 @@ MyBeautifulComponentToIgnore.tsx
|
|
|
61
74
|
directoryToIgnore/
|
|
62
75
|
```
|
|
63
76
|
|
|
64
|
-
Приведенная выше команда применит все codemods в директории `
|
|
77
|
+
Приведенная выше команда применит все codemods в директории `src` (находится в корне текущей директории), игонорируя файл `MyBeautifulComponentToIgnore.tsx` и директорию `directoryToIgnore`, указанные в `.codemodignore` (находится в корне текущей директории).
|
|
78
|
+
|
|
79
|
+
### `--log-file <file>`
|
|
80
|
+
|
|
81
|
+
Есть вероятность, что применить автоматические миграции не представляется возможным. В таком случае приложение выведет в консоль подсказку, какие изменения необходимо внести вручную. Этих изменений может быть большое количество, для удобства можно воспользоваться опцией `--log-file <file>`, тогда все инструкции будут записаны в указанный файл (если его не существует, то он будет создан автоматически).
|
|
82
|
+
|
|
83
|
+
### `--input-file <file>`
|
|
84
|
+
|
|
85
|
+
Если вы хотите перечислить файлы и директории, которые нужно включить в обработку, в отдельном конфигурационном файле, это можно сделать, указав опцию `--input-file <file>`:
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
// .input-file
|
|
89
|
+
MyBeautifulComponent.tsx
|
|
90
|
+
src/components
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### `--alias`
|
|
65
94
|
|
|
66
95
|
> Обратите внимание, если вы используете собственный адаптер над библиотекой `VKUI` и делаете ре-экспорт существующих компонентов, то можете воспользоваться опцией `--alias` для указания правильного пути.
|
|
67
96
|
|
|
68
97
|
```shell
|
|
69
98
|
npx @vkontakte/vkui-codemods --all --alias "@myscope/VKUIFake"
|
|
70
99
|
```
|
|
100
|
+
|
|
101
|
+
## Примеры
|
|
102
|
+
|
|
103
|
+
Представленный ниже скрипт позволит запустить все имеющиеся миграции в файлах `App.tsx` и `Main.tsx` в папке `src`:
|
|
104
|
+
|
|
105
|
+
```shell
|
|
106
|
+
npx @vkontakte/vkui-codemods --path src/App.tsx src/Main.tsx --all
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Следующий скрипт запустит миграции компонентов `Flex` и `Separator` при обновлении на версию VKUI v7 в текущей директории:
|
|
110
|
+
|
|
111
|
+
```shell
|
|
112
|
+
npx @vkontakte/vkui-codemods flex separator -tv 7
|
|
113
|
+
```
|
|
@@ -26,13 +26,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
26
26
|
}) : function(o, v) {
|
|
27
27
|
o["default"] = v;
|
|
28
28
|
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
36
46
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
47
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
48
|
};
|
package/dist/cli.js
CHANGED
|
@@ -40,6 +40,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.runCli = void 0;
|
|
43
|
+
var fs_1 = __importDefault(require("fs"));
|
|
43
44
|
var chalk_1 = __importDefault(require("chalk"));
|
|
44
45
|
var commander_1 = require("commander");
|
|
45
46
|
var prompts_1 = __importDefault(require("prompts"));
|
|
@@ -47,18 +48,14 @@ var autoDetectVKUIVersion_1 = require("./autoDetectVKUIVersion");
|
|
|
47
48
|
var getAvailableCodemods_js_1 = __importDefault(require("./getAvailableCodemods.js"));
|
|
48
49
|
var package_json_1 = __importDefault(require("../package.json"));
|
|
49
50
|
var logger_js_1 = __importDefault(require("./helpers/logger.js"));
|
|
50
|
-
var trimStringValue = function (value) {
|
|
51
|
-
return typeof value === 'string' ? value.trim() : value;
|
|
52
|
-
};
|
|
53
51
|
var promptAvailableCodemods = function (codemods) { return __awaiter(void 0, void 0, void 0, function () {
|
|
54
|
-
var
|
|
52
|
+
var value;
|
|
55
53
|
return __generator(this, function (_a) {
|
|
56
54
|
switch (_a.label) {
|
|
57
55
|
case 0: return [4 /*yield*/, (0, prompts_1.default)({
|
|
58
|
-
type: '
|
|
59
|
-
name: '
|
|
60
|
-
message: 'Pick
|
|
61
|
-
initial: 0,
|
|
56
|
+
type: 'multiselect',
|
|
57
|
+
name: 'value',
|
|
58
|
+
message: 'Pick codemods',
|
|
62
59
|
choices: codemods.map(function (name) { return ({ title: name, value: name }); }),
|
|
63
60
|
}, {
|
|
64
61
|
onCancel: function () {
|
|
@@ -66,24 +63,53 @@ var promptAvailableCodemods = function (codemods) { return __awaiter(void 0, voi
|
|
|
66
63
|
},
|
|
67
64
|
})];
|
|
68
65
|
case 1:
|
|
69
|
-
|
|
70
|
-
|
|
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
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}); };
|
|
75
|
+
var promptTransformVersions = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
76
|
+
var value;
|
|
77
|
+
return __generator(this, function (_a) {
|
|
78
|
+
switch (_a.label) {
|
|
79
|
+
case 0: return [4 /*yield*/, (0, prompts_1.default)({
|
|
80
|
+
type: 'select',
|
|
81
|
+
name: 'value',
|
|
82
|
+
message: 'Pick version',
|
|
83
|
+
choices: [
|
|
84
|
+
{ title: 'v6', value: '6' },
|
|
85
|
+
{ title: 'v7', value: '7' },
|
|
86
|
+
],
|
|
87
|
+
}, {
|
|
88
|
+
onCancel: function () {
|
|
89
|
+
process.exit(1);
|
|
90
|
+
},
|
|
91
|
+
})];
|
|
92
|
+
case 1:
|
|
93
|
+
value = (_a.sent()).value;
|
|
94
|
+
return [2 /*return*/, value];
|
|
71
95
|
}
|
|
72
96
|
});
|
|
73
97
|
}); };
|
|
74
98
|
var runCli = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
75
|
-
var program, options,
|
|
99
|
+
var program, options, codemods, transformsVersion, availableCodemods, wrongCodemods, _i, codemods_1, codemodName;
|
|
76
100
|
return __generator(this, function (_a) {
|
|
77
101
|
switch (_a.label) {
|
|
78
102
|
case 0:
|
|
79
103
|
program = new commander_1.Command('@vkontakte/vkui-codemod')
|
|
80
104
|
.version(package_json_1.default.version || 'unknown')
|
|
81
|
-
.argument('[codemod-
|
|
82
|
-
.usage("".concat(chalk_1.default.green('[codemod-
|
|
105
|
+
.argument('[codemod-names...]', 'which codemods should be applied')
|
|
106
|
+
.usage("".concat(chalk_1.default.green('[codemod-names...]')))
|
|
83
107
|
.option('-l --list', 'list available codemods')
|
|
84
108
|
.option('--all', 'apply all available codemods')
|
|
85
109
|
.option('-tv --transforms-version <transformsVersion>', 'vkui major version transforms (available versions: "6", "7")')
|
|
86
|
-
.option('-p --path
|
|
110
|
+
.option('-p --path [paths...]', 'file paths where codemods need to apply (space separated list), default: current directory')
|
|
111
|
+
.option('--input-file <file>', 'apply codemods only to file/directory listed in the file')
|
|
112
|
+
.option('--log-file <file>', 'log migration instructions with required manual changes to the file instead of the console')
|
|
87
113
|
.option('--dry-run', 'no changes are made to files')
|
|
88
114
|
.option('--ignore-config <config>', 'ignore files if they match patterns sourced from a configuration file (e.g. a .gitignore)')
|
|
89
115
|
.option('--debug', "all logs are shown")
|
|
@@ -93,28 +119,50 @@ var runCli = function () { return __awaiter(void 0, void 0, void 0, function ()
|
|
|
93
119
|
})
|
|
94
120
|
.parse(process.argv);
|
|
95
121
|
options = program.opts();
|
|
96
|
-
|
|
122
|
+
codemods = program.processedArgs[0];
|
|
97
123
|
transformsVersion = options.transformsVersion || (0, autoDetectVKUIVersion_1.autoDetectVKUIVersion)();
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
124
|
+
if (!!transformsVersion) return [3 /*break*/, 2];
|
|
125
|
+
return [4 /*yield*/, promptTransformVersions()];
|
|
126
|
+
case 1:
|
|
127
|
+
transformsVersion = _a.sent();
|
|
128
|
+
_a.label = 2;
|
|
129
|
+
case 2:
|
|
130
|
+
availableCodemods = (0, getAvailableCodemods_js_1.default)(transformsVersion);
|
|
102
131
|
if (options.list) {
|
|
103
|
-
|
|
104
|
-
logger_js_1.default.info(codemods);
|
|
132
|
+
logger_js_1.default.info(availableCodemods);
|
|
105
133
|
process.exit(0);
|
|
106
134
|
}
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
135
|
+
if (options.inputFile && !fs_1.default.existsSync(options.inputFile)) {
|
|
136
|
+
logger_js_1.default.error("Input file ".concat(options.inputFile, " does not exist."));
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
if (codemods.length > 0) {
|
|
140
|
+
wrongCodemods = [];
|
|
141
|
+
for (_i = 0, codemods_1 = codemods; _i < codemods_1.length; _i++) {
|
|
142
|
+
codemodName = codemods_1[_i];
|
|
143
|
+
if (!availableCodemods.includes(codemodName)) {
|
|
144
|
+
wrongCodemods.push(codemodName);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (wrongCodemods.length > 0) {
|
|
148
|
+
logger_js_1.default.error("The following codemods doesn't exist: ".concat(wrongCodemods, ". Please check the available codemods by running with --list option"));
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!(codemods.length === 0 && !options.all)) return [3 /*break*/, 4];
|
|
153
|
+
return [4 /*yield*/, promptAvailableCodemods(availableCodemods)];
|
|
154
|
+
case 3:
|
|
155
|
+
codemods = _a.sent();
|
|
156
|
+
_a.label = 4;
|
|
157
|
+
case 4:
|
|
158
|
+
if (options.all) {
|
|
159
|
+
codemods = availableCodemods;
|
|
160
|
+
}
|
|
161
|
+
return [2 /*return*/, {
|
|
162
|
+
flags: options,
|
|
163
|
+
codemods: codemods,
|
|
164
|
+
transformsVersion: transformsVersion,
|
|
165
|
+
}];
|
|
118
166
|
}
|
|
119
167
|
});
|
|
120
168
|
}); };
|
package/dist/codemod-helpers.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createAttributeManipulator = exports.removeAttribute = void 0;
|
|
3
|
+
exports.createAttributeManipulator = exports.getStringValueFromAttribute = exports.removeAttribute = exports.removeProps = void 0;
|
|
4
4
|
exports.getImportInfo = getImportInfo;
|
|
5
|
+
exports.renameImportName = renameImportName;
|
|
6
|
+
exports.renameIdentifier = renameIdentifier;
|
|
7
|
+
exports.renameTypeIdentifier = renameTypeIdentifier;
|
|
5
8
|
exports.renameProp = renameProp;
|
|
9
|
+
exports.renameSubComponent = renameSubComponent;
|
|
6
10
|
exports.swapBooleanValue = swapBooleanValue;
|
|
7
11
|
var report_1 = require("./report");
|
|
8
12
|
function getImportInfo(j, file, componentName, alias) {
|
|
@@ -18,6 +22,30 @@ function getImportInfo(j, file, componentName, alias) {
|
|
|
18
22
|
});
|
|
19
23
|
return { localName: localImportName };
|
|
20
24
|
}
|
|
25
|
+
function renameImportName(j, source, componentName, newName, alias, renameOnlyImportedName) {
|
|
26
|
+
source
|
|
27
|
+
.find(j.ImportDeclaration, { source: { value: alias } })
|
|
28
|
+
.find(j.ImportSpecifier, { local: { name: componentName } })
|
|
29
|
+
.forEach(function (path) {
|
|
30
|
+
var newSpecifier = j.importSpecifier(j.identifier(newName), renameOnlyImportedName ? j.identifier(componentName) : j.identifier(newName));
|
|
31
|
+
newSpecifier.importKind = path.value.importKind;
|
|
32
|
+
j(path).replaceWith(newSpecifier);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function renameIdentifier(j, source, oldName, newName) {
|
|
36
|
+
source.find(j.Identifier, { name: oldName }).forEach(function (path) {
|
|
37
|
+
j(path).replaceWith(j.identifier(newName));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function renameTypeIdentifier(j, source, oldName, newName) {
|
|
41
|
+
source
|
|
42
|
+
.find(j.TSTypeReference, { typeName: { type: 'Identifier', name: oldName } })
|
|
43
|
+
.forEach(function (path) {
|
|
44
|
+
if (path.node.typeName.type === 'Identifier') {
|
|
45
|
+
path.node.typeName.name = newName;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
21
49
|
function renameProp(j, source, componentName, renameMap) {
|
|
22
50
|
var from = Object.keys(renameMap);
|
|
23
51
|
return source
|
|
@@ -32,6 +60,14 @@ function renameProp(j, source, componentName, renameMap) {
|
|
|
32
60
|
j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(renameMap[attribute.node.name.name]), attribute.node.value));
|
|
33
61
|
});
|
|
34
62
|
}
|
|
63
|
+
function renameSubComponent(j, source, componentName, prevSubcomponentName, newSubcomponentName) {
|
|
64
|
+
source
|
|
65
|
+
.find(j.MemberExpression, {
|
|
66
|
+
object: { name: componentName },
|
|
67
|
+
property: { name: prevSubcomponentName },
|
|
68
|
+
})
|
|
69
|
+
.replaceWith(j.memberExpression(j.identifier(componentName), j.identifier(newSubcomponentName)));
|
|
70
|
+
}
|
|
35
71
|
function swapBooleanValue(api, source, componentName, previousPropName, currentPropName) {
|
|
36
72
|
var j = api.jscodeshift;
|
|
37
73
|
source
|
|
@@ -56,10 +92,59 @@ function swapBooleanValue(api, source, componentName, previousPropName, currentP
|
|
|
56
92
|
}
|
|
57
93
|
});
|
|
58
94
|
}
|
|
95
|
+
var removeProps = function (j, api, source, componentName, propsNames, createReportMessage) {
|
|
96
|
+
if (createReportMessage === void 0) { createReportMessage = function () { return ''; }; }
|
|
97
|
+
var needToShowReport = false;
|
|
98
|
+
source
|
|
99
|
+
.find(j.JSXElement, {
|
|
100
|
+
openingElement: {
|
|
101
|
+
name: {
|
|
102
|
+
name: componentName,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
.forEach(function (path) {
|
|
107
|
+
var attributes = path.node.openingElement.attributes;
|
|
108
|
+
var newAttributes = attributes === null || attributes === void 0 ? void 0 : attributes.filter(function (attr) {
|
|
109
|
+
if (attr.type === 'JSXAttribute') {
|
|
110
|
+
var attrName = attr.name ? attr.name.name : null;
|
|
111
|
+
if (typeof attrName === 'string') {
|
|
112
|
+
return !propsNames.includes(attrName);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (attr.type === 'JSXSpreadAttribute') {
|
|
116
|
+
needToShowReport = true;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
});
|
|
120
|
+
path.node.openingElement.attributes = newAttributes;
|
|
121
|
+
});
|
|
122
|
+
if (needToShowReport) {
|
|
123
|
+
(0, report_1.report)(api, ": ".concat(componentName, " has been changed. Manual changes required: ").concat(createReportMessage()));
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
exports.removeProps = removeProps;
|
|
59
127
|
var removeAttribute = function (attributes, attribute) {
|
|
60
128
|
attributes === null || attributes === void 0 ? void 0 : attributes.splice(attributes === null || attributes === void 0 ? void 0 : attributes.indexOf(attribute), 1);
|
|
61
129
|
};
|
|
62
130
|
exports.removeAttribute = removeAttribute;
|
|
131
|
+
/**
|
|
132
|
+
* @description Функция достает из атрибута строковое значение. Если вернулся null, значит значение не строковое
|
|
133
|
+
*/
|
|
134
|
+
var getStringValueFromAttribute = function (attribute) {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
if (((_a = attribute.value) === null || _a === void 0 ? void 0 : _a.type) === 'StringLiteral') {
|
|
137
|
+
return attribute.value.value;
|
|
138
|
+
}
|
|
139
|
+
if (((_b = attribute.value) === null || _b === void 0 ? void 0 : _b.type) === 'JSXExpressionContainer') {
|
|
140
|
+
var expression = attribute.value.expression;
|
|
141
|
+
if (expression.type === 'StringLiteral') {
|
|
142
|
+
return expression.value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
};
|
|
147
|
+
exports.getStringValueFromAttribute = getStringValueFromAttribute;
|
|
63
148
|
var createAttributeManipulator = function (props, api) {
|
|
64
149
|
var map = new Map(Object.entries(props));
|
|
65
150
|
return {
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
37
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
3
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
4
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
5
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -72,13 +49,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
72
49
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
73
50
|
};
|
|
74
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
var fs_1 = __importDefault(require("fs"));
|
|
53
|
+
var node_events_1 = require("node:events");
|
|
75
54
|
var chalk_1 = __importDefault(require("chalk"));
|
|
76
55
|
var cross_spawn_1 = require("cross-spawn");
|
|
77
56
|
var prompts_1 = __importDefault(require("prompts"));
|
|
78
57
|
var cli_js_1 = require("./cli.js");
|
|
79
|
-
var getAvailableCodemods_js_1 =
|
|
58
|
+
var getAvailableCodemods_js_1 = require("./getAvailableCodemods.js");
|
|
80
59
|
var logger_js_1 = __importDefault(require("./helpers/logger.js"));
|
|
81
|
-
|
|
60
|
+
var MAX_PRINTED_PATHS = 5;
|
|
61
|
+
function runJSCodeShift(_a) {
|
|
62
|
+
var codemodName = _a.codemodName, transformsVersion = _a.transformsVersion, paths = _a.paths, flags = _a.flags, logStream = _a.logStream;
|
|
82
63
|
var args = ['--parser=tsx', '--extensions=tsx,ts', "--alias=".concat(flags.alias)];
|
|
83
64
|
if (flags.dryRun) {
|
|
84
65
|
args.push('--dry');
|
|
@@ -89,20 +70,20 @@ function runJSCodeShift(codemodName, transformsVersion, workingDirectory, flags)
|
|
|
89
70
|
if (!flags.debug) {
|
|
90
71
|
args.push('--silent');
|
|
91
72
|
}
|
|
92
|
-
var result = (0, cross_spawn_1.sync)('node', __spreadArray(__spreadArray([
|
|
73
|
+
var result = (0, cross_spawn_1.sync)('node', __spreadArray(__spreadArray(__spreadArray([
|
|
93
74
|
require.resolve('jscodeshift/bin/jscodeshift'),
|
|
94
75
|
'--no-babel',
|
|
95
76
|
'--fail-on-error',
|
|
96
77
|
'-t',
|
|
97
78
|
"".concat(getAvailableCodemods_js_1.TRANSFORM_DIR, "/v").concat(transformsVersion, "/").concat(codemodName, ".js")
|
|
98
79
|
], args, true), [
|
|
99
|
-
|
|
100
|
-
], false), {
|
|
101
|
-
stdio: 'inherit',
|
|
80
|
+
'--ignore-pattern node_modules'
|
|
81
|
+
], false), (flags.inputFile ? ["--stdin < ".concat(flags.inputFile)] : paths), true), {
|
|
82
|
+
stdio: ['inherit', logStream !== null && logStream !== void 0 ? logStream : 'inherit', 'inherit'],
|
|
102
83
|
shell: true,
|
|
103
84
|
});
|
|
104
85
|
if (result.status === 1) {
|
|
105
|
-
logger_js_1.default.error("Codemod ".concat(codemodName, " failed to apply"));
|
|
86
|
+
logger_js_1.default.error("Codemod ".concat(codemodName, " failed to apply."));
|
|
106
87
|
return;
|
|
107
88
|
}
|
|
108
89
|
}
|
|
@@ -130,14 +111,24 @@ function promptConfirmation() {
|
|
|
130
111
|
});
|
|
131
112
|
});
|
|
132
113
|
}
|
|
114
|
+
function getWorkingPathsInfo(paths, inputFile) {
|
|
115
|
+
if (inputFile) {
|
|
116
|
+
return "from ".concat(inputFile);
|
|
117
|
+
}
|
|
118
|
+
if (paths.length > MAX_PRINTED_PATHS) {
|
|
119
|
+
return "".concat(paths.slice(0, MAX_PRINTED_PATHS).join(', '), " and ").concat(paths.length - MAX_PRINTED_PATHS, " more");
|
|
120
|
+
}
|
|
121
|
+
return paths.join(', ');
|
|
122
|
+
}
|
|
133
123
|
function verifyConfiguration(_a) {
|
|
134
124
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
135
|
-
var confirmed;
|
|
136
|
-
var
|
|
125
|
+
var formattedPaths, confirmed;
|
|
126
|
+
var paths = _b.paths, inputFile = _b.inputFile, codemodNames = _b.codemodNames, transformsVersion = _b.transformsVersion;
|
|
137
127
|
return __generator(this, function (_c) {
|
|
138
128
|
switch (_c.label) {
|
|
139
129
|
case 0:
|
|
140
|
-
|
|
130
|
+
formattedPaths = getWorkingPathsInfo(paths, inputFile);
|
|
131
|
+
logger_js_1.default.info("Please ".concat(chalk_1.default.cyan('verify'), " the following information:\n working files/directories: ").concat(formattedPaths, "\n target vkui major version: ").concat(transformsVersion, "\n codemods to apply: ").concat(codemodNames ? codemodNames : chalk_1.default.red('all'), "\n "));
|
|
141
132
|
return [4 /*yield*/, promptConfirmation()];
|
|
142
133
|
case 1:
|
|
143
134
|
confirmed = _c.sent();
|
|
@@ -151,43 +142,40 @@ function verifyConfiguration(_a) {
|
|
|
151
142
|
});
|
|
152
143
|
}
|
|
153
144
|
var run = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
154
|
-
|
|
145
|
+
function applyCodemods(logStream) {
|
|
146
|
+
codemods.forEach(function (codemodName) {
|
|
147
|
+
logger_js_1.default.info("Codemod ".concat(codemodName, " in process..."));
|
|
148
|
+
runJSCodeShift({ codemodName: codemodName, transformsVersion: transformsVersion, paths: paths, flags: flags, logStream: logStream });
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
var _a, flags, codemods, transformsVersion, paths, logStream;
|
|
155
152
|
return __generator(this, function (_b) {
|
|
156
153
|
switch (_b.label) {
|
|
157
154
|
case 0: return [4 /*yield*/, (0, cli_js_1.runCli)()];
|
|
158
155
|
case 1:
|
|
159
|
-
_a = _b.sent(), flags = _a.flags,
|
|
160
|
-
|
|
161
|
-
if (!(codemodName && workingDirectory)) return [3 /*break*/, 4];
|
|
162
|
-
codemodes = (0, getAvailableCodemods_js_1.default)(transformsVersion);
|
|
163
|
-
if (!codemodes.includes(codemodName)) return [3 /*break*/, 3];
|
|
156
|
+
_a = _b.sent(), flags = _a.flags, codemods = _a.codemods, transformsVersion = _a.transformsVersion;
|
|
157
|
+
paths = flags.path ? flags.path : [process.cwd()];
|
|
164
158
|
return [4 /*yield*/, verifyConfiguration({
|
|
165
|
-
|
|
159
|
+
paths: paths,
|
|
160
|
+
inputFile: flags.inputFile,
|
|
166
161
|
transformsVersion: transformsVersion,
|
|
167
|
-
|
|
162
|
+
codemodNames: flags.all ? undefined : codemods,
|
|
168
163
|
})];
|
|
169
164
|
case 2:
|
|
170
165
|
_b.sent();
|
|
171
166
|
logger_js_1.default.info("\n 🚀 Let's go!");
|
|
172
|
-
|
|
173
|
-
|
|
167
|
+
if (!flags.logFile) return [3 /*break*/, 4];
|
|
168
|
+
logStream = fs_1.default.createWriteStream(flags.logFile, { flags: 'a' });
|
|
169
|
+
return [4 /*yield*/, (0, node_events_1.once)(logStream, 'open')];
|
|
174
170
|
case 3:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
171
|
+
_b.sent();
|
|
172
|
+
applyCodemods(logStream);
|
|
173
|
+
logStream.end();
|
|
174
|
+
return [3 /*break*/, 5];
|
|
178
175
|
case 4:
|
|
179
|
-
|
|
180
|
-
|
|
176
|
+
applyCodemods();
|
|
177
|
+
_b.label = 5;
|
|
181
178
|
case 5:
|
|
182
|
-
_b.sent();
|
|
183
|
-
logger_js_1.default.info("\n 🚀 Let's go!");
|
|
184
|
-
codemodes = (0, getAvailableCodemods_js_1.default)(transformsVersion);
|
|
185
|
-
codemodes.forEach(function (codemod) {
|
|
186
|
-
logger_js_1.default.info("Codemod ".concat(codemod, " in process..."));
|
|
187
|
-
runJSCodeShift(codemod, transformsVersion, workingDirectory, flags);
|
|
188
|
-
});
|
|
189
|
-
_b.label = 6;
|
|
190
|
-
case 6:
|
|
191
179
|
logger_js_1.default.info("\n All done! Please check that everything is applied correctly.\n If it's not the case - feel free to contact VKUI Team.\n Do not forget to run ".concat(chalk_1.default.cyan.bold('prettier'), " to eliminate unwanted code formatting after applying migrations.\n Happy coding with ").concat(chalk_1.default.green.bold("v".concat(transformsVersion)), "!"));
|
|
192
180
|
return [2 /*return*/];
|
|
193
181
|
}
|