Skip to content

Commit ce47bcf

Browse files
Use telemetry data to detect known components and helpers (#154)
* first pass * intergration test * update readme for usage * PR fixes * dog fooding * improve test converage * re-enable debug * fix tests * more tests * rename tests * add attr node bailout * coerce boolean and numbers to string * define isWallStreet * improve test coverage * revert failing test * regex * update ember-codemods-telemetry-helpers
1 parent a26088d commit ce47bcf

89 files changed

Lines changed: 1607 additions & 47 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
**/__testfixtures__/**/*.*
1+
**/__testfixtures__/**/*.js
2+
**/fixtures/**

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
"prettier/prettier": "error"
1414
},
1515
overrides: [{
16-
files: ['**/test.js'],
16+
files: ['**/test.js', '**/*.test.js'],
1717
env: {
1818
jest: true
1919
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,9 @@ typings/
6262

6363
#editors
6464
.vscode
65+
66+
67+
tmp
68+
*.log
69+
test/**/yarn.lock
70+
-mock-telemetry.json

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ cache: yarn
88
script:
99
- yarn lint
1010
- yarn test
11+
- yarn test:integration
1112

1213
after_success:
1314
- yarn coveralls

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ember-angle-brackets-codemod
22

33
[![Ember Observer Score](https://emberobserver.com/badges/ember-angle-brackets-codemod.svg)](https://emberobserver.com/addons/ember-angle-brackets-codemod)
4-
[![Build Status](https://travis-ci.org/ember-codemods/ember-angle-brackets-codemod.svg?branch=master)](https://travis-ci.org/ember-codemods/ember-angle-brackets-codemod)
4+
[![Build Status](https://travis-ci.org/ember-codemods/ember-angle-brackets-codemod.svg?branch=master)](https://travis-ci.org/ember-codemods/ember-angle-brackets-codemod)
55
[![Coverage Status](https://coveralls.io/repos/github/ember-codemods/ember-angle-brackets-codemod/badge.svg?branch=master)](https://coveralls.io/github/ember-codemods/ember-angle-brackets-codemod?branch=master)
66
[![npm version](http://img.shields.io/npm/v/ember-angle-brackets-codemod.svg?style=flat)](https://npmjs.org/package/ember-angle-brackets-codemod "View this project on npm")
77
[![dependencies Status](https://david-dm.org/ember-codemods/ember-angle-brackets-codemod/status.svg)](https://david-dm.org/ember-codemods/ember-angle-brackets-codemod)
@@ -12,16 +12,18 @@ in an Ember.js app
1212

1313
Refer to this [RFC](https://github.com/emberjs/rfcs/blob/master/text/0311-angle-bracket-invocation.md) for more details on Angle brackets invocation syntax.
1414

15-
## Usage
15+
## Usage
1616

1717
**WARNING**: `jscodeshift`, and thus this codemod, **edits your files in place**.
1818
It does not make a copy. Make sure your code is checked into a source control
1919
repository like Git and that you have no outstanding changes to commit before
2020
running this tool.
2121

22+
1. Start your ember development server
23+
2. Run Codemod, pointing it at the address of the development server
2224
```sh
2325
$ cd my-ember-app-or-addon
24-
$ npx ember-angle-brackets-codemod angle-brackets app/templates
26+
$ npx ember-angle-brackets-codemod http://localhost:4200 path/of/files/ or /some**/*glob.hbs
2527
```
2628

2729
## From
@@ -62,7 +64,7 @@ To help the codemod disambiguate components and helpers, you can define a list o
6264
```js
6365
{
6466
"helpers": [
65-
"date-formatter",
67+
"date-formatter",
6668
"info-pill"
6769
]
6870
}
@@ -115,7 +117,7 @@ If there are files that don't convert well, you can skip them by specifying an o
115117

116118
## Debugging Workflow
117119
Oftentimes, you want to debug the codemod or the transform to identify issues with the code or to understand
118-
how the transforms are working, or to troubleshoot why some tests are failing.
120+
how the transforms are working, or to troubleshoot why some tests are failing.
119121

120122
Hence we recommend a debugging work-flow like below to quickly find out what is causing the issue.
121123

@@ -134,11 +136,11 @@ const params = a.value.params.map(p => {
134136
### 2. Inspect the process with node debug
135137
Here we are going to start the tests selectively in node debug mode. Since the
136138
codemod is bootstrapped using [codemod-cli](https://github.com/rwjblue/codemod-cli) which is using [jest](https://jestjs.io/) in turn
137-
to run the tests, jest is having an option `-t <name-of-spec>` to run a particular
139+
to run the tests, jest is having an option `-t <name-of-spec>` to run a particular
138140
set of tests instead of running the whole test suite.
139141
140142
We are making use of both these features to start our tests in this particular fashion.
141-
For more details on node debug, visit the [official](https://nodejs.org/en/docs/guides/debugging-getting-started/)
143+
For more details on node debug, visit the [official](https://nodejs.org/en/docs/guides/debugging-getting-started/)
142144
Node.js debugging guide, and for jest documentation on tests, please refer [here](https://jestjs.io/docs/en/cli).
143145
144146
```sh

bin/cli.js

100644100755
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
#!/usr/bin/env node
22
'use strict';
3+
const { gatherTelemetryForUrl, analyzeEmberObject } = require('ember-codemods-telemetry-helpers');
34

4-
require('codemod-cli').runTransform(
5-
__dirname,
6-
process.argv[2] /* transform name */,
7-
process.argv.slice(3) /* paths or globs */,
8-
'hbs'
9-
);
5+
(async () => {
6+
await gatherTelemetryForUrl(process.argv[2], analyzeEmberObject);
7+
8+
require('codemod-cli').runTransform(
9+
__dirname,
10+
'angle-brackets' /* transform name */,
11+
process.argv.slice(2) /* paths or globs */,
12+
'hbs'
13+
);
14+
})();

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
"bin": "./bin/cli.js",
2222
"scripts": {
2323
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
24+
"debug:integration": "node --inspect-brk ./test/run-test.js",
2425
"deploy": "npm version patch && git push && git push --tags && npm publish",
2526
"lint": "eslint . --cache",
27+
"test:integration": "node ./test/run-test.js",
2628
"test": "codemod-cli test --coverage"
2729
},
2830
"jest": {
@@ -31,18 +33,21 @@
3133
]
3234
},
3335
"dependencies": {
34-
"codemod-cli": "^2.0.0",
36+
"codemod-cli": "^2.1.0",
37+
"ember-codemods-telemetry-helpers": "^1.1.0",
3538
"ember-template-recast": "^3.2.8",
36-
"winston": "^3.2.1"
39+
"winston": "^3.2.1",
40+
"debug": "^4.1.1"
3741
},
3842
"devDependencies": {
3943
"coveralls": "^3.0.7",
4044
"eslint": "^6.6.0",
4145
"eslint-config-prettier": "^6.7.0",
4246
"eslint-plugin-prettier": "^3.1.1",
47+
"execa": "^3.3.0",
4348
"jest": "^24.9.0",
4449
"prettier": "^1.19.1",
45-
"release-it": "^12.2.1",
50+
"release-it": "^12.4.3",
4651
"release-it-lerna-changelog": "^1.0.3"
4752
},
4853
"engines": {

test/fixtures/input/.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
root = true
6+
7+
8+
[*]
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
indent_style = space
14+
indent_size = 2
15+
16+
[*.hbs]
17+
insert_final_newline = false
18+
19+
[*.{diff,md}]
20+
trim_trailing_whitespace = false

test/fixtures/input/.ember-cli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
/**
3+
Ember CLI sends analytics information by default. The data is completely
4+
anonymous, but there are times when you might want to disable this behavior.
5+
6+
Setting `disableAnalytics` to true will prevent any data from being sent.
7+
*/
8+
"disableAnalytics": false
9+
}

test/fixtures/input/.eslintignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# unconventional js
2+
/blueprints/*/files/
3+
/vendor/
4+
5+
# compiled output
6+
/dist/
7+
/tmp/
8+
9+
# dependencies
10+
/bower_components/
11+
12+
# misc
13+
/coverage/
14+
15+
# ember-try
16+
/.node_modules.ember-try/

0 commit comments

Comments
 (0)