Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated CLI #131

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-onions-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codemod-utils/cli": major
---

Replaced @codemod-utils/ember-cli-string with @codemod-utils/ember. Made codemod name a positional argument.
3 changes: 1 addition & 2 deletions packages/cli/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
/.prettierignore
/.prettierrc.cjs
/build.sh
/codemod-test-fixture.sh
/codemod-test-fixtures.sh
/update-test-fixtures.sh
/tests/
10 changes: 5 additions & 5 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ _CLI to create a codemod project_

## Usage

Step 1. Use `npx` to run `@codemod-utils/cli`. Alternatively, you can globally install the package.
Step 1. Use `npx` to run `@codemod-utils/cli`.

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

This will create a folder named `<your-codemod-name>`.
Expand Down Expand Up @@ -39,10 +39,10 @@ git push -u origin main

### Arguments

You must pass `--name` to name your codemod.
You must pass the name of your codemod.

```sh
npx @codemod-utils/cli --name ember-codemod-v1-to-v2
npx @codemod-utils/cli ember-codemod-v1-to-v2
```


Expand All @@ -61,7 +61,7 @@ The options are:
- [`ast-javascript`](../ast/javascript/README.md)
- [`ast-template`](../ast/template/README.md)
- [`blueprints`](../blueprints/README.md)
- [`ember-cli-string`](../ember-cli-string/README.md)
- [`ember`](../ember/README.md)
- [`json`](../json/README.md)

</details>
Expand Down
77 changes: 42 additions & 35 deletions packages/cli/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,52 @@ import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

import { createCodemod } from '../src/index.js';
import type { CodemodOptions } from '../src/types/index.js';

// Provide a title to the process in `ps`
process.title = '@codemod-utils/cli';

// Set codemod options
const argv = yargs(hideBin(process.argv))
.option('addon', {
choices: [
'ast-javascript',
'ast-template',
'blueprints',
'ember-cli-string',
'json',
] as const,
describe: 'Optional @codemod-utils packages to install',
type: 'array',
})
.option('name', {
demandOption: true,
describe: 'Name of your codemod',
type: 'string',
})
.option('root', {
describe: 'Where to run @codemod-utils/cli',
type: 'string',
})
.option('typescript', {
default: true,
describe: 'Create a TypeScript project?',
type: 'boolean',
yargs(hideBin(process.argv))
.command({
builder: (yargs) => {
return yargs
.positional('name', {
describe: 'Name of your codemod',
type: 'string',
})
.option('addon', {
choices: [
'ast-javascript',
'ast-template',
'blueprints',
'ember',
'json',
] as const,
describe: 'Optional @codemod-utils packages to install',
type: 'array',
})
.option('root', {
describe: 'Where to run @codemod-utils/cli',
type: 'string',
})
.option('typescript', {
default: true,
describe: 'Create a TypeScript project?',
type: 'boolean',
})
.demandOption(['name']);
},
command: '* [name]',
describe: 'Creates a codemod project',
handler: (argv) => {
createCodemod({
addons: new Set(argv['addon']),
hasTypeScript: argv['typescript'],
name: argv['name'],
projectRoot: argv['root'] ?? process.cwd(),
});
},
})
.demandCommand()
.strict()
.parseSync();

const codemodOptions: CodemodOptions = {
addons: new Set(argv['addon']),
hasTypeScript: argv['typescript'],
name: argv['name'],
projectRoot: argv['root'] ?? process.cwd(),
};

createCodemod(codemodOptions);
44 changes: 0 additions & 44 deletions packages/cli/codemod-test-fixture.sh

This file was deleted.

32 changes: 0 additions & 32 deletions packages/cli/codemod-test-fixtures.sh

This file was deleted.

3 changes: 1 addition & 2 deletions packages/cli/src/blueprints/__npmignore__
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
/.prettierignore
/.prettierrc.cjs
/build.sh
/codemod-test-fixture.sh
/codemod-test-fixtures.sh
/update-test-fixtures.sh
/CONTRIBUTING.md
/create-test-fixture.sh
/tests/
44 changes: 0 additions & 44 deletions packages/cli/src/blueprints/codemod-test-fixture.sh

This file was deleted.

20 changes: 0 additions & 20 deletions packages/cli/src/blueprints/codemod-test-fixtures.sh

This file was deleted.

23 changes: 23 additions & 0 deletions packages/cli/src/blueprints/update-test-fixtures.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env sh

#----------
#
# A. Purpose
#
# Fix all test fixtures after updating the source code.
#
# B. Usage
#
# ./update-test-fixtures.sh
#
#---------
<% if (options.codemod.hasTypeScript) { %>
# Compile TypeScript
pnpm build
<% } %>
# Update fixtures
rm -r "tests/fixtures/sample-project/output"
cp -r "tests/fixtures/sample-project/input" "tests/fixtures/sample-project/output"

./dist/bin/<%= options.codemod.name %>.js \
--root "tests/fixtures/sample-project/output"
5 changes: 1 addition & 4 deletions packages/cli/src/steps/create-files-from-blueprints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ function resolveBlueprintFilePath(
function setExecutePermissions(options: Options) {
const { codemod, projectRoot } = options;

const files = new Set([
'codemod-test-fixture.sh',
'codemod-test-fixtures.sh',
]);
const files = new Set(['update-test-fixtures.sh']);

if (codemod.hasTypeScript) {
files.add(`bin/${codemod.name}.ts`);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type Addon =
| 'ast-javascript'
| 'ast-template'
| 'blueprints'
| 'ember-cli-string'
| 'ember'
| 'json';

type CodemodOptions = {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/blueprints/get-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const latestVersions = new Map([
['@codemod-utils/ast-javascript', '1.2.8'],
['@codemod-utils/ast-template', '1.1.4'],
['@codemod-utils/blueprints', '1.1.5'],
['@codemod-utils/ember-cli-string', '1.1.4'],
['@codemod-utils/ember', '2.0.0'],
['@codemod-utils/files', '2.0.4'],
['@codemod-utils/json', '1.1.9'],
['@codemod-utils/tests', '1.1.7'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
/.prettierignore
/.prettierrc.cjs
/build.sh
/codemod-test-fixture.sh
/codemod-test-fixtures.sh
/update-test-fixtures.sh
/CONTRIBUTING.md
/create-test-fixture.sh
/tests/

This file was deleted.

Loading