Skip to content

Commit

Permalink
Cleanup argv (#76416)
Browse files Browse the repository at this point in the history
  • Loading branch information
lramos15 authored Jul 2, 2019
1 parent 39c9d85 commit 01defd1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/vs/code/node/cliProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { LocalizationsService } from 'vs/platform/localizations/node/localizations';
import { Schemas } from 'vs/base/common/network';
import { SpdLogService } from 'vs/platform/log/node/spdlogService';
import { buildTelemetryMessage } from 'vs/platform/environment/node/argv';
import { buildTelemetryMessage } from 'vs/platform/telemetry/node/telemetry';

const notFound = (id: string) => localize('notFound', "Extension '{0}' not found.", id);
const notInstalled = (id: string) => localize('notInstalled', "Extension '{0}' is not installed.", id);
Expand Down
38 changes: 1 addition & 37 deletions src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import * as os from 'os';
import { localize } from 'vs/nls';
import { ParsedArgs } from 'vs/platform/environment/common/environment';
import { join } from 'vs/base/common/path';
import { statSync, readFileSync } from 'fs';
import { writeFileSync, readdirSync } from 'vs/base/node/pfs';
import { writeFileSync } from 'vs/base/node/pfs';

/**
* This code is also used by standalone cli's. Avoid adding any other dependencies.
Expand Down Expand Up @@ -219,41 +218,6 @@ export function buildVersionMessage(version: string | undefined, commit: string
return `${version || localize('unknownVersion', "Unknown version")}\n${commit || localize('unknownCommit', "Unknown commit")}\n${process.arch}`;
}

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);
}

/**
* Converts an argument into an array
* @param arg a argument value. Can be undefined, an entry or an array
Expand Down
44 changes: 44 additions & 0 deletions src/vs/platform/telemetry/node/telemetry.ts
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);
}

0 comments on commit 01defd1

Please sign in to comment.