@vkontakte/vkui-codemods 0.0.3

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.
Files changed (46) hide show
  1. package/README.md +63 -0
  2. package/dist/cli.js +113 -0
  3. package/dist/codemod-helpers.js +76 -0
  4. package/dist/getAvailableCodemods.js +19 -0
  5. package/dist/helpers/logger.js +30 -0
  6. package/dist/index.js +193 -0
  7. package/dist/report.js +13 -0
  8. package/dist/transforms/accordion.js +25 -0
  9. package/dist/transforms/action-sheet-item.js +33 -0
  10. package/dist/transforms/action-sheet.js +45 -0
  11. package/dist/transforms/alert.js +48 -0
  12. package/dist/transforms/appearance-provider.js +19 -0
  13. package/dist/transforms/banner.js +22 -0
  14. package/dist/transforms/calendar-range.js +21 -0
  15. package/dist/transforms/calendar.js +23 -0
  16. package/dist/transforms/chip.js +17 -0
  17. package/dist/transforms/chips-input.js +17 -0
  18. package/dist/transforms/config-provider.js +68 -0
  19. package/dist/transforms/content-card.js +19 -0
  20. package/dist/transforms/custom-scroll-view.js +26 -0
  21. package/dist/transforms/date-input.js +25 -0
  22. package/dist/transforms/date-range-input.js +29 -0
  23. package/dist/transforms/fixed-layout.js +32 -0
  24. package/dist/transforms/forbid-imports.js +25 -0
  25. package/dist/transforms/form-item.js +23 -0
  26. package/dist/transforms/gradient-prop-change.js +29 -0
  27. package/dist/transforms/horizontal-cell-show-more.js +22 -0
  28. package/dist/transforms/modal-card.js +32 -0
  29. package/dist/transforms/modal-page-header.js +32 -0
  30. package/dist/transforms/pagination.js +31 -0
  31. package/dist/transforms/panel-header-content.js +32 -0
  32. package/dist/transforms/popover.js +118 -0
  33. package/dist/transforms/popper.js +95 -0
  34. package/dist/transforms/range-slider.js +49 -0
  35. package/dist/transforms/rich-tooltip.js +24 -0
  36. package/dist/transforms/search.js +18 -0
  37. package/dist/transforms/simple-cell.js +47 -0
  38. package/dist/transforms/split-col.js +33 -0
  39. package/dist/transforms/tappable.js +30 -0
  40. package/dist/transforms/text-tooltip.js +139 -0
  41. package/dist/transforms/tooltip.js +162 -0
  42. package/dist/transforms/typography.js +68 -0
  43. package/dist/transforms/users-stack.js +33 -0
  44. package/dist/transforms/visually-hidden-input.js +42 -0
  45. package/dist/types.js +2 -0
  46. package/package.json +44 -0
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # VKUI v6 Codemods
2
+
3
+ Чтобы упростить переход на новую мажорную версию, можно воспользоваться инструментом по автоматической миграции ваших компонентов.
4
+
5
+ > Для начала обновите ваше приложение до новой мажорной версии (**v6**) в соответствии с требованиями вашего пакетного менеджера и среды
6
+
7
+ > Обратите внимание, минимальная поддерживаемая версия **React** увеличена до `v18.2.0`
8
+
9
+ > Пока для перевода доступны только `Typescript`-файлы (_.ts/_.tsx)
10
+
11
+ Перейдите в директорию с исходниками вашего проекта (обычно это `src/`) и запустите следующую команду:
12
+
13
+ ```shell
14
+ npx @vkontakte/vkui-codemods
15
+ ```
16
+
17
+ Инструмент представляет собой консольное приложение, с помощью которого вы можете выбрать необходимые изменения и применить их, доступны следующие команды:
18
+
19
+ ```
20
+ $ npx @vkontakte/vkui-codemods --help
21
+
22
+ Usage: @vkontakte/vkui-codemod [codemod-name]
23
+
24
+ Arguments:
25
+ codemod-name which codemod should be applied
26
+
27
+ Options:
28
+ -V, --version output the version number
29
+ -l --list list available codemods
30
+ --all apply all available codemods
31
+ -p --path <paths> path to files in which to apply the codemods (default: current directory)
32
+ --dry-run no changes are made to files
33
+ --ignore-config <config> ignore files if they match patterns sourced from a configuration file (e.g. a .gitignore)
34
+ --debug all logs are shown
35
+ --alias <alias> in case you have adapter over original library (default: "@vkontakte/vkui")
36
+ -h, --help display help for command
37
+ ```
38
+
39
+ При запуске приложения без аргументов будет предложено выбрать один из имеющихся codemod (их название отражает название компонента, к которому будет применено изменение). Если вам необходимо применить все имеющиеся codemods, запустите команду с опцией `--all`:
40
+
41
+ ```shell
42
+ npx @vkontakte/vkui-codemods --all
43
+ ```
44
+
45
+ Если вы хотите исключить некоторые файлы или директории из обработки, то временно создайте файл (по примеру .gitignore) с перечисленными исключениями:
46
+
47
+ ```shell
48
+ npx @vkontakte/vkui-codemods --all --path "./examples" --ignore-config "./.codemodignore"
49
+ ```
50
+
51
+ ```
52
+ // .codemodignore
53
+ MyBeautifulComponentToIgnore.tsx
54
+ directoryToIgnore/
55
+ ```
56
+
57
+ Приведенная выше команда применит все codemods в директории `examples` (находится в корне текущей директории), игонорируя файл `MyBeautifulComponentToIgnore.tsx` и директорию `directoryToIgnore`, указанные в `.codemodignore` (находится в корне текущей директории)
58
+
59
+ > Обратите внимание, если вы используете собственный адаптер над библиотекой `VKUI` и делаете ре-экспорт существующих компонентов, то можете воспользоваться опцией `--alias` для указания правильного пути.
60
+
61
+ ```shell
62
+ npx @vkontakte/vkui-codemods --all --alias "@myscope/VKUIFake"
63
+ ```
package/dist/cli.js ADDED
@@ -0,0 +1,113 @@
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;
13
+ return g = { next: verb(0), "throw": verb(1), "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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.runCli = void 0;
43
+ var chalk_1 = __importDefault(require("chalk"));
44
+ var commander_1 = require("commander");
45
+ var prompts_1 = __importDefault(require("prompts"));
46
+ var getAvailableCodemods_js_1 = __importDefault(require("./getAvailableCodemods.js"));
47
+ var logger_js_1 = __importDefault(require("./helpers/logger.js"));
48
+ var package_json_1 = __importDefault(require("../package.json"));
49
+ var trimStringValue = function (value) {
50
+ return typeof value === 'string' ? value.trim() : value;
51
+ };
52
+ var promptAvailableCodemods = function (codemods) { return __awaiter(void 0, void 0, void 0, function () {
53
+ var codemod;
54
+ return __generator(this, function (_a) {
55
+ switch (_a.label) {
56
+ case 0: return [4 /*yield*/, (0, prompts_1.default)({
57
+ type: 'select',
58
+ name: 'codemod',
59
+ message: 'Pick a codemod',
60
+ initial: 0,
61
+ choices: codemods.map(function (name) { return ({ title: name, value: name }); }),
62
+ }, {
63
+ onCancel: function () {
64
+ process.exit(1);
65
+ },
66
+ })];
67
+ case 1:
68
+ codemod = (_a.sent()).codemod;
69
+ return [2 /*return*/, codemod];
70
+ }
71
+ });
72
+ }); };
73
+ var runCli = function () { return __awaiter(void 0, void 0, void 0, function () {
74
+ var program, options, codemodName, codemods, codemods;
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0:
78
+ program = new commander_1.Command('@vkontakte/vkui-codemod')
79
+ .version(package_json_1.default.version || 'unknown')
80
+ .argument('[codemod-name]', 'which codemod should be applied', trimStringValue)
81
+ .usage("".concat(chalk_1.default.green('[codemod-name]')))
82
+ .option('-l --list', 'list available codemods')
83
+ .option('--all', 'apply all available codemods')
84
+ .option('-p --path <paths>', 'path to files in which to apply the codemods')
85
+ .option('--dry-run', 'no changes are made to files')
86
+ .option('--ignore-config <config>', 'ignore files if they match patterns sourced from a configuration file (e.g. a .gitignore)')
87
+ .option('--debug', "all logs are shown")
88
+ .option('--alias <alias>', "in case you have adapter over original library", '@vkontakte/vkui')
89
+ .configureOutput({
90
+ writeErr: function (str) { return logger_js_1.default.info("".concat(chalk_1.default.red(str))); },
91
+ })
92
+ .parse(process.argv);
93
+ options = program.opts();
94
+ codemodName = program.args[0];
95
+ if (options.list) {
96
+ codemods = (0, getAvailableCodemods_js_1.default)();
97
+ logger_js_1.default.info(codemods);
98
+ process.exit(0);
99
+ }
100
+ if (!(!codemodName && !options.all)) return [3 /*break*/, 2];
101
+ codemods = (0, getAvailableCodemods_js_1.default)();
102
+ return [4 /*yield*/, promptAvailableCodemods(codemods)];
103
+ case 1:
104
+ codemodName = _a.sent();
105
+ _a.label = 2;
106
+ case 2: return [2 /*return*/, {
107
+ flags: options,
108
+ codemodName: codemodName,
109
+ }];
110
+ }
111
+ });
112
+ }); };
113
+ exports.runCli = runCli;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAttributeManipulator = exports.renameProp = exports.getImportInfo = void 0;
4
+ function getImportInfo(j, file, componentName, alias) {
5
+ var source = j(file.source);
6
+ var localImportName = componentName;
7
+ var componentImport = source
8
+ .find(j.ImportDeclaration)
9
+ .filter(function (path) { return path.node.source.value === alias; })
10
+ .find(j.ImportSpecifier, { imported: { name: componentName } });
11
+ componentImport.forEach(function (path) {
12
+ if (path.node.local && path.node.local.name !== path.node.imported.name) {
13
+ localImportName = path.node.local.name;
14
+ }
15
+ });
16
+ return { localName: localImportName };
17
+ }
18
+ exports.getImportInfo = getImportInfo;
19
+ function renameProp(j, source, componentName, renameMap) {
20
+ var from = Object.keys(renameMap);
21
+ return source
22
+ .find(j.JSXOpeningElement)
23
+ .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === componentName; })
24
+ .find(j.JSXAttribute)
25
+ .filter(function (attribute) {
26
+ var attributeName = attribute.node.name.name;
27
+ return typeof attributeName === 'string' ? from.includes(attributeName) : false;
28
+ })
29
+ .forEach(function (attribute) {
30
+ j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier(renameMap[attribute.node.name.name]), attribute.node.value));
31
+ });
32
+ }
33
+ exports.renameProp = renameProp;
34
+ var createAttributeManipulator = function (props, api) {
35
+ var map = new Map(Object.entries(props));
36
+ return {
37
+ has: function (attributeKey) {
38
+ return typeof attributeKey === 'string' ? map.has(attributeKey) : false;
39
+ },
40
+ getReplacers: function (attributeKeyProp) {
41
+ var attributeKey = typeof attributeKeyProp === 'string' ? attributeKeyProp : '';
42
+ var found = map.get(attributeKey);
43
+ if (found && found.reportText) {
44
+ var text = typeof found.reportText === 'function' ? found.reportText() : found.reportText;
45
+ try {
46
+ api.report(text);
47
+ }
48
+ catch (_a) {
49
+ console.warn(text);
50
+ }
51
+ }
52
+ return {
53
+ action: found && found.action,
54
+ keyTo: function () {
55
+ if (!found || !found.keyTo) {
56
+ return attributeKey;
57
+ }
58
+ if (typeof found.keyTo === 'string') {
59
+ return found.keyTo;
60
+ }
61
+ return found.keyTo(attributeKey);
62
+ },
63
+ valueTo: function (attributeKeyValue) {
64
+ if (!found || !found.valueTo) {
65
+ return attributeKeyValue;
66
+ }
67
+ if (typeof found.valueTo === 'string') {
68
+ return found.valueTo;
69
+ }
70
+ return found.valueTo(attributeKeyValue, api);
71
+ },
72
+ };
73
+ },
74
+ };
75
+ };
76
+ exports.createAttributeManipulator = createAttributeManipulator;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TRANSFORM_DIR = void 0;
7
+ var fs_1 = __importDefault(require("fs"));
8
+ exports.TRANSFORM_DIR = "".concat(__dirname, "/transforms");
9
+ var CODEMODS = [];
10
+ function getAvailableCodemods() {
11
+ if (CODEMODS.length === 0) {
12
+ CODEMODS = fs_1.default
13
+ .readdirSync(exports.TRANSFORM_DIR)
14
+ .filter(function (fname) { return fname.endsWith('.js'); })
15
+ .map(function (fname) { return fname.slice(0, -3); });
16
+ }
17
+ return CODEMODS;
18
+ }
19
+ exports.default = getAvailableCodemods;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Logger = /** @class */ (function () {
4
+ function Logger() {
5
+ this.quiet = false;
6
+ }
7
+ Logger.prototype.setQuietMode = function () {
8
+ this.quiet = true;
9
+ };
10
+ Logger.prototype.log = function (level, message) {
11
+ if (this.quiet) {
12
+ return;
13
+ }
14
+ console.log("[".concat(level, "]: "), message, '\n');
15
+ };
16
+ Logger.prototype.debug = function (message) {
17
+ this.log('debug', message);
18
+ };
19
+ Logger.prototype.info = function (message) {
20
+ this.log('info', message);
21
+ };
22
+ Logger.prototype.warn = function (message) {
23
+ this.log('warn', message);
24
+ };
25
+ Logger.prototype.error = function (message) {
26
+ this.log('error', message);
27
+ };
28
+ return Logger;
29
+ }());
30
+ exports.default = new Logger();
package/dist/index.js ADDED
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env node
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ var __generator = (this && this.__generator) || function (thisArg, body) {
36
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
37
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
38
+ function verb(n) { return function (v) { return step([n, v]); }; }
39
+ function step(op) {
40
+ if (f) throw new TypeError("Generator is already executing.");
41
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
42
+ 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;
43
+ if (y = 0, t) op = [op[0] & 2, t.value];
44
+ switch (op[0]) {
45
+ case 0: case 1: t = op; break;
46
+ case 4: _.label++; return { value: op[1], done: false };
47
+ case 5: _.label++; y = op[1]; op = [0]; continue;
48
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
49
+ default:
50
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
51
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
52
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
53
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
54
+ if (t[2]) _.ops.pop();
55
+ _.trys.pop(); continue;
56
+ }
57
+ op = body.call(thisArg, _);
58
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
59
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
60
+ }
61
+ };
62
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
63
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
64
+ if (ar || !(i in from)) {
65
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
66
+ ar[i] = from[i];
67
+ }
68
+ }
69
+ return to.concat(ar || Array.prototype.slice.call(from));
70
+ };
71
+ var __importDefault = (this && this.__importDefault) || function (mod) {
72
+ return (mod && mod.__esModule) ? mod : { "default": mod };
73
+ };
74
+ Object.defineProperty(exports, "__esModule", { value: true });
75
+ var chalk_1 = __importDefault(require("chalk"));
76
+ var cross_spawn_1 = require("cross-spawn");
77
+ var prompts_1 = __importDefault(require("prompts"));
78
+ var cli_js_1 = require("./cli.js");
79
+ var getAvailableCodemods_js_1 = __importStar(require("./getAvailableCodemods.js"));
80
+ var logger_js_1 = __importDefault(require("./helpers/logger.js"));
81
+ function runJSCodeShift(codemodName, workingDirectory, flags) {
82
+ var args = ['--parser=tsx', '--extensions=tsx,ts', "--alias=".concat(flags.alias)];
83
+ if (flags.dryRun) {
84
+ args.push('--dry');
85
+ }
86
+ if (flags.ignoreConfig) {
87
+ args.push("--ignore-config=".concat(flags.ignoreConfig));
88
+ }
89
+ if (!flags.debug) {
90
+ args.push('--silent');
91
+ }
92
+ var result = (0, cross_spawn_1.sync)('node', __spreadArray(__spreadArray([
93
+ require.resolve('jscodeshift/bin/jscodeshift'),
94
+ '--no-babel',
95
+ '--fail-on-error',
96
+ '-t',
97
+ "".concat(getAvailableCodemods_js_1.TRANSFORM_DIR, "/").concat(codemodName, ".js")
98
+ ], args, true), [
99
+ workingDirectory,
100
+ ], false), {
101
+ stdio: 'inherit',
102
+ shell: true,
103
+ });
104
+ if (result.status === 1) {
105
+ logger_js_1.default.error("Codemod ".concat(codemodName, " failed to apply"));
106
+ return;
107
+ }
108
+ }
109
+ function promptConfirmation() {
110
+ return __awaiter(this, void 0, void 0, function () {
111
+ var confirmation;
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0: return [4 /*yield*/, (0, prompts_1.default)({
115
+ type: 'toggle',
116
+ name: 'confirmation',
117
+ message: "Would you like to continue?",
118
+ initial: true,
119
+ active: 'Yes',
120
+ inactive: 'No',
121
+ }, {
122
+ onCancel: function () {
123
+ process.exit(1);
124
+ },
125
+ })];
126
+ case 1:
127
+ confirmation = (_a.sent()).confirmation;
128
+ return [2 /*return*/, confirmation];
129
+ }
130
+ });
131
+ });
132
+ }
133
+ function verifyConfiguration(workingDirectory, codemodName) {
134
+ return __awaiter(this, void 0, void 0, function () {
135
+ var confirmed;
136
+ return __generator(this, function (_a) {
137
+ switch (_a.label) {
138
+ case 0:
139
+ logger_js_1.default.info("Please ".concat(chalk_1.default.cyan('verify'), " the following information:\n working directory: ").concat(workingDirectory, "\n codemod to apply: ").concat(codemodName ? codemodName : chalk_1.default.red('all'), "\n "));
140
+ return [4 /*yield*/, promptConfirmation()];
141
+ case 1:
142
+ confirmed = _a.sent();
143
+ if (!confirmed) {
144
+ logger_js_1.default.info('Exiting without changes...');
145
+ process.exit(0);
146
+ }
147
+ return [2 /*return*/];
148
+ }
149
+ });
150
+ });
151
+ }
152
+ var run = function () { return __awaiter(void 0, void 0, void 0, function () {
153
+ var _a, flags, codemodName, workingDirectory, codemodes, codemodes;
154
+ return __generator(this, function (_b) {
155
+ switch (_b.label) {
156
+ case 0: return [4 /*yield*/, (0, cli_js_1.runCli)()];
157
+ case 1:
158
+ _a = _b.sent(), flags = _a.flags, codemodName = _a.codemodName;
159
+ workingDirectory = flags.path ? flags.path : process.cwd();
160
+ if (!(codemodName && workingDirectory)) return [3 /*break*/, 4];
161
+ codemodes = (0, getAvailableCodemods_js_1.default)();
162
+ if (!codemodes.includes(codemodName)) return [3 /*break*/, 3];
163
+ return [4 /*yield*/, verifyConfiguration(workingDirectory, codemodName)];
164
+ case 2:
165
+ _b.sent();
166
+ logger_js_1.default.info("\n 🚀 Let's go!");
167
+ runJSCodeShift(codemodName, workingDirectory, flags);
168
+ return [3 /*break*/, 4];
169
+ case 3:
170
+ logger_js_1.default.error("Codemod ".concat(codemodName, " doesn't exist. Please check the available codemods by running with --list option"));
171
+ process.exit(0);
172
+ _b.label = 4;
173
+ case 4:
174
+ if (!(flags.all && workingDirectory)) return [3 /*break*/, 6];
175
+ return [4 /*yield*/, verifyConfiguration(workingDirectory)];
176
+ case 5:
177
+ _b.sent();
178
+ logger_js_1.default.info("\n 🚀 Let's go!");
179
+ codemodes = (0, getAvailableCodemods_js_1.default)();
180
+ codemodes.forEach(function (codemod) {
181
+ logger_js_1.default.info("Codemod ".concat(codemod, " in process..."));
182
+ runJSCodeShift(codemod, workingDirectory, flags);
183
+ });
184
+ _b.label = 6;
185
+ case 6:
186
+ logger_js_1.default.info("\n All done! Please check if everything is applied correctly. \n If it's not the case - feel free to contact VKUI Team. \n Happy coding with ".concat(chalk_1.default.green.bold('v6'), "!"));
187
+ return [2 /*return*/];
188
+ }
189
+ });
190
+ }); };
191
+ run().catch(function (error) {
192
+ logger_js_1.default.error(error);
193
+ });
package/dist/report.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.report = void 0;
7
+ var chalk_1 = __importDefault(require("chalk"));
8
+ var package_json_1 = __importDefault(require("../package.json"));
9
+ function report(api, message) {
10
+ var report = api.report;
11
+ report("".concat(message, " Advise ").concat(chalk_1.default.white.bgBlue.bold('migration guide'), " - ").concat(package_json_1.default.homepage, "#/Migration \n\n"));
12
+ }
13
+ exports.report = report;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parser = void 0;
7
+ var chalk_1 = __importDefault(require("chalk"));
8
+ var codemod_helpers_1 = require("../codemod-helpers");
9
+ var report_1 = require("../report");
10
+ exports.parser = 'tsx';
11
+ function transformer(file, api, options) {
12
+ var alias = options.alias;
13
+ var j = api.jscodeshift;
14
+ var source = j(file.source);
15
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Accordion', alias).localName;
16
+ (0, codemod_helpers_1.renameProp)(j, source, localName, { open: 'expanded' });
17
+ var accordionComponents = source
18
+ .find(j.JSXOpeningElement)
19
+ .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; });
20
+ if (accordionComponents.length > 0) {
21
+ (0, report_1.report)(api, ": ".concat(chalk_1.default.white.bgBlue('Accordion'), " has been changed. Manual changes required."));
22
+ }
23
+ return source.toSource();
24
+ }
25
+ exports.default = transformer;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ var codemod_helpers_1 = require("../codemod-helpers");
5
+ exports.parser = 'tsx';
6
+ function transformer(file, api, options) {
7
+ var alias = options.alias;
8
+ var j = api.jscodeshift;
9
+ var source = j(file.source);
10
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'ActionSheetItem', alias).localName;
11
+ source
12
+ .find(j.JSXOpeningElement)
13
+ .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
14
+ .find(j.JSXAttribute)
15
+ .filter(function (attribute) { return attribute.node.name.name === 'autoClose'; })
16
+ .forEach(function (attribute) {
17
+ var node = attribute.node;
18
+ if (!node.value) {
19
+ j(attribute).remove();
20
+ }
21
+ else if (node.value.type === 'JSXExpressionContainer' &&
22
+ node.value.expression.type === 'BooleanLiteral') {
23
+ if (node.value.expression.value) {
24
+ j(attribute).remove();
25
+ }
26
+ else {
27
+ j(attribute).replaceWith(j.jsxAttribute(j.jsxIdentifier('autoCloseDisabled')));
28
+ }
29
+ }
30
+ });
31
+ return source.toSource();
32
+ }
33
+ exports.default = transformer;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parser = void 0;
7
+ var chalk_1 = __importDefault(require("chalk"));
8
+ var codemod_helpers_1 = require("../codemod-helpers");
9
+ var report_1 = require("../report");
10
+ exports.parser = 'tsx';
11
+ function transformer(file, api, options) {
12
+ var alias = options.alias;
13
+ var j = api.jscodeshift;
14
+ var source = j(file.source);
15
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'ActionSheet', alias).localName;
16
+ var openingTargetElements = source
17
+ .find(j.JSXOpeningElement)
18
+ .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; });
19
+ openingTargetElements.forEach(function (path) {
20
+ var attributes = path.value.attributes;
21
+ var noRequiredProp = true;
22
+ if (attributes) {
23
+ attributes.forEach(function (attr) {
24
+ if (attr.type === 'JSXAttribute') {
25
+ if (attr.name.name === 'toggleRef') {
26
+ noRequiredProp = false;
27
+ }
28
+ if (attr.name.name === 'popupDirection' && attr.value) {
29
+ if (attr.value.type === 'StringLiteral') {
30
+ attr.name.name = 'placement';
31
+ }
32
+ else {
33
+ (0, report_1.report)(api, ": prop ".concat(chalk_1.default.white.bgBlue('popupDirection'), " in ").concat(chalk_1.default.white.bgBlue('ActionSheet'), " must be replaced manually."));
34
+ }
35
+ }
36
+ }
37
+ });
38
+ }
39
+ if (noRequiredProp) {
40
+ (0, report_1.report)(api, ": prop ".concat(chalk_1.default.white.bgBlue('toggleRef'), " in ").concat(chalk_1.default.white.bgBlue('ActionSheet'), " is required."));
41
+ }
42
+ });
43
+ return source.toSource();
44
+ }
45
+ exports.default = transformer;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parser = void 0;
4
+ var codemod_helpers_1 = require("../codemod-helpers");
5
+ exports.parser = 'tsx';
6
+ function replaceInArrayExpression(j, path) {
7
+ j(path)
8
+ .find(j.ArrayExpression)
9
+ .find(j.ObjectExpression)
10
+ .find(j.ObjectProperty)
11
+ .filter(function (path) { return path.value.key.type === 'Identifier' && path.value.key.name === 'autoClose'; })
12
+ .forEach(function (property) {
13
+ var propertyValue = property.value;
14
+ if (propertyValue.value.type === 'BooleanLiteral') {
15
+ if (propertyValue.value.value) {
16
+ j(property).remove();
17
+ }
18
+ else {
19
+ j(property).replaceWith(j.property('init', j.jsxIdentifier('autoCloseDisabled'), j.booleanLiteral(true)));
20
+ }
21
+ }
22
+ });
23
+ }
24
+ function transformer(file, api, options) {
25
+ var alias = options.alias;
26
+ var j = api.jscodeshift;
27
+ var source = j(file.source);
28
+ var localName = (0, codemod_helpers_1.getImportInfo)(j, file, 'Alert', alias).localName;
29
+ source
30
+ .find(j.JSXOpeningElement)
31
+ .filter(function (path) { return path.value.name.type === 'JSXIdentifier' && path.value.name.name === localName; })
32
+ .find(j.JSXAttribute)
33
+ .filter(function (attribute) { return attribute.node.name.name === 'actions'; })
34
+ .forEach(function (attribute) {
35
+ var node = attribute.node.value;
36
+ if (node && node.type === 'JSXExpressionContainer') {
37
+ replaceInArrayExpression(j, attribute);
38
+ if (node.expression.type === 'Identifier') {
39
+ var decl = source.findVariableDeclarators(node.expression.name);
40
+ decl.forEach(function (path) {
41
+ replaceInArrayExpression(j, path);
42
+ });
43
+ }
44
+ }
45
+ });
46
+ return source.toSource();
47
+ }
48
+ exports.default = transformer;