Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Adding spinners for setup command #51

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@types/uuid": "^3.4.5",
"@typescript-eslint/eslint-plugin": "^2.24.0",
"@typescript-eslint/parser": "^2.24.0",
"clui": "^0.3.6",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"husky": ">=1",
Expand Down Expand Up @@ -77,6 +78,7 @@
"@azure/identity": "^1.0.0",
"@azure/keyvault-secrets": "^4.0.0",
"@azure/ms-rest-nodeauth": "^3.0.0",
"@types/clui": "^0.3.0",
"@types/fs-extra": "^8.0.0",
"@types/git-url-parse": "^9.0.0",
"@types/mkdirp": "^0.5.2",
Expand Down
105 changes: 93 additions & 12 deletions src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ICoreApi } from "azure-devops-node-api/CoreApi";
import { IGitApi } from "azure-devops-node-api/GitApi";
import commander from "commander";
import fs from "fs";
import cli from "clui";
import chalk from "chalk";
import yaml from "js-yaml";
import { defaultConfigFile } from "../config";
import { getBuildApi, getWebApi } from "../lib/azdoClient";
Expand Down Expand Up @@ -46,7 +48,8 @@ import { build as buildError, log as logError } from "../lib/errorBuilder";
import { errorStatusCode } from "../lib/errorStatusCode";
import { exec } from "../lib/shell";
import { ConfigYaml } from "../types";

import { turnOnConsoleLogging, turnOffConsoleLogging } from "../lib/util";
const Spinner = cli.Spinner;
interface CommandOptions {
file: string | undefined;
}
Expand All @@ -62,6 +65,36 @@ interface APIClients {
buildAPI: IBuildApi;
}

const installPromiseHelper = (
delegate: Promise<void>,
onSuccess: { (): void; (): void },
spinner: cli.Spinner
): Promise<void> => {
return new Promise((resolve) => {
spinner.start();
delegate.then(() => {
spinner.stop();
onSuccess();
resolve();
});
});
};

const logStatusSpinner = async (
pendingMessage: string,
completionMessage: string,
delegate: Promise<void>
): Promise<void> => {
const spinner = new Spinner(pendingMessage);
return Promise.resolve(
installPromiseHelper(
delegate,
() => console.log(chalk.green(`✅ ${completionMessage}`)),
spinner
)
);
};

export const isAzCLIInstall = async (): Promise<void> => {
try {
const result = await exec("az", ["--version"]);
Expand Down Expand Up @@ -199,13 +232,41 @@ export const createAppRepoTasks = async (
rc.acrName,
RESOURCE_GROUP_LOCATION
);
await setupVariableGroup(rc);
await helmRepo(gitAPI, rc);
await appRepo(gitAPI, rc);
await createLifecyclePipeline(buildAPI, rc);
await completePullRequest(gitAPI, rc, HLD_REPO);
await createBuildPipeline(buildAPI, rc);
await completePullRequest(gitAPI, rc, HLD_REPO);
await logStatusSpinner(
"Updating variable group",
"Variable group updated",
setupVariableGroup(rc)
);
await logStatusSpinner(
"Creating Helm repo",
"Helm repo created",
helmRepo(gitAPI, rc)
);
await logStatusSpinner(
"Creating App repo",
"App repo created",
appRepo(gitAPI, rc)
);
await logStatusSpinner(
"Creating Lifecycle pipeline",
"Lifecycle pipeline build success",
createLifecyclePipeline(buildAPI, rc)
);
await logStatusSpinner(
"Approving HLD pull request",
"HLD pull request completed",
completePullRequest(gitAPI, rc, HLD_REPO)
);
await logStatusSpinner(
"Creating Build-Update pipeline",
"Build-Update pipeline build success",
createBuildPipeline(buildAPI, rc)
);
await logStatusSpinner(
"Approving HLD pull request",
"HLD pull request completed",
completePullRequest(gitAPI, rc, HLD_REPO)
);
return true;
} else {
return false;
Expand Down Expand Up @@ -277,17 +338,37 @@ export const execute = async (

const { coreAPI, gitAPI, buildAPI } = await getAPIClients();

if (logger.level == "info") {
turnOffConsoleLogging(logger);
}
await createProjectIfNotExist(coreAPI, rc);
await setupVariableGroup(rc);
await hldRepo(gitAPI, rc);
await manifestRepo(gitAPI, rc);
await createHLDtoManifestPipeline(buildAPI, rc);
await logStatusSpinner(
"Creating vaiable group",
"Variable group created",
setupVariableGroup(rc)
);
await logStatusSpinner(
"Creating HLD repo",
"HLD repo created",
hldRepo(gitAPI, rc)
);
await logStatusSpinner(
"Creating Manifest repo",
"Manifest repo created",
manifestRepo(gitAPI, rc)
);
await logStatusSpinner(
"Creating HLD to Manifest pipeline",
"HLD to Manifest pipeline build success",
createHLDtoManifestPipeline(buildAPI, rc)
);
await createAppRepoTasks(gitAPI, buildAPI, rc);

createCLIConfig(rc); // to write storage account information.
createSetupLog(rc);
await exitFn(0);
} catch (err) {
turnOnConsoleLogging(logger);
logError(buildError(errorStatusCode.CMD_EXE_ERR, "setup-cmd-failed", err));

const msg = getErrorMessage(requestContext, err);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"storageTableName": "Enter storage table name",
"storagePartitionKey": "Enter storage partition key",
"storageAccessKey": "Enter storage access key",
"storageKeVaultName": "Enter key vault name (have the value as empty and hit enter key to skip)"
"storageKeyVaultName": "Enter key vault name (have the value as empty and hit enter key to skip)"
},
"errors": {
"init_cmd_failed": "Init command was not successfully executed.",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/promptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const azureKeyVaultName = (
): QuestionCollection => {
return {
default: defaultValue,
message: `${i18n.prompt.storageKeVaultName}\n`,
message: `${i18n.prompt.storageKeyVaultName}\n`,
name: "azdo_storage_key_vault_name",
type: "input",
validate: validator.validateStorageKeyVaultName,
Expand Down
20 changes: 20 additions & 0 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { transports, Logger } from "winston";
/**
* Deep clone an object.
*
Expand All @@ -19,3 +20,22 @@ export const sleep = (timeInMs: number): Promise<unknown> => {
}, timeInMs);
});
};

export const turnOffConsoleLogging = (logger: Logger): void => {
//If logging level is not verbose
if (logger.level !== "silly") {
logger.transports.forEach((t) => {
if (t instanceof transports.Console) {
t.silent = true;
}
});
}
};

export const turnOnConsoleLogging = (logger: Logger): void => {
logger.transports.forEach((t) => {
if (t instanceof transports.Console) {
t.silent = false;
}
});
};
Loading