mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
Code refactor
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import * as os from 'os';
|
||||
|
||||
import Constants from '../Constants';
|
||||
import ScriptBuilder from './ScriptBuilder';
|
||||
import PowerShellToolRunner from './PowerShellToolRunner';
|
||||
|
||||
export default class Utils {
|
||||
static setPSModulePath(azPSVersion: string = "") {
|
||||
@@ -23,6 +25,29 @@ export default class Utils {
|
||||
process.env.PSModulePath = `${modulePath}${process.env.PSModulePath}`;
|
||||
}
|
||||
|
||||
static async getLatestModule(moduleName: string): Promise<any> {
|
||||
let output: string = "";
|
||||
const options: any = {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
output += data.toString();
|
||||
}
|
||||
}
|
||||
};
|
||||
await PowerShellToolRunner.init();
|
||||
await PowerShellToolRunner.executePowerShellScriptBlock(new ScriptBuilder()
|
||||
.getLatestModuleScript(moduleName), options);
|
||||
const outputJson = JSON.parse(output.trim());
|
||||
if (!(Constants.Success in outputJson)) {
|
||||
throw new Error(outputJson[Constants.Error]);
|
||||
}
|
||||
const azLatestVersion: string = outputJson[Constants.AzVersion];
|
||||
if (!Utils.isValidVersion(azLatestVersion)) {
|
||||
throw new Error(`Invalid AzPSVersion: ${azLatestVersion}`);
|
||||
}
|
||||
return azLatestVersion;
|
||||
}
|
||||
|
||||
static isValidVersion(version: string): boolean {
|
||||
return !!version.match(Constants.versionPattern);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user