Skip to content

Commit 25164fe

Browse files
committed
Make codegen directory output to codemods/
1 parent 985c0e9 commit 25164fe

File tree

10 files changed

+31
-12
lines changed

10 files changed

+31
-12
lines changed

.changeset/long-lamps-reflect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codeshift/initializer': minor
3+
---
4+
5+
Codemods are now output to the codemods/ directory instead of src/ to be more flexible when working with both isolated packages and pre-existing packages such as monorepos etc. Tooling should continue to work as expected regardless

packages/initializer/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# @codeshift/initializer
22

3-
Initialize new codemod folders
3+
Codegens codeshift packages

packages/initializer/src/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function getPackageJson(packageName: string, version = '0.0.0') {
4343

4444
function getNpmIgnore() {
4545
return `src/
46+
codemods/
4647
**/__test__
4748
**/*.spec.(ts|js)
4849
.vscode
@@ -96,7 +97,7 @@ function updateConfig(
9697
});
9798

9899
const transformPath = `./${
99-
!isReduced ? 'src/' : ''
100+
!isReduced ? 'codemods/' : ''
100101
}${transformName}/transform`;
101102

102103
properties.push(
@@ -140,9 +141,13 @@ export function initDirectory(
140141
targetPath = './',
141142
isReduced = false,
142143
) {
143-
fs.copySync(path.join(TEMPLATE_PATH, isReduced ? 'src' : ''), targetPath, {
144-
filter: src => !src.includes('src/codemod'),
145-
});
144+
fs.copySync(
145+
path.join(TEMPLATE_PATH, isReduced ? 'codemods' : ''),
146+
targetPath,
147+
{
148+
filter: src => !src.includes('codemods/codemod'),
149+
},
150+
);
146151

147152
if (!isReduced) {
148153
fs.writeFileSync(
@@ -174,20 +179,20 @@ export function initTransform(
174179
throw new Error(`Provided version ${id} is not a valid semver version`);
175180
}
176181

177-
const transformPath = path.join(targetPath, !isReduced ? 'src' : '', id);
182+
const transformPath = path.join(targetPath, !isReduced ? 'codemods' : '', id);
178183

179184
if (fs.existsSync(transformPath)) {
180185
throw new Error(`Codemod for ${type} "${id}" already exists`);
181186
}
182187

183188
const codemodTemplateDestinationPath = path.join(
184189
targetPath,
185-
!isReduced ? 'src' : '',
190+
!isReduced ? 'codemods' : '',
186191
'codemod',
187192
);
188193

189194
fs.copySync(
190-
path.join(TEMPLATE_PATH, 'src', 'codemod'),
195+
path.join(TEMPLATE_PATH, 'codemods', 'codemod'),
191196
codemodTemplateDestinationPath,
192197
);
193198
fs.renameSync(codemodTemplateDestinationPath, transformPath);

packages/initializer/template/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ This project was bootstrapped with [CodeshiftCommunity 🚚](https://www.codeshi
1010

1111
Runs the codeshift CLI useful for testing transform files as if they have been published
1212

13-
**example:** `npm run dev -t src/10.0.0/transform.ts`
13+
**example:** `npm run dev -t codemods/10.0.0/transform.ts`
14+
15+
Alternatively, you can run `npm run dev` to see an interactive list of codemods to choose from.
1416

1517
See the [cli reference](https://www.codeshiftcommunity.com/docs/cli) for more information.
1618

packages/initializer/template/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["src/**/*"],
2+
"include": ["codemods/**/*"],
33
"compilerOptions": {
44
"outDir": "dist",
55
"esModuleInterop": true,

website/docs/external-packages.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ react-cool-library/
3939
package.json
4040
tsconfig.json
4141
jest.config.js
42-
src/
42+
codemods/
4343
10.0.0/ // semver version
4444
transform.ts // main logic (should contain a transformer)
4545
transform.spec.ts // main tests
@@ -57,3 +57,10 @@ See the [Testing guide](testing) for help getting started with unit tests.
5757
Since your new codeshift package can simply be treated as an NPM package you can simply run `npm version [patch\minor\major]` and `npm publish`.
5858

5959
Your package will now be accessible via the `codeshift/cli`. Refer to the [Consuming guide](consuming) for information about how to run your new codemods.
60+
61+
## Examples
62+
63+
Here are some helpful example of this setup working in the wild:
64+
65+
- [Compiled codemods](https://github.com/atlassian-labs/compiled/tree/master/packages/codemods)
66+
- [Webdriver.io codemods](https://github.com/webdriverio/codemod)

website/docs/guides/monorepos.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ points to them.
5757

5858
See the [configuration guide](/docs/configuration) for help writing config files.
5959

60-
## Initialization
60+
## Initializing
6161

6262
Codeshift provides a CLI to quickly codegen a working codemod package around your existing source files. To do so, run `init` with the `--config-only` flag,
6363
which will output a bare-bones configuration. If you provide a `--transform` or `--preset` it will also generate empty transform files in addition.

0 commit comments

Comments
 (0)