Skip to content

Commit

Permalink
chore: Patched #53
Browse files Browse the repository at this point in the history
  • Loading branch information
ijlee2 committed Jul 25, 2023
1 parent d977b81 commit e40d16a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ npx @codemod-utils/cli --name <your-codemod-name>

## Tutorials

- [`ember-codemod-rename-tests`](./tutorials/ember-codemod-rename-tests/00-introduction.md)
- [`ember-codemod-rename-test-modules`](./tutorials/ember-codemod-rename-test-modules/00-introduction.md)


## Codemods written with @codemod-utils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Introduction

Thanks for trying out `@codemod-utils`!

In this tutorial, we will create a codemod called `ember-codemod-rename-tests` (to be precise, rename test modules).
Thanks for trying out `@codemod-utils`! In this tutorial, we will create a codemod called `ember-codemod-rename-test-modules`.

```ts
/* Before: Module names are inconsistent (thanks to copy-paste) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

We can use `@codemod-utils/cli` (a command-line interface) to create a Node project. It comes with lint, test, CI (continuous integration), and documentation out of the box.

By default, the CLI adds `@codemod-utils/files` and `@codemod-utils/tests` (these packages are "core"), because every codemod will need them. For `ember-codemod-rename-tests`, we need to parse and update JS and TS files, so we will instruct the CLI to add `@codemod-utils/ast-javascript` (an "addon").
By default, the CLI adds `@codemod-utils/files` and `@codemod-utils/tests` (these packages are "core"), because every codemod will need them. For `ember-codemod-rename-test-modules`, we need to parse and update JS and TS files, so we will instruct the CLI to add `@codemod-utils/ast-javascript` (an "addon").

Goals:

- Use `@codemod-utils/cli` to create a project
- Familiarize with `lint`, `lint:fix`, and `test`


## Use the CLI
Expand All @@ -15,10 +16,10 @@ Change the directory to a place where you like to keep projects. Then, run these

```sh
# Create project
npx @codemod-utils/cli --name ember-codemod-rename-tests --addon ast-javascript
npx @codemod-utils/cli --name ember-codemod-rename-test-modules --addon ast-javascript

# Install dependencies
cd ember-codemod-rename-tests
cd ember-codemod-rename-test-modules
pnpm install
```

Expand All @@ -39,6 +40,31 @@ git push -u origin main
```


## Local development

As you write code, you will want to lint and test files.

```sh
# Lint files
pnpm lint
pnpm lint:fix

# Test files
pnpm test
```

Try running these scripts now. They should pass out of the box. (The scripts for local development are documented in `CONTRIBUTING.md`.)


## Update configurations

The CLI added a few placeholders. At some point (before the initial commit or, at the latest, before publishing the codemod), you will want to manually update these files:

- `LICENSE.md` - copyright information
- `package.json` - `author`, `description`, `repository` (remove `private` to publish the codemod)
- `README.md` - link to the CI status badge, description, codemod arguments


<div align="center">
<div>
Next: <a href="./02-understand-the-folder-structure.md">Understand the folder structure</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Goals:

## Folder structure

Let's take a look how `ember-codemod-rename-tests` is structured as a tree. For simplicity, the tree only shows what's important for the tutorial.
Let's take a look how `ember-codemod-rename-test-modules` is structured as a tree. For simplicity, the tree only shows what's important for the tutorial.

```sh
ember-codemod-rename-tests
ember-codemod-rename-test-modules
├── bin
│ └── ember-codemod-rename-tests.ts
│ └── ember-codemod-rename-test-modules.ts
├── src
│ ├── (blueprints)
│ ├── steps
Expand Down Expand Up @@ -45,13 +45,13 @@ The `bin` folder has an **executable file**. This file allows your users ("end-d
pnpm build

# Run codemod
./dist/bin/ember-codemod-rename-tests.js --root <path/to/your/project>
./dist/bin/ember-codemod-rename-test-modules.js --root <path/to/your/project>
```

It also means, you can test the codemod on a project on your local machine.

```sh
./dist/bin/ember-codemod-rename-tests.js --root ../../work-projects/client
./dist/bin/ember-codemod-rename-test-modules.js --root ../../work-projects/client
```


Expand Down Expand Up @@ -234,9 +234,9 @@ Note, the conventions for folder names may change in the future, so that we can

To run the codemod (written in TypeScript), it must be compiled to JavaScript first.

Running the `build` script (re-)creates the `dist` folder. The files in this folder are what is shipped to the end-developers.
Running the `build` script (re)creates the `dist` folder. The files in this folder are what is shipped to the end-developers.

Running the `test` script (re-)creates the `dist-for-testing` folder. The files in this folder are what is tested. The fixture files are created in the `tmp` folder.
Running the `test` script (re)creates the `dist-for-testing` folder. The files in this folder are what is tested. The fixture files are created in the `tmp` folder.


### codemod-test-fixtures.sh
Expand Down

0 comments on commit e40d16a

Please sign in to comment.