Skip to content

Commit f5e5e7f

Browse files
author
Robert Jackson
authored
update readme (#17)
update readme
2 parents 5e9f676 + 7cfe1ac commit f5e5e7f

1 file changed

Lines changed: 68 additions & 9 deletions

File tree

README.md

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,88 @@
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+
This package does provide one gathering function: `analyzeEmberObject`. The function does a "best effort" analysis of the app runtime, return such things as most Ember object types (Components, Helpers, Routes, etc) and "own" properties.
57+
58+
```javascript
59+
const { analyzeEmberObject } = require('ember-codemods-telemetry-helpers');
60+
```
61+
62+
## Contributing
63+
64+
### Installation
65+
66+
* clone the repo
67+
* change into the repo directory
68+
* `yarn`
69+
70+
### Running tests
71+
72+
* `yarn test`
73+
1574
## More info
1675

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

2079

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.
80+
This project was extracted from (ember-native-class-codemod)(https://github.com/ember-codemods/ember-native-class-codemod).
81+
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.
2382

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"
83+
The idea for the extraction was to put the harness in this package
84+
(extracted from the native class codemod), but have the actual "telemetry gathering"
2685
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
86+
for example, for [implicit this codemod](https://github.com/ember-codemods/ember-no-implicit-this-codemod) and
2887
[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
2988
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)