Skip to content

Commit 4b0998b

Browse files
update readme
1 parent 5e9f676 commit 4b0998b

1 file changed

Lines changed: 63 additions & 9 deletions

File tree

README.md

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,83 @@
11
# ember-codemods-telemetry-helpers
22

3-
[![Build Status](https://travis-ci.com/ember-codemods/ember-codemods-telemetry-helpers.svg?branch=master)](https://travis-ci.com/ember-codemods/ember-codemods-telemetry-helpers)
3+
[![Build Status](https://travis-ci.com/ember-codemods/ember-codemods-telemetry-helpers.svg?branch=master)](https://travis-ci.com/ember-codemods/ember-codemods-telemetry-helpers) [![npm](https://img.shields.io/npm/v/ember-codemods-telemetry-helpers.svg?label=npm)](https://www.npmjs.com/package/ember-codemods-temetry-helpers)
44

5-
[![npm](https://img.shields.io/npm/v/ember-codemods-telemetry-helpers.svg?label=npm)](https://www.npmjs.com/package/ember-codemods-temetry-helpers)
65

7-
Telemetry helpers runs the app, grabs basic info about all of the modules at runtime.
6+
Telemetry helpers runs the app, grabs basic info about all of the modules at runtime.
87
This allows the codemod to know the names of every helper, component, route, controller, etc in the app without guessing / relying on static analysis.
98
They basically help you to create "runtime assisted codemods".
109

1110
## Goal
1211
The goal of the project though was to enable each codemod to manage its own type of data gathering
1312
and that the gather-telemetry-helpers package provides the harness to run that custom gathering function
1413

14+
## Usage
15+
16+
Assuming you are authoring a codemod with [codemod-cli](https://github.com/rwjblue/codemod-cli), `ember-codemods-telemetry-helpers` allows you freedom to assign your own "telemetry gathering" function while provide one of its own out of the box (opt-in).
17+
18+
```javascript
19+
#!/usr/bin/env node
20+
'use strict';
21+
22+
const { gatherTelemetryForUrl } = require('ember-codemods-telemetry-helpers');
23+
const appLocation = process.argv[2];
24+
const args = process.argv.slice(3);
25+
26+
// Gather only helpers
27+
function findHelpers(possibleEmberObject) {
28+
if (
29+
possibleEmberObject &&
30+
possibleEmberObject.default &&
31+
possibleEmberObject.default.isHelperFactory
32+
) {
33+
return true;
34+
}
35+
}
36+
37+
38+
(async () => {
39+
await gatherTelemetryForUrl(appLocation, findHelpers);
40+
41+
require('codemod-cli').runTransform(__dirname, 'my-cool-transform', args, 'hbs');
42+
})();
43+
```
44+
45+
All invocations of `gatherTelemetryForUrl` internally returns an object enumerated with properties named after all possible entries within `window.require.entries`. The values of each property is the value returned from within the gathering function. Usuing the example above, the output might be (for example):
46+
47+
```javascript
48+
{
49+
'ember-inflector/lib/helpers/pluralize': true,
50+
'ember-inflector/lib/helpers/singularize': true,
51+
'input/helpers/app-version': true,
52+
'input/helpers/pluralize': true,
53+
'input/helpers/singularize': true,
54+
}
55+
56+
```
57+
## Contributing
58+
59+
### Installation
60+
61+
* clone the repo
62+
* change into the repo directory
63+
* `yarn`
64+
65+
### Running tests
66+
67+
* `yarn test`
68+
1569
## More info
1670

17-
See "Gathering runtime data" section of
71+
See "Gathering runtime data" section of
1872
https://github.com/ember-codemods/ember-native-class-codemod#gathering-runtime-data for some additonal info
1973

2074

21-
This project was extracted from (ember-native-class-codemod)(https://github.com/ember-codemods/ember-native-class-codemod).
22-
That codemod uses (puppeteer)(https://github.com/GoogleChrome/puppeteer) (via this lib) to visit the Ember app and gather telemetry necessary to convert to native classes.
75+
This project was extracted from (ember-native-class-codemod)(https://github.com/ember-codemods/ember-native-class-codemod).
76+
That codemod uses (puppeteer)(https://github.com/GoogleChrome/puppeteer) (via this lib) to visit the Ember app and gather telemetry necessary to convert to native classes.
2377

24-
The idea for the extraction was to put the harness in this package
25-
(extracted from the native class codemod), but have the actual "telemetry gathering"
78+
The idea for the extraction was to put the harness in this package
79+
(extracted from the native class codemod), but have the actual "telemetry gathering"
2680
live in each individual codemod project because the things that they need are quite different
27-
for example, for [implicit this codemod](https://github.com/ember-codemods/ember-no-implicit-this-codemod) and
81+
for example, for [implicit this codemod](https://github.com/ember-codemods/ember-no-implicit-this-codemod) and
2882
[angle brackets codemod](https://github.com/ember-codemods/ember-angle-brackets-codemod) all we need to know is an array of the helpers and components in the app
2983
but for [native class codemod](https://github.com/ember-codemods/ember-native-class-codemod) it needs much more info (names and types of methods, properties, etc on each default export)

0 commit comments

Comments
 (0)