@bubblewrap/core 1.13.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +63 -0
  3. package/dist/index.d.ts +17 -0
  4. package/dist/index.js +56 -0
  5. package/dist/lib/BufferedLog.d.ts +20 -0
  6. package/dist/lib/BufferedLog.js +83 -0
  7. package/dist/lib/Config.d.ts +9 -0
  8. package/dist/lib/Config.js +50 -0
  9. package/dist/lib/DigitalAssetLinks.d.ts +3 -0
  10. package/dist/lib/DigitalAssetLinks.js +37 -0
  11. package/dist/lib/FetchUtils.d.ts +17 -0
  12. package/dist/lib/FetchUtils.js +79 -0
  13. package/dist/lib/GooglePlay.d.ts +41 -0
  14. package/dist/lib/GooglePlay.js +92 -0
  15. package/dist/lib/GradleWrapper.d.ts +31 -0
  16. package/dist/lib/GradleWrapper.js +62 -0
  17. package/dist/lib/ImageHelper.d.ts +37 -0
  18. package/dist/lib/ImageHelper.js +112 -0
  19. package/dist/lib/Log.d.ts +88 -0
  20. package/dist/lib/Log.js +114 -0
  21. package/dist/lib/Result.d.ts +46 -0
  22. package/dist/lib/Result.js +97 -0
  23. package/dist/lib/ShortcutInfo.d.ts +32 -0
  24. package/dist/lib/ShortcutInfo.js +84 -0
  25. package/dist/lib/TwaGenerator.d.ts +39 -0
  26. package/dist/lib/TwaGenerator.js +362 -0
  27. package/dist/lib/TwaManifest.d.ts +234 -0
  28. package/dist/lib/TwaManifest.js +384 -0
  29. package/dist/lib/androidSdk/AndroidSdkTools.d.ts +87 -0
  30. package/dist/lib/androidSdk/AndroidSdkTools.js +226 -0
  31. package/dist/lib/errors/ValidatePathError.d.ts +9 -0
  32. package/dist/lib/errors/ValidatePathError.js +16 -0
  33. package/dist/lib/features/AppsFlyerFeature.d.ts +8 -0
  34. package/dist/lib/features/AppsFlyerFeature.js +70 -0
  35. package/dist/lib/features/EmptyFeature.d.ts +28 -0
  36. package/dist/lib/features/EmptyFeature.js +44 -0
  37. package/dist/lib/features/Feature.d.ts +120 -0
  38. package/dist/lib/features/Feature.js +17 -0
  39. package/dist/lib/features/FeatureManager.d.ts +36 -0
  40. package/dist/lib/features/FeatureManager.js +137 -0
  41. package/dist/lib/features/FirstRunFlagFeature.d.ts +8 -0
  42. package/dist/lib/features/FirstRunFlagFeature.js +43 -0
  43. package/dist/lib/features/LocationDelegationFeature.d.ts +7 -0
  44. package/dist/lib/features/LocationDelegationFeature.js +32 -0
  45. package/dist/lib/features/PlayBillingFeature.d.ts +7 -0
  46. package/dist/lib/features/PlayBillingFeature.js +53 -0
  47. package/dist/lib/jdk/JarSigner.d.ts +13 -0
  48. package/dist/lib/jdk/JarSigner.js +55 -0
  49. package/dist/lib/jdk/JdkHelper.d.ts +55 -0
  50. package/dist/lib/jdk/JdkHelper.js +127 -0
  51. package/dist/lib/jdk/KeyTool.d.ts +57 -0
  52. package/dist/lib/jdk/KeyTool.js +136 -0
  53. package/dist/lib/mock/MockLog.d.ts +37 -0
  54. package/dist/lib/mock/MockLog.js +70 -0
  55. package/dist/lib/types/WebManifest.d.ts +44 -0
  56. package/dist/lib/types/WebManifest.js +17 -0
  57. package/dist/lib/util.d.ts +82 -0
  58. package/dist/lib/util.js +279 -0
  59. package/dist/lib/wrappers/svg2img.d.ts +14 -0
  60. package/dist/lib/wrappers/svg2img.js +39 -0
  61. package/package.json +58 -0
  62. package/template_project/app/.gitignore +1 -0
  63. package/template_project/app/build.gradle +211 -0
  64. package/template_project/app/src/main/AndroidManifest.xml +204 -0
  65. package/template_project/app/src/main/java/Application.java +35 -0
  66. package/template_project/app/src/main/java/DelegationService.java +18 -0
  67. package/template_project/app/src/main/java/LauncherActivity.java +62 -0
  68. package/template_project/app/src/main/res/drawable-anydpi/shortcut_legacy_background.xml +25 -0
  69. package/template_project/app/src/main/res/drawable-anydpi/shortcut_monochrome.xml +27 -0
  70. package/template_project/app/src/main/res/drawable-anydpi-v26/shortcut_maskable.xml +32 -0
  71. package/template_project/app/src/main/res/drawable-anydpi-v26/shortcut_monochrome.xml +26 -0
  72. package/template_project/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +33 -0
  73. package/template_project/app/src/main/res/values/colors.xml +18 -0
  74. package/template_project/app/src/main/res/values/strings.xml +50 -0
  75. package/template_project/app/src/main/res/xml/filepaths.xml +18 -0
  76. package/template_project/app/src/main/res/xml/shortcuts.xml +16 -0
  77. package/template_project/build.gradle +42 -0
  78. package/template_project/enable-debug.sh +27 -0
  79. package/template_project/gradle/wrapper/gradle-wrapper.jar +0 -0
  80. package/template_project/gradle/wrapper/gradle-wrapper.properties +5 -0
  81. package/template_project/gradle.properties +14 -0
  82. package/template_project/gradlew +188 -0
  83. package/template_project/gradlew.bat +100 -0
  84. package/template_project/settings.gradle +1 -0
@@ -0,0 +1,37 @@
1
+ import { Log } from '../../lib/Log';
2
+ /**
3
+ * An utility class for testing used for get the logging messages without printing to the user.
4
+ */
5
+ export declare class MockLog implements Log {
6
+ private receivedData;
7
+ /**
8
+ * Creates a new MockLog instance.
9
+ */
10
+ constructor();
11
+ getReceivedData(): Array<string>;
12
+ /**
13
+ * Saves the debug message to the Logger.
14
+ * @param message The message the be saved.
15
+ */
16
+ debug(message: string): void;
17
+ /**
18
+ * Saves the debug message to the Logger.
19
+ * @param message The message the be saved.
20
+ */
21
+ info(message: string): void;
22
+ /**
23
+ * Saves the debug message to the Logger.
24
+ * @param message The message the be saved.
25
+ */
26
+ warn(message: string): void;
27
+ /**
28
+ * Saves the debug message to the Logger.
29
+ * @param message The message the be saved.
30
+ */
31
+ error(message: string): void;
32
+ setVerbose(): void;
33
+ /**
34
+ * Creates a new MockLog.
35
+ */
36
+ newLog(): Log;
37
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2020 Google Inc. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.MockLog = void 0;
19
+ /**
20
+ * An utility class for testing used for get the logging messages without printing to the user.
21
+ */
22
+ class MockLog {
23
+ /**
24
+ * Creates a new MockLog instance.
25
+ */
26
+ constructor() {
27
+ this.receivedData = [];
28
+ }
29
+ getReceivedData() {
30
+ return this.receivedData;
31
+ }
32
+ /**
33
+ * Saves the debug message to the Logger.
34
+ * @param message The message the be saved.
35
+ */
36
+ debug(message) {
37
+ this.receivedData.push(message);
38
+ }
39
+ /**
40
+ * Saves the debug message to the Logger.
41
+ * @param message The message the be saved.
42
+ */
43
+ info(message) {
44
+ this.receivedData.push(message);
45
+ }
46
+ /**
47
+ * Saves the debug message to the Logger.
48
+ * @param message The message the be saved.
49
+ */
50
+ warn(message) {
51
+ this.receivedData.push(message);
52
+ }
53
+ /**
54
+ * Saves the debug message to the Logger.
55
+ * @param message The message the be saved.
56
+ */
57
+ error(message) {
58
+ this.receivedData.push(message);
59
+ }
60
+ setVerbose() {
61
+ // Not implemented for testing.
62
+ }
63
+ /**
64
+ * Creates a new MockLog.
65
+ */
66
+ newLog() {
67
+ return new MockLog();
68
+ }
69
+ }
70
+ exports.MockLog = MockLog;
@@ -0,0 +1,44 @@
1
+ export interface WebManifestIcon {
2
+ src: string;
3
+ sizes?: string;
4
+ purpose?: string;
5
+ mimeType?: string;
6
+ size?: number;
7
+ }
8
+ export interface WebManifestShortcutJson {
9
+ name?: string;
10
+ short_name?: string;
11
+ url?: string;
12
+ icons?: Array<WebManifestIcon>;
13
+ }
14
+ declare type WebManifestDisplayMode = 'browser' | 'minimal-ui' | 'standalone' | 'fullscreen';
15
+ export declare type OrientationLock = 'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary';
16
+ export interface ShareTargetParams {
17
+ title?: string;
18
+ text?: string;
19
+ url?: string;
20
+ files?: FilesParams[];
21
+ }
22
+ export interface FilesParams {
23
+ name: string;
24
+ accept: string[];
25
+ }
26
+ export interface ShareTarget {
27
+ action?: string;
28
+ method?: string;
29
+ enctype?: string;
30
+ params?: ShareTargetParams;
31
+ }
32
+ export interface WebManifestJson {
33
+ name?: string;
34
+ short_name?: string;
35
+ start_url?: string;
36
+ display?: WebManifestDisplayMode;
37
+ theme_color?: string;
38
+ background_color?: string;
39
+ icons?: Array<WebManifestIcon>;
40
+ shortcuts?: Array<WebManifestShortcutJson>;
41
+ share_target?: ShareTarget;
42
+ orientation?: OrientationLock;
43
+ }
44
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2019 Google Inc. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,82 @@
1
+ /// <reference types="node" />
2
+ import { WebManifestIcon, WebManifestJson } from './types/WebManifest';
3
+ import { Log } from './Log';
4
+ import { Orientation } from './TwaManifest';
5
+ export declare function execute(cmd: string[], env: NodeJS.ProcessEnv, log?: Log): Promise<{
6
+ stdout: string;
7
+ stderr: string;
8
+ }>;
9
+ export declare function executeFile(cmd: string, args: string[], env: NodeJS.ProcessEnv, log?: Log, cwd?: string): Promise<{
10
+ stdout: string;
11
+ stderr: string;
12
+ }>;
13
+ export declare function unzipFile(zipFile: string, destinationPath: string, deleteZipWhenDone?: boolean): Promise<void>;
14
+ export declare function untar(tarFile: string, destinationPath: string, deleteZipWhenDone?: boolean): Promise<void>;
15
+ export declare function execInteractive(cwd: string, args: string[], env: NodeJS.ProcessEnv): Promise<number>;
16
+ /**
17
+ * Fetches data for the largest icon from the web app manifest with a given purpose.
18
+ * @param {Array<WebManifestIcon>|undefined} icons List of the manifest icons.
19
+ * @param {string} purpose Purpose filter that the icon must match.
20
+ * @param {number} minSize The minimum required icon size enforced id provided.
21
+ */
22
+ export declare function findSuitableIcon(icons: WebManifestIcon[] | undefined, purpose: string, minSize?: number): WebManifestIcon | null;
23
+ /**
24
+ * Generates an Android Application Id / Package Name, using the reverse hostname as a base
25
+ * and appending `.twa` to the end.
26
+ *
27
+ * Replaces invalid characters, as described in the Android documentation with `_`.
28
+ *
29
+ * https://developer.android.com/guide/topics/manifest/manifest-element.html#package
30
+ *
31
+ * @param {String} host the original hostname
32
+ */
33
+ export declare function generatePackageId(host: string): string | null;
34
+ /**
35
+ * Validates if a string is not null and not empty.
36
+ * @param input the string to be validated
37
+ * @param fieldName the field represented by the string
38
+ * @returns {string | null} a description of the error or null if no erro is found.
39
+ */
40
+ export declare function validateNotEmpty(input: string | null | undefined, fieldName: string): string | null;
41
+ /**
42
+ * Validates a Package Id, according to the documentation at:
43
+ * https://developer.android.com/studio/build/application-id
44
+ *
45
+ * Rules summary for the Package Id:
46
+ * - It must have at least two segments (one or more dots).
47
+ * - Each segment must start with a letter [a-zA-Z].
48
+ * - All characters must be alphanumeric or an underscore [a-zA-Z0-9_].
49
+ *
50
+ * @param {string} input the package name to be validated
51
+ * @returns {string | null} a description of the error or null if no erro is found.
52
+ */
53
+ export declare function validatePackageId(input: string): string | null;
54
+ /**
55
+ * Removes a file or directory. If the path is a directory, recursively deletes files and
56
+ * directories inside it.
57
+ */
58
+ export declare function rmdir(path: string): Promise<void>;
59
+ /**
60
+ * Given a Web Manifest's URL, the function returns the web manifest as a JSON object.
61
+ *
62
+ * @param {URL} webManifestUrl the URL where the Web Manifest is available.
63
+ * @returns {Promise<WebManifestJson}
64
+ */
65
+ export declare function getWebManifest(webManifestUrl: URL): Promise<WebManifestJson>;
66
+ /**
67
+ * Given a JSON string, the function returns an escaped representation of the string.
68
+ * eg: Turns every " instance into \\".
69
+ *
70
+ * @param {string} stringToReplace the string before the manipulation.
71
+ * @returns {string} the string after the manipulation.
72
+ */
73
+ export declare function escapeJsonString(stringToReplace: string): string;
74
+ export declare function toAndroidScreenOrientation(orientation: Orientation): string;
75
+ /**
76
+ * Escapes a string that will be written to the Gradle file. The characters need to be escaped
77
+ * multiple times, as they also need to be escaped inside the Gradle file.
78
+ *
79
+ * As an example, "Andre's Code" needs to be written as "Andre\\\'s Code" to the Gradle file, so
80
+ * it is properly escaped when passed to AAPT.
81
+ */
82
+ export declare function escapeGradleString(input: string): string;
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2019 Google Inc. All Rights Reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.escapeGradleString = exports.toAndroidScreenOrientation = exports.escapeJsonString = exports.getWebManifest = exports.rmdir = exports.validatePackageId = exports.validateNotEmpty = exports.generatePackageId = exports.findSuitableIcon = exports.execInteractive = exports.untar = exports.unzipFile = exports.executeFile = exports.execute = void 0;
19
+ const extractZip = require("extract-zip");
20
+ const fs = require("fs");
21
+ const path_1 = require("path");
22
+ const util_1 = require("util");
23
+ const child_process_1 = require("child_process");
24
+ const tar_1 = require("tar");
25
+ const FetchUtils_1 = require("./FetchUtils");
26
+ const execPromise = util_1.promisify(child_process_1.exec);
27
+ const execFilePromise = util_1.promisify(child_process_1.execFile);
28
+ const extractZipPromise = util_1.promisify(extractZip);
29
+ // Regex for disallowed characters on Android Packages, as per
30
+ // https://developer.android.com/guide/topics/manifest/manifest-element.html#package
31
+ const DISALLOWED_ANDROID_PACKAGE_CHARS_REGEX = /[^a-zA-Z0-9_\.]/g;
32
+ const VALID_PACKAGE_ID_SEGMENT_REGEX = /^[a-zA-Z][A-Za-z0-9_]*$/;
33
+ async function execute(cmd, env, log) {
34
+ const joinedCmd = cmd.join(' ');
35
+ if (log) {
36
+ log.debug(`Executing shell: ${joinedCmd}`);
37
+ }
38
+ return await execPromise(joinedCmd, { env: env });
39
+ }
40
+ exports.execute = execute;
41
+ async function executeFile(cmd, args, env, log, cwd) {
42
+ if (log) {
43
+ log.debug(`Executing command ${cmd} with args ${args}`);
44
+ }
45
+ return await execFilePromise(cmd, args, { env: env, cwd: cwd });
46
+ }
47
+ exports.executeFile = executeFile;
48
+ async function unzipFile(zipFile, destinationPath, deleteZipWhenDone = false) {
49
+ await extractZipPromise(zipFile, { dir: destinationPath });
50
+ if (deleteZipWhenDone) {
51
+ fs.unlinkSync(zipFile);
52
+ }
53
+ }
54
+ exports.unzipFile = unzipFile;
55
+ async function untar(tarFile, destinationPath, deleteZipWhenDone = false) {
56
+ console.log(`Extracting ${tarFile} to ${destinationPath}`);
57
+ await tar_1.x({
58
+ file: tarFile,
59
+ cwd: destinationPath,
60
+ unlink: true,
61
+ });
62
+ if (deleteZipWhenDone) {
63
+ fs.unlinkSync(tarFile);
64
+ }
65
+ }
66
+ exports.untar = untar;
67
+ function execInteractive(cwd, args, env) {
68
+ const shell = child_process_1.spawn(`"${cwd}"`, args, {
69
+ stdio: 'inherit',
70
+ env: env,
71
+ shell: true,
72
+ });
73
+ return new Promise((resolve, reject) => {
74
+ shell.on('close', (code) => {
75
+ if (code === 0) {
76
+ resolve(code);
77
+ }
78
+ else {
79
+ reject(code);
80
+ }
81
+ });
82
+ });
83
+ }
84
+ exports.execInteractive = execInteractive;
85
+ /**
86
+ * Fetches data for the largest icon from the web app manifest with a given purpose.
87
+ * @param {Array<WebManifestIcon>|undefined} icons List of the manifest icons.
88
+ * @param {string} purpose Purpose filter that the icon must match.
89
+ * @param {number} minSize The minimum required icon size enforced id provided.
90
+ */
91
+ function findSuitableIcon(icons, purpose, minSize = 0) {
92
+ if (icons == undefined || icons.length === 0) {
93
+ return null;
94
+ }
95
+ let largestIcon = null;
96
+ let largestIconSize = 0;
97
+ for (const icon of icons) {
98
+ const size = (icon.sizes || '0x0').split(' ')
99
+ .map((size) => Number.parseInt(size, 10))
100
+ .reduce((max, size) => Math.max(max, size), 0);
101
+ const purposes = new Set((icon.purpose || 'any').split(' '));
102
+ if (purposes.has(purpose) && (!largestIcon || largestIconSize < size)) {
103
+ largestIcon = icon;
104
+ largestIconSize = size;
105
+ }
106
+ }
107
+ if (largestIcon === null || (minSize > 0 && largestIconSize < minSize)) {
108
+ return null;
109
+ }
110
+ largestIcon.size = largestIconSize;
111
+ return largestIcon;
112
+ }
113
+ exports.findSuitableIcon = findSuitableIcon;
114
+ /**
115
+ * Generates an Android Application Id / Package Name, using the reverse hostname as a base
116
+ * and appending `.twa` to the end.
117
+ *
118
+ * Replaces invalid characters, as described in the Android documentation with `_`.
119
+ *
120
+ * https://developer.android.com/guide/topics/manifest/manifest-element.html#package
121
+ *
122
+ * @param {String} host the original hostname
123
+ */
124
+ function generatePackageId(host) {
125
+ host = host.trim();
126
+ if (host.length === 0) {
127
+ return null;
128
+ }
129
+ const parts = host.split('.').reverse();
130
+ const packageId = [];
131
+ for (const part of parts) {
132
+ if (part.trim().length === 0) {
133
+ continue;
134
+ }
135
+ packageId.push(part);
136
+ }
137
+ if (packageId.length === 0) {
138
+ return null;
139
+ }
140
+ packageId.push('twa');
141
+ return packageId.join('.').replace(DISALLOWED_ANDROID_PACKAGE_CHARS_REGEX, '_');
142
+ }
143
+ exports.generatePackageId = generatePackageId;
144
+ /**
145
+ * Validates if a string is not null and not empty.
146
+ * @param input the string to be validated
147
+ * @param fieldName the field represented by the string
148
+ * @returns {string | null} a description of the error or null if no erro is found.
149
+ */
150
+ function validateNotEmpty(input, fieldName) {
151
+ if (input === null || input === undefined || input.trim().length <= 0) {
152
+ return `${fieldName} cannot be empty`;
153
+ }
154
+ return null;
155
+ }
156
+ exports.validateNotEmpty = validateNotEmpty;
157
+ /**
158
+ * Validates a Package Id, according to the documentation at:
159
+ * https://developer.android.com/studio/build/application-id
160
+ *
161
+ * Rules summary for the Package Id:
162
+ * - It must have at least two segments (one or more dots).
163
+ * - Each segment must start with a letter [a-zA-Z].
164
+ * - All characters must be alphanumeric or an underscore [a-zA-Z0-9_].
165
+ *
166
+ * @param {string} input the package name to be validated
167
+ * @returns {string | null} a description of the error or null if no erro is found.
168
+ */
169
+ function validatePackageId(input) {
170
+ const error = validateNotEmpty(input, 'packageId');
171
+ if (error !== null) {
172
+ return error;
173
+ }
174
+ const parts = input.split('.');
175
+ if (parts.length < 2) {
176
+ return 'packageId must have at least 2 sections separated by "."';
177
+ }
178
+ for (const part of parts) {
179
+ if (part.match(VALID_PACKAGE_ID_SEGMENT_REGEX) === null) {
180
+ return `Invalid packageId section: "${part}". Only alphanumeric characters and ` +
181
+ 'underscore [a-zA-Z0-9_] are allowed in packageId sections. Each section must ' +
182
+ 'start with a letter [a-zA-Z]';
183
+ }
184
+ }
185
+ return null;
186
+ }
187
+ exports.validatePackageId = validatePackageId;
188
+ /**
189
+ * Removes a file or directory. If the path is a directory, recursively deletes files and
190
+ * directories inside it.
191
+ */
192
+ async function rmdir(path) {
193
+ if (!fs.existsSync(path)) {
194
+ return;
195
+ }
196
+ const stat = await fs.promises.stat(path);
197
+ // This is a regular file. Just delete it.
198
+ if (stat.isFile()) {
199
+ await fs.promises.unlink(path);
200
+ return;
201
+ }
202
+ // This is a directory. We delete files and sub directories inside it, then delete the
203
+ // directory itself.
204
+ const entries = fs.readdirSync(path);
205
+ await Promise.all(entries.map((entry) => rmdir(path_1.join(path, entry))));
206
+ await fs.promises.rmdir(path);
207
+ }
208
+ exports.rmdir = rmdir;
209
+ ;
210
+ /**
211
+ * Given a Web Manifest's URL, the function returns the web manifest as a JSON object.
212
+ *
213
+ * @param {URL} webManifestUrl the URL where the Web Manifest is available.
214
+ * @returns {Promise<WebManifestJson}
215
+ */
216
+ async function getWebManifest(webManifestUrl) {
217
+ const response = await FetchUtils_1.fetchUtils.fetch(webManifestUrl.toString());
218
+ if (response.status !== 200) {
219
+ throw new Error(`Failed to download Web Manifest ${webManifestUrl}. ` +
220
+ `Responded with status ${response.status}`);
221
+ }
222
+ return await response.json();
223
+ }
224
+ exports.getWebManifest = getWebManifest;
225
+ /**
226
+ * Given a JSON string, the function returns an escaped representation of the string.
227
+ * eg: Turns every " instance into \\".
228
+ *
229
+ * @param {string} stringToReplace the string before the manipulation.
230
+ * @returns {string} the string after the manipulation.
231
+ */
232
+ function escapeJsonString(stringToReplace) {
233
+ // The 'g' flag is for replacing all of the instances.
234
+ const regExp = new RegExp('\"', 'g');
235
+ return stringToReplace.replace(regExp, '\\\\\"');
236
+ }
237
+ exports.escapeJsonString = escapeJsonString;
238
+ // This is the value of the screenOrientation for the LauncherActivity which determines the
239
+ // orientation of the splash screen.
240
+ // This methods maps the Web Manifest orientation to the android screenOrientation:
241
+ // - "default" => "unspecified"
242
+ // - "any" => "unspecified"
243
+ // - "natural " => "unspecified"
244
+ // - "portrait" => "userPortrait"
245
+ // - "portrait-primary" => "portrait"
246
+ // - "portrait-secondary" => "reversePortrait"
247
+ // - "landscape" => "userLandscape"
248
+ // - "landscape-primary" => "landscape"
249
+ // - "landscape-secondary" => "reverseLandscape"
250
+ //
251
+ // For more details, check the web orientation lock documentation at:
252
+ // https://developer.mozilla.org/en-US/docs/Web/API/Screen/lockOrientation
253
+ //
254
+ // And the Android screenOrientation at:
255
+ // https://developer.android.com/guide/topics/manifest/activity-element#screen
256
+ //
257
+ function toAndroidScreenOrientation(orientation) {
258
+ switch (orientation) {
259
+ case 'portrait': return 'ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT';
260
+ case 'portrait-primary': return 'ActivityInfo.SCREEN_ORIENTATION_PORTRAIT';
261
+ case 'portrait-secondary': return 'ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT';
262
+ case 'landscape': return 'ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE';
263
+ case 'landspace-primary': return 'ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE';
264
+ case 'landscape-secondary': return 'ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE';
265
+ default: return 'ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED';
266
+ }
267
+ }
268
+ exports.toAndroidScreenOrientation = toAndroidScreenOrientation;
269
+ /**
270
+ * Escapes a string that will be written to the Gradle file. The characters need to be escaped
271
+ * multiple times, as they also need to be escaped inside the Gradle file.
272
+ *
273
+ * As an example, "Andre's Code" needs to be written as "Andre\\\'s Code" to the Gradle file, so
274
+ * it is properly escaped when passed to AAPT.
275
+ */
276
+ function escapeGradleString(input) {
277
+ return input.replace(/[\\']/g, '\\\\\\$&');
278
+ }
279
+ exports.escapeGradleString = escapeGradleString;