@bubblewrap/core
Version:
Core Library to generate, build and sign TWA projects
87 lines (86 loc) • 4.19 kB
TypeScript
import { WebManifestIcon, WebManifestJson } from './types/WebManifest';
import { Log } from './Log';
import { Orientation } from './TwaManifest';
export declare function execute(cmd: string[], env: NodeJS.ProcessEnv, log?: Log): Promise<{
stdout: string;
stderr: string;
}>;
export declare function executeFile(cmd: string, args: string[], env: NodeJS.ProcessEnv, log?: Log, cwd?: string): Promise<{
stdout: string;
stderr: string;
}>;
export declare function unzipFile(zipFile: string, destinationPath: string, deleteZipWhenDone?: boolean): Promise<void>;
export declare function untar(tarFile: string, destinationPath: string, deleteZipWhenDone?: boolean): Promise<void>;
export declare function execInteractive(cwd: string, args: string[], env: NodeJS.ProcessEnv): Promise<number>;
/**
* Fetches data for the largest icon from the web app manifest with a given purpose.
* @param {Array<WebManifestIcon>|undefined} icons List of the manifest icons.
* @param {string} purpose Purpose filter that the icon must match.
* @param {number} minSize The minimum required icon size enforced id provided.
*/
export declare function findSuitableIcon(icons: WebManifestIcon[] | undefined, purpose: string, minSize?: number): WebManifestIcon | null;
/**
* Generates an Android Application Id / Package Name, using the reverse hostname as a base
* and appending `.twa` to the end.
*
* Replaces invalid characters, as described in the Android documentation with `_`.
*
* https://developer.android.com/guide/topics/manifest/manifest-element.html#package
*
* @param {String} host the original hostname
*/
export declare function generatePackageId(host: string): string | null;
/**
* Validates if a string is not null and not empty.
* @param input the string to be validated
* @param fieldName the field represented by the string
* @returns {string | null} a description of the error or null if no erro is found.
*/
export declare function validateNotEmpty(input: string | null | undefined, fieldName: string): string | null;
/**
* Validates a Package Id, according to the documentation at:
* https://developer.android.com/studio/build/application-id
*
* Rules summary for the Package Id:
* - It must have at least two segments (one or more dots).
* - Each segment must start with a letter [a-zA-Z].
* - All characters must be alphanumeric or an underscore [a-zA-Z0-9_].
*
* @param {string} input the package name to be validated
* @returns {string | null} a description of the error or null if no erro is found.
*/
export declare function validatePackageId(input: string): string | null;
/**
* Removes a file or directory. If the path is a directory, recursively deletes files and
* directories inside it.
*/
export declare function rmdir(path: string): Promise<void>;
/**
* Given a Web Manifest's URL, the function returns the web manifest as a JSON object.
*
* @param {URL} webManifestUrl the URL where the Web Manifest is available.
* @returns {Promise<WebManifestJson}
*/
export declare function getWebManifest(webManifestUrl: URL): Promise<WebManifestJson>;
/**
* Given a JSON string, the function returns an escaped representation of the string.
* eg: Turns every " instance into \\".
*
* @param {string} stringToReplace the string before the manipulation.
* @returns {string} the string after the manipulation.
*/
export declare function escapeJsonString(stringToReplace: string): string;
export declare function toAndroidScreenOrientation(orientation: Orientation): string;
/**
* Escapes a string that will be written to the Gradle file. The characters need to be escaped
* multiple times, as they also need to be escaped inside the Gradle file.
*
* As an example, "Andre's Code" needs to be written as "Andre\\\'s Code" to the Gradle file, so
* it is properly escaped when passed to AAPT.
*/
export declare function escapeGradleString(input: string): string;
/**
* Escapes a string that will be used inside a double quoted block in the shell. The characters
* ", $, `, and \ need escaping even when the string is surrounded by double quotes.
*/
export declare function escapeDoubleQuotedShellString(input: string): string;