From 0aca1bb026186dfd9c559f83de68d7784e368ce5 Mon Sep 17 00:00:00 2001 From: Buqete Mucolli Date: Wed, 17 Jul 2024 16:51:15 +0200 Subject: [PATCH 1/7] TA-3148: Update NodeExportTransport and export/import logic to work with JSON files --- src/content/factory/widget-manager.factory.ts | 2 +- src/content/manager/analysis.manager.ts | 2 +- src/content/manager/asset.manager.ts | 2 +- .../batch-export-import-constants.ts | 8 ++-- src/interfaces/package-export-transport.ts | 6 +-- src/services/file-service.ts | 2 +- .../batch-import-export-service.ts | 2 +- .../package-manager/package-service.ts | 2 +- src/services/studio/studio.service.ts | 16 +++---- src/util/json.ts | 15 +++++++ src/util/yaml.ts | 9 ---- tests/config/config-diff.spec.ts | 9 ++-- tests/config/config-export.spec.ts | 44 +++++++++---------- tests/config/config-import.spec.ts | 12 ++--- tests/config/config-list-variables.spec.ts | 2 +- tests/utls/config-utils.ts | 21 ++++----- 16 files changed, 80 insertions(+), 74 deletions(-) create mode 100644 src/util/json.ts delete mode 100644 src/util/yaml.ts diff --git a/src/content/factory/widget-manager.factory.ts b/src/content/factory/widget-manager.factory.ts index beb2841..2771a3a 100644 --- a/src/content/factory/widget-manager.factory.ts +++ b/src/content/factory/widget-manager.factory.ts @@ -3,7 +3,7 @@ import * as path from "path"; import { FatalError, logger } from "../../util/logger"; import { WidgetManager } from "../manager/widget.manager"; import * as AdmZip from "adm-zip"; -import {parse} from "../../util/yaml"; +import {parse} from "../../util/json"; interface Manifest { key: string; diff --git a/src/content/manager/analysis.manager.ts b/src/content/manager/analysis.manager.ts index 3869415..f79e10c 100644 --- a/src/content/manager/analysis.manager.ts +++ b/src/content/manager/analysis.manager.ts @@ -2,7 +2,7 @@ import { BaseManager } from "./base.manager"; import { ManagerConfig } from "../../interfaces/manager-config.interface"; import { AssetManager } from "./asset.manager"; import * as fs from "fs"; -import {stringify} from "../../util/yaml"; +import {stringify} from "../../util/json"; import * as FormData from "form-data"; export class AnalysisManager extends BaseManager { diff --git a/src/content/manager/asset.manager.ts b/src/content/manager/asset.manager.ts index 9db91c2..e198dd4 100644 --- a/src/content/manager/asset.manager.ts +++ b/src/content/manager/asset.manager.ts @@ -1,7 +1,7 @@ import { BaseManager } from "./base.manager"; import { ManagerConfig } from "../../interfaces/manager-config.interface"; import { SaveContentNode } from "../../interfaces/save-content-node.interface"; -import { parse, stringify } from "../../util/yaml"; +import { parse, stringify } from "../../util/json"; export class AssetManager extends BaseManager { public static ASSET_FILE_PREFIX = "asset_"; diff --git a/src/interfaces/batch-export-import-constants.ts b/src/interfaces/batch-export-import-constants.ts index 1407566..a0c815e 100644 --- a/src/interfaces/batch-export-import-constants.ts +++ b/src/interfaces/batch-export-import-constants.ts @@ -1,11 +1,11 @@ export enum BatchExportImportConstants { - STUDIO_FILE_NAME = "studio.yml", - VARIABLES_FILE_NAME = "variables.yml", - MANIFEST_FILE_NAME = "manifest.yml", + STUDIO_FILE_NAME = "studio.json", + VARIABLES_FILE_NAME = "variables.json", + MANIFEST_FILE_NAME = "manifest.json", STUDIO = "STUDIO", APP_MODE_VIEWER = "VIEWER", ZIP_EXTENSION = ".zip", - YAML_EXTENSION = ".yml", + JSON_EXTENSION = ".json", NODES_FOLDER_NAME = "nodes/", SCENARIO_NODE = "SCENARIO" } \ No newline at end of file diff --git a/src/interfaces/package-export-transport.ts b/src/interfaces/package-export-transport.ts index fb1ec7a..5f3343f 100644 --- a/src/interfaces/package-export-transport.ts +++ b/src/interfaces/package-export-transport.ts @@ -51,7 +51,7 @@ export interface NodeExportTransport { name: string; type: string; exportSerializationType: string; - configuration: string; + configuration: NodeConfiguration; schemaVersion: number; spaceId: string; @@ -60,8 +60,8 @@ export interface NodeExportTransport { serializedDocument?: Buffer; } -export interface NodeSerializedContent { - variables: VariableDefinition[] +export interface NodeConfiguration { + [key: string]: any; } export interface StudioPackageManifest { diff --git a/src/services/file-service.ts b/src/services/file-service.ts index 9da10aa..4fa8451 100644 --- a/src/services/file-service.ts +++ b/src/services/file-service.ts @@ -2,7 +2,7 @@ import * as fs from "fs"; import * as path from "path"; import { ManifestNodeTransport } from "../interfaces/manifest-transport"; import { FatalError, logger } from "../util/logger"; -import {parse} from "../util/yaml"; +import {parse} from "../util/json"; export class FileService { public static readonly fileDownloadedMessage = "File downloaded successfully. New filename: "; diff --git a/src/services/package-manager/batch-import-export-service.ts b/src/services/package-manager/batch-import-export-service.ts index 6830c32..b304d8d 100644 --- a/src/services/package-manager/batch-import-export-service.ts +++ b/src/services/package-manager/batch-import-export-service.ts @@ -10,7 +10,7 @@ import { } from "../../interfaces/package-export-transport"; import {FileService, fileService} from "../file-service"; import {studioService} from "../studio/studio.service"; -import {parse, stringify} from "../../util/yaml" +import {parse, stringify} from "../../util/json" import * as FormData from "form-data"; import {BatchExportImportConstants} from "../../interfaces/batch-export-import-constants"; import {packageApi} from "../../api/package-api"; diff --git a/src/services/package-manager/package-service.ts b/src/services/package-manager/package-service.ts index bba4919..f296030 100644 --- a/src/services/package-manager/package-service.ts +++ b/src/services/package-manager/package-service.ts @@ -21,7 +21,7 @@ import {SpaceTransport} from "../../interfaces/save-space.interface"; import {ManifestDependency, ManifestNodeTransport} from "../../interfaces/manifest-transport"; import {DataPoolInstallVersionReport} from "../../interfaces/data-pool-manager.interfaces"; import {SemanticVersioning} from "../../util/semantic-versioning" -import {stringify} from "../../util/yaml"; +import {stringify} from "../../util/json"; import * as FormData from "form-data"; class PackageService { diff --git a/src/services/studio/studio.service.ts b/src/services/studio/studio.service.ts index 61a5458..c037b7d 100644 --- a/src/services/studio/studio.service.ts +++ b/src/services/studio/studio.service.ts @@ -1,11 +1,11 @@ import { + NodeConfiguration, NodeExportTransport, - NodeSerializedContent, PackageExportTransport, PackageKeyAndVersionPair, StudioPackageManifest, VariableExportTransport, - VariableManifestTransport + VariableManifestTransport, } from "../../interfaces/package-export-transport"; import {packageApi} from "../../api/package-api"; @@ -17,7 +17,7 @@ import { } from "../../interfaces/package-manager.interfaces"; import {dataModelService} from "../package-manager/datamodel-service"; import {IZipEntry} from "adm-zip"; -import {parse, stringify} from "../../util/yaml"; +import {parse, stringify} from "../../util/json"; import {nodeApi} from "../../api/node-api"; import {variablesApi} from "../../api/variables-api"; import {spaceApi} from "../../api/space-api"; @@ -140,7 +140,7 @@ class StudioService { } private deleteScenarioAssets(packageZip: AdmZip): void { - packageZip.getEntries().filter(entry => entry.entryName.startsWith(BatchExportImportConstants.NODES_FOLDER_NAME) && entry.entryName.endsWith(BatchExportImportConstants.YAML_EXTENSION)) + packageZip.getEntries().filter(entry => entry.entryName.startsWith(BatchExportImportConstants.NODES_FOLDER_NAME) && entry.entryName.endsWith(BatchExportImportConstants.JSON_EXTENSION)) .forEach(entry => { const node: NodeExportTransport = parse(entry.getData().toString()); if (node.type === BatchExportImportConstants.SCENARIO_NODE) { @@ -157,10 +157,10 @@ class StudioService { return; } - const packageEntry = packageZip.getEntry("package.yml"); + const packageEntry = packageZip.getEntry("package.json"); const exportedNode: NodeExportTransport = parse(packageEntry.getData().toString()); - const nodeContent: NodeSerializedContent = parse(exportedNode.configuration); + const nodeContent: NodeConfiguration = exportedNode.configuration; nodeContent.variables = nodeContent.variables.map(variable => ({ ...variable, @@ -168,7 +168,7 @@ class StudioService { connectionVariablesByKey.get(variable.key).metadata : variable.metadata })); - exportedNode.configuration = stringify(nodeContent); + exportedNode.configuration = nodeContent; packageZip.updateFile(packageEntry, Buffer.from(stringify(exportedNode))); } @@ -212,7 +212,7 @@ class StudioService { const packageZip = new AdmZip(file.getData()); packageZip.getEntries().forEach(nodeFile => { - if (nodeFile.entryName.endsWith(BatchExportImportConstants.YAML_EXTENSION)) { + if (nodeFile.entryName.endsWith(BatchExportImportConstants.JSON_EXTENSION)) { const updatedNodeFile = this.updateSpaceIdForNode(nodeFile.getData().toString(), spaceId); packageZip.updateFile(nodeFile, Buffer.from(updatedNodeFile)); } diff --git a/src/util/json.ts b/src/util/json.ts new file mode 100644 index 0000000..7f45a68 --- /dev/null +++ b/src/util/json.ts @@ -0,0 +1,15 @@ + +export function stringify(data: any): string { + return JSON.stringify(data, replacer, 2); +} + +export function parse(data: string): T { + return JSON.parse(data); +} + +const replacer = (key, value) => { + if (value instanceof Map) { + return Object.fromEntries(value); + } + return value; +}; diff --git a/src/util/yaml.ts b/src/util/yaml.ts deleted file mode 100644 index 8c9c951..0000000 --- a/src/util/yaml.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as YAML from "yaml"; - -export function stringify(data: any): string { - return YAML.stringify(data, {doubleQuotedAsJSON: true, indent: 2, lineWidth: 200}); -} - -export function parse(data: string): T { - return YAML.parse(data); -} diff --git a/tests/config/config-diff.spec.ts b/tests/config/config-diff.spec.ts index 3e9aec4..8504fe1 100644 --- a/tests/config/config-diff.spec.ts +++ b/tests/config/config-diff.spec.ts @@ -1,7 +1,6 @@ import {PackageManifestTransport} from "../../src/interfaces/package-export-transport"; import {ConfigUtils} from "../utls/config-utils"; import * as path from "path"; -import {stringify} from "../../src/util/yaml"; import {mockCreateReadStream, mockExistsSync, mockReadFileSync} from "../utls/fs-mock-utils"; import { PackageDiffMetadata, @@ -22,7 +21,7 @@ describe("Config diff", () => { const manifest: PackageManifestTransport[] = []; manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("package-key", "STUDIO")); - const firstPackageNode = ConfigUtils.buildPackageNode("package-key", stringify({metadata: {description: "test"}, variables: [], dependencies: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("package-key", {metadata: {description: "test"}, variables: [], dependencies: []}); const firstChildNode = ConfigUtils.buildChildNode("key-1", "package-key", "TEST"); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstChildNode], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip]); @@ -49,7 +48,7 @@ describe("Config diff", () => { const manifest: PackageManifestTransport[] = []; manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("package-key", "STUDIO")); - const firstPackageNode = ConfigUtils.buildPackageNode("package-key", stringify({metadata: {description: "test"}, variables: [], dependencies: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("package-key", {metadata: {description: "test"}, variables: [], dependencies: []}); const firstChildNode = ConfigUtils.buildChildNode("key-1", "package-key", "TEST"); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstChildNode], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip]); @@ -91,7 +90,7 @@ describe("Config diff", () => { const manifest: PackageManifestTransport[] = []; manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("package-key", "STUDIO")); - const firstPackageNode = ConfigUtils.buildPackageNode("package-key", stringify({metadata: {description: "test"}, variables: [], dependencies: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("package-key", {metadata: {description: "test"}, variables: [], dependencies: []}); const firstChildNode = ConfigUtils.buildChildNode("key-1", "package-key", "TEST"); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstChildNode], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip]); @@ -137,7 +136,7 @@ describe("Config diff", () => { const manifest: PackageManifestTransport[] = []; manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("package-key", "STUDIO")); - const firstPackageNode = ConfigUtils.buildPackageNode("package-key", stringify({metadata: {description: "test"}, variables: [], dependencies: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("package-key", {metadata: {description: "test"}, variables: [], dependencies: []}); const firstChildNode = ConfigUtils.buildChildNode("key-1", "package-key", "TEST"); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstChildNode], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip]); diff --git a/tests/config/config-export.spec.ts b/tests/config/config-export.spec.ts index 85612d5..a6d520a 100644 --- a/tests/config/config-export.spec.ts +++ b/tests/config/config-export.spec.ts @@ -1,9 +1,9 @@ import {ConfigUtils} from "../utls/config-utils"; import { - DependencyTransport, NodeExportTransport, NodeSerializedContent, + DependencyTransport, NodeConfiguration, NodeExportTransport, PackageManifestTransport, StudioPackageManifest, - VariableManifestTransport + VariableManifestTransport, } from "../../src/interfaces/package-export-transport"; import {mockAxiosGet, mockAxiosPost, mockedPostRequestBodyByUrl} from "../utls/http-requests-mock"; import {ConfigCommand} from "../../src/commands/config.command"; @@ -13,7 +13,7 @@ import {FileService} from "../../src/services/file-service"; import * as fs from "fs"; import AdmZip = require("adm-zip"); -import { parse, stringify } from "../../src/util/yaml"; +import { parse, stringify } from "../../src/util/json"; import { PackageManagerVariableType, VariableDefinition, @@ -109,7 +109,7 @@ describe("Config export", () => { } ]; - const firstPackageNode = ConfigUtils.buildPackageNode("key-1", stringify({variables: firstPackageVariableDefinition})); + const firstPackageNode = ConfigUtils.buildPackageNode("key-1", {variables: firstPackageVariableDefinition}); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [], "1.0.0"); const secondPackageVariableDefinition: VariableDefinition[] = [ @@ -125,7 +125,7 @@ describe("Config export", () => { } ]; - const secondPackageNode = ConfigUtils.buildPackageNode("key-2", stringify({variables: secondPackageVariableDefinition})); + const secondPackageNode = ConfigUtils.buildPackageNode("key-2", {variables: secondPackageVariableDefinition}); const secondPackageZip = ConfigUtils.buildExportPackageZip(secondPackageNode, [], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip, secondPackageZip]); @@ -258,12 +258,12 @@ describe("Config export", () => { manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-1", BatchExportImportConstants.STUDIO)); manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-2", BatchExportImportConstants.STUDIO)); - const firstPackageNode = ConfigUtils.buildPackageNode("key-1", ""); + const firstPackageNode = ConfigUtils.buildPackageNode("key-1", {}); const firstPackageScenarioChild = ConfigUtils.buildChildNode("child-1-scenario", firstPackageNode.key, "SCENARIO"); const firstPackageTestChild = ConfigUtils.buildChildNode("child-2", firstPackageNode.key, "TEST"); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstPackageScenarioChild, firstPackageTestChild], "1.0.0"); - const secondPackageNode = ConfigUtils.buildPackageNode("key-2", ""); + const secondPackageNode = ConfigUtils.buildPackageNode("key-2", {}); const secondPackageScenarioChild = ConfigUtils.buildChildNode("child-3-scenario", secondPackageNode.key, "SCENARIO"); const secondPackageTestChild = ConfigUtils.buildChildNode("child-4", secondPackageNode.key, "TEST"); const secondPackageZip = ConfigUtils.buildExportPackageZip(secondPackageNode, [secondPackageScenarioChild, secondPackageTestChild], "1.0.0"); @@ -287,15 +287,15 @@ describe("Config export", () => { const actualZip = new AdmZip(fileBuffer); const firstPackageExportedZip = new AdmZip(actualZip.getEntry("key-1_1.0.0.zip").getData()); - expect(firstPackageExportedZip.getEntry("nodes/child-1-scenario.yml")).toBeNull(); - expect(firstPackageExportedZip.getEntry("nodes/child-2.yml").getData().toString()).toEqual(stringify(firstPackageTestChild)); + expect(firstPackageExportedZip.getEntry("nodes/child-1-scenario.json")).toBeNull(); + expect(firstPackageExportedZip.getEntry("nodes/child-2.json").getData().toString()).toEqual(stringify(firstPackageTestChild)); const secondPackageExportedZip = new AdmZip(actualZip.getEntry("key-2_1.0.0.zip").getData()); - expect(secondPackageExportedZip.getEntry("nodes/child-3-scenario.yml")).toBeNull(); - expect(secondPackageExportedZip.getEntry("nodes/child-4.yml").getData().toString()).toEqual(stringify(secondPackageTestChild)); + expect(secondPackageExportedZip.getEntry("nodes/child-3-scenario.json")).toBeNull(); + expect(secondPackageExportedZip.getEntry("nodes/child-4.json").getData().toString()).toEqual(stringify(secondPackageTestChild)); }) - it("Should add appName to metadata for CONNECTION variables of package.yml files", async () => { + it("Should add appName to metadata for CONNECTION variables of package.json files", async () => { const manifest: PackageManifestTransport[] = []; manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-1", BatchExportImportConstants.STUDIO)); manifest.push(ConfigUtils.buildManifestForKeyAndFlavor("key-2", BatchExportImportConstants.STUDIO)); @@ -313,7 +313,7 @@ describe("Config export", () => { } ]; - const firstPackageNode = ConfigUtils.buildPackageNode("key-1", stringify({variables: firstPackageVariableDefinition})); + const firstPackageNode = ConfigUtils.buildPackageNode("key-1", {variables: firstPackageVariableDefinition}); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [], "1.0.0"); const secondPackageVariableDefinition: VariableDefinition[] = [ @@ -332,7 +332,7 @@ describe("Config export", () => { } ]; - const secondPackageNode = ConfigUtils.buildPackageNode("key-2", stringify({variables: secondPackageVariableDefinition})); + const secondPackageNode = ConfigUtils.buildPackageNode("key-2", {variables: secondPackageVariableDefinition}); const secondPackageZip = ConfigUtils.buildExportPackageZip(secondPackageNode, [], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZip(manifest, [firstPackageZip, secondPackageZip]); @@ -403,9 +403,9 @@ describe("Config export", () => { const actualZip = new AdmZip(fileBuffer); const firstPackageExportedZip = new AdmZip(actualZip.getEntry("key-1_1.0.0.zip").getData()); - const firstPackageExportedNode: NodeExportTransport = parse(firstPackageExportedZip.getEntry("package.yml").getData().toString()); + const firstPackageExportedNode: NodeExportTransport = parse(firstPackageExportedZip.getEntry("package.json").getData().toString()); expect(firstPackageExportedNode).toBeTruthy(); - const firstPackageContent: NodeSerializedContent = parse(firstPackageExportedNode.configuration); + const firstPackageContent: NodeConfiguration = firstPackageExportedNode.configuration; expect(firstPackageContent.variables).toHaveLength(2); expect(firstPackageContent.variables).toEqual([ { @@ -420,9 +420,9 @@ describe("Config export", () => { ]); const secondPackageExportedZip = new AdmZip(actualZip.getEntry("key-2_1.0.0.zip").getData()); - const secondPackageExportedNode: NodeExportTransport = parse(secondPackageExportedZip.getEntry("package.yml").getData().toString()); + const secondPackageExportedNode: NodeExportTransport = parse(secondPackageExportedZip.getEntry("package.json").getData().toString()); expect(secondPackageExportedNode).toBeTruthy(); - const secondPackageContent: NodeSerializedContent = parse(secondPackageExportedNode.configuration); + const secondPackageContent: NodeConfiguration = secondPackageExportedNode.configuration; expect(secondPackageContent.variables).toHaveLength(2); expect(secondPackageContent.variables).toEqual([{ ...secondPackageVariableDefinition[0], @@ -458,7 +458,7 @@ describe("Config export", () => { } ]; - const firstPackageNode = ConfigUtils.buildPackageNode("key_with_underscores_1", stringify({variables: firstPackageVariableDefinition})); + const firstPackageNode = ConfigUtils.buildPackageNode("key_with_underscores_1", {variables: firstPackageVariableDefinition}); const firstPackageScenarioChild = ConfigUtils.buildChildNode("child-1-scenario", firstPackageNode.key, "SCENARIO"); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [firstPackageScenarioChild], "1.0.0"); @@ -511,9 +511,9 @@ describe("Config export", () => { const actualZip = new AdmZip(fileBuffer); const firstPackageExportedZip = new AdmZip(actualZip.getEntry("key_with_underscores_1_1.0.0.zip").getData()); - const firstPackageExportedNode: NodeExportTransport = parse(firstPackageExportedZip.getEntry("package.yml").getData().toString()); + const firstPackageExportedNode: NodeExportTransport = parse(firstPackageExportedZip.getEntry("package.json").getData().toString()); expect(firstPackageExportedNode).toBeTruthy(); - const firstPackageContent: NodeSerializedContent = parse(firstPackageExportedNode.configuration); + const firstPackageContent: NodeConfiguration = firstPackageExportedNode.configuration; expect(firstPackageContent.variables).toHaveLength(3); expect(firstPackageContent.variables).toEqual([ { @@ -532,7 +532,7 @@ describe("Config export", () => { } ]); - expect(firstPackageExportedZip.getEntry("nodes/child-1-scenario.yml")).toBeNull(); + expect(firstPackageExportedZip.getEntry("nodes/child-1-scenario.json")).toBeNull(); }) it("Should export by packageKeys without dependencies", async () => { diff --git a/tests/config/config-import.spec.ts b/tests/config/config-import.spec.ts index 2cde1bb..e16c964 100644 --- a/tests/config/config-import.spec.ts +++ b/tests/config/config-import.spec.ts @@ -12,7 +12,7 @@ import { import {ConfigUtils} from "../utls/config-utils"; import {mockWriteFileSync, testTransport} from "../jest.setup"; import * as path from "path"; -import {stringify} from "../../src/util/yaml"; +import {stringify} from "../../src/util/json"; import {SpaceTransport} from "../../src/interfaces/save-space.interface"; import {packageApi} from "../../src/api/package-api"; import { @@ -68,7 +68,7 @@ describe("Config import", () => { const studioManifest: StudioPackageManifest[] = []; studioManifest.push(ConfigUtils.buildStudioManifestForKeyWithSpace("key-2", "spaceName", "space-id")); - const firstPackageNode = ConfigUtils.buildPackageNode("key-2", stringify({variables: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("key-2", {variables: []}); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZipWithStudioManifest(manifest, studioManifest,[firstPackageZip]); @@ -112,7 +112,7 @@ describe("Config import", () => { const studioManifest: StudioPackageManifest[] = []; studioManifest.push(ConfigUtils.buildStudioManifestForKeyWithSpace("key-2", "spaceName", "space")); - const firstPackageNode = ConfigUtils.buildPackageNode("key-2", stringify({variables: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("key-2", {variables: []}); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZipWithStudioManifest(manifest, studioManifest,[firstPackageZip]); @@ -139,7 +139,7 @@ describe("Config import", () => { const studioManifest: StudioPackageManifest[] = []; studioManifest.push(ConfigUtils.buildStudioManifestForKeyWithSpace("key-2", "space", "spaceId")); - const firstPackageNode = ConfigUtils.buildPackageNode("key-2", stringify({variables: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("key-2", {variables: []}); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZipWithStudioManifest(manifest, studioManifest,[firstPackageZip]); @@ -186,7 +186,7 @@ describe("Config import", () => { const studioManifest: StudioPackageManifest[] = []; studioManifest.push(ConfigUtils.buildStudioManifestForKeyWithSpace("key-2", "spaceName", null)); - const firstPackageNode = ConfigUtils.buildPackageNode("key-2", stringify({variables: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("key-2", {variables: []}); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZipWithStudioManifest(manifest, studioManifest,[firstPackageZip]); @@ -225,7 +225,7 @@ describe("Config import", () => { const studioManifest: StudioPackageManifest[] = []; studioManifest.push(ConfigUtils.buildStudioManifestForKeyWithSpace("key-2", "otherName", null)); - const firstPackageNode = ConfigUtils.buildPackageNode("key-2", stringify({variables: []})); + const firstPackageNode = ConfigUtils.buildPackageNode("key-2", {variables: []}); const firstPackageZip = ConfigUtils.buildExportPackageZip(firstPackageNode, [], "1.0.0"); const exportedPackagesZip = ConfigUtils.buildBatchExportZipWithStudioManifest(manifest, studioManifest,[firstPackageZip]); diff --git a/tests/config/config-list-variables.spec.ts b/tests/config/config-list-variables.spec.ts index 45f479e..a63c87b 100644 --- a/tests/config/config-list-variables.spec.ts +++ b/tests/config/config-list-variables.spec.ts @@ -5,7 +5,7 @@ import * as path from "path"; import {PackageKeyAndVersionPair, VariableManifestTransport} from "../../src/interfaces/package-export-transport"; import {PackageManagerVariableType} from "../../src/interfaces/package-manager.interfaces"; import {mockAxiosPost, mockedPostRequestBodyByUrl} from "../utls/http-requests-mock"; -import {parse} from "../../src/util/yaml"; +import {parse} from "../../src/util/json"; import * as fs from "fs"; describe("Config listVariables", () => { diff --git a/tests/utls/config-utils.ts b/tests/utls/config-utils.ts index 0ab9683..b4ac0e9 100644 --- a/tests/utls/config-utils.ts +++ b/tests/utls/config-utils.ts @@ -1,10 +1,10 @@ import AdmZip = require("adm-zip"); import { - DependencyTransport, + DependencyTransport, NodeConfiguration, NodeExportTransport, - PackageManifestTransport, StudioPackageManifest + PackageManifestTransport, StudioPackageManifest, } from "../../src/interfaces/package-export-transport"; -import {stringify} from "../../src/util/yaml"; +import {stringify} from "../../src/util/json"; import {SpaceTransport} from "../../src/interfaces/save-space.interface"; export class ConfigUtils { @@ -12,8 +12,8 @@ export class ConfigUtils { public static buildBatchExportZipWithStudioManifest(manifest: PackageManifestTransport[], studioManifest: StudioPackageManifest[], packageZips: AdmZip[]): AdmZip { const zipExport = new AdmZip(); - zipExport.addFile("manifest.yml", Buffer.from(stringify(manifest))); - zipExport.addFile("studio.yml", Buffer.from(stringify(studioManifest))); + zipExport.addFile("manifest.json", Buffer.from(stringify(manifest))); + zipExport.addFile("studio.json", Buffer.from(stringify(studioManifest))); packageZips.forEach(packageZip => { const fileName = `${packageZip.getZipComment()}.zip` packageZip.addZipComment("") @@ -25,7 +25,8 @@ export class ConfigUtils { public static buildBatchExportZip(manifest: PackageManifestTransport[], packageZips: AdmZip[]): AdmZip { const zipExport = new AdmZip(); - zipExport.addFile("manifest.yml", Buffer.from(stringify(manifest))); + const str = stringify(manifest); + zipExport.addFile("manifest.json", Buffer.from(stringify(manifest))); packageZips.forEach(packageZip => { const fileName = `${packageZip.getZipComment()}.zip` packageZip.addZipComment("") @@ -38,11 +39,11 @@ export class ConfigUtils { public static buildExportPackageZip(packageNode: NodeExportTransport, childNodes: NodeExportTransport[], version: string): AdmZip { const zipExport = new AdmZip(); - zipExport.addFile("package.yml", Buffer.from(stringify(packageNode))); + zipExport.addFile("package.json", Buffer.from(stringify(packageNode))); zipExport.addFile("nodes/", Buffer.alloc(0)); childNodes.forEach(child => { - zipExport.addFile(`nodes/${child.key}.yml`, Buffer.from(stringify(child))); + zipExport.addFile(`nodes/${child.key}.json`, Buffer.from(stringify(child))); }); zipExport.addZipComment(`${packageNode.key}_${version}`); @@ -59,7 +60,7 @@ export class ConfigUtils { }; } - public static buildPackageNode(key: string, configuration: string): NodeExportTransport { + public static buildPackageNode(key: string, configuration: NodeConfiguration): NodeExportTransport { return { key, parentNodeKey: key, @@ -81,7 +82,7 @@ export class ConfigUtils { name: "name", type: type, exportSerializationType: "YAML", - configuration: "", + configuration: {}, schemaVersion: 1, invalidContent: false, serializedDocument: null, From 8af0670af06583d2a6c0f2327da3d93fce606a51 Mon Sep 17 00:00:00 2001 From: Buqete Mucolli Date: Wed, 17 Jul 2024 17:02:46 +0200 Subject: [PATCH 2/7] TA-3148: Increase version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 61dbfcd..607d138 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@celonis/content-cli", - "version": "0.9.0", + "version": "0.10.0", "description": "CLI Tool to help manage content in Celonis EMS", "main": "content-cli.js", "bin": { From deaa7a423ecf70e636bd91f212a734f7aa4d6b94 Mon Sep 17 00:00:00 2001 From: Buqete Mucolli Date: Thu, 18 Jul 2024 13:17:20 +0200 Subject: [PATCH 3/7] TA-3148: Revert back the changes made to Studio logic --- src/content/factory/widget-manager.factory.ts | 2 +- src/content/manager/analysis.manager.ts | 2 +- src/content/manager/asset.manager.ts | 2 +- src/services/file-service.ts | 2 +- src/services/package-manager/package-service.ts | 2 +- src/util/yaml.ts | 9 +++++++++ 6 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/util/yaml.ts diff --git a/src/content/factory/widget-manager.factory.ts b/src/content/factory/widget-manager.factory.ts index 2771a3a..beb2841 100644 --- a/src/content/factory/widget-manager.factory.ts +++ b/src/content/factory/widget-manager.factory.ts @@ -3,7 +3,7 @@ import * as path from "path"; import { FatalError, logger } from "../../util/logger"; import { WidgetManager } from "../manager/widget.manager"; import * as AdmZip from "adm-zip"; -import {parse} from "../../util/json"; +import {parse} from "../../util/yaml"; interface Manifest { key: string; diff --git a/src/content/manager/analysis.manager.ts b/src/content/manager/analysis.manager.ts index f79e10c..3869415 100644 --- a/src/content/manager/analysis.manager.ts +++ b/src/content/manager/analysis.manager.ts @@ -2,7 +2,7 @@ import { BaseManager } from "./base.manager"; import { ManagerConfig } from "../../interfaces/manager-config.interface"; import { AssetManager } from "./asset.manager"; import * as fs from "fs"; -import {stringify} from "../../util/json"; +import {stringify} from "../../util/yaml"; import * as FormData from "form-data"; export class AnalysisManager extends BaseManager { diff --git a/src/content/manager/asset.manager.ts b/src/content/manager/asset.manager.ts index e198dd4..9db91c2 100644 --- a/src/content/manager/asset.manager.ts +++ b/src/content/manager/asset.manager.ts @@ -1,7 +1,7 @@ import { BaseManager } from "./base.manager"; import { ManagerConfig } from "../../interfaces/manager-config.interface"; import { SaveContentNode } from "../../interfaces/save-content-node.interface"; -import { parse, stringify } from "../../util/json"; +import { parse, stringify } from "../../util/yaml"; export class AssetManager extends BaseManager { public static ASSET_FILE_PREFIX = "asset_"; diff --git a/src/services/file-service.ts b/src/services/file-service.ts index 4fa8451..9da10aa 100644 --- a/src/services/file-service.ts +++ b/src/services/file-service.ts @@ -2,7 +2,7 @@ import * as fs from "fs"; import * as path from "path"; import { ManifestNodeTransport } from "../interfaces/manifest-transport"; import { FatalError, logger } from "../util/logger"; -import {parse} from "../util/json"; +import {parse} from "../util/yaml"; export class FileService { public static readonly fileDownloadedMessage = "File downloaded successfully. New filename: "; diff --git a/src/services/package-manager/package-service.ts b/src/services/package-manager/package-service.ts index f296030..bba4919 100644 --- a/src/services/package-manager/package-service.ts +++ b/src/services/package-manager/package-service.ts @@ -21,7 +21,7 @@ import {SpaceTransport} from "../../interfaces/save-space.interface"; import {ManifestDependency, ManifestNodeTransport} from "../../interfaces/manifest-transport"; import {DataPoolInstallVersionReport} from "../../interfaces/data-pool-manager.interfaces"; import {SemanticVersioning} from "../../util/semantic-versioning" -import {stringify} from "../../util/json"; +import {stringify} from "../../util/yaml"; import * as FormData from "form-data"; class PackageService { diff --git a/src/util/yaml.ts b/src/util/yaml.ts new file mode 100644 index 0000000..3d7d19f --- /dev/null +++ b/src/util/yaml.ts @@ -0,0 +1,9 @@ +import * as YAML from "yaml"; + +export function stringify(data: any): string { + return YAML.stringify(data, {doubleQuotedAsJSON: true, indent: 2, lineWidth: 200}); +} + +export function parse(data: string): T { + return YAML.parse(data); +} \ No newline at end of file From d8846de03672aed418984fa8ad945f1c794358a0 Mon Sep 17 00:00:00 2001 From: Buqete Mucolli Date: Thu, 18 Jul 2024 13:22:25 +0200 Subject: [PATCH 4/7] TA-3148: Dummy commit --- src/util/yaml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/yaml.ts b/src/util/yaml.ts index 3d7d19f..8c9c951 100644 --- a/src/util/yaml.ts +++ b/src/util/yaml.ts @@ -6,4 +6,4 @@ export function stringify(data: any): string { export function parse(data: string): T { return YAML.parse(data); -} \ No newline at end of file +} From 70efc91204872bd99361909ef9c86d7bc4f653cb Mon Sep 17 00:00:00 2001 From: Buqete Mucolli Date: Thu, 18 Jul 2024 17:36:39 +0200 Subject: [PATCH 5/7] TA-3148: Remove unused variable --- tests/utls/config-utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/utls/config-utils.ts b/tests/utls/config-utils.ts index b4ac0e9..e796278 100644 --- a/tests/utls/config-utils.ts +++ b/tests/utls/config-utils.ts @@ -25,7 +25,6 @@ export class ConfigUtils { public static buildBatchExportZip(manifest: PackageManifestTransport[], packageZips: AdmZip[]): AdmZip { const zipExport = new AdmZip(); - const str = stringify(manifest); zipExport.addFile("manifest.json", Buffer.from(stringify(manifest))); packageZips.forEach(packageZip => { const fileName = `${packageZip.getZipComment()}.zip` From 6ec49ee07e92e51a164650a22dccfbc8f6e15542 Mon Sep 17 00:00:00 2001 From: Buqete Mucolli Date: Thu, 18 Jul 2024 17:47:33 +0200 Subject: [PATCH 6/7] TA-3148: Remove unnecessary reassignment --- src/services/studio/studio.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/services/studio/studio.service.ts b/src/services/studio/studio.service.ts index c037b7d..83b659b 100644 --- a/src/services/studio/studio.service.ts +++ b/src/services/studio/studio.service.ts @@ -168,7 +168,6 @@ class StudioService { connectionVariablesByKey.get(variable.key).metadata : variable.metadata })); - exportedNode.configuration = nodeContent; packageZip.updateFile(packageEntry, Buffer.from(stringify(exportedNode))); } From 14cb3ead3ee61a09ba67106fadaab277086660f5 Mon Sep 17 00:00:00 2001 From: Buqete Mucolli Date: Thu, 18 Jul 2024 17:55:14 +0200 Subject: [PATCH 7/7] TA-3148: Add optional variables property on NodeConfiguration transport --- src/interfaces/package-export-transport.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/interfaces/package-export-transport.ts b/src/interfaces/package-export-transport.ts index 5f3343f..9f20c51 100644 --- a/src/interfaces/package-export-transport.ts +++ b/src/interfaces/package-export-transport.ts @@ -61,6 +61,7 @@ export interface NodeExportTransport { } export interface NodeConfiguration { + variables?: VariableDefinition[]; [key: string]: any; }