Skip to content

Commit

Permalink
Merge branch 'master' into fisgeci/tn-x-add-datamodel-mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
fisgeci committed Aug 11, 2023
2 parents d9127aa + 56d51a2 commit 27fe221
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 38 deletions.
6 changes: 4 additions & 2 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <your-chosen-profile>
content-cli list packages -p <profileName> --json --packageKeys <package1> <package2>
```

### List all data pools of the team
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/package.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class PackageCommand {
await this.contentService.batchPush(profile, this.packageManagerFactory.createPushManagers(spaceKey));
}

public async listPackages(jsonResponse: boolean, includeDependencies: boolean): Promise<void> {
public async listPackages(jsonResponse: boolean, includeDependencies: boolean, packageKeys:string[]): Promise<void> {
if (jsonResponse) {
await packageService.findAndExportListOfAllPackages(includeDependencies);
await packageService.findAndExportListOfAllPackages(includeDependencies, packageKeys ?? []);
} else {
await packageService.listPackages();
}
Expand Down
3 changes: 2 additions & 1 deletion src/content-cli-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export class List {
.option("-p, --profile <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 <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();
});

Expand Down
6 changes: 3 additions & 3 deletions src/content/factory/widget-manager.factory.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/content/manager/analysis-bookmarks.manager.ts
Original file line number Diff line number Diff line change
@@ -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_";
Expand Down
6 changes: 2 additions & 4 deletions src/content/manager/analysis.manager.ts
Original file line number Diff line number Diff line change
@@ -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/";
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 3 additions & 5 deletions src/content/manager/asset.manager.ts
Original file line number Diff line number Diff line change
@@ -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_";
Expand Down Expand Up @@ -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);
}
}
6 changes: 2 additions & 4 deletions src/services/data-pool/data-pool-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/services/file-service.ts
Original file line number Diff line number Diff line change
@@ -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: ";
Expand All @@ -18,8 +18,8 @@ export class FileService {
}

public readManifestFile(importedFileName: string): Promise<ManifestNodeTransport[]> {
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);
}
Expand Down
11 changes: 8 additions & 3 deletions src/services/package-manager/package-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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: ";
Expand All @@ -29,10 +29,15 @@ class PackageService {
});
}

public async findAndExportListOfAllPackages(includeDependencies: boolean): Promise<void> {
public async findAndExportListOfAllPackages(includeDependencies: boolean, packageKeys:string[]): Promise<void> {
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");
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions src/util/json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function parseJso

Check failure on line 1 in src/util/json.ts

View workflow job for this annotation

GitHub Actions / Npm install and npm build

'(' expected.
9 changes: 9 additions & 0 deletions src/util/yaml.ts
Original file line number Diff line number Diff line change
@@ -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<T>(data: string): T {
return YAML.parse(data);
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

[email protected]:
version "0.1.0"
Expand Down

0 comments on commit 27fe221

Please sign in to comment.