@ornikar/kitt-universal 25.58.0 → 25.58.1-canary.01e4aa02ad8f3c2fd23f16498fb058cc1cad88cd.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ornikar/kitt-universal",
3
- "version": "25.58.0",
3
+ "version": "25.58.1-canary.01e4aa02ad8f3c2fd23f16498fb058cc1cad88cd.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "directory": "@ornikar/kitt-universal",
@@ -71,10 +71,15 @@
71
71
  "./translations/es-ES.json": "./translations/es-ES.json",
72
72
  "./babel-plugin-csf-to-jest": "./babel-plugin-csf-to-jest.js"
73
73
  },
74
+ "bin": {
75
+ "run-all-transforms": "./scripts/run-all-transformers.js",
76
+ "run-transform": "./scripts/run-transformer.js"
77
+ },
74
78
  "engines": {
75
79
  "node": ">=20.10.0"
76
80
  },
77
81
  "scripts": {
82
+ "migrate": "node scripts/run-all-transforms.js",
78
83
  "build": "ORNIKAR_ONLY=kitt-universal yarn ../.. build",
79
84
  "lint:eslint": "yarn ../.. eslint --report-unused-disable-directives --quiet @ornikar/kitt-universal"
80
85
  },
@@ -166,6 +171,7 @@
166
171
  "@types/react-transition-group": "4.2.3",
167
172
  "expo-document-picker": "11.10.1",
168
173
  "expo-image-picker": "14.7.1",
174
+ "jscodeshift": "17.3.0",
169
175
  "react": "18.3.1",
170
176
  "react-dom": "18.3.1",
171
177
  "react-error-boundary": "3.1.4",
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const { spawnSync } = require('node:child_process');
6
+ const fs = require('node:fs');
7
+ const path = require('node:path');
8
+
9
+ // --- Handle CLI arguments ---
10
+ const targetPath = process.argv[2];
11
+
12
+ if (!targetPath) {
13
+ console.error('❌ Usage: node scripts/run-all-transformers.js <targetPath>');
14
+ process.exit(1);
15
+ }
16
+
17
+ // Ensure the path exists
18
+ if (!fs.existsSync(targetPath)) {
19
+ console.error(`❌ Path "${targetPath}" does not exist.`);
20
+ process.exit(1);
21
+ }
22
+
23
+ const transformsDir = path.join(__dirname, 'transformers');
24
+
25
+ // Read all .js files in the transformers directory
26
+ const transformFiles = fs.readdirSync(transformsDir).filter((file) => file.endsWith('.js'));
27
+
28
+ if (transformFiles.length === 0) {
29
+ console.log('✅ No transformers to apply.');
30
+ process.exit(0);
31
+ }
32
+
33
+ console.log(`🛠 Found ${transformFiles.length} transformer(s) to apply to: ${targetPath}\n`);
34
+
35
+ transformFiles.forEach((file) => {
36
+ const transformPath = path.join(transformsDir, file);
37
+ console.log(`➡️ Running transformer: ${file}`);
38
+
39
+ const result = spawnSync(
40
+ 'jscodeshift',
41
+ ['-t', transformPath, targetPath, '--parser=tsx'],
42
+ { stdio: 'inherit' }, // Show output in terminal
43
+ );
44
+
45
+ if (result.error) {
46
+ console.error(`❌ Error running ${file}:`, result.error.message);
47
+ } else {
48
+ console.log(`✅ Finished: ${file}\n`);
49
+ }
50
+ });
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ const { spawnSync } = require('node:child_process');
6
+ const fs = require('node:fs');
7
+ const path = require('node:path');
8
+
9
+ // --- Handle CLI arguments ---
10
+ const transformerName = process.argv[2];
11
+ const targetPath = process.argv[3];
12
+
13
+ if (!transformerName || !targetPath) {
14
+ console.error('❌ Usage: node scripts/run-transformer.js <transformerName> <targetPath>');
15
+ process.exit(1);
16
+ }
17
+
18
+ const transformPath = path.join(__dirname, 'transformers', `${transformerName}.js`);
19
+
20
+ // Ensure the transformer file exists
21
+ if (!fs.existsSync(transformPath)) {
22
+ console.error(`❌ Transform "${transformerName}" not found at ${transformPath}`);
23
+ process.exit(1);
24
+ }
25
+
26
+ // Ensure the path exists
27
+ if (!fs.existsSync(targetPath)) {
28
+ console.error(`❌ Target path "${targetPath}" does not exist.`);
29
+ process.exit(1);
30
+ }
31
+
32
+ console.log(`➡️ Running transformer "${transformerName}" on ${targetPath}\n`);
33
+
34
+ const result = spawnSync('jscodeshift', ['-t', transformPath, targetPath, '--parser=tsx'], { stdio: 'inherit' });
35
+
36
+ if (result.error) {
37
+ console.error('❌ Error:', result.error.message);
38
+ process.exit(1);
39
+ } else {
40
+ console.log(`✅ Transform "${transformerName}" completed.`);
41
+ }
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable prefer-destructuring */
4
+ /* eslint-disable unicorn/no-array-method-this-argument */
5
+
6
+ // List of modal component names we want to transform
7
+ const MODAL_COMPONENTS = ['FullscreenModal', 'CardModal', 'NavigationModal'];
8
+
9
+ module.exports = function transformer(fileInfo, api) {
10
+ // jscodeshift library
11
+ const j = api.jscodeshift;
12
+ // Parse the source code of the file
13
+ const root = j(fileInfo.source);
14
+
15
+ // Iterate over each modal component found in the source code
16
+ MODAL_COMPONENTS.forEach((componentName) => {
17
+ // Find instances of the modal component
18
+ root
19
+ .find(j.JSXElement, {
20
+ openingElement: {
21
+ name: { type: 'JSXIdentifier', name: componentName },
22
+ },
23
+ })
24
+ .forEach((path) => {
25
+ // Get the node (the JSXElement) from the path
26
+ const node = path.node;
27
+
28
+ // Check if the modal component already has children or if it is self-closing
29
+ const hasChildren = Array.isArray(node.children) && node.children.length > 0;
30
+ if (!node.openingElement.selfClosing && hasChildren) {
31
+ // If it already has children, do nothing and skip transformation
32
+ return;
33
+ }
34
+
35
+ // Extract the attributes from the JSX element (like `header`, `body`, `footer`)
36
+ const attributes = node.openingElement.attributes;
37
+
38
+ // Initialize a map to hold potential new children: header, body, footer
39
+ const newChildrenMap = {
40
+ header: null,
41
+ body: null,
42
+ footer: null,
43
+ };
44
+
45
+ // An array to keep attributes that are not `header`, `body`, or `footer`
46
+ const keptAttributes = [];
47
+
48
+ // Loop over the attributes to check if any match `header`, `body`, or `footer`
49
+ attributes.forEach((attr) => {
50
+ if (
51
+ attr.type === 'JSXAttribute' &&
52
+ attr.name &&
53
+ Object.prototype.hasOwnProperty.call(newChildrenMap, attr.name.name)
54
+ ) {
55
+ const key = attr.name.name;
56
+ const value = attr.value;
57
+
58
+ // Check if the value of the attribute is an expression (like a ternary)
59
+ if (value?.type === 'JSXExpressionContainer') {
60
+ const expression = value.expression;
61
+
62
+ // If it's a JSXElement or JSXFragment, keep it as it is
63
+ if (j.JSXElement.check(expression) || j.JSXFragment.check(expression)) {
64
+ newChildrenMap[key] = expression;
65
+ } else {
66
+ // Otherwise, wrap it in an expression container to handle non-JSX expressions
67
+ newChildrenMap[key] = j.jsxExpressionContainer(expression);
68
+ }
69
+ }
70
+ } else {
71
+ // Keep any other attributes (that are not header/body/footer)
72
+ keptAttributes.push(attr);
73
+ }
74
+ });
75
+
76
+ // If no new children were found (no `header`, `body`, or `footer`), do nothing
77
+ if (Object.values(newChildrenMap).every((v) => v === null)) {
78
+ return;
79
+ }
80
+
81
+ // If the modal component was self-closing, convert it to a regular JSX element with children
82
+ if (node.openingElement.selfClosing) {
83
+ node.openingElement.selfClosing = false;
84
+ node.closingElement = j.jsxClosingElement(j.jsxIdentifier(node.openingElement.name.name));
85
+ }
86
+
87
+ // Retain all the other attributes and set the new ones
88
+ node.openingElement.attributes = keptAttributes;
89
+
90
+ // Force the order of children: header → body → footer
91
+ const orderedChildren = Object.values(newChildrenMap).filter(Boolean);
92
+ node.children = orderedChildren;
93
+ });
94
+ });
95
+
96
+ // Return the modified source code after transformation
97
+ return root.toSource({ quote: 'single' });
98
+ };