@commercetools-frontend/codemod 0.2.0 → 21.13.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/README.md +11 -3
- package/bin/mc-codemod.js +1 -1
- package/build/package.json +40 -0
- package/build/src/cli.js +77 -0
- package/build/src/index.js +8 -0
- package/build/{transforms → src/transforms}/remove-deprecated-modal-level-props.js +18 -11
- package/build/{transforms → src/transforms}/rename-js-to-jsx.js +0 -0
- package/build/src/transforms/rename-mod-css-to-module-css.js +34 -0
- package/build/{types.js → src/types.js} +0 -0
- package/package.json +7 -7
- package/build/cli.js +0 -66
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Codemod transformations for Custom Applications.
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
$ npx @commercetools-frontend/codemod <transform> <glob_pattern>
|
|
12
|
+
$ npx @commercetools-frontend/codemod@latest <transform> <glob_pattern>
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
We recommend to run `prettier` on the modified files to preserve the formatting configured on your project. For example, you can run `prettier --write $(git diff --name-only)`.
|
|
@@ -23,7 +23,7 @@ We recommend to run `prettier` on the modified files to preserve the formatting
|
|
|
23
23
|
Remove deprecated `level` and `baseZIndex` props from modal page components.
|
|
24
24
|
|
|
25
25
|
```
|
|
26
|
-
$ npx @commercetools-frontend/codemod remove-deprecated-modal-level-props 'src/**/*.js'
|
|
26
|
+
$ npx @commercetools-frontend/codemod@latest remove-deprecated-modal-level-props 'src/**/*.{js,jsx,ts,tsx}'
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
### `rename-js-to-jsx`
|
|
@@ -31,5 +31,13 @@ $ npx @commercetools-frontend/codemod remove-deprecated-modal-level-props 'src/*
|
|
|
31
31
|
Rename `.js` files using React JSX syntax to `.jsx`.
|
|
32
32
|
|
|
33
33
|
```
|
|
34
|
-
$ npx @commercetools-frontend/codemod rename-js-to-jsx 'src/**/*.js'
|
|
34
|
+
$ npx @commercetools-frontend/codemod@latest rename-js-to-jsx 'src/**/*.js'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### `rename-mod-css-to-module-css`
|
|
38
|
+
|
|
39
|
+
Rename `.mod.css` files to `.module.css` and update imports.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
$ npx @commercetools-frontend/codemod@latest rename-mod-css-to-module-css 'src/**/*.{js,jsx,ts,tsx}'
|
|
35
43
|
```
|
package/bin/mc-codemod.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commercetools-frontend/codemod",
|
|
3
|
+
"version": "21.13.1",
|
|
4
|
+
"description": "Codemod transformations for Custom Applications",
|
|
5
|
+
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/commercetools/merchant-center-application-kit.git",
|
|
9
|
+
"directory": "packages/codemod"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://docs.commercetools.com/custom-applications",
|
|
12
|
+
"keywords": ["javascript", "frontend", "codemod", "toolkit"],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"main": "./build/src/index.js",
|
|
18
|
+
"files": ["bin", "build", "package.json", "LICENSE", "README.md"],
|
|
19
|
+
"bin": {
|
|
20
|
+
"mc-codemod": "./bin/mc-codemod.js"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "rimraf build && tsc",
|
|
24
|
+
"build:bundles:watch": "yarn build -w"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"cac": "6.7.12",
|
|
28
|
+
"glob": "8.0.3",
|
|
29
|
+
"jscodeshift": "0.13.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@tsconfig/node16": "^1.0.3",
|
|
33
|
+
"@types/jscodeshift": "0.11.5",
|
|
34
|
+
"rimraf": "3.0.2",
|
|
35
|
+
"typescript": "4.7.4"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=14"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/build/src/cli.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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.run = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const cac_1 = __importDefault(require("cac"));
|
|
9
|
+
const glob_1 = __importDefault(require("glob"));
|
|
10
|
+
// @ts-ignore internal module
|
|
11
|
+
const Runner_1 = __importDefault(require("jscodeshift/src/Runner"));
|
|
12
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
13
|
+
const cli = (0, cac_1.default)('mc-codemod');
|
|
14
|
+
const transforms = [
|
|
15
|
+
{
|
|
16
|
+
name: 'remove-deprecated-modal-level-props',
|
|
17
|
+
description: 'Remove deprecated "level" and "baseZIndex" props from modal page components.',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'rename-js-to-jsx',
|
|
21
|
+
description: 'Rename ".js" files using React JSX syntax to ".jsx".',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'rename-mod-css-to-module-css',
|
|
25
|
+
description: 'Rename ".mod.css" files to ".module.css" and update imports.',
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
const executeCodemod = async (transform, globPattern, globalOptions) => {
|
|
29
|
+
const files = glob_1.default.sync(globPattern);
|
|
30
|
+
const runJscodeshift = async (transformPath, filePaths, options) => {
|
|
31
|
+
await Runner_1.default.run(transformPath, filePaths, options);
|
|
32
|
+
};
|
|
33
|
+
switch (transform) {
|
|
34
|
+
case 'remove-deprecated-modal-level-props':
|
|
35
|
+
case 'rename-js-to-jsx':
|
|
36
|
+
case 'rename-mod-css-to-module-css': {
|
|
37
|
+
const transformPath = path_1.default.join(__dirname, `transforms/${transform}.js`);
|
|
38
|
+
await runJscodeshift(transformPath, files, {
|
|
39
|
+
extensions: 'tsx,ts,jsx,js',
|
|
40
|
+
ignorePattern: [
|
|
41
|
+
'**/node_modules/**',
|
|
42
|
+
'**/public/**',
|
|
43
|
+
'**/dist/**',
|
|
44
|
+
'**/build/**',
|
|
45
|
+
],
|
|
46
|
+
parser: 'tsx',
|
|
47
|
+
verbose: 0,
|
|
48
|
+
dry: globalOptions.dryRun,
|
|
49
|
+
});
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
default:
|
|
53
|
+
throw new Error(`Unknown transform ${transform}.`);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const run = () => {
|
|
57
|
+
cli.option('--dry-run', `(optional) Executes the command but does not send any mutation request.`, { default: false });
|
|
58
|
+
// Default command
|
|
59
|
+
cli
|
|
60
|
+
.command('')
|
|
61
|
+
.usage('\n\n Codemods for updating Custom Applications.')
|
|
62
|
+
.action(() => {
|
|
63
|
+
cli.outputHelp();
|
|
64
|
+
});
|
|
65
|
+
// Transform commands
|
|
66
|
+
transforms.forEach((transform) => {
|
|
67
|
+
cli
|
|
68
|
+
.command(`${transform.name} <glob-pattern>`, transform.description)
|
|
69
|
+
.usage(`${transform.name} <glob-pattern>\n\n ${transform.description}`)
|
|
70
|
+
.action((globPattern, globalOptions) => executeCodemod(transform.name, globPattern, globalOptions));
|
|
71
|
+
});
|
|
72
|
+
cli.help();
|
|
73
|
+
cli.version(package_json_1.default.version);
|
|
74
|
+
cli.parse();
|
|
75
|
+
};
|
|
76
|
+
exports.run = run;
|
|
77
|
+
exports.default = exports.run;
|
|
@@ -0,0 +1,8 @@
|
|
|
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.cli = void 0;
|
|
7
|
+
const cli_1 = __importDefault(require("./cli"));
|
|
8
|
+
exports.cli = cli_1.default;
|
|
@@ -15,19 +15,26 @@ function removeDeprecatedModalLevelProps(file, api, options) {
|
|
|
15
15
|
const node = path.node;
|
|
16
16
|
if (node.name.type === 'JSXIdentifier' &&
|
|
17
17
|
componentNamesWithDeprecatedZIndexProps.includes(node.name.name)) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
if (options.dry) {
|
|
19
|
+
api.stats(file.path);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
node.attributes =
|
|
23
|
+
node.attributes?.filter((attribute) => {
|
|
24
|
+
if (attribute.type === 'JSXAttribute' &&
|
|
25
|
+
attribute.name.type === 'JSXIdentifier') {
|
|
26
|
+
const hasDeprecatedAttribute = deprecatedPropsToBeRemoved.includes(attribute.name.name);
|
|
27
|
+
hasModifications = true;
|
|
28
|
+
return !hasDeprecatedAttribute;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}) ?? [];
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
root.find(j.JSXOpeningElement).forEach(removeDepreactedPropsFromComponent);
|
|
31
|
-
return hasModifications
|
|
36
|
+
return hasModifications
|
|
37
|
+
? root.toSource({ ...options, quote: 'single' })
|
|
38
|
+
: null;
|
|
32
39
|
}
|
|
33
40
|
exports.default = removeDeprecatedModalLevelProps;
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
function renameModCssToModuleCss(file, api, options) {
|
|
9
|
+
const j = api.jscodeshift;
|
|
10
|
+
let hasModifications = false;
|
|
11
|
+
function renameImportModCssToModuleCss(astPath) {
|
|
12
|
+
const node = astPath.node;
|
|
13
|
+
if (typeof node.source.value === 'string' &&
|
|
14
|
+
node.source.value.endsWith('.mod.css')) {
|
|
15
|
+
if (options.dry) {
|
|
16
|
+
api.stats(file.path);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const previousCssModulesFilePath = node.source.value;
|
|
20
|
+
const nextCssModulesFilePath = previousCssModulesFilePath.replace('.mod.css', '.module.css');
|
|
21
|
+
node.source.value = nextCssModulesFilePath;
|
|
22
|
+
hasModifications = true;
|
|
23
|
+
// Side effect for renaming the actual CSS module file.
|
|
24
|
+
fs_1.default.renameSync(path_1.default.join(path_1.default.dirname(file.path), previousCssModulesFilePath), path_1.default.join(path_1.default.dirname(file.path), nextCssModulesFilePath));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const root = j(file.source);
|
|
29
|
+
root.find(j.ImportDeclaration).forEach(renameImportModCssToModuleCss);
|
|
30
|
+
return hasModifications
|
|
31
|
+
? root.toSource({ ...options, quote: 'single' })
|
|
32
|
+
: null;
|
|
33
|
+
}
|
|
34
|
+
exports.default = renameModCssToModuleCss;
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/codemod",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "21.13.1",
|
|
4
4
|
"description": "Codemod transformations for Custom Applications",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
|
-
"main": "./build/
|
|
17
|
+
"main": "./build/src/index.js",
|
|
18
18
|
"files": ["bin", "build", "package.json", "LICENSE", "README.md"],
|
|
19
19
|
"bin": {
|
|
20
20
|
"mc-codemod": "./bin/mc-codemod.js"
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
"build:bundles:watch": "yarn build -w"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
27
|
+
"cac": "6.7.12",
|
|
28
|
+
"glob": "8.0.3",
|
|
29
|
+
"jscodeshift": "0.13.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsconfig/
|
|
32
|
+
"@tsconfig/node16": "^1.0.3",
|
|
33
33
|
"@types/jscodeshift": "0.11.5",
|
|
34
34
|
"rimraf": "3.0.2",
|
|
35
|
-
"typescript": "4.
|
|
35
|
+
"typescript": "4.7.4"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=14"
|
package/build/cli.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
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.run = void 0;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const mri_1 = __importDefault(require("mri"));
|
|
9
|
-
const glob_1 = __importDefault(require("glob"));
|
|
10
|
-
// @ts-ignore internal module
|
|
11
|
-
const Runner_1 = __importDefault(require("jscodeshift/src/Runner"));
|
|
12
|
-
const run = () => {
|
|
13
|
-
const flags = (0, mri_1.default)(process.argv.slice(2), {
|
|
14
|
-
alias: { help: ['h'] },
|
|
15
|
-
boolean: ['dry-run'],
|
|
16
|
-
});
|
|
17
|
-
const commands = flags._;
|
|
18
|
-
if (commands.length === 0 || (flags.help && commands.length === 0)) {
|
|
19
|
-
console.log(`
|
|
20
|
-
Usage: mc-codemod [global-options] [transform] [glob-pattern]
|
|
21
|
-
|
|
22
|
-
Global options:
|
|
23
|
-
|
|
24
|
-
--dry-run (optional) Executes the command but does not send any mutation request.
|
|
25
|
-
|
|
26
|
-
Transforms:
|
|
27
|
-
|
|
28
|
-
remove-deprecated-modal-level-props Remove deprecated "level" and "baseZIndex" props from modal page components.
|
|
29
|
-
rename-js-to-jsx Rename ".js" files using React JSX syntax to ".jsx".
|
|
30
|
-
`);
|
|
31
|
-
process.exit(0);
|
|
32
|
-
}
|
|
33
|
-
const [transform, globPattern] = commands;
|
|
34
|
-
const files = glob_1.default.sync(globPattern);
|
|
35
|
-
const runJscodeshift = async (transformPath, filePaths, options) => {
|
|
36
|
-
await Runner_1.default.run(transformPath, filePaths, options);
|
|
37
|
-
};
|
|
38
|
-
const execute = async () => {
|
|
39
|
-
switch (transform) {
|
|
40
|
-
case 'remove-deprecated-modal-level-props':
|
|
41
|
-
case 'rename-js-to-jsx': {
|
|
42
|
-
const transformPath = path_1.default.join(__dirname, `transforms/${transform}.js`);
|
|
43
|
-
await runJscodeshift(transformPath, files, {
|
|
44
|
-
extensions: 'tsx,ts,jsx,js',
|
|
45
|
-
ignorePattern: [
|
|
46
|
-
'**/node_modules/**',
|
|
47
|
-
'**/public/**',
|
|
48
|
-
'**/dist/**',
|
|
49
|
-
'**/build/**',
|
|
50
|
-
],
|
|
51
|
-
parser: 'tsx',
|
|
52
|
-
verbose: 0,
|
|
53
|
-
dry: flags['dry-run'],
|
|
54
|
-
});
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
default:
|
|
58
|
-
throw new Error(`Unknown transform ${transform}.`);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
execute().catch((error) => {
|
|
62
|
-
console.error(error.stack || error.message || error);
|
|
63
|
-
process.exit(1);
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
exports.run = run;
|