Skip to content

Commit

Permalink
make API w. custom ui configutations
Browse files Browse the repository at this point in the history
  • Loading branch information
bsrdjan committed Feb 19, 2021
1 parent 9cc3dae commit a2743ba
Show file tree
Hide file tree
Showing 10 changed files with 852 additions and 57 deletions.
10 changes: 9 additions & 1 deletion abap-api-tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,17 @@ const cp: RfcConnectionParameters = {
// Call templates and annotations
R = await a.get(cp, ["stfc_connection", "stfc_structure"]);
// Call templates and ui components (based on "full" annotations)
// Call templates and ui components, using standard ui configuration
R = await a.make(R.annotations as AnnotationsType, "fudamental-ngx");
// Call templates and ui components, using custom ui configuration
const customUi = loadFromFile("ui5-custom.yaml");
const customAbap = loadFromFile("ui5-custom-abap.yaml");
R = await a..make(annotations, {
ui: customUi,
abap: customAbap, // optional
});
})();
```

Expand Down
4 changes: 2 additions & 2 deletions abap-api-tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion abap-api-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "abap-api-tools",
"description": "ABAP api tools",
"version": "1.8.0",
"version": "1.9.0",
"homepage": "https://github.com/sap/fundamental-tools",
"author": "SAP",
"license": "Apache-2.0",
Expand Down
25 changes: 21 additions & 4 deletions abap-api-tools/src/ts/abap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import {
DockerVolume,
} from "./constants";
import { AnnotationsType, Backend } from "./backend";
import { Frontend, FrontendResult } from "./frontend";
import {
Frontend,
FrontendResult,
UiConfigType,
UiConfigTableType,
AbapConfigType,
} from "./frontend";
import { fileLoad, log, makeDir, deleteFile, getTimestamp } from "./utils";

export let Signature = `abap api`;
Expand All @@ -35,8 +41,19 @@ export const Command = Object.freeze({

export type ApiListType = Record<string, string[]>;

export type AbapCliUiConfig = {
ui: UiConfigType;
abap?: AbapConfigType;
};

export type Destination = string | RfcConnectionParameters;
export { RfcConnectionParameters, AnnotationsType };
export {
RfcConnectionParameters,
AnnotationsType,
UiConfigType,
UiConfigTableType,
AbapConfigType,
};

export type Arguments = {
//[argName: string]: unknown;
Expand All @@ -52,7 +69,7 @@ export type Arguments = {
dest?: Destination;
save?: boolean;
textOnly?: string;
ui?: string;
ui?: string | AbapCliUiConfig;
"sort-fields"?: boolean;
runInBg?: boolean;
};
Expand Down Expand Up @@ -227,7 +244,7 @@ export class AbapCliApi {

make(
annotations: AnnotationsType,
ui: string,
ui: string | AbapCliUiConfig,
options?: { "sort-fields"?: boolean; debug?: boolean }
): AbapCliResult {
if (options) {
Expand Down
106 changes: 58 additions & 48 deletions abap-api-tools/src/ts/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type ElementHTML = {

// yaml config files

type AbapConfigType = Record<
export type AbapConfigType = Record<
string,
{
type: string;
Expand All @@ -76,15 +76,15 @@ type AbapConfigType = Record<
}
>;

type UiConfigTableType = {
export type UiConfigTableType = {
header?: string;
header_row?: string;
body?: string;
row: string;
footer?: string;
};

type UiConfigType = Record<string, string | UiConfigTableType>;
export type UiConfigType = Record<string, string | UiConfigTableType>;

export type FrontendResult = Record<string, { js: string; html?: string }>;
export class Frontend {
Expand Down Expand Up @@ -138,55 +138,65 @@ export class Frontend {
}

if (argv.ui) {
// ui configuration
try {
// local ui first
this.configPath.ui = path.join(
DefaultFolder.userConfig,
`${argv.ui}.yaml`
);
this.uiConfig = fileLoad(this.configPath.ui) as UiConfigType;
this.configPath.uiLocal = true;
log.debug(`local ui configuration ${argv.ui}`);
} catch (ex) {
if (ex.code !== "ENOENT") throw ex; // ignore file not found error
}
if (typeof argv.ui === "string") {
// ui configuration
try {
// local ui first
this.configPath.ui = path.join(
DefaultFolder.userConfig,
`${argv.ui}.yaml`
);
this.uiConfig = fileLoad(this.configPath.ui) as UiConfigType;
this.configPath.uiLocal = true;
log.debug(`local ui configuration ${argv.ui}`);
} catch (ex) {
if (ex.code !== "ENOENT") throw ex; // ignore file not found error
}

// default ui 2nd
if (isEmpty(this.uiConfig)) {
this.configPath.ui = path.join(
DefaultFolder.configuration,
"ui",
`${argv.ui}.yaml`
);
this.uiConfig = fileLoad(this.configPath.ui) as UiConfigType;
log.debug(`default ui configuration ${argv.ui}`);
}
// default ui 2nd
if (isEmpty(this.uiConfig)) {
this.configPath.ui = path.join(
DefaultFolder.configuration,
"ui",
`${argv.ui}.yaml`
);
this.uiConfig = fileLoad(this.configPath.ui) as UiConfigType;
log.debug(`default ui configuration ${argv.ui}`);
}

try {
// local abap first
this.configPath.abap = path.join(
DefaultFolder.userConfig,
`${argv.ui}-abap.yaml`
);
this.abapConfig = fileLoad(this.configPath.abap) as AbapConfigType;
this.configPath.abapLocal = true;
log.debug(`local abap configuration ${argv.ui}`);
} catch (ex) {
if (ex.code !== "ENOENT") throw ex; // ignore file not found error
}
try {
// local abap first
this.configPath.abap = path.join(
DefaultFolder.userConfig,
`${argv.ui}-abap.yaml`
);
this.abapConfig = fileLoad(this.configPath.abap) as AbapConfigType;
this.configPath.abapLocal = true;
log.debug(`local abap configuration ${argv.ui}`);
} catch (ex) {
if (ex.code !== "ENOENT") throw ex; // ignore file not found error
}

// default abap 2nd
if (isEmpty(this.abapConfig)) {
this.configPath.abap = path.join(
DefaultFolder.configuration,
"ui",
`${argv.ui}-abap.yaml`
);
this.abapConfig = fileLoad(this.configPath.abap) as AbapConfigType;
log.debug(`default abap configuration ${argv.ui}`);
// default abap 2nd
if (isEmpty(this.abapConfig)) {
this.configPath.abap = path.join(
DefaultFolder.configuration,
"ui",
`${argv.ui}-abap.yaml`
);
this.abapConfig = fileLoad(this.configPath.abap) as AbapConfigType;
log.debug(`default abap configuration ${argv.ui}`);
}
} else {
// ui configuration passed by CLI api
this.uiConfig = argv.ui.ui;
if (argv.ui.abap) {
this.abapConfig = argv.ui.abap;
}
}
} else {
}

if (isEmpty(this.abapConfig)) {
// default abap
this.configPath.abap = path.join(
DefaultFolder.configuration,
Expand Down
22 changes: 21 additions & 1 deletion abap-api-tools/tests/cliapi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe("Integration API", () => {
test("make: stfc_structure", async () => {
expect.assertions(1);

const expectedFn = "make_stfc_stfc_structure.yaml";
const expectedFn = "make_stfc_structure.yaml";

const annotations = loadFromFile("get_stfc_structure.yaml").annotations;
const result = api.make(annotations, "fundamental-ngx");
Expand All @@ -95,4 +95,24 @@ describe("Integration API", () => {
expectedResult.frontend.STFC_STRUCTURE.html
);
});

test("make: stfc_structure with custom ui configuration", async () => {
expect.assertions(1);

const expectedFn = "make_stfc_structure_custom.yaml";

const annotations = loadFromFile("get_stfc_structure.yaml").annotations;
const customUi = loadFromFile("ui5-custom.yaml");
const customAbap = loadFromFile("ui5-custom-abap.yaml");
const result = api.make(annotations, {
ui: customUi,
abap: customAbap,
});
//saveToFile(expectedFn, result);

const expectedResult = loadFromFile(expectedFn);
expect(result.frontend.STFC_STRUCTURE.html).toEqual(
expectedResult.frontend.STFC_STRUCTURE.html
);
});
});
Loading

0 comments on commit a2743ba

Please sign in to comment.