diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 2e6d0db..db7aebd 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -318,10 +318,12 @@ The command takes your permissions into consideration and only lists the packages you have access to.  - It is also possible to download packages in JSON format by adding '--json' option. -- It is also possible to include package dependencies by adding '--includeDependencies' flag +- When the JSON format option is used, also possible to include package dependencies by adding '--includeDependencies' flag +- When the JSON format option is used, also possible to filter packages by adding '--packageKeys' parameter ``` content-cli list packages -p +content-cli list packages -p --json --packageKeys ``` ### List all data pools of the team @@ -421,7 +423,7 @@ In order to batch push a list of data pools use the following command: ``` { "targetTeamDomain": "dev1", - "dataPoolImports": [ + "dataPoolImportRequests": [ { "sourcePoolId": "850728cc-c679-4925-954a-87fb39abb12b", "targetPoolId": "80a1389d-50c5-4976-ad6e-fb5b7a2b5517", diff --git a/package.json b/package.json index 96a3a06..04070ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@celonis/content-cli", - "version": "0.4.3", + "version": "0.4.5", "description": "CLI Tool to help manage content in Celonis EMS", "main": "content-cli.js", "bin": { @@ -22,7 +22,7 @@ "semver": "^7.3.2", "valid-url": "^1.0.9", "winston": "^3.1.0", - "yaml": "^1.7.2" + "yaml": "2.0.0-8" }, "devDependencies": { "@types/adm-zip": "^0.4.34", diff --git a/src/commands/package.command.ts b/src/commands/package.command.ts index 5ffcb5a..4fd1ce3 100644 --- a/src/commands/package.command.ts +++ b/src/commands/package.command.ts @@ -36,9 +36,9 @@ export class PackageCommand { await this.contentService.batchPush(profile, this.packageManagerFactory.createPushManagers(spaceKey)); } - public async listPackages(jsonResponse: boolean, includeDependencies: boolean): Promise { + public async listPackages(jsonResponse: boolean, includeDependencies: boolean, packageKeys:string[]): Promise { if (jsonResponse) { - await packageService.findAndExportListOfAllPackages(includeDependencies); + await packageService.findAndExportListOfAllPackages(includeDependencies, packageKeys ?? []); } else { await packageService.listPackages(); } diff --git a/src/content-cli-list.ts b/src/content-cli-list.ts index b32f312..d2c194e 100644 --- a/src/content-cli-list.ts +++ b/src/content-cli-list.ts @@ -17,8 +17,9 @@ export class List { .option("-p, --profile ", "Profile which you want to use to list packages") .option("--json", "Return response as json type", "") .option("--includeDependencies", "Include variables and dependencies", "") + .option("--packageKeys ", "Lists only given package keys") .action(async cmd => { - await new PackageCommand().listPackages(cmd.json, cmd.includeDependencies) + await new PackageCommand().listPackages(cmd.json, cmd.includeDependencies, cmd.packageKeys) process.exit(); }); diff --git a/src/content/factory/widget-manager.factory.ts b/src/content/factory/widget-manager.factory.ts index 31b99e2..beb2841 100644 --- a/src/content/factory/widget-manager.factory.ts +++ b/src/content/factory/widget-manager.factory.ts @@ -1,9 +1,9 @@ import * as fs from "fs"; import * as path from "path"; import { FatalError, logger } from "../../util/logger"; -import * as YAML from "yaml"; import { WidgetManager } from "../manager/widget.manager"; import * as AdmZip from "adm-zip"; +import {parse} from "../../util/yaml"; interface Manifest { key: string; @@ -46,11 +46,11 @@ export class WidgetManagerFactory { public fetchManifest(): Manifest { if (fs.existsSync(path.resolve(process.cwd(), "manifest.yaml"))) { - return YAML.parse(fs.readFileSync(path.resolve(process.cwd(), "manifest.yaml"), { encoding: "utf-8" })); + return parse(fs.readFileSync(path.resolve(process.cwd(), "manifest.yaml"), { encoding: "utf-8" })); } if (fs.existsSync(path.resolve(process.cwd(), "manifest.yml"))) { - return YAML.parse(fs.readFileSync(path.resolve(process.cwd(), "manifest.yml"), { encoding: "utf-8" })); + return parse(fs.readFileSync(path.resolve(process.cwd(), "manifest.yml"), { encoding: "utf-8" })); } return null; diff --git a/src/content/manager/analysis-bookmarks.manager.ts b/src/content/manager/analysis-bookmarks.manager.ts index f5eb401..eeeab6f 100644 --- a/src/content/manager/analysis-bookmarks.manager.ts +++ b/src/content/manager/analysis-bookmarks.manager.ts @@ -1,10 +1,7 @@ import { BaseManager } from "./base.manager"; import { ManagerConfig } from "../../interfaces/manager-config.interface"; -import * as YAML from "yaml"; import * as fs from "fs"; -YAML.scalarOptions.str.doubleQuoted.jsonEncoding = true; - export class AnalysisBookmarksManager extends BaseManager { private static BASE_URL = "/process-analytics/api/bookmarks/"; private static ANALYSIS_BOOKMARKS_FILE_PREFIX = "studio_analysis_bookmarks_"; diff --git a/src/content/manager/analysis.manager.ts b/src/content/manager/analysis.manager.ts index 396999d..1abb678 100644 --- a/src/content/manager/analysis.manager.ts +++ b/src/content/manager/analysis.manager.ts @@ -1,10 +1,8 @@ import { BaseManager } from "./base.manager"; import { ManagerConfig } from "../../interfaces/manager-config.interface"; -import * as YAML from "yaml"; import { AssetManager } from "./asset.manager"; import * as fs from "fs"; - -YAML.scalarOptions.str.doubleQuoted.jsonEncoding = true; +import {stringify} from "../../util/yaml"; export class AnalysisManager extends BaseManager { private static BASE_URL = "/process-mining/api/analysis/"; @@ -77,7 +75,7 @@ export class AnalysisManager extends BaseManager { protected getSerializedFileContent(data: any): string { if (this.packageManager) { - return YAML.stringify(data); + return stringify(data); } return JSON.stringify(data); } diff --git a/src/content/manager/asset.manager.ts b/src/content/manager/asset.manager.ts index 83fcfb0..ff47ad6 100644 --- a/src/content/manager/asset.manager.ts +++ b/src/content/manager/asset.manager.ts @@ -1,9 +1,7 @@ import { BaseManager } from "./base.manager"; import { ManagerConfig } from "../../interfaces/manager-config.interface"; import { SaveContentNode } from "../../interfaces/save-content-node.interface"; -import * as YAML from "yaml"; - -YAML.scalarOptions.str.doubleQuoted.jsonEncoding = true; +import { parse, stringify } from "../../util/yaml"; export class AssetManager extends BaseManager { public static ASSET_FILE_PREFIX = "asset_"; @@ -63,12 +61,12 @@ export class AssetManager extends BaseManager { } private toNodeTransport(): SaveContentNode { - const asset = YAML.parse(this.content) as SaveContentNode; + const asset = parse(this.content) as SaveContentNode; asset.rootNodeKey = this.packageKey; return asset; } protected getSerializedFileContent(data: any): string { - return YAML.stringify(data); + return stringify(data); } } diff --git a/src/services/data-pool/data-pool-service.ts b/src/services/data-pool/data-pool-service.ts index b57e328..3f67715 100644 --- a/src/services/data-pool/data-pool-service.ts +++ b/src/services/data-pool/data-pool-service.ts @@ -10,7 +10,6 @@ class DataPoolService { const importReport = await dataPoolApi.executeDataPoolsBatchImport(requestFileContent); const importReportString = JSON.stringify(importReport, null, 4); - logger.info("Data Pools batch import succeeded!"); if (outputToJsonFile) { const reportFileName = "batch_import_report_" + uuidv4() + ".json"; fileService.writeToFileWithGivenName(importReportString, reportFileName); @@ -24,11 +23,10 @@ class DataPoolService { const exportedDataPool = await dataPoolApi.exportDataPool(poolId); const exportedDataPoolString = JSON.stringify(exportedDataPool, null, 4); - logger.info("Data Pools export succeeded!"); if (outputToJsonFile) { - const reportFileName = "data_pool_" + poolId + ".json"; + const reportFileName = uuidv4() + "data_pool_" + poolId + ".json"; fileService.writeToFileWithGivenName(exportedDataPoolString, reportFileName); - logger.info("Export file: " + reportFileName); + logger.info(FileService.fileDownloadedMessage + reportFileName); } else { logger.info("Exported Data Pool: \n" + exportedDataPoolString); } diff --git a/src/services/file-service.ts b/src/services/file-service.ts index 23367b4..9da10aa 100644 --- a/src/services/file-service.ts +++ b/src/services/file-service.ts @@ -1,8 +1,8 @@ import * as fs from "fs"; import * as path from "path"; -import * as YAML from "yaml"; -import {ManifestNodeTransport} from "../interfaces/manifest-transport"; -import {FatalError, logger} from "../util/logger"; +import { ManifestNodeTransport } from "../interfaces/manifest-transport"; +import { FatalError, logger } from "../util/logger"; +import {parse} from "../util/yaml"; export class FileService { public static readonly fileDownloadedMessage = "File downloaded successfully. New filename: "; @@ -18,8 +18,8 @@ export class FileService { } public readManifestFile(importedFileName: string): Promise { - const manifest: ManifestNodeTransport[] = YAML.parse( - fs.readFileSync(path.resolve(importedFileName + "/manifest.yml"), {encoding: "utf-8"}) + const manifest: ManifestNodeTransport[] = parse( + fs.readFileSync(path.resolve(importedFileName + "/manifest.yml"), { encoding: "utf-8" }) ); return Promise.all(manifest); } diff --git a/src/services/package-manager/package-service.ts b/src/services/package-manager/package-service.ts index 8f4e75e..f4f259f 100644 --- a/src/services/package-manager/package-service.ts +++ b/src/services/package-manager/package-service.ts @@ -9,7 +9,6 @@ import {nodeApi} from "../../api/node-api"; import {packageDependenciesApi} from "../../api/package-dependencies-api"; import {variableService} from "./variable-service"; import {spaceService} from "./space-service"; -import * as YAML from "yaml"; import * as fs from "fs"; import AdmZip = require("adm-zip"); import * as path from "path"; @@ -18,6 +17,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"; class PackageService { protected readonly fileDownloadedMessage = "File downloaded successfully. New filename: "; @@ -29,10 +29,15 @@ class PackageService { }); } - public async findAndExportListOfAllPackages(includeDependencies: boolean): Promise { + public async findAndExportListOfAllPackages(includeDependencies: boolean, packageKeys:string[]): Promise { const fieldsToInclude = ["key", "name", "changeDate", "activatedDraftId", "spaceId"]; let nodesListToExport: BatchExportNodeTransport[] = await packageApi.findAllPackages(); + if (packageKeys.length > 0) { + nodesListToExport = nodesListToExport.filter(node => { + return packageKeys.includes(node.rootNodeKey); + }) + } if (includeDependencies) { fieldsToInclude.push("type", "value", "dependencies", "id", "updateAvailable", "version", "poolId", "node", "dataModelId", "dataPool", "datamodels"); @@ -453,7 +458,7 @@ class PackageService { const zip = new AdmZip(); - zip.addFile("manifest.yml", Buffer.from(YAML.stringify(manifestNodes), "utf8")); + zip.addFile("manifest.yml", Buffer.from(stringify(manifestNodes), "utf8")); for (const packageZip of packageZips) { zip.addFile(`${packageZip.packageKey}_${packageZip.version}.zip`, packageZip.data) } diff --git a/src/util/json.ts b/src/util/json.ts new file mode 100644 index 0000000..7661244 --- /dev/null +++ b/src/util/json.ts @@ -0,0 +1 @@ +export function parseJso \ No newline at end of file diff --git a/src/util/yaml.ts b/src/util/yaml.ts new file mode 100644 index 0000000..8c9c951 --- /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); +} diff --git a/yarn.lock b/yarn.lock index 0b8cdf9..b7e5d00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2703,10 +2703,10 @@ yallist@^3.0.2: resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd" integrity sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g== -yaml@^1.7.2: - version "1.10.0" - resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e" - integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg== +yaml@2.0.0-8: + version "2.0.0-8" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.0.0-8.tgz#226365f0d804ba7fb8cc2b527a00a7a4a3d8ea5f" + integrity sha512-QaYgJZMfWD6fKN/EYMk6w1oLWPCr1xj9QaPSZW5qkDb3y8nGCXhy2Ono+AF4F+CSL/vGcqswcAT0BaS//pgD2A== yamux-js@0.1.0: version "0.1.0"