-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
|
||
import { readdirSync } from 'vs/base/node/pfs'; | ||
import { statSync, readFileSync } from 'fs'; | ||
import { join } from 'vs/base/common/path'; | ||
|
||
export function buildTelemetryMessage(appRoot: string, extensionsPath: string): string { | ||
// Gets all the directories inside the extension directory | ||
const dirs = readdirSync(extensionsPath).filter(files => { | ||
// This handles case where broken symbolic links can cause statSync to throw and error | ||
try { | ||
return statSync(join(extensionsPath, files)).isDirectory(); | ||
} catch { | ||
return false; | ||
} | ||
}); | ||
const telemetryJsonFolders: string[] = []; | ||
dirs.forEach((dir) => { | ||
const files = readdirSync(join(extensionsPath, dir)).filter(file => file === 'telemetry.json'); | ||
// We know it contains a telemetry.json file so we add it to the list of folders which have one | ||
if (files.length === 1) { | ||
telemetryJsonFolders.push(dir); | ||
} | ||
}); | ||
const mergedTelemetry = Object.create(null); | ||
// Simple function to merge the telemetry into one json object | ||
const mergeTelemetry = (contents: string, dirName: string) => { | ||
const telemetryData = JSON.parse(contents); | ||
mergedTelemetry[dirName] = telemetryData; | ||
}; | ||
telemetryJsonFolders.forEach((folder) => { | ||
const contents = readFileSync(join(extensionsPath, folder, 'telemetry.json')).toString(); | ||
mergeTelemetry(contents, folder); | ||
}); | ||
let contents = readFileSync(join(appRoot, 'telemetry-core.json')).toString(); | ||
mergeTelemetry(contents, 'vscode-core'); | ||
contents = readFileSync(join(appRoot, 'telemetry-extensions.json')).toString(); | ||
mergeTelemetry(contents, 'vscode-extensions'); | ||
return JSON.stringify(mergedTelemetry, null, 4); | ||
} |