UNPKG

@sap-ux/project-access

Version:

Library to access SAP Fiori tools projects

172 lines 7.06 kB
import type { Logger } from '@sap-ux/logger'; import type { NewI18nEntry } from '@sap-ux/i18n'; import type { I18nBundles } from '../i18n/index.js'; import type { ApplicationStructure, I18nPropertiesPaths, Project, ProjectType } from '../info/index.js'; import type { Editor } from 'mem-fs-editor'; import type { Package } from '../package/index.js'; import type { AnnotationFile, Manifest } from '../webapp/index.js'; interface BaseAccess { readonly project: Project; readonly root: string; readonly projectType: ProjectType; } export interface ApplicationAccessOptions extends ProjectAccessOptions { fs?: Editor; } export interface ApplicationAccess extends BaseAccess { readonly app: ApplicationStructure; /** * Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist. * * @param newEntries - translation entries to write in the `.properties` file * @returns - boolean or exception * @description It also update `manifest.json` file if `@i18n` entry is missing from `"sap.ui5":{"models": {}}` * as * ```JSON * { * "sap.ui5": { * "models": { * "@i18n": { * "type": "sap.ui.model.resource.ResourceModel", * "uri": "i18n/i18n.properties" * } * } * } * } * ``` */ createAnnotationI18nEntries(newEntries: NewI18nEntry[]): Promise<boolean>; /** * Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist. * * @param newEntries - translation entries to write in the `.properties` file * @param modelKey - i18n model key. Default key is `i18n` * @returns boolean or exception * @description It also update `manifest.json` file if `<modelKey>` entry is missing from `"sap.ui5":{"models": {}}` * as * ```JSON * { * "sap.ui5": { * "models": { * "<modelKey>": { * "type": "sap.ui.model.resource.ResourceModel", * "uri": "i18n/i18n.properties" * } * } * } * } * ``` */ createUI5I18nEntries(newEntries: NewI18nEntry[], modelKey?: string): Promise<boolean>; /** * Maintains new translation entries in an existing i18n file or in a new i18n properties file if it does not exist. * * @param newEntries translation entries to write in the `.properties` file * @returns boolean or exception * @description If `i18n` entry is missing from `"sap.app":{}`, default `i18n/i18n.properties` is used. Update of `manifest.json` file is not needed. */ createManifestI18nEntries(newEntries: NewI18nEntry[]): Promise<boolean>; /** * Maintains new translation entries in CAP i18n files. * * @param filePath absolute path to file in which the translation entry will be used. * @param newI18nEntries translation entries to write in the i18n file. * @returns boolean or exception */ createCapI18nEntries(filePath: string, newI18nEntries: NewI18nEntry[]): Promise<boolean>; /** * Return the application id of this app, which is the relative path from the project root * to the app root. * * @returns - Application root path */ getAppId(): string; /** * Return the absolute application root path. * * @returns - Application root path */ getAppRoot(): string; /** * For a given app in project, retrieves i18n bundles for 'sap.app' namespace,`models` of `sap.ui5` namespace and service for cap services. * * @returns i18n bundles or exception */ getI18nBundles(): Promise<I18nBundles>; /** * Return absolute paths to i18n.properties files from manifest. * * @returns absolute paths to i18n.properties */ getI18nPropertiesPaths(): Promise<I18nPropertiesPaths>; /** * Returns an instance of @sap/ux-specification for the application. */ getSpecification<T>(): Promise<T>; /** * Updates package.json file asynchronously by keeping the previous indentation. * * @param packageJson - updated package.json file content * @param memFs - optional mem-fs-editor instance */ updatePackageJSON(packageJson: Package, memFs?: Editor): Promise<void>; /** * Updates manifest.json file asynchronously by keeping the previous indentation. * * @param manifest - updated manifest.json file content * @param memFs - optional mem-fs-editor instance */ updateManifestJSON(manifest: Manifest, memFs?: Editor): Promise<void>; /** * Reads and returns the parsed `manifest.json` file for the application. * * @param memFs - optional mem-fs-editor instance * @returns A promise resolving to the parsed `manifest.json` content. */ readManifest(memFs?: Editor): Promise<Manifest>; /** * Reads and returns all Flex Changes (`*.change` files) associated with the application. * * @param memFs - optional mem-fs-editor instance * @returns A promise that resolves to an array of flex change files. */ readFlexChanges(memFs?: Editor): Promise<{ [key: string]: string; }>; /** * Reads and returns all annotation files associated with the application's main service. * * @param memFs - optional mem-fs-editor instance * @returns A promise resolving to an array of annotation file descriptors. */ readAnnotationFiles(memFs?: Editor): Promise<AnnotationFile[]>; } export interface ProjectAccessOptions { logger?: Logger; memFs?: Editor; } export interface ProjectAccess extends BaseAccess { /** * Returns list of application IDs. * * @returns - array of application IDs. For single application projects it will return [''] */ getApplicationIds: () => string[]; /** * Returns an instance of an application for a given application ID (the relative path from project root to app root, NOT the 'sap.app.id' from the manifest). * It contains information about the application, like paths and services. * * @param appId - application ID (the relative path from project root to app root, NOT the 'sap.app.id' from the manifest) * @returns - Instance of ApplicationAccess that contains information about the application, like paths and services */ getApplication: (appId: string) => ApplicationAccess; /** * Get application ID (the relative path from project root to app root) for a given 'sap.app.id' from the manifest. * * @param manifestAppId - The 'sap.app.id' from the manifest * @returns - application ID (the relative path from project root to app root) or undefined if not found */ getApplicationIdByManifestAppId: (manifestAppId: string) => Promise<string | undefined>; } export {}; //# sourceMappingURL=index.d.ts.map