Skip to content

Commit

Permalink
update the code based on telemetry data changes
Browse files Browse the repository at this point in the history
  • Loading branch information
suchitadoshi1987 committed Apr 24, 2020
1 parent e052e28 commit 3c0e546
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const finder = require('find-package-json');
const recast = require('ember-template-recast');
const fs = require('fs');
const path = require('path');
const { appResolver, detectTypeAndName } = require('../transforms/no-implicit-this/helpers/util');
const { appResolver, detectTypeAndName, TELEMETRY_KEY } = require('../transforms/no-implicit-this/helpers/util');
const { gatherSingleTelemetryForUrl, getTelemetry } = require('ember-codemods-telemetry-helpers');
const appLocation = process.argv[2];
const args = process.argv.slice(3);
Expand Down Expand Up @@ -93,7 +93,13 @@ function findAppName(f) {
debug('Gathering telemetry data from %s ...', appLocation);

// This is for collecting metadata for the app just once to generate the map of lookupnames to local properties
await gatherSingleTelemetryForUrl(appLocation, appResolver, lookupNames, appName);
await gatherSingleTelemetryForUrl(
appLocation,
{ telemetryKey: TELEMETRY_KEY },
appResolver,
lookupNames,
appName
);

let telemetry = getTelemetry();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"single-telemetry": {
"telemetry-data": {
"component:handlebars-with-prefix-component-properties-only": {
"type": "Component",
"localProperties": ["baz", "bang"],
Expand Down
3 changes: 2 additions & 1 deletion transforms/no-implicit-this/helpers/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const path = require('path');
// sorta. telemetry needs to be defined.
// telemtry can be populated with -mock-telemetry.json
const KNOWN_HELPERS = require('./known-helpers');
const { TELEMETRY_KEY } = require('./util');

function getTelemetryObjByName(name, telemetry) {
let telemetryLookupName = Object.keys(telemetry).find(item => item.split(':').pop() === name);
Expand All @@ -18,7 +19,7 @@ function transform(root, options = {}) {
let b = recast.builders;

let scopedParams = [];
let telemetry = options.telemetry ? options.telemetry['single-telemetry'] : {};
let telemetry = options.telemetry ? options.telemetry[TELEMETRY_KEY] : {};

let customHelpers = options.customHelpers || [];

Expand Down
3 changes: 2 additions & 1 deletion transforms/no-implicit-this/helpers/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const globby = require('globby');
const TELEMETRY_KEY = 'telemetry-data';

/**
* Generates a lookup name for a backing js class.
Expand Down Expand Up @@ -112,4 +113,4 @@ function appResolver(lookupNames, currAppName) {
return mapping;
}

module.exports = { appResolver, detectTypeAndName };
module.exports = { appResolver, detectTypeAndName, TELEMETRY_KEY };

0 comments on commit 3c0e546

Please sign in to comment.