Skip to content

Commit

Permalink
Removed unnecessary file path resolutions. Added tests. (#46)
Browse files Browse the repository at this point in the history
* revert: Ensured that .github folder is present

* revert: Ensured that tests folder is present

* revert: Ensured that root files are present

* refactor: Renamed function

* chore: Added test fixtures

* refactor: Added tests

* Updated documentation

* Updated blueprints

* chore: Added changeset

---------

Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
  • Loading branch information
ijlee2 and ijlee2 authored Jul 9, 2023
1 parent a7bffec commit 6cb6777
Show file tree
Hide file tree
Showing 187 changed files with 3,950 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-kiwis-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codemod-utils/cli": patch
---

Removed unnecessary file path resolutions. Added tests.
28 changes: 17 additions & 11 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@

# @codemod-utils/cli

_CLI to create a codemod_
_CLI to create a codemod project_


## Usage

Use `npx` to run `@codemod-utils/cli` and provide the codemod's name. (Alternatively, you can globally install `@codemod-utils/cli`.)
Step 1. Use `npx` to run `@codemod-utils/cli`. Alternatively, you can globally install the package.

```sh
npx @codemod-utils/cli --name <your-codemod-name> <additional arguments>
```

This will create a folder named `<your-codemod-name>`. Change to this directory, then run the following scripts:
This will create a folder named `<your-codemod-name>`.

Step 2. Change to the codemod directory, then run these scripts in sequence:

```sh
# Install dependencies
pnpm install
```

# Push to a (new) GitHub repository
```sh
# Commit changes
git init
git add .
git commit -m "Initial commit"
git branch -M main
```

```sh
# Push changes (to a new repo)
git remote add origin git@github.com:<your-github-handle>/<your-repo-name>.git
git branch -M main
git push -u origin main
```

Before pushing to the repository, consider updating `README.md` (e.g. link to the CI status badge).


### Arguments

Expand All @@ -41,15 +47,15 @@ npx @codemod-utils/cli --name ember-codemod-v1-to-v2


<details>
<summary>Optional: Add <code>@codemod-utils</code> packages</summary>
<summary>Optional: Add more utilities</summary>

By default, `@codemod-utils/cli` only installs [`@codemod-utils/files`](../files/README.md) and [`@codemod-utils/tests`](../tests/README.md). To add more utilities, pass `--addon` and the list of package names.
By default, `@codemod-utils/cli` only installs [`@codemod-utils/files`](../files/README.md) and [`@codemod-utils/tests`](../tests/README.md). If you need more, pass `--addon` and list the package names.

```sh
npx @codemod-utils/cli --addon blueprints json
```

The available package names are:
The options are:

- [`ast-javascript`](../ast/javascript/README.md)
- [`ast-template`](../ast/template/README.md)
Expand All @@ -66,7 +72,7 @@ The available package names are:
Pass `--root` to run the codemod somewhere else (i.e. not in the current directory).

```sh
npx @codemod-utils/cli --root=<path/to/your/project>
npx @codemod-utils/cli --root <path/to/your/project>
```

</details>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@codemod-utils/cli",
"version": "0.1.1",
"description": "CLI to create a codemod",
"description": "CLI to create a codemod project",
"keywords": [
"codemod",
"ember-codemod"
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/blueprints/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _Codemod to [PROVIDE A SHORT DESCRIPTION.]_
Pass `--root` to run the codemod somewhere else (i.e. not in the current directory).

```sh
npx <%= options.codemod.name %> --root=<path/to/your/project>
npx <%= options.codemod.name %> --root <path/to/your/project>
```

</details>
Expand All @@ -36,12 +36,12 @@ cd <path/to/cloned/repo>
pnpm build

# Run codemod
./dist/bin/<%= options.codemod.name %>.js --root=<path/to/your/project>
./dist/bin/<%= options.codemod.name %>.js --root <path/to/your/project>
```<% } else { %>```sh
cd <path/to/cloned/repo>

# Run codemod
./bin/<%= options.codemod.name %>.js --root=<path/to/your/project>
./bin/<%= options.codemod.name %>.js --root <path/to/your/project>
```<% } %>
Expand Down
File renamed without changes.
17 changes: 4 additions & 13 deletions packages/cli/src/migration/steps/create-files-from-blueprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ function getFilesToSkip(options: Options): string[] {
files.add('src/blueprints/.gitkeep');
files.add('src/utils/blueprints/blueprints-root.__js__');
files.add('src/utils/blueprints.__js__');
files.add('__tests__/utils/blueprints/blueprints-root.test.__js__');
files.add('tests/utils/blueprints/blueprints-root.test.__js__');
}

if (!codemod.hasTypeScript) {
files.add('__build.sh__');
files.add('build.sh');
files.add('src/types/index.ts');
files.add('tsconfig.build.json');
files.add('tsconfig.json');
Expand All @@ -36,22 +36,13 @@ function resolveBlueprintFilePath(
const { codemod } = options;

return blueprintFilePath
.replace('__github__/', '.github/')
.replace('__tests__/', 'tests/')
.replace('__codemod-name__', codemod.name)
.replace('__eslintignore__', '.eslintignore')
.replace('__eslintrc.cjs__', '.eslintrc.cjs')
.replace('__gitignore__', '.gitignore')
.replace('__npmignore__', '.npmignore')
.replace('__prettierrc.cjs__', '.prettierrc.cjs')
.replace('__build.sh__', 'build.sh')
.replace('__codemod-test-fixture.sh__', 'codemod-test-fixture.sh')
.replace('__codemod-test-fixtures.sh__', 'codemod-test-fixtures.sh')
.replace('__CONTRIBUTING.md__', 'CONTRIBUTING.md')
.replace('.__js__', codemod.hasTypeScript ? '.ts' : '.js');
}

function updateFilePermissions(options: Options) {
function setExecutePermissions(options: Options) {
const { codemod, projectRoot } = options;

const files = new Set([
Expand Down Expand Up @@ -104,5 +95,5 @@ export function createFilesFromBlueprints(options: Options): void {
);

createFiles(fileMap, options);
updateFilePermissions(options);
setExecutePermissions(options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _Codemod to [PROVIDE A SHORT DESCRIPTION.]_
Pass `--root` to run the codemod somewhere else (i.e. not in the current directory).

```sh
npx ember-codemod-args-to-signature --root=<path/to/your/project>
npx ember-codemod-args-to-signature --root <path/to/your/project>
```

</details>
Expand All @@ -33,7 +33,7 @@ To better meet your needs, consider cloning the repo and running the codemod loc
cd <path/to/cloned/repo>

# Run codemod
./bin/ember-codemod-args-to-signature.js --root=<path/to/your/project>
./bin/ember-codemod-args-to-signature.js --root <path/to/your/project>
```


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _Codemod to [PROVIDE A SHORT DESCRIPTION.]_
Pass `--root` to run the codemod somewhere else (i.e. not in the current directory).

```sh
npx ember-codemod-pod-to-octane --root=<path/to/your/project>
npx ember-codemod-pod-to-octane --root <path/to/your/project>
```

</details>
Expand All @@ -33,7 +33,7 @@ To better meet your needs, consider cloning the repo and running the codemod loc
cd <path/to/cloned/repo>

# Run codemod
./bin/ember-codemod-pod-to-octane.js --root=<path/to/your/project>
./bin/ember-codemod-pod-to-octane.js --root <path/to/your/project>
```


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# compiled output
/dist/
/dist-for-testing/
/tmp/

# dependencies
/node_modules/

# misc
!.*
.*/
/src/blueprints/
/tests/fixtures/
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

module.exports = {
root: true,
parser: '@babel/eslint-parser',
parserOptions: {
ecmaVersion: 'latest',
requireConfigFile: false,
sourceType: 'module',
},
plugins: ['simple-import-sort'],
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:n/recommended',
'plugin:prettier/recommended',
],
rules: {
curly: 'error',
'simple-import-sort/exports': 'error',
'simple-import-sort/imports': 'error',
},
overrides: [
// JavaScript files
{
files: ['**/*.js'],
rules: {
'import/no-duplicates': 'error',
},
},
// Node files
{
files: ['./.eslintrc.{cjs,js}', './.prettierrc.{cjs,js}'],
env: {
browser: false,
node: true,
},
extends: ['plugin:n/recommended'],
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Ask for better documentation
about: Ask for better documentation
title: ''
labels: 'enhance: documentation'
assignees: ''

---

Hello! Thanks for taking time to suggest how we can improve documentation.

Here, documentation can mean a few different things, including README, code comments, and tests. Anything that will help everyone understand how to use `ember-codemod-args-to-signature`!


## I would like to see... πŸ™‹β€β™€οΈπŸ™‹β€β™‚οΈ

A clear, concise description of what you want to happen.


## Why and how πŸ’¬

A clear, concise description of why you want something to happen and how we might be able to solve the problem.


## Additional context βž•

If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Ask for new feature or refactor
about: Ask for new feature or refactor
title: ''
labels: 'enhance: code'
assignees: ''

---

Hello! Thanks for taking time to suggest how we can improve `ember-codemod-args-to-signature`.

Before you make a new issue, please search for similar issues. It's possible that someone has made a request already.


## I would like to see... πŸ™‹β€β™€οΈπŸ™‹β€β™‚οΈ

A clear, concise description of what you want to happen.


## Why and how πŸ’¬

A clear, concise description of why you want something to happen and how we might be able to solve the problem.


## Additional context βž•

If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the request here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Report bug
about: Report bug
title: ''
labels: bug
assignees: ''

---

Hello! Thanks for taking time to make a bug report.

Before you make a new issue, please search for similar issues. It's possible that someone has reported this bug already.


## Describe the bug 🐞

A clear and concise description of the bug.


## Expected behavior πŸ€”

A clear and concise description of what you expected to see.


## Minimal reproduction πŸ”¬

Describe steps to reproduce the issue.

1. ...
1. ...
1. ...

If possible, please share a repo with the minimum files to reproduce the issue.


## Additional context βž•

If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Report outdated dependency
about: Report outdated dependency
title: ''
labels: 'enhance: dependency'
assignees: ''

---

Hello! Thanks for taking time to make an outdated dependency report.

Before you make a new issue, please search for similar issues. It's possible that someone has made a request for update already.


## List outdated dependencies πŸ”—

When you ran `pnpm outdated`, what did you see?

```sh
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Package β”‚ Current β”‚ Latest β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ @sondr3/minitest (dev) β”‚ 0.1.1 β”‚ 0.1.2 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```


## Risk analysis ⚠️

Are there breaking changes that we should be aware of? Please add links to the `CHANGELOG`s, if they are available.


## Additional context βž•

If needed, you can provide more context (e.g. reference materials, screenshots, GIFs) for the problem here.
Loading

0 comments on commit 6cb6777

Please sign in to comment.