|
1 | 1 | # ember-codemods-telemetry-helpers |
2 | 2 |
|
3 | | -[](https://travis-ci.com/ember-codemods/ember-codemods-telemetry-helpers) |
| 3 | +[](https://travis-ci.com/ember-codemods/ember-codemods-telemetry-helpers) [](https://www.npmjs.com/package/ember-codemods-temetry-helpers) |
4 | 4 |
|
5 | | -[](https://www.npmjs.com/package/ember-codemods-temetry-helpers) |
6 | 5 |
|
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. |
8 | 7 | This allows the codemod to know the names of every helper, component, route, controller, etc in the app without guessing / relying on static analysis. |
9 | 8 | They basically help you to create "runtime assisted codemods". |
10 | 9 |
|
11 | 10 | ## Goal |
12 | 11 | The goal of the project though was to enable each codemod to manage its own type of data gathering |
13 | 12 | and that the gather-telemetry-helpers package provides the harness to run that custom gathering function |
14 | 13 |
|
| 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 | + |
15 | 74 | ## More info |
16 | 75 |
|
17 | | -See "Gathering runtime data" section of |
| 76 | +See "Gathering runtime data" section of |
18 | 77 | https://github.com/ember-codemods/ember-native-class-codemod#gathering-runtime-data for some additonal info |
19 | 78 |
|
20 | 79 |
|
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. |
23 | 82 |
|
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" |
26 | 85 | 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 |
28 | 87 | [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 |
29 | 88 | 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