@availity/mui-codemod 0.1.0-alpha.0 → 0.1.0-alpha.1
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/CHANGELOG.md +7 -0
- package/dist/codemod.d.mts +193 -0
- package/dist/codemod.d.ts +193 -0
- package/dist/codemod.js +185 -0
- package/dist/codemod.mjs +168 -0
- package/package.json +1 -1
- package/src/codemod.js +3 -3
- package/src/lib/v1.0.0/grid-v2-props/index.js +1 -0
- package/src/lib/v1.0.0/system-props/index.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.1.0-alpha.1](https://github.com/Availity/element/compare/@availity/mui-codemod@0.1.0-alpha.0...@availity/mui-codemod@0.1.0-alpha.1) (2025-02-25)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **mui-codemod:** fix src references ([249d425](https://github.com/Availity/element/commit/249d425be22d33c30afa406bf3728f409875dcfd))
|
|
11
|
+
|
|
5
12
|
## 0.1.0-alpha.0 (2025-02-24)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const childProcess = require('child_process');
|
|
3
|
+
const { promises: fs } = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const yargs = require('yargs');
|
|
6
|
+
const jscodeshiftPackage = require('jscodeshift/package.json');
|
|
7
|
+
const postcssCliPackage = require('postcss-cli/package.json');
|
|
8
|
+
|
|
9
|
+
const jscodeshiftDirectory = path.dirname(require.resolve('jscodeshift'));
|
|
10
|
+
const jscodeshiftExecutable = path.join(jscodeshiftDirectory, jscodeshiftPackage.bin.jscodeshift);
|
|
11
|
+
|
|
12
|
+
const postcssCliDirectory = path.dirname(require.resolve('postcss-cli'));
|
|
13
|
+
const postcssExecutable = path.join(postcssCliDirectory, postcssCliPackage.bin.postcss);
|
|
14
|
+
|
|
15
|
+
async function runJscodeshiftTransform(transform, files, flags, codemodFlags) {
|
|
16
|
+
const paths = [
|
|
17
|
+
path.resolve(__dirname, './src', `${transform}/index.js`),
|
|
18
|
+
path.resolve(__dirname, './src', `${transform}.js`),
|
|
19
|
+
path.resolve(__dirname, './node', `${transform}/index.js`),
|
|
20
|
+
path.resolve(__dirname, './node', `${transform}.js`),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
let transformerPath;
|
|
24
|
+
let error;
|
|
25
|
+
for (const item of paths) {
|
|
26
|
+
try {
|
|
27
|
+
await fs.stat(item);
|
|
28
|
+
error = undefined;
|
|
29
|
+
transformerPath = item;
|
|
30
|
+
break;
|
|
31
|
+
} catch (srcPathError) {
|
|
32
|
+
error = srcPathError;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (error) {
|
|
38
|
+
if (error?.code === 'ENOENT') {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Transform '${transform}' not found. Check out ${path.resolve(__dirname, './README.md for a list of available codemods.')}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const args = [
|
|
47
|
+
jscodeshiftExecutable,
|
|
48
|
+
'--transform',
|
|
49
|
+
transformerPath,
|
|
50
|
+
...codemodFlags,
|
|
51
|
+
'--extensions',
|
|
52
|
+
'js,ts,jsx,tsx,json',
|
|
53
|
+
'--parser',
|
|
54
|
+
flags.parser || 'tsx',
|
|
55
|
+
'--ignore-pattern',
|
|
56
|
+
'**/node_modules/**',
|
|
57
|
+
'--ignore-pattern',
|
|
58
|
+
'**/*.css'
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
if (flags.dry) {
|
|
62
|
+
args.push('--dry');
|
|
63
|
+
}
|
|
64
|
+
if (flags.print) {
|
|
65
|
+
args.push('--print');
|
|
66
|
+
}
|
|
67
|
+
if (flags.jscodeshift) {
|
|
68
|
+
args.push(flags.jscodeshift);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
args.push(...files);
|
|
72
|
+
|
|
73
|
+
console.log(`Executing command: jscodeshift ${args.join(' ')}`);
|
|
74
|
+
const jscodeshiftProcess = childProcess.spawnSync('node', args, { stdio: 'inherit' });
|
|
75
|
+
|
|
76
|
+
if (jscodeshiftProcess.error) {
|
|
77
|
+
throw jscodeshiftProcess.error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const parseCssFilePaths = async (files) => {
|
|
82
|
+
const cssFiles = await Promise.all(files.map(async (filePath) => {
|
|
83
|
+
const stat = await fs.stat(filePath);
|
|
84
|
+
if (stat.isDirectory()) {
|
|
85
|
+
return `${filePath}/**/*.css`;
|
|
86
|
+
}
|
|
87
|
+
if (filePath.endsWith('.css')) {
|
|
88
|
+
return filePath;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return null;
|
|
92
|
+
}),);
|
|
93
|
+
|
|
94
|
+
return cssFiles.filter(Boolean);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
async function runPostcssTransform(transform, files) {
|
|
98
|
+
const paths = [
|
|
99
|
+
path.resolve(__dirname, './src', `${transform}/postcss.config.js`),
|
|
100
|
+
path.resolve(__dirname, './node', `${transform}/postcss.config.js`),
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
let configPath;
|
|
104
|
+
let error;
|
|
105
|
+
for (const item of paths) {
|
|
106
|
+
try {
|
|
107
|
+
await fs.stat(item);
|
|
108
|
+
error = undefined;
|
|
109
|
+
configPath = item;
|
|
110
|
+
break;
|
|
111
|
+
} catch (srcPathError) {
|
|
112
|
+
error = srcPathError;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (error) {
|
|
118
|
+
if (error?.code !== 'ENOENT') {
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
const cssPaths = await parseCssFilePaths(files);
|
|
123
|
+
|
|
124
|
+
if (cssPaths.length > 0) {
|
|
125
|
+
const args = [
|
|
126
|
+
postcssExecutable,
|
|
127
|
+
...cssPaths,
|
|
128
|
+
'--config',
|
|
129
|
+
configPath,
|
|
130
|
+
'--replace',
|
|
131
|
+
'--verbose',
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
console.log(`Executing command: postcss ${args.join(' ')}`);
|
|
135
|
+
const postCssProcess = childProcess.spawnSync('node', args, { stdio: 'inherit' });
|
|
136
|
+
|
|
137
|
+
if (postCssProcess.error) {
|
|
138
|
+
throw postCssProcess.error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function run(argv) {
|
|
145
|
+
const { codemod, paths, ...flags } = argv;
|
|
146
|
+
const files = paths.map((filePath) => path.resolve(filePath));
|
|
147
|
+
|
|
148
|
+
runJscodeshiftTransform(codemod, files, flags, argv._);
|
|
149
|
+
runPostcssTransform(codemod, files);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
yargs.command({
|
|
153
|
+
command: '$0 <codemod> <paths...>',
|
|
154
|
+
describe: 'Applies a `@mui/codemod` to the specified paths',
|
|
155
|
+
builder: (command) => {
|
|
156
|
+
return command
|
|
157
|
+
.positional('codemod', {
|
|
158
|
+
description: 'The name of the codemod',
|
|
159
|
+
type: 'string'
|
|
160
|
+
})
|
|
161
|
+
.positional('paths', {
|
|
162
|
+
array: true,
|
|
163
|
+
description: 'Paths forwarded to `jscodeshift`',
|
|
164
|
+
type: 'string',
|
|
165
|
+
})
|
|
166
|
+
.option('dry', {
|
|
167
|
+
description: 'dry run (no changes are made to files)',
|
|
168
|
+
default: false,
|
|
169
|
+
type: 'boolean'
|
|
170
|
+
})
|
|
171
|
+
.option('parser', {
|
|
172
|
+
description: 'which parser for jscodeshift to use',
|
|
173
|
+
default: 'tsx',
|
|
174
|
+
type: 'string'
|
|
175
|
+
})
|
|
176
|
+
.option('print', {
|
|
177
|
+
description: 'print transformed files to stdout, useful for development',
|
|
178
|
+
default: false,
|
|
179
|
+
type: 'boolean'
|
|
180
|
+
})
|
|
181
|
+
.option('jscodeshift', {
|
|
182
|
+
description: '(Advanced) Pass options directly to jscodeshift',
|
|
183
|
+
default: false,
|
|
184
|
+
type: 'string'
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
handler: run,
|
|
188
|
+
})
|
|
189
|
+
.scriptName('npx @availity/mui-codemod')
|
|
190
|
+
.example('$0 v4.0.0/theme-spacing-api src')
|
|
191
|
+
.example('$0 v5.0.0/component-rename-prop src -- --component=Grid --from=prop --to=newProp')
|
|
192
|
+
.help()
|
|
193
|
+
.parse();
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const childProcess = require('child_process');
|
|
3
|
+
const { promises: fs } = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const yargs = require('yargs');
|
|
6
|
+
const jscodeshiftPackage = require('jscodeshift/package.json');
|
|
7
|
+
const postcssCliPackage = require('postcss-cli/package.json');
|
|
8
|
+
|
|
9
|
+
const jscodeshiftDirectory = path.dirname(require.resolve('jscodeshift'));
|
|
10
|
+
const jscodeshiftExecutable = path.join(jscodeshiftDirectory, jscodeshiftPackage.bin.jscodeshift);
|
|
11
|
+
|
|
12
|
+
const postcssCliDirectory = path.dirname(require.resolve('postcss-cli'));
|
|
13
|
+
const postcssExecutable = path.join(postcssCliDirectory, postcssCliPackage.bin.postcss);
|
|
14
|
+
|
|
15
|
+
async function runJscodeshiftTransform(transform, files, flags, codemodFlags) {
|
|
16
|
+
const paths = [
|
|
17
|
+
path.resolve(__dirname, './src', `${transform}/index.js`),
|
|
18
|
+
path.resolve(__dirname, './src', `${transform}.js`),
|
|
19
|
+
path.resolve(__dirname, './node', `${transform}/index.js`),
|
|
20
|
+
path.resolve(__dirname, './node', `${transform}.js`),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
let transformerPath;
|
|
24
|
+
let error;
|
|
25
|
+
for (const item of paths) {
|
|
26
|
+
try {
|
|
27
|
+
await fs.stat(item);
|
|
28
|
+
error = undefined;
|
|
29
|
+
transformerPath = item;
|
|
30
|
+
break;
|
|
31
|
+
} catch (srcPathError) {
|
|
32
|
+
error = srcPathError;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (error) {
|
|
38
|
+
if (error?.code === 'ENOENT') {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Transform '${transform}' not found. Check out ${path.resolve(__dirname, './README.md for a list of available codemods.')}`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const args = [
|
|
47
|
+
jscodeshiftExecutable,
|
|
48
|
+
'--transform',
|
|
49
|
+
transformerPath,
|
|
50
|
+
...codemodFlags,
|
|
51
|
+
'--extensions',
|
|
52
|
+
'js,ts,jsx,tsx,json',
|
|
53
|
+
'--parser',
|
|
54
|
+
flags.parser || 'tsx',
|
|
55
|
+
'--ignore-pattern',
|
|
56
|
+
'**/node_modules/**',
|
|
57
|
+
'--ignore-pattern',
|
|
58
|
+
'**/*.css'
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
if (flags.dry) {
|
|
62
|
+
args.push('--dry');
|
|
63
|
+
}
|
|
64
|
+
if (flags.print) {
|
|
65
|
+
args.push('--print');
|
|
66
|
+
}
|
|
67
|
+
if (flags.jscodeshift) {
|
|
68
|
+
args.push(flags.jscodeshift);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
args.push(...files);
|
|
72
|
+
|
|
73
|
+
console.log(`Executing command: jscodeshift ${args.join(' ')}`);
|
|
74
|
+
const jscodeshiftProcess = childProcess.spawnSync('node', args, { stdio: 'inherit' });
|
|
75
|
+
|
|
76
|
+
if (jscodeshiftProcess.error) {
|
|
77
|
+
throw jscodeshiftProcess.error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const parseCssFilePaths = async (files) => {
|
|
82
|
+
const cssFiles = await Promise.all(files.map(async (filePath) => {
|
|
83
|
+
const stat = await fs.stat(filePath);
|
|
84
|
+
if (stat.isDirectory()) {
|
|
85
|
+
return `${filePath}/**/*.css`;
|
|
86
|
+
}
|
|
87
|
+
if (filePath.endsWith('.css')) {
|
|
88
|
+
return filePath;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return null;
|
|
92
|
+
}),);
|
|
93
|
+
|
|
94
|
+
return cssFiles.filter(Boolean);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
async function runPostcssTransform(transform, files) {
|
|
98
|
+
const paths = [
|
|
99
|
+
path.resolve(__dirname, './src', `${transform}/postcss.config.js`),
|
|
100
|
+
path.resolve(__dirname, './node', `${transform}/postcss.config.js`),
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
let configPath;
|
|
104
|
+
let error;
|
|
105
|
+
for (const item of paths) {
|
|
106
|
+
try {
|
|
107
|
+
await fs.stat(item);
|
|
108
|
+
error = undefined;
|
|
109
|
+
configPath = item;
|
|
110
|
+
break;
|
|
111
|
+
} catch (srcPathError) {
|
|
112
|
+
error = srcPathError;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (error) {
|
|
118
|
+
if (error?.code !== 'ENOENT') {
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
const cssPaths = await parseCssFilePaths(files);
|
|
123
|
+
|
|
124
|
+
if (cssPaths.length > 0) {
|
|
125
|
+
const args = [
|
|
126
|
+
postcssExecutable,
|
|
127
|
+
...cssPaths,
|
|
128
|
+
'--config',
|
|
129
|
+
configPath,
|
|
130
|
+
'--replace',
|
|
131
|
+
'--verbose',
|
|
132
|
+
];
|
|
133
|
+
|
|
134
|
+
console.log(`Executing command: postcss ${args.join(' ')}`);
|
|
135
|
+
const postCssProcess = childProcess.spawnSync('node', args, { stdio: 'inherit' });
|
|
136
|
+
|
|
137
|
+
if (postCssProcess.error) {
|
|
138
|
+
throw postCssProcess.error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function run(argv) {
|
|
145
|
+
const { codemod, paths, ...flags } = argv;
|
|
146
|
+
const files = paths.map((filePath) => path.resolve(filePath));
|
|
147
|
+
|
|
148
|
+
runJscodeshiftTransform(codemod, files, flags, argv._);
|
|
149
|
+
runPostcssTransform(codemod, files);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
yargs.command({
|
|
153
|
+
command: '$0 <codemod> <paths...>',
|
|
154
|
+
describe: 'Applies a `@mui/codemod` to the specified paths',
|
|
155
|
+
builder: (command) => {
|
|
156
|
+
return command
|
|
157
|
+
.positional('codemod', {
|
|
158
|
+
description: 'The name of the codemod',
|
|
159
|
+
type: 'string'
|
|
160
|
+
})
|
|
161
|
+
.positional('paths', {
|
|
162
|
+
array: true,
|
|
163
|
+
description: 'Paths forwarded to `jscodeshift`',
|
|
164
|
+
type: 'string',
|
|
165
|
+
})
|
|
166
|
+
.option('dry', {
|
|
167
|
+
description: 'dry run (no changes are made to files)',
|
|
168
|
+
default: false,
|
|
169
|
+
type: 'boolean'
|
|
170
|
+
})
|
|
171
|
+
.option('parser', {
|
|
172
|
+
description: 'which parser for jscodeshift to use',
|
|
173
|
+
default: 'tsx',
|
|
174
|
+
type: 'string'
|
|
175
|
+
})
|
|
176
|
+
.option('print', {
|
|
177
|
+
description: 'print transformed files to stdout, useful for development',
|
|
178
|
+
default: false,
|
|
179
|
+
type: 'boolean'
|
|
180
|
+
})
|
|
181
|
+
.option('jscodeshift', {
|
|
182
|
+
description: '(Advanced) Pass options directly to jscodeshift',
|
|
183
|
+
default: false,
|
|
184
|
+
type: 'string'
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
handler: run,
|
|
188
|
+
})
|
|
189
|
+
.scriptName('npx @availity/mui-codemod')
|
|
190
|
+
.example('$0 v4.0.0/theme-spacing-api src')
|
|
191
|
+
.example('$0 v5.0.0/component-rename-prop src -- --component=Grid --from=prop --to=newProp')
|
|
192
|
+
.help()
|
|
193
|
+
.parse();
|
package/dist/codemod.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/codemod.js
|
|
27
|
+
var childProcess = require("child_process");
|
|
28
|
+
var { promises: fs } = require("fs");
|
|
29
|
+
var path = require("path");
|
|
30
|
+
var yargs = require("yargs");
|
|
31
|
+
var jscodeshiftPackage = require("jscodeshift/package.json");
|
|
32
|
+
var postcssCliPackage = require("postcss-cli/package.json");
|
|
33
|
+
var jscodeshiftDirectory = path.dirname(require.resolve("jscodeshift"));
|
|
34
|
+
var jscodeshiftExecutable = path.join(jscodeshiftDirectory, jscodeshiftPackage.bin.jscodeshift);
|
|
35
|
+
var postcssCliDirectory = path.dirname(require.resolve("postcss-cli"));
|
|
36
|
+
var postcssExecutable = path.join(postcssCliDirectory, postcssCliPackage.bin.postcss);
|
|
37
|
+
async function runJscodeshiftTransform(transform, files, flags, codemodFlags) {
|
|
38
|
+
const paths = [
|
|
39
|
+
path.resolve(__dirname, "./src", `${transform}/index.js`),
|
|
40
|
+
path.resolve(__dirname, "./src", `${transform}.js`),
|
|
41
|
+
path.resolve(__dirname, "./node", `${transform}/index.js`),
|
|
42
|
+
path.resolve(__dirname, "./node", `${transform}.js`)
|
|
43
|
+
];
|
|
44
|
+
let transformerPath;
|
|
45
|
+
let error;
|
|
46
|
+
for (const item of paths) {
|
|
47
|
+
try {
|
|
48
|
+
await fs.stat(item);
|
|
49
|
+
error = void 0;
|
|
50
|
+
transformerPath = item;
|
|
51
|
+
break;
|
|
52
|
+
} catch (srcPathError) {
|
|
53
|
+
error = srcPathError;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (error) {
|
|
58
|
+
if ((error == null ? void 0 : error.code) === "ENOENT") {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Transform '${transform}' not found. Check out ${path.resolve(__dirname, "./README.md for a list of available codemods.")}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
const args = [
|
|
66
|
+
jscodeshiftExecutable,
|
|
67
|
+
"--transform",
|
|
68
|
+
transformerPath,
|
|
69
|
+
...codemodFlags,
|
|
70
|
+
"--extensions",
|
|
71
|
+
"js,ts,jsx,tsx,json",
|
|
72
|
+
"--parser",
|
|
73
|
+
flags.parser || "tsx",
|
|
74
|
+
"--ignore-pattern",
|
|
75
|
+
"**/node_modules/**",
|
|
76
|
+
"--ignore-pattern",
|
|
77
|
+
"**/*.css"
|
|
78
|
+
];
|
|
79
|
+
if (flags.dry) {
|
|
80
|
+
args.push("--dry");
|
|
81
|
+
}
|
|
82
|
+
if (flags.print) {
|
|
83
|
+
args.push("--print");
|
|
84
|
+
}
|
|
85
|
+
if (flags.jscodeshift) {
|
|
86
|
+
args.push(flags.jscodeshift);
|
|
87
|
+
}
|
|
88
|
+
args.push(...files);
|
|
89
|
+
console.log(`Executing command: jscodeshift ${args.join(" ")}`);
|
|
90
|
+
const jscodeshiftProcess = childProcess.spawnSync("node", args, { stdio: "inherit" });
|
|
91
|
+
if (jscodeshiftProcess.error) {
|
|
92
|
+
throw jscodeshiftProcess.error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
var parseCssFilePaths = async (files) => {
|
|
96
|
+
const cssFiles = await Promise.all(files.map(async (filePath) => {
|
|
97
|
+
const stat = await fs.stat(filePath);
|
|
98
|
+
if (stat.isDirectory()) {
|
|
99
|
+
return `${filePath}/**/*.css`;
|
|
100
|
+
}
|
|
101
|
+
if (filePath.endsWith(".css")) {
|
|
102
|
+
return filePath;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}));
|
|
106
|
+
return cssFiles.filter(Boolean);
|
|
107
|
+
};
|
|
108
|
+
async function runPostcssTransform(transform, files) {
|
|
109
|
+
const paths = [
|
|
110
|
+
path.resolve(__dirname, "./src", `${transform}/postcss.config.js`),
|
|
111
|
+
path.resolve(__dirname, "./node", `${transform}/postcss.config.js`)
|
|
112
|
+
];
|
|
113
|
+
let configPath;
|
|
114
|
+
let error;
|
|
115
|
+
for (const item of paths) {
|
|
116
|
+
try {
|
|
117
|
+
await fs.stat(item);
|
|
118
|
+
error = void 0;
|
|
119
|
+
configPath = item;
|
|
120
|
+
break;
|
|
121
|
+
} catch (srcPathError) {
|
|
122
|
+
error = srcPathError;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (error) {
|
|
127
|
+
if ((error == null ? void 0 : error.code) !== "ENOENT") {
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
const cssPaths = await parseCssFilePaths(files);
|
|
132
|
+
if (cssPaths.length > 0) {
|
|
133
|
+
const args = [
|
|
134
|
+
postcssExecutable,
|
|
135
|
+
...cssPaths,
|
|
136
|
+
"--config",
|
|
137
|
+
configPath,
|
|
138
|
+
"--replace",
|
|
139
|
+
"--verbose"
|
|
140
|
+
];
|
|
141
|
+
console.log(`Executing command: postcss ${args.join(" ")}`);
|
|
142
|
+
const postCssProcess = childProcess.spawnSync("node", args, { stdio: "inherit" });
|
|
143
|
+
if (postCssProcess.error) {
|
|
144
|
+
throw postCssProcess.error;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function run(argv) {
|
|
150
|
+
const { codemod, paths, ...flags } = argv;
|
|
151
|
+
const files = paths.map((filePath) => path.resolve(filePath));
|
|
152
|
+
runJscodeshiftTransform(codemod, files, flags, argv._);
|
|
153
|
+
runPostcssTransform(codemod, files);
|
|
154
|
+
}
|
|
155
|
+
yargs.command({
|
|
156
|
+
command: "$0 <codemod> <paths...>",
|
|
157
|
+
describe: "Applies a `@mui/codemod` to the specified paths",
|
|
158
|
+
builder: (command) => {
|
|
159
|
+
return command.positional("codemod", {
|
|
160
|
+
description: "The name of the codemod",
|
|
161
|
+
type: "string"
|
|
162
|
+
}).positional("paths", {
|
|
163
|
+
array: true,
|
|
164
|
+
description: "Paths forwarded to `jscodeshift`",
|
|
165
|
+
type: "string"
|
|
166
|
+
}).option("dry", {
|
|
167
|
+
description: "dry run (no changes are made to files)",
|
|
168
|
+
default: false,
|
|
169
|
+
type: "boolean"
|
|
170
|
+
}).option("parser", {
|
|
171
|
+
description: "which parser for jscodeshift to use",
|
|
172
|
+
default: "tsx",
|
|
173
|
+
type: "string"
|
|
174
|
+
}).option("print", {
|
|
175
|
+
description: "print transformed files to stdout, useful for development",
|
|
176
|
+
default: false,
|
|
177
|
+
type: "boolean"
|
|
178
|
+
}).option("jscodeshift", {
|
|
179
|
+
description: "(Advanced) Pass options directly to jscodeshift",
|
|
180
|
+
default: false,
|
|
181
|
+
type: "string"
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
handler: run
|
|
185
|
+
}).scriptName("npx @availity/mui-codemod").example("$0 v4.0.0/theme-spacing-api src").example("$0 v5.0.0/component-rename-prop src -- --component=Grid --from=prop --to=newProp").help().parse();
|
package/dist/codemod.mjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
6
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// src/codemod.js
|
|
10
|
+
var childProcess = __require("child_process");
|
|
11
|
+
var { promises: fs } = __require("fs");
|
|
12
|
+
var path = __require("path");
|
|
13
|
+
var yargs = __require("yargs");
|
|
14
|
+
var jscodeshiftPackage = __require("jscodeshift/package.json");
|
|
15
|
+
var postcssCliPackage = __require("postcss-cli/package.json");
|
|
16
|
+
var jscodeshiftDirectory = path.dirname(__require.resolve("jscodeshift"));
|
|
17
|
+
var jscodeshiftExecutable = path.join(jscodeshiftDirectory, jscodeshiftPackage.bin.jscodeshift);
|
|
18
|
+
var postcssCliDirectory = path.dirname(__require.resolve("postcss-cli"));
|
|
19
|
+
var postcssExecutable = path.join(postcssCliDirectory, postcssCliPackage.bin.postcss);
|
|
20
|
+
async function runJscodeshiftTransform(transform, files, flags, codemodFlags) {
|
|
21
|
+
const paths = [
|
|
22
|
+
path.resolve(__dirname, "./src", `${transform}/index.js`),
|
|
23
|
+
path.resolve(__dirname, "./src", `${transform}.js`),
|
|
24
|
+
path.resolve(__dirname, "./node", `${transform}/index.js`),
|
|
25
|
+
path.resolve(__dirname, "./node", `${transform}.js`)
|
|
26
|
+
];
|
|
27
|
+
let transformerPath;
|
|
28
|
+
let error;
|
|
29
|
+
for (const item of paths) {
|
|
30
|
+
try {
|
|
31
|
+
await fs.stat(item);
|
|
32
|
+
error = void 0;
|
|
33
|
+
transformerPath = item;
|
|
34
|
+
break;
|
|
35
|
+
} catch (srcPathError) {
|
|
36
|
+
error = srcPathError;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (error) {
|
|
41
|
+
if ((error == null ? void 0 : error.code) === "ENOENT") {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Transform '${transform}' not found. Check out ${path.resolve(__dirname, "./README.md for a list of available codemods.")}`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
const args = [
|
|
49
|
+
jscodeshiftExecutable,
|
|
50
|
+
"--transform",
|
|
51
|
+
transformerPath,
|
|
52
|
+
...codemodFlags,
|
|
53
|
+
"--extensions",
|
|
54
|
+
"js,ts,jsx,tsx,json",
|
|
55
|
+
"--parser",
|
|
56
|
+
flags.parser || "tsx",
|
|
57
|
+
"--ignore-pattern",
|
|
58
|
+
"**/node_modules/**",
|
|
59
|
+
"--ignore-pattern",
|
|
60
|
+
"**/*.css"
|
|
61
|
+
];
|
|
62
|
+
if (flags.dry) {
|
|
63
|
+
args.push("--dry");
|
|
64
|
+
}
|
|
65
|
+
if (flags.print) {
|
|
66
|
+
args.push("--print");
|
|
67
|
+
}
|
|
68
|
+
if (flags.jscodeshift) {
|
|
69
|
+
args.push(flags.jscodeshift);
|
|
70
|
+
}
|
|
71
|
+
args.push(...files);
|
|
72
|
+
console.log(`Executing command: jscodeshift ${args.join(" ")}`);
|
|
73
|
+
const jscodeshiftProcess = childProcess.spawnSync("node", args, { stdio: "inherit" });
|
|
74
|
+
if (jscodeshiftProcess.error) {
|
|
75
|
+
throw jscodeshiftProcess.error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
var parseCssFilePaths = async (files) => {
|
|
79
|
+
const cssFiles = await Promise.all(files.map(async (filePath) => {
|
|
80
|
+
const stat = await fs.stat(filePath);
|
|
81
|
+
if (stat.isDirectory()) {
|
|
82
|
+
return `${filePath}/**/*.css`;
|
|
83
|
+
}
|
|
84
|
+
if (filePath.endsWith(".css")) {
|
|
85
|
+
return filePath;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}));
|
|
89
|
+
return cssFiles.filter(Boolean);
|
|
90
|
+
};
|
|
91
|
+
async function runPostcssTransform(transform, files) {
|
|
92
|
+
const paths = [
|
|
93
|
+
path.resolve(__dirname, "./src", `${transform}/postcss.config.js`),
|
|
94
|
+
path.resolve(__dirname, "./node", `${transform}/postcss.config.js`)
|
|
95
|
+
];
|
|
96
|
+
let configPath;
|
|
97
|
+
let error;
|
|
98
|
+
for (const item of paths) {
|
|
99
|
+
try {
|
|
100
|
+
await fs.stat(item);
|
|
101
|
+
error = void 0;
|
|
102
|
+
configPath = item;
|
|
103
|
+
break;
|
|
104
|
+
} catch (srcPathError) {
|
|
105
|
+
error = srcPathError;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (error) {
|
|
110
|
+
if ((error == null ? void 0 : error.code) !== "ENOENT") {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
const cssPaths = await parseCssFilePaths(files);
|
|
115
|
+
if (cssPaths.length > 0) {
|
|
116
|
+
const args = [
|
|
117
|
+
postcssExecutable,
|
|
118
|
+
...cssPaths,
|
|
119
|
+
"--config",
|
|
120
|
+
configPath,
|
|
121
|
+
"--replace",
|
|
122
|
+
"--verbose"
|
|
123
|
+
];
|
|
124
|
+
console.log(`Executing command: postcss ${args.join(" ")}`);
|
|
125
|
+
const postCssProcess = childProcess.spawnSync("node", args, { stdio: "inherit" });
|
|
126
|
+
if (postCssProcess.error) {
|
|
127
|
+
throw postCssProcess.error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function run(argv) {
|
|
133
|
+
const { codemod, paths, ...flags } = argv;
|
|
134
|
+
const files = paths.map((filePath) => path.resolve(filePath));
|
|
135
|
+
runJscodeshiftTransform(codemod, files, flags, argv._);
|
|
136
|
+
runPostcssTransform(codemod, files);
|
|
137
|
+
}
|
|
138
|
+
yargs.command({
|
|
139
|
+
command: "$0 <codemod> <paths...>",
|
|
140
|
+
describe: "Applies a `@mui/codemod` to the specified paths",
|
|
141
|
+
builder: (command) => {
|
|
142
|
+
return command.positional("codemod", {
|
|
143
|
+
description: "The name of the codemod",
|
|
144
|
+
type: "string"
|
|
145
|
+
}).positional("paths", {
|
|
146
|
+
array: true,
|
|
147
|
+
description: "Paths forwarded to `jscodeshift`",
|
|
148
|
+
type: "string"
|
|
149
|
+
}).option("dry", {
|
|
150
|
+
description: "dry run (no changes are made to files)",
|
|
151
|
+
default: false,
|
|
152
|
+
type: "boolean"
|
|
153
|
+
}).option("parser", {
|
|
154
|
+
description: "which parser for jscodeshift to use",
|
|
155
|
+
default: "tsx",
|
|
156
|
+
type: "string"
|
|
157
|
+
}).option("print", {
|
|
158
|
+
description: "print transformed files to stdout, useful for development",
|
|
159
|
+
default: false,
|
|
160
|
+
type: "boolean"
|
|
161
|
+
}).option("jscodeshift", {
|
|
162
|
+
description: "(Advanced) Pass options directly to jscodeshift",
|
|
163
|
+
default: false,
|
|
164
|
+
type: "string"
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
handler: run
|
|
168
|
+
}).scriptName("npx @availity/mui-codemod").example("$0 v4.0.0/theme-spacing-api src").example("$0 v5.0.0/component-rename-prop src -- --component=Grid --from=prop --to=newProp").help().parse();
|
package/package.json
CHANGED
package/src/codemod.js
CHANGED
|
@@ -15,8 +15,8 @@ const postcssExecutable = path.join(postcssCliDirectory, postcssCliPackage.bin.p
|
|
|
15
15
|
|
|
16
16
|
async function runJscodeshiftTransform(transform, files, flags, codemodFlags) {
|
|
17
17
|
const paths = [
|
|
18
|
-
path.resolve(__dirname, './
|
|
19
|
-
path.resolve(__dirname, './
|
|
18
|
+
path.resolve(__dirname, './lib', `${transform}/index.js`),
|
|
19
|
+
path.resolve(__dirname, './lib', `${transform}.js`),
|
|
20
20
|
path.resolve(__dirname, './node', `${transform}/index.js`),
|
|
21
21
|
path.resolve(__dirname, './node', `${transform}.js`),
|
|
22
22
|
];
|
|
@@ -97,7 +97,7 @@ const parseCssFilePaths = async (files) => {
|
|
|
97
97
|
|
|
98
98
|
async function runPostcssTransform(transform, files) {
|
|
99
99
|
const paths = [
|
|
100
|
-
path.resolve(__dirname, './
|
|
100
|
+
path.resolve(__dirname, './lib', `${transform}/postcss.config.js`),
|
|
101
101
|
path.resolve(__dirname, './node', `${transform}/postcss.config.js`),
|
|
102
102
|
];
|
|
103
103
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './grid-v2-props';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './removeSystemProps';
|