Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit a63ac68

Browse files
author
Laurie
committed
Initial scaffolding
1 parent 64f582a commit a63ac68

File tree

9 files changed

+6519
-0
lines changed

9 files changed

+6519
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# codemods
2+
23
Tools for migrating MDX projects from v1 to v2
4+
5+
To run `jscodeshift -t <path-to-transform> <path-to-project>`
6+
7+
When published `npx codemods <path-to-project>` (This may be a longer package name than codemods when published)

bin/cli.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import path from "path";
2+
import execa from "execa";
3+
4+
export const transformerDirectory = path.join(__dirname, "../", "transforms");
5+
export const jscodeshiftExecutable = require.resolve(".bin/jscodeshift");
6+
7+
export function runTransform(targetDir) {
8+
const transformerPath = path.join(transformerDirectory, `mdx-v2.js`);
9+
10+
let args = [];
11+
12+
args.push("--ignore-pattern=**/node_modules/**");
13+
14+
args.push("--extensions=mdx");
15+
16+
args = args.concat(["--transform", transformerPath, targetDir]);
17+
18+
console.log(`Executing command: jscodeshift ${args.join(" ")}`);
19+
20+
const result = execa.sync(jscodeshiftExecutable, args, {
21+
stdio: "inherit",
22+
stripEof: false,
23+
});
24+
25+
if (result.error) {
26+
throw result.error;
27+
}
28+
}
29+
30+
export function run() {
31+
let [targetDir] = process.argv.slice(2);
32+
33+
if (!targetDir) {
34+
console.log(
35+
`You have not provided a target directory to run the codemod against, will default to root.`
36+
);
37+
targetDir = `.`;
38+
}
39+
runTransform(targetDir);
40+
}

bin/codemods.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require("./cli").run();

package-lock.json

+6,413
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "codemods",
3+
"version": "1.0.0",
4+
"description": "Tools for migrating MDX projects from v1 to v2",
5+
"main": "index.js",
6+
"dependencies": {
7+
"execa": "^5.0.0",
8+
"jscodeshift": "^0.11.0"
9+
},
10+
"devDependencies": {
11+
"jest": "^26.6.3"
12+
},
13+
"scripts": {
14+
"test": "echo \"Error: no test specified\" && exit 1",
15+
"jest": "jest"
16+
},
17+
"repository": {
18+
"type": "git",
19+
"url": "git+https://github.com/mdx-js/codemods.git"
20+
},
21+
"keywords": [],
22+
"author": "",
23+
"license": "ISC",
24+
"bugs": {
25+
"url": "https://github.com/mdx-js/codemods/issues"
26+
},
27+
"homepage": "https://github.com/mdx-js/codemods#readme",
28+
"bin": "./bin/codemods.js"
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: test
3+
---
4+
5+
This is a test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: test
3+
---
4+
5+
This is a test
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const tests = [`example`];
2+
3+
const defineTest = require(`jscodeshift/dist/testUtils`).defineTest;
4+
5+
// This won't work, we'll need to use inline or snapshot tests instead
6+
describe(`codemods`, () => {
7+
tests.forEach((test) =>
8+
defineTest(__dirname, `mdx-v2`, { parser: `mdx` }, `${test}`)
9+
);
10+
});

src/transforms/mdx-v2.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function jsCodeShift({ source, path }) {
2+
console.log(source);
3+
dummyForJohn();
4+
return source;
5+
}
6+
7+
function dummyForJohn() {
8+
//noop
9+
}

0 commit comments

Comments
 (0)