@ornikar/kitt-universal 25.58.0 → 25.58.1-canary.3703fdd8c845452ef85a7328ca509b5645f6f56f.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.3703fdd8c845452ef85a7328ca509b5645f6f56f.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,102 @@
1
+ 'use strict';
2
+
3
+ /* eslint-disable prefer-destructuring */
4
+ /* eslint-disable unicorn/no-array-method-this-argument */
5
+
6
+ // Use local jscodeshift instance directly
7
+ const jscodeshift = require('jscodeshift');
8
+
9
+ // List of modal component names we want to transform
10
+ const MODAL_COMPONENTS = ['FullscreenModal', 'CardModal', 'NavigationModal'];
11
+
12
+ module.exports = function transformer(fileInfo, api) {
13
+ // Use the jscodeshift API to parse the file
14
+ const j = api.jscodeshift || jscodeshift;
15
+
16
+ // Parse the source code of the file
17
+ const root = j(fileInfo.source);
18
+
19
+ // Iterate over each modal component found in the source code
20
+ MODAL_COMPONENTS.forEach((componentName) => {
21
+ // Find instances of the modal component
22
+ root
23
+ .find(j.JSXElement, {
24
+ openingElement: {
25
+ name: { type: 'JSXIdentifier', name: componentName },
26
+ },
27
+ })
28
+ .forEach((path) => {
29
+ // Get the node (the JSXElement) from the path
30
+ const node = path.node;
31
+
32
+ // Check if the modal component already has children or if it is self-closing
33
+ const hasChildren = Array.isArray(node.children) && node.children.length > 0;
34
+ if (!node.openingElement.selfClosing && hasChildren) {
35
+ // If it already has children, do nothing and skip transformation
36
+ return;
37
+ }
38
+
39
+ // Extract the attributes from the JSX element (like `header`, `body`, `footer`)
40
+ const attributes = node.openingElement.attributes;
41
+
42
+ // Initialize a map to hold potential new children: header, body, footer
43
+ const newChildrenMap = {
44
+ header: null,
45
+ body: null,
46
+ footer: null,
47
+ };
48
+
49
+ // An array to keep attributes that are not `header`, `body`, or `footer`
50
+ const keptAttributes = [];
51
+
52
+ // Loop over the attributes to check if any match `header`, `body`, or `footer`
53
+ attributes.forEach((attr) => {
54
+ if (
55
+ attr.type === 'JSXAttribute' &&
56
+ attr.name &&
57
+ Object.prototype.hasOwnProperty.call(newChildrenMap, attr.name.name)
58
+ ) {
59
+ const key = attr.name.name;
60
+ const value = attr.value;
61
+
62
+ // Check if the value of the attribute is an expression (like a ternary)
63
+ if (value?.type === 'JSXExpressionContainer') {
64
+ const expression = value.expression;
65
+
66
+ // If it's a JSXElement or JSXFragment, keep it as it is
67
+ if (j.JSXElement.check(expression) || j.JSXFragment.check(expression)) {
68
+ newChildrenMap[key] = expression;
69
+ } else {
70
+ // Otherwise, wrap it in an expression container to handle non-JSX expressions
71
+ newChildrenMap[key] = j.jsxExpressionContainer(expression);
72
+ }
73
+ }
74
+ } else {
75
+ // Keep any other attributes (that are not header/body/footer)
76
+ keptAttributes.push(attr);
77
+ }
78
+ });
79
+
80
+ // If no new children were found (no `header`, `body`, or `footer`), do nothing
81
+ if (Object.values(newChildrenMap).every((v) => v === null)) {
82
+ return;
83
+ }
84
+
85
+ // If the modal component was self-closing, convert it to a regular JSX element with children
86
+ if (node.openingElement.selfClosing) {
87
+ node.openingElement.selfClosing = false;
88
+ node.closingElement = j.jsxClosingElement(j.jsxIdentifier(node.openingElement.name.name));
89
+ }
90
+
91
+ // Retain all the other attributes and set the new ones
92
+ node.openingElement.attributes = keptAttributes;
93
+
94
+ // Force the order of children: header → body → footer
95
+ const orderedChildren = Object.values(newChildrenMap).filter(Boolean);
96
+ node.children = orderedChildren;
97
+ });
98
+ });
99
+
100
+ // Return the modified source code after transformation
101
+ return root.toSource({ quote: 'single' });
102
+ };