Skip to content
Open
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
23 changes: 13 additions & 10 deletions src/commands/asset-registry/asset-registry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { AssetRegistryApi } from "./asset-registry-api";
import { AssetRegistryDescriptor, ValidateOptions } from "./asset-registry.interfaces";
import { Context } from "../../core/command/cli-context";
import { fileService, FileService } from "../../core/utils/file-service";
import { CuiFileService } from "../../core/utils/cui-file-service";
import { FatalError, logger } from "../../core/utils/logger";
import { v4 as uuidv4 } from "uuid";

export class AssetRegistryService {
private readonly api: AssetRegistryApi;
private readonly cuiFileService: CuiFileService;

constructor(context: Context) {
this.api = new AssetRegistryApi(context);
this.cuiFileService = new CuiFileService(context);
}

public async listTypes(jsonResponse: boolean): Promise<void> {
Expand All @@ -18,8 +21,8 @@ export class AssetRegistryService {

if (jsonResponse) {
const filename = uuidv4() + ".json";
fileService.writeToFileWithGivenName(JSON.stringify(metadata), filename);
logger.info(FileService.fileDownloadedMessage + filename);
const writtenFilename = await this.cuiFileService.writeToFileWithGivenName(JSON.stringify(metadata), filename);
logger.info(FileService.fileDownloadedMessage + writtenFilename);
} else {
if (descriptors.length === 0) {
logger.info("No asset types registered.");
Expand All @@ -36,27 +39,27 @@ export class AssetRegistryService {

if (jsonResponse) {
const filename = uuidv4() + ".json";
fileService.writeToFileWithGivenName(JSON.stringify(descriptor), filename);
logger.info(FileService.fileDownloadedMessage + filename);
const writtenFilename = await this.cuiFileService.writeToFileWithGivenName(JSON.stringify(descriptor), filename);
logger.info(FileService.fileDownloadedMessage + writtenFilename);
} else {
this.logDescriptorDetail(descriptor);
}
}

public async getSchema(assetType: string, jsonResponse: boolean): Promise<void> {
const data = await this.api.getSchema(assetType);
this.outputResponse(data, jsonResponse);
await this.outputResponse(data, jsonResponse);
}

public async getExamples(assetType: string, jsonResponse: boolean): Promise<void> {
const data = await this.api.getExamples(assetType);
this.outputResponse(data, jsonResponse);
await this.outputResponse(data, jsonResponse);
}

public async validate(opts: ValidateOptions): Promise<void> {
const payload = this.buildValidatePayload(opts);
const data = await this.api.validate(opts.assetType, payload);
this.outputResponse(data, opts.json);
await this.outputResponse(data, opts.json);
}

private static readonly INLINE_VALIDATION_NODE_KEY = "validation-node";
Expand Down Expand Up @@ -112,11 +115,11 @@ export class AssetRegistryService {
}
}

private outputResponse(data: any, jsonResponse: boolean): void {
private async outputResponse(data: any, jsonResponse: boolean): Promise<void> {
if (jsonResponse) {
const filename = uuidv4() + ".json";
fileService.writeToFileWithGivenName(JSON.stringify(data, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + filename);
const writtenFilename = await this.cuiFileService.writeToFileWithGivenName(JSON.stringify(data, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + writtenFilename);
} else {
logger.info(typeof data === "string" ? data : JSON.stringify(data, null, 2));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AdmZip = require("adm-zip");
import { resolve } from "node:path";
import { Context } from "../../../core/command/cli-context";
import { fileService, FileService } from "../../../core/utils/file-service";
import { CuiFileService } from "../../../core/utils/cui-file-service";
import { FatalError, logger } from "../../../core/utils/logger";
import { GitService } from "../../../core/git-profile/git/git.service";
import { SinglePackageExportApi } from "../api/single-package-export-api";
Expand Down Expand Up @@ -37,12 +38,14 @@ export class BranchExportImportCommandService {
private readonly singlePackageImportApi: SinglePackageImportApi;
private readonly branchApi: BranchApi;
private readonly gitService: GitService;
private readonly cuiFileService: CuiFileService;

constructor(context: Context) {
this.singlePackageExportApi = new SinglePackageExportApi(context);
this.singlePackageImportApi = new SinglePackageImportApi(context);
this.branchApi = new BranchApi(context);
this.gitService = new GitService(context);
this.cuiFileService = new CuiFileService(context);
}

public async exportBranch(packageKey: string, branchKey: string, options: BranchExportOptions = {}): Promise<void> {
Expand All @@ -51,7 +54,7 @@ export class BranchExportImportCommandService {
if (options.gitEnabled) {
const pushedKey = await this.pushBranchToGit(packageKey, branchKey);
if (jsonResponse) {
BranchExportImportCommandService.writeJson({ packageKey: pushedKey, branchName: branchKey });
await this.writeJson({ packageKey: pushedKey, branchName: branchKey });
} else {
logger.info(`Exported ${pushedKey} to Git branch '${branchKey}'.`);
}
Expand All @@ -63,7 +66,7 @@ export class BranchExportImportCommandService {
try {
const message = this.writeLocalArtifact(sourceDir, packageKey, !!options.zip);
if (jsonResponse) {
BranchExportImportCommandService.writeJson({ packageKey: branchPackageKey, branchName: branchKey });
await this.writeJson({ packageKey: branchPackageKey, branchName: branchKey });
} else {
logger.info(message);
}
Expand Down Expand Up @@ -93,7 +96,7 @@ export class BranchExportImportCommandService {

const summary: BranchSyncSummary = { packageKey: mainKey, branchName: BranchUtils.MAIN_BRANCH_KEY, synced };
if (jsonResponse) {
BranchExportImportCommandService.writeJson(summary);
await this.writeJson(summary);
} else {
logger.info(`Exported Git mirror for ${mainKey}: ${synced.length} package(s) pushed.`);
}
Expand All @@ -110,7 +113,7 @@ export class BranchExportImportCommandService {
await this.importPackageSourceDir(workingDir, !!options.overwrite);

if (options.jsonResponse) {
BranchExportImportCommandService.writeJson({ packageKey: branchPackageKey, branchName: branchKey });
await this.writeJson({ packageKey: branchPackageKey, branchName: branchKey });
} else {
const origin = options.gitEnabled ? `Git branch '${branchKey}'` : (options.file ?? options.directory);
logger.info(`Imported ${origin} into ${branchPackageKey}.`);
Expand Down Expand Up @@ -270,9 +273,9 @@ export class BranchExportImportCommandService {
&& branch.branchKey?.toLowerCase() !== BranchUtils.MAIN_BRANCH_KEY;
}

private static writeJson(payload: unknown): void {
private async writeJson(payload: unknown): Promise<void> {
const filename = `${uuidv4()}.json`;
fileService.writeToFileWithGivenName(JSON.stringify(payload, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + filename);
const writtenFilename = await this.cuiFileService.writeToFileWithGivenName(JSON.stringify(payload, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + writtenFilename);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { v4 as uuidv4 } from "uuid";
import { Context } from "../../../core/command/cli-context";
import { fileService, FileService } from "../../../core/utils/file-service";
import { CuiFileService } from "../../../core/utils/cui-file-service";
import { logger } from "../../../core/utils/logger";
import { BranchApi } from "./api/branch.api";
import {
Expand All @@ -20,17 +21,19 @@ import {

export class BranchCommandService {
private readonly branchApi: BranchApi;
private readonly cuiFileService: CuiFileService;

constructor(context: Context) {
this.branchApi = new BranchApi(context);
this.cuiFileService = new CuiFileService(context);
}

public async setBranchingEnabled(packageKey: string, enabled: boolean, jsonResponse: boolean): Promise<BranchingSettingsTransport> {
const transport: BranchingSettingsTransport = { branchingEnabled: enabled };
const result = await this.branchApi.configureBranchingSettings(packageKey, transport);

if (jsonResponse) {
BranchCommandService.writeJson(result);
await this.writeJson(result);
} else {
logger.info(`Branching ${result.branchingEnabled ? "enabled" : "disabled"} for package ${packageKey}.`);
}
Expand All @@ -47,7 +50,7 @@ export class BranchCommandService {
}

if (jsonResponse) {
BranchCommandService.writeJson(result);
await this.writeJson(result);
} else if (result) {
BranchCommandService.printBranch(result);
}
Expand All @@ -58,7 +61,7 @@ export class BranchCommandService {
const branches = await this.branchApi.listBranches(packageKey);

if (jsonResponse) {
BranchCommandService.writeJson(branches);
await this.writeJson(branches);
} else if (branches.length === 0) {
logger.info(`No branches found for ${packageKey}.`);
} else {
Expand All @@ -82,7 +85,7 @@ export class BranchCommandService {
const preview = await this.branchApi.mergePreview(targetPackageKey, transport);

if (jsonResponse) {
BranchCommandService.writeJson(preview);
await this.writeJson(preview);
} else {
BranchCommandService.printPreviewSummary(targetPackageKey, sourceKey, sourceVersion, preview);
}
Expand Down Expand Up @@ -115,7 +118,7 @@ export class BranchCommandService {
const result = await this.branchApi.merge(targetPackageKey, transport);

if (options.jsonResponse) {
BranchCommandService.writeJson(result);
await this.writeJson(result);
} else {
logger.info(
`Merge applied: published ${result.packageKey}@${result.version} from ${effectiveSourceKey}@${effectiveSourceVersion}.`
Expand Down Expand Up @@ -153,10 +156,10 @@ export class BranchCommandService {
return versionCreate;
}

private static writeJson(payload: unknown): void {
private async writeJson(payload: unknown): Promise<void> {
const filename = `${uuidv4()}.json`;
fileService.writeToFileWithGivenName(JSON.stringify(payload, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + filename);
const writtenFilename = await this.cuiFileService.writeToFileWithGivenName(JSON.stringify(payload, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + writtenFilename);
}

private static printBranch(branch: BranchTransport): void {
Expand Down
13 changes: 8 additions & 5 deletions src/commands/configuration-management/metadata.service.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import { v4 as uuidv4 } from "uuid";
import { Context } from "../../core/command/cli-context";
import { PackageMetadataExportTransport } from "./interfaces/package-export.interfaces";
import { fileService, FileService } from "../../core/utils/file-service";
import { FileService } from "../../core/utils/file-service";
import { CuiFileService } from "../../core/utils/cui-file-service";
import { logger } from "../../core/utils/logger";
import { MetadataApi } from "./api/metadata-api";

export class MetadataService {

private metadataApi: MetadataApi;
private readonly cuiFileService: CuiFileService;

constructor(context: Context) {
this.metadataApi = new MetadataApi(context);
this.cuiFileService = new CuiFileService(context);
}

public async exportPackagesMetadata(packageKeys: string[], jsonResponse: boolean): Promise<void> {
const exportedPackagesMetadata: PackageMetadataExportTransport[] = await this.metadataApi.exportPackagesMetadata(packageKeys);

if (jsonResponse) {
this.exportListOfPackagesMetadata(exportedPackagesMetadata);
await this.exportListOfPackagesMetadata(exportedPackagesMetadata);
} else {
exportedPackagesMetadata.forEach(pkg => {
logger.info(`${pkg.key} - Has Unpublished Changes: ${pkg.hasUnpublishedChanges}`);
});
}
}

private exportListOfPackagesMetadata(packagesMetadata: PackageMetadataExportTransport[]): void {
private async exportListOfPackagesMetadata(packagesMetadata: PackageMetadataExportTransport[]): Promise<void> {
const filename = uuidv4() + ".json";
fileService.writeToFileWithGivenName(JSON.stringify(packagesMetadata), filename);
logger.info(FileService.fileDownloadedMessage + filename);
const writtenFilename = await this.cuiFileService.writeToFileWithGivenName(JSON.stringify(packagesMetadata), filename);
logger.info(FileService.fileDownloadedMessage + writtenFilename);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { NodeDependencyApi } from "./api/node-dependency-api";
import { Context } from "../../core/command/cli-context";
import { fileService, FileService } from "../../core/utils/file-service";
import { FileService } from "../../core/utils/file-service";
import { CuiFileService } from "../../core/utils/cui-file-service";
import { logger } from "../../core/utils/logger";
import { v4 as uuidv4 } from "uuid";
import { NodeDependencyTransport } from "./interfaces/node-dependency.interfaces";

export class NodeDependencyService {
private readonly nodeDependencyApi: NodeDependencyApi;
private readonly cuiFileService: CuiFileService;

constructor(context: Context) {
this.nodeDependencyApi = new NodeDependencyApi(context);
this.cuiFileService = new CuiFileService(context);
}

public async listNodeDependencies(packageKey: string, nodeKey: string, version: string, jsonResponse: boolean): Promise<void> {
Expand All @@ -23,8 +26,8 @@ export class NodeDependencyService {

if (jsonResponse) {
const filename = uuidv4() + ".json";
fileService.writeToFileWithGivenName(JSON.stringify(dependencies, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + filename);
const writtenFilename = await this.cuiFileService.writeToFileWithGivenName(JSON.stringify(dependencies, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + writtenFilename);
} else {
if (dependencies.length === 0) {
logger.info("No dependencies found for this node.");
Expand Down
15 changes: 9 additions & 6 deletions src/commands/configuration-management/node-diff.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import * as fs from "node:fs";
import { v4 as uuidv4 } from "uuid";
import { logger } from "../../core/utils/logger";
import { fileService, FileService } from "../../core/utils/file-service";
import { FileService } from "../../core/utils/file-service";
import { CuiFileService } from "../../core/utils/cui-file-service";
import { Context } from "../../core/command/cli-context";
import { NodeDiffApi } from "./api/node-diff-api";
import { NodeConfigurationDiffTransport } from "./interfaces/node-diff.interfaces";

export class NodeDiffService {
private nodeDiffApi: NodeDiffApi;
private readonly cuiFileService: CuiFileService;

constructor(context: Context) {
this.nodeDiffApi = new NodeDiffApi(context);
this.cuiFileService = new CuiFileService(context);
}

public async diff(
Expand All @@ -28,7 +31,7 @@ export class NodeDiffService {
});

if (jsonResponse) {
this.exportDiffAsJson(nodeDiff);
await this.exportDiffAsJson(nodeDiff);
} else {
this.logDiff(nodeDiff);
}
Expand All @@ -49,16 +52,16 @@ export class NodeDiffService {
});

if (jsonResponse) {
this.exportDiffAsJson(nodeDiff);
await this.exportDiffAsJson(nodeDiff);
} else {
this.logDiff(nodeDiff);
}
}

private exportDiffAsJson(nodeDiff: NodeConfigurationDiffTransport): void {
private async exportDiffAsJson(nodeDiff: NodeConfigurationDiffTransport): Promise<void> {
const filename = uuidv4() + ".json";
fileService.writeToFileWithGivenName(JSON.stringify(nodeDiff, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + filename);
const writtenFilename = await this.cuiFileService.writeToFileWithGivenName(JSON.stringify(nodeDiff, null, 2), filename);
logger.info(FileService.fileDownloadedMessage + writtenFilename);
}

private logDiff(nodeDiff: NodeConfigurationDiffTransport): void {
Expand Down
Loading
Loading