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

Migrate to codemod-cli structure. #114

Merged
merged 1 commit into from
Jun 26, 2018
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/__testfixtures__/
__testfixtures__
37 changes: 30 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,42 @@
This codemod is intended to automatically convert your projects from the older
`moduleFor*` syntax of `ember-qunit@2` to the newer syntax proposed by [emberjs/rfcs#232](https://github.com/emberjs/rfcs/blob/master/text/0232-simplify-qunit-testing-api.md).

## Installation
This codemod can be used in conjunction with [ember-test-helpers-codemod](https://github.com/simonihmig/ember-test-helpers-codemod).

## Usage

To run a specific codemod from this project, you would run the following:

```sh
npm install -g ember-qunit-codemod
```
npx special-project <TRANSFORM NAME> path/of/files/ or/some**/*glob.js

## Usage
# or

```sh
ember-qunit-codemod ./tests/
yarn global add special-project
special-project <TRANSFORM NAME> path/of/files/ or/some**/*glob.js
```

This codemod can be used in conjunction with [ember-test-helpers-codemod](https://github.com/simonihmig/ember-test-helpers-codemod).
## Transforms

<!--TRANSFORMS_START-->
* [convert-module-for-to-setup-test](transforms/convert-module-for-to-setup-test/README.md)
<!--TRANSFORMS_END-->

## Contributing

### Installation

* clone the repo
* change into the repo directory
* `yarn`

### Running tests

* `yarn test`

### Update Documentation

* `yarn update-docs`

## Credit

Expand Down
90 changes: 0 additions & 90 deletions __tests__/bin-test.js

This file was deleted.

40 changes: 0 additions & 40 deletions __tests__/codemod-test.js

This file was deleted.

20 changes: 5 additions & 15 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
#!/usr/bin/env node
'use strict';

const execa = require('execa');
const chalk = require('chalk');
const path = require('path');

try {
let transformPath = path.join(__dirname, '/../ember-qunit-codemod.js');
let targetDir = process.argv[2];
execa('jscodeshift', ['-t', transformPath, '--extensions', 'js,ts', targetDir], {
stdio: 'inherit',
env: process.env,
});
} catch (e) {
console.error(chalk.red(e.stack)); // eslint-disable-line no-console
process.exit(-1);
}
require('codemod-cli').runTransform(
__dirname,
process.argv[2] /* transform name */,
process.argv.slice(3) /* paths or globs */
);
15 changes: 4 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.1",
"description": "codemod script for ember-qunit",
"keywords": [
"codemod-cli",
"codemod",
"qunit"
],
Expand All @@ -19,25 +20,17 @@
"bin": "./bin/cli.js",
"scripts": {
"lint": "eslint .",
"test": "jest"
"test": "codemod-cli test",
"update-docs": "codemod-cli update-docs"
},
"dependencies": {
"@babel/parser": "^7.0.0-beta.48",
"chalk": "^2.4.1",
"execa": "^0.10.0",
"jscodeshift": "^0.5.1",
"recast": "^0.15.0"
"codemod-cli": "^0.2.0"
},
"devDependencies": {
"babel-preset-env": "^1.7.0",
"broccoli-test-helper": "^1.2.0",
"co": "^4.6.0",
"eslint": "^5.0.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.0",
"jest": "^23.1.0",
"jest-diff": "^23.0.1",
"jest-matcher-utils": "^23.0.1",
"prettier": "^1.13.5"
},
"engines": {
Expand Down
23 changes: 23 additions & 0 deletions transforms/convert-module-for-to-setup-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# main

This codemod transforms from the `moduleFor*` style system to `setup*Test` system.

## Usage

```
npx ember-qunit-codemod convert-module-for-to-setup-test path/of/files/ or/some**/*glob.js

# or

yarn global add ember-qunit-codemod
ember-qunit-codemod convert-module-for-to-setup-test path/of/files/ or/some**/*glob.js
```

## Input / Output

<!--FIXTURES_TOC_START-->
<!--FIXTURES_TOC_END-->

<!--FIXTURES_CONTENT_START-->
<!--FIXTURE_CONTENT_END-->

Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
'use strict';

const { getParser } = require('codemod-cli').jscodeshift;

module.exports = function(file, api) {
let j = api.jscodeshift;
try {
let parser = require('recast/parsers/typescript');

j = api.jscodeshift.withParser(parser);
} catch (e) {
// eslint-disable-next-line
console.log(
'Could not load typescript aware parser, falling back to standard recast parser...'
);
}
let j = getParser(api);

const root = j(file.source);

Expand Down
8 changes: 8 additions & 0 deletions transforms/convert-module-for-to-setup-test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

const { runTransformTest } = require('codemod-cli');

runTransformTest({
type: 'jscodeshift',
name: 'convert-module-for-to-setup-test',
});
Loading