From e40d16a64bc864eef05e7b0d3054c3135ba917e7 Mon Sep 17 00:00:00 2001 From: ijlee2 Date: Tue, 25 Jul 2023 21:51:18 +0200 Subject: [PATCH] chore: Patched #53 --- README.md | 2 +- .../00-introduction.md | 4 +-- .../01-create-a-project.md | 32 +++++++++++++++++-- .../02-understand-the-folder-structure.md | 14 ++++---- 4 files changed, 38 insertions(+), 14 deletions(-) rename tutorials/{ember-codemod-rename-tests => ember-codemod-rename-test-modules}/00-introduction.md (86%) rename tutorials/{ember-codemod-rename-tests => ember-codemod-rename-test-modules}/01-create-a-project.md (50%) rename tutorials/{ember-codemod-rename-tests => ember-codemod-rename-test-modules}/02-understand-the-folder-structure.md (92%) diff --git a/README.md b/README.md index b7e641a2..311e1586 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ npx @codemod-utils/cli --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 diff --git a/tutorials/ember-codemod-rename-tests/00-introduction.md b/tutorials/ember-codemod-rename-test-modules/00-introduction.md similarity index 86% rename from tutorials/ember-codemod-rename-tests/00-introduction.md rename to tutorials/ember-codemod-rename-test-modules/00-introduction.md index 4801e30e..a22df823 100644 --- a/tutorials/ember-codemod-rename-tests/00-introduction.md +++ b/tutorials/ember-codemod-rename-test-modules/00-introduction.md @@ -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) */ diff --git a/tutorials/ember-codemod-rename-tests/01-create-a-project.md b/tutorials/ember-codemod-rename-test-modules/01-create-a-project.md similarity index 50% rename from tutorials/ember-codemod-rename-tests/01-create-a-project.md rename to tutorials/ember-codemod-rename-test-modules/01-create-a-project.md index f39e688e..726720c5 100644 --- a/tutorials/ember-codemod-rename-tests/01-create-a-project.md +++ b/tutorials/ember-codemod-rename-test-modules/01-create-a-project.md @@ -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 @@ -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 ``` @@ -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 + +
Next: Understand the folder structure diff --git a/tutorials/ember-codemod-rename-tests/02-understand-the-folder-structure.md b/tutorials/ember-codemod-rename-test-modules/02-understand-the-folder-structure.md similarity index 92% rename from tutorials/ember-codemod-rename-tests/02-understand-the-folder-structure.md rename to tutorials/ember-codemod-rename-test-modules/02-understand-the-folder-structure.md index d325f8aa..3ef8b77e 100644 --- a/tutorials/ember-codemod-rename-tests/02-understand-the-folder-structure.md +++ b/tutorials/ember-codemod-rename-test-modules/02-understand-the-folder-structure.md @@ -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 @@ -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 +./dist/bin/ember-codemod-rename-test-modules.js --root ``` 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 ``` @@ -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