diff --git a/src/projectInitializer.ts b/src/projectInitializer.ts index 10999a7f..a8b32429 100755 --- a/src/projectInitializer.ts +++ b/src/projectInitializer.ts @@ -60,12 +60,11 @@ export class ProjectInitializer { const scaffoldType = ScaffoldType.Local; // Step 1: Get project name - const projectPath = await this.generateProjectFolder(scaffoldType); + const projectPath = + await this.generateProjectFolder(telemetryContext, scaffoldType); if (!projectPath) { throw new CancelOperationError( `Project initialization cancelled: Project name input cancelled.`); - } else { - telemetryContext.properties.projectPath = projectPath; } // Step 2: Select platform @@ -178,8 +177,9 @@ export class ProjectInitializer { return templateSelection; } - private async generateProjectFolder(scaffoldType: ScaffoldType): - Promise { + private async generateProjectFolder( + telemetryContext: TelemetryContext, + scaffoldType: ScaffoldType): Promise { // Get default workbench path. const settings = await IoTWorkbenchSettings.getInstance(); const workbench = settings.getWorkbenchPath(); @@ -223,6 +223,10 @@ export class ProjectInitializer { } } }); + if (projectName) { + const projectNameMd5 = utils.getHashFromString(projectName); + telemetryContext.properties.projectName = projectNameMd5; + } const projectPath = projectName ? path.join(projectRootPath, projectName) : undefined; diff --git a/src/utils.ts b/src/utils.ts index d532cc22..e58f7a7e 100755 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,6 +2,7 @@ // Licensed under the MIT License. import * as cp from 'child_process'; +import * as crypto from 'crypto'; import * as fs from 'fs-plus'; import * as path from 'path'; import * as vscode from 'vscode'; @@ -890,4 +891,17 @@ export function shouldShowLandingPage(context: vscode.ExtensionContext): boolean { const hasPopUp = context.globalState.get(ConfigKey.hasPopUp, false); return !hasPopUp; +} + +/** + * Hash a string and get hash value. + * @param stringToHash string to hash + * @param algorithm hash algorithm + */ +export function getHashFromString( + stringToHash: string, algorithm = 'md5'): string { + const hash = crypto.createHash(algorithm); + hash.update(stringToHash); + const hashValue = hash.digest('hex'); + return hashValue; } \ No newline at end of file