@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
387 lines (385 loc) • 19.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Angular15Upgrader = exports.Angular15UpgraderMessages = exports.UpgradeType = void 0;
const common_1 = require("../common");
const package_json_upgrader_1 = require("./upgrader/package-json-upgrader");
const tsconfig_upgrader_1 = require("./upgrader/tsconfig-upgrader");
const logger_1 = require("./utils/logger");
const git_ignore_upgrader_1 = require("./upgrader/git-ignore-upgrader");
const angular_json_upgrader_1 = require("./upgrader/angular-json-upgrader");
const file_replacement_upgrader_1 = require("./upgrader/file-replacement-upgrader");
const ci_build_yml_upgrader_1 = require("./upgrader/ci-build-yml-upgrader");
const replace_upgrader_1 = require("./upgrader/replace-upgrader");
const config_1 = require("./configs/config");
const remove_upgrader_1 = require("./upgrader/remove-upgrader");
const main_debugger_1 = require("./utils/main-debugger");
const command_runner_1 = require("./utils/command-runner");
const log_parser_1 = require("./upgrader/audit/log-parser");
const version_json_upgrader_1 = require("./upgrader/version-json-upgrader");
const jasmine_test_upgrader_1 = require("./upgrader/jasmine-test-upgrader");
const update_shell_references_1 = require("./utils/update-shell-references");
const main_1 = require("../eslint/main");
const ui_test_automation_legacy_upgrader_1 = require("./upgrader/ui-test-automation-legacy-upgrader");
/**
* Represents the type of upgrade that needs to be performed.
*/
var UpgradeType;
(function (UpgradeType) {
UpgradeType["WithBaseConfig"] = "WithBaseConfig";
UpgradeType["WithoutBaseConfig"] = "WithoutBaseConfig";
UpgradeType["NoOperation"] = "NoOperation";
})(UpgradeType = exports.UpgradeType || (exports.UpgradeType = {}));
/**
* Represents the messages that are displayed during the upgrade process.
*/
var Angular15UpgraderMessages;
(function (Angular15UpgraderMessages) {
Angular15UpgraderMessages["StartingUpgrade"] = "Starting Angular 15 upgrade process...";
Angular15UpgraderMessages["UpdateBasicPaths"] = "Updating basic paths for the upgrade...";
Angular15UpgraderMessages["Initialization"] = "Initializing upgraders...";
Angular15UpgraderMessages["FinalizeInfoLintFix"] = "There are eslint violations that needs fix... After fixing the violations, please run the following commands:\n\n npx eslint . --fix \n\n gulp lintApp \n\n gulp build \n\n ";
Angular15UpgraderMessages["CannotRunStageThreeExternal"] = "The ui-test-automation_legacy is for internal extension upgrade only.";
Angular15UpgraderMessages["Completed"] = "Upgrade completed!";
})(Angular15UpgraderMessages = exports.Angular15UpgraderMessages || (exports.Angular15UpgraderMessages = {}));
/**
* This is the main class of the EslintUpgrader tool.
* It is responsible for upgrading the Tslint to Eslint.
*/
class Angular15Upgrader {
/**
* The debug mode.
*/
debug = false;
/**
* It determines whether to run angualr 15 upgrade for the internal extension or external sdk.
*/
internal = false;
/**
* If running in the pipeline, the pipeline needs to automatically update for the @msft-sme pacakges instead of WAC CLI.
*/
pipeline = false;
/**
* The main debugger.
*/
mainDebugger;
/**
* The main debugger version.
*/
version = '1.0.1';
/**
* The paths of the configuration files.
*/
tsconfigBaseFilePath;
tsconfigFilePath;
angularJsonFilePath;
gitIgnoreFilePath;
packageJsonFilePath;
versionJsonFilePath;
packageLockJsonFilePath;
nodeModulesFolderPath;
e2eFolderPath;
testTsFilePath;
testTsFileTemplatePath;
cIBuildYmlFilePath;
pullRequestYmlFilePath;
srcTsConfigSpecFilePath;
srcTsConfigLibProdFilePath;
gulpCompileTsFilePath;
gulpCompileTsTemplatePath;
gulpIndexTsFilePath;
gulpIndexTsTemplatePath;
uiTestAutomationLegacyFilePath;
uiTestAutomationLegacyFolderPath;
logFilePath;
/**
* The upgrader for each configuration file.
*/
packageJsonUpgrader;
versionJsonUpgrader;
tSConfigUpgrader;
tSConfigBaseUpgrader;
gitIgnoreUpgrader;
angularJsonUpgrader;
testTsUpgrader;
cIBuildUpgrader;
pullRequestUpgrader;
srcTsConfigLibProdUpgrader;
srcTsConfigSpecUpgrader;
gulpCompileTsUpgrader;
gulpIndexTsUpgrader;
logParser;
jasmineTestUpgrader;
uITestAutomationLegacyUpgrader;
/**
* The file names for each configuration file.
*/
tsconfigBaseFileName = 'tsconfig.base.json';
tsconfigFileName = 'tsconfig.json';
packageJsonFileName = 'package.json';
versionJsonFileName = 'version.json';
packageLockJsonFileName = 'package-lock.json';
angularFileName = 'angular.json';
e2eFolderName = 'e2e';
nodeModulesFolderName = 'node_modules';
gitIgnoreFileName = '.gitignore';
testTsFileName = 'test.ts';
cIBuildYmlFileName = 'ci-build.yml';
pullRequestYmlFileName = 'pull-request.yml';
srcTsConfigLibProdFileName = 'tsconfig.lib.prod.json';
srcTsConfigSpecFileName = 'tsconfig.spec.json';
gulpCompileTsFileName = 'compile.ts';
gulpIndexTsFileName = 'index.ts';
logFileName = 'log.txt';
constructor() {
logger_1.Logger.log(Angular15UpgraderMessages.StartingUpgrade);
common_1.Common.rootPath = process.cwd();
logger_1.Logger.log(common_1.Common.rootPath);
}
/**
* The upgrader main function.
* If only runs the unit test
* node ./node_modules/@microsoft/windows-admin-center-sdk/tools/wac-cli/src/index.js angular15Upgrade --pipeline false --stage 2
* @param pipeline It determines whether to run this command on the pipeline.
* @param debug It determines whether to run the debug mode.
* @param internal It determines whether to run angualr 15 upgrade for the internal extension or external sdk.
* @param stage '0' - the default Angular 15 stage, '1' - the Angular core stage, '2' - the Angular 15 unit test stage, '3' - the legacy ui-test-automation stage.
*/
async upgrade(pipeline = false, stage = 0, internal = false, debug = false) {
this.debug = !!debug;
this.pipeline = !!pipeline;
this.internal = !!internal;
logger_1.Logger.log(this.version);
logger_1.Logger.log(Angular15UpgraderMessages.StartingUpgrade);
logger_1.Logger.log('Passed in parameters: ' + this.pipeline + ' ' + stage + ' ' + this.internal + ' ' + this.debug);
this.mainDebugger = this.debug ? new main_debugger_1.MainDebugger() : undefined;
logger_1.Logger.log(Angular15UpgraderMessages.UpdateBasicPaths);
this.updateBasicPaths();
logger_1.Logger.log(Angular15UpgraderMessages.Initialization);
this.initialization();
switch (stage) {
case 0:
logger_1.Logger.log('0');
await this.criticalConfigurationFilesUpdates();
await this.installDependenciesPreparation();
await this.installLKGElectronToChromium();
await this.installDependencies();
// Fix any eslint errors that doesn't match the latest eslint rules.
await this.fixEslintErrors(this.pipeline);
await this.gulpQuick();
await this.gulpBuildPostAudit();
// Fix any eslint errors that is triggered by audit.
await this.fixEslintErrors(this.pipeline);
await this.gulpBuildProd();
await this.gulpBuildProdPostAudit();
// Fix any eslint errors clean-ups.
await this.fixEslintErrors(this.pipeline);
await this.jasmineTestUpgrader.run();
break;
case 1:
logger_1.Logger.log('1');
await this.criticalConfigurationFilesUpdates();
await this.installDependenciesPreparation();
await this.installLKGElectronToChromium();
await this.installDependencies();
// Fix any eslint errors that doesn't match the latest eslint rules.
await this.fixEslintErrors(this.pipeline);
await this.gulpQuick();
await this.gulpBuildPostAudit();
// Fix any eslint errors that is triggered by audit.
await this.fixEslintErrors(this.pipeline);
await this.gulpBuildProd();
await this.gulpBuildProdPostAudit();
// Fix any eslint errors clean-ups.
await this.fixEslintErrors(this.pipeline);
break;
case 2:
logger_1.Logger.log('2');
await this.gulpIndexTsUpgrader.run();
await this.testTsUpgrader.run();
await this.jasmineTestUpgrader.run();
break;
case 3:
logger_1.Logger.log('3');
if (!this.internal) {
logger_1.Logger.log(Angular15UpgraderMessages.CannotRunStageThreeExternal);
}
else {
await this.packageJsonUpgrader.run(this.pipeline),
await this.installUTALegacyDevDependency();
await this.uITestAutomationLegacyUpgrader.run();
await this.installDependenciesForUITestAutomation();
}
default:
logger_1.Logger.log('default');
break;
}
}
async criticalConfigurationFilesUpdates() {
Promise.all([
this.packageJsonUpgrader.run(this.pipeline),
this.versionJsonUpgrader.run(),
this.tSConfigBaseUpgrader.runBase(),
this.tSConfigUpgrader.run(),
this.gitIgnoreUpgrader.run(),
this.angularJsonUpgrader.run(),
this.testTsUpgrader.run(),
this.cIBuildUpgrader.run(),
this.pullRequestUpgrader.run(),
this.srcTsConfigLibProdUpgrader.run(),
this.srcTsConfigSpecUpgrader.run(),
this.gulpCompileTsUpgrader.run(),
this.gulpIndexTsUpgrader.run()
]).then((results) => {
console.log('All Promises have completed:', results);
if (this.debug) {
this.mainDebugger.verifyTestData(this).then(() => {
logger_1.Logger.log(Angular15UpgraderMessages.Completed);
});
}
})
.catch((error) => {
logger_1.Logger.error('At least one Promise encountered an error:' + error);
});
}
initialization() {
this.packageJsonUpgrader = new package_json_upgrader_1.PackageJsonUpgrader(this.packageJsonFilePath);
this.versionJsonUpgrader = new version_json_upgrader_1.VersionJsonUpgrader(this.versionJsonFilePath);
this.tSConfigBaseUpgrader = new tsconfig_upgrader_1.TSConfigUpgrader(this.tsconfigBaseFilePath, this.tsconfigBaseFileName);
this.tSConfigUpgrader = new tsconfig_upgrader_1.TSConfigUpgrader(this.tsconfigFilePath, this.tsconfigFileName);
this.gitIgnoreUpgrader = new git_ignore_upgrader_1.GitIgnoreUpgrader(this.gitIgnoreFilePath);
this.angularJsonUpgrader = new angular_json_upgrader_1.AngularJsonUpgrader(this.angularJsonFilePath);
this.testTsUpgrader = new file_replacement_upgrader_1.FileReplacementUpgrader(this.testTsFileTemplatePath, this.testTsFilePath);
this.cIBuildUpgrader = new ci_build_yml_upgrader_1.CIBuildYmlUpgrader(this.cIBuildYmlFilePath, this.cIBuildYmlFileName);
this.pullRequestUpgrader = new ci_build_yml_upgrader_1.CIBuildYmlUpgrader(this.pullRequestYmlFilePath, this.pullRequestYmlFileName);
this.srcTsConfigLibProdUpgrader = new replace_upgrader_1.ReplaceUpgrader(this.srcTsConfigLibProdFilePath, config_1.srcTsConfigLibProdReplaces, this.srcTsConfigLibProdFileName);
this.srcTsConfigSpecUpgrader = new remove_upgrader_1.RemoveUpgrader(this.srcTsConfigSpecFilePath, config_1.srcTsConfigSpecRemoves, this.srcTsConfigSpecFileName);
this.gulpCompileTsUpgrader = new file_replacement_upgrader_1.FileReplacementUpgrader(this.gulpCompileTsTemplatePath, this.gulpCompileTsFilePath);
this.gulpIndexTsUpgrader = new file_replacement_upgrader_1.FileReplacementUpgrader(this.gulpIndexTsTemplatePath, this.gulpIndexTsFilePath);
this.jasmineTestUpgrader = new jasmine_test_upgrader_1.JasmineTestUpgrader(this.testTsFilePath, this.debug);
this.uITestAutomationLegacyUpgrader = new ui_test_automation_legacy_upgrader_1.UITestAutomationLegacyUpgrader(this.uiTestAutomationLegacyFilePath, this.packageJsonFileName);
this.logParser = new log_parser_1.LogParser(this.logFilePath, this.logFileName);
}
updateBasicPaths() {
this.tsconfigBaseFilePath = common_1.Common.rootPath + '\\' + this.tsconfigBaseFileName;
this.tsconfigFilePath = common_1.Common.rootPath + '\\' + this.tsconfigFileName;
this.angularJsonFilePath = common_1.Common.rootPath + '\\' + this.angularFileName;
this.packageJsonFilePath = common_1.Common.rootPath + '\\' + this.packageJsonFileName;
this.versionJsonFilePath = common_1.Common.rootPath + '\\' + this.versionJsonFileName;
this.packageLockJsonFilePath = common_1.Common.rootPath + '\\' + this.packageLockJsonFileName;
this.nodeModulesFolderPath = common_1.Common.rootPath + '\\' + this.nodeModulesFolderName;
this.e2eFolderPath = common_1.Common.rootPath + '\\' + this.e2eFolderName;
this.gitIgnoreFilePath = common_1.Common.rootPath + '\\' + this.gitIgnoreFileName;
this.srcTsConfigLibProdFilePath = common_1.Common.rootPath + '\\src\\' + this.srcTsConfigLibProdFileName;
this.srcTsConfigSpecFilePath = common_1.Common.rootPath + '\\src\\' + this.srcTsConfigSpecFileName;
this.cIBuildYmlFilePath = common_1.Common.rootPath + '\\build\\pipelines\\' + this.cIBuildYmlFileName;
this.pullRequestYmlFilePath = common_1.Common.rootPath + '\\build\\pipelines\\' + this.pullRequestYmlFileName;
this.testTsFilePath = common_1.Common.rootPath + '\\src\\' + this.testTsFileName;
this.testTsFileTemplatePath = common_1.Common.cliRootPath.replace('wac-cli', 'module-template\\angular15\\test.ts');
this.gulpCompileTsFilePath = common_1.Common.rootPath + '\\gulpfile.ts\\common\\' + this.gulpCompileTsFileName;
this.gulpCompileTsTemplatePath = common_1.Common.cliRootPath.replace('wac-cli', 'module-template\\angular15\\gulpfile.ts\\common\\compile.ts');
this.gulpIndexTsFilePath = common_1.Common.rootPath + '\\gulpfile.ts\\' + this.gulpIndexTsFileName;
this.gulpIndexTsTemplatePath = common_1.Common.cliRootPath.replace('wac-cli', 'module-template\\angular15\\gulpfile.ts\\index.ts');
this.uiTestAutomationLegacyFilePath = common_1.Common.rootPath + '\\ui-test-automation\\' + this.packageJsonFileName;
this.uiTestAutomationLegacyFolderPath = common_1.Common.rootPath + '\\ui-test-automation\\';
this.logFilePath = common_1.Common.rootPath + '\\' + this.logFileName;
if (this.debug) {
this.mainDebugger.updateTestData(this);
}
}
async gulpBuildPostAudit() {
return this.logParser.run();
}
gulpQuick() {
const gulpQuick = 'gulp quick';
logger_1.Logger.log(gulpQuick);
return (0, command_runner_1.runCommand)(gulpQuick, this.debug, true, Angular15UpgraderMessages.Completed, this.logFileName).then((response) => {
console.log(response);
});
}
gulpBuildProd() {
const gulpBuild = 'gulp build --prod';
logger_1.Logger.log(gulpBuild);
return (0, command_runner_1.runCommand)(gulpBuild, this.debug, true, Angular15UpgraderMessages.Completed, this.logFileName).then((response) => {
console.log(response);
});
}
async gulpBuildProdPostAudit() {
return this.logParser.run();
}
async installUTALegacyDevDependency() {
const setprefixCmd = 'npm config set save-prefix=';
logger_1.Logger.log(setprefixCmd);
await (0, command_runner_1.runCommand)(setprefixCmd, this.debug);
const cmd = 'npm install @msft-sme/ui-test-automation@latest --save-dev --force';
logger_1.Logger.log(cmd);
await (0, command_runner_1.runCommand)(cmd, this.debug);
}
async installDependenciesPreparation() {
await this.removeNodeModuleFolder();
await this.removePackageLockJsonFile();
await this.removeE2EFolder();
await this.checkEslintRCFile();
(0, update_shell_references_1.updateShellReferences)('', this.internal);
}
async checkEslintRCFile() {
const esLintUpgrader = new main_1.EslintUpgrader();
await esLintUpgrader.replaceEslintConfig();
}
async installMicrosftSignalR() {
const cmd = 'npm install @microsoft/signalr@6.0.8 --save';
logger_1.Logger.log(cmd);
await (0, command_runner_1.runCommand)(cmd, this.debug);
}
async removePackageLockJsonFile() {
const cmd = `del ${this.packageLockJsonFilePath}`;
logger_1.Logger.log(cmd);
await (0, command_runner_1.runCommand)(cmd, this.debug);
}
async removeNodeModuleFolder() {
const cmd = `rmdir /s /q ${this.nodeModulesFolderPath}`;
logger_1.Logger.log(cmd);
await (0, command_runner_1.runCommand)(cmd, this.debug);
}
async removeE2EFolder() {
const cmd = `rmdir /s /q ${this.e2eFolderPath}`;
logger_1.Logger.log(cmd);
await (0, command_runner_1.runCommand)(cmd, this.debug);
}
async installDependencies() {
// Needs to be installed on the SDK root dependency.
if (!this.internal) {
await this.installMicrosftSignalR();
}
const cmd = 'npm install --force';
logger_1.Logger.log(cmd);
await (0, command_runner_1.runCommand)(cmd, this.debug);
}
async installDependenciesForUITestAutomation() {
const cmd = 'pushd ' + this.uiTestAutomationLegacyFolderPath + '&& del package-lock.json && npm install && popd';
await (0, command_runner_1.runCommand)(cmd, this.debug);
}
async fixEslintErrors(ignore = false) {
if (ignore) {
return;
}
const rootFileLinterFix = 'npx eslint . --fix';
logger_1.Logger.log(rootFileLinterFix);
await (0, command_runner_1.runCommand)(rootFileLinterFix, this.debug, true, Angular15UpgraderMessages.FinalizeInfoLintFix);
const projectLinterFix = 'npx ng lint --fix';
logger_1.Logger.log(projectLinterFix);
await (0, command_runner_1.runCommand)(projectLinterFix, this.debug, true, Angular15UpgraderMessages.FinalizeInfoLintFix);
}
/**
* electron-to-chromium 1.4.533 - 1.4.535 are bad versions that is also the latest, meaning any dependency uses ^1.4.xxx are also blocked,
* below are the dependency list:
* /@angular-devkit/build-angular@15.2.8 -> browserslist@4.21.5 that has dependency on ^1.4.284(which always grab 1.4.535)
* always force 1.4.532
*/
async installLKGElectronToChromium() {
const cmd = 'npm install electron-to-chromium@1.4.532 --force';
logger_1.Logger.log(cmd);
await (0, command_runner_1.runCommand)(cmd, this.debug);
}
}
exports.Angular15Upgrader = Angular15Upgrader;
//# sourceMappingURL=main.js.map