@rock-js/plugin-metro 0.8.13
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.
- package/README.md +7 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/bundle/__tests__/filterPlatformAssetScales-test.d.ts +8 -0
- package/dist/src/lib/bundle/__tests__/filterPlatformAssetScales-test.js +29 -0
- package/dist/src/lib/bundle/__tests__/filterPlatformAssetScales-test.js.map +1 -0
- package/dist/src/lib/bundle/assetCatalogIOS.d.ts +21 -0
- package/dist/src/lib/bundle/assetCatalogIOS.js +54 -0
- package/dist/src/lib/bundle/assetCatalogIOS.js.map +1 -0
- package/dist/src/lib/bundle/assetPathUtils.d.ts +28 -0
- package/dist/src/lib/bundle/assetPathUtils.js +72 -0
- package/dist/src/lib/bundle/assetPathUtils.js.map +1 -0
- package/dist/src/lib/bundle/buildBundle.d.ts +57 -0
- package/dist/src/lib/bundle/buildBundle.js +99 -0
- package/dist/src/lib/bundle/buildBundle.js.map +1 -0
- package/dist/src/lib/bundle/command.d.ts +2 -0
- package/dist/src/lib/bundle/command.d.ts.map +1 -0
- package/dist/src/lib/bundle/command.js +135 -0
- package/dist/src/lib/bundle/command.js.map +1 -0
- package/dist/src/lib/bundle/createKeepFileAsync.d.ts +10 -0
- package/dist/src/lib/bundle/createKeepFileAsync.js +28 -0
- package/dist/src/lib/bundle/createKeepFileAsync.js.map +1 -0
- package/dist/src/lib/bundle/filterPlatformAssetScales.d.ts +9 -0
- package/dist/src/lib/bundle/filterPlatformAssetScales.js +36 -0
- package/dist/src/lib/bundle/filterPlatformAssetScales.js.map +1 -0
- package/dist/src/lib/bundle/getAssetDestPathAndroid.d.ts +10 -0
- package/dist/src/lib/bundle/getAssetDestPathAndroid.js +16 -0
- package/dist/src/lib/bundle/getAssetDestPathAndroid.js.map +1 -0
- package/dist/src/lib/bundle/getAssetDestPathIOS.d.ts +10 -0
- package/dist/src/lib/bundle/getAssetDestPathIOS.js +19 -0
- package/dist/src/lib/bundle/getAssetDestPathIOS.js.map +1 -0
- package/dist/src/lib/bundle/index.d.ts +11 -0
- package/dist/src/lib/bundle/index.js +106 -0
- package/dist/src/lib/bundle/index.js.map +1 -0
- package/dist/src/lib/bundle/saveAssets.d.ts +10 -0
- package/dist/src/lib/bundle/saveAssets.js +112 -0
- package/dist/src/lib/bundle/saveAssets.js.map +1 -0
- package/dist/src/lib/getDevMiddleware.d.ts +2 -0
- package/dist/src/lib/getDevMiddleware.js +15 -0
- package/dist/src/lib/getDevMiddleware.js.map +1 -0
- package/dist/src/lib/getReactNativeDeps.d.ts +3 -0
- package/dist/src/lib/getReactNativeDeps.js +15 -0
- package/dist/src/lib/getReactNativeDeps.js.map +1 -0
- package/dist/src/lib/loadMetroConfig.d.ts +24 -0
- package/dist/src/lib/loadMetroConfig.js +76 -0
- package/dist/src/lib/loadMetroConfig.js.map +1 -0
- package/dist/src/lib/pluginMetro.d.ts +3 -0
- package/dist/src/lib/pluginMetro.d.ts.map +1 -0
- package/dist/src/lib/pluginMetro.js +12 -0
- package/dist/src/lib/pluginMetro.js.map +1 -0
- package/dist/src/lib/start/OpenDebuggerKeyboardHandler.d.ts +35 -0
- package/dist/src/lib/start/OpenDebuggerKeyboardHandler.d.ts.map +1 -0
- package/dist/src/lib/start/OpenDebuggerKeyboardHandler.js +128 -0
- package/dist/src/lib/start/OpenDebuggerKeyboardHandler.js.map +1 -0
- package/dist/src/lib/start/attachKeyHandlers.d.ts +14 -0
- package/dist/src/lib/start/attachKeyHandlers.d.ts.map +1 -0
- package/dist/src/lib/start/attachKeyHandlers.js +107 -0
- package/dist/src/lib/start/attachKeyHandlers.js.map +1 -0
- package/dist/src/lib/start/command.d.ts +8 -0
- package/dist/src/lib/start/command.d.ts.map +1 -0
- package/dist/src/lib/start/command.js +110 -0
- package/dist/src/lib/start/command.js.map +1 -0
- package/dist/src/lib/start/createDevMiddlewareLogger.d.ts +18 -0
- package/dist/src/lib/start/createDevMiddlewareLogger.d.ts.map +1 -0
- package/dist/src/lib/start/createDevMiddlewareLogger.js +27 -0
- package/dist/src/lib/start/createDevMiddlewareLogger.js.map +1 -0
- package/dist/src/lib/start/loadMetroConfig.d.ts +24 -0
- package/dist/src/lib/start/loadMetroConfig.d.ts.map +1 -0
- package/dist/src/lib/start/loadMetroConfig.js +76 -0
- package/dist/src/lib/start/loadMetroConfig.js.map +1 -0
- package/dist/src/lib/start/metroPlatformResolver.d.ts +24 -0
- package/dist/src/lib/start/metroPlatformResolver.d.ts.map +1 -0
- package/dist/src/lib/start/metroPlatformResolver.js +38 -0
- package/dist/src/lib/start/metroPlatformResolver.js.map +1 -0
- package/dist/src/lib/start/runServer.d.ts +32 -0
- package/dist/src/lib/start/runServer.d.ts.map +1 -0
- package/dist/src/lib/start/runServer.js +133 -0
- package/dist/src/lib/start/runServer.js.map +1 -0
- package/dist/src/utils/loadMetroConfig.d.ts +24 -0
- package/dist/src/utils/loadMetroConfig.js +76 -0
- package/dist/src/utils/loadMetroConfig.js.map +1 -0
- package/dist/src/utils/metroPlatformResolver.d.ts +24 -0
- package/dist/src/utils/metroPlatformResolver.js +38 -0
- package/dist/src/utils/metroPlatformResolver.js.map +1 -0
- package/dist/src/utils/parseKeyValueParamArray.d.ts +8 -0
- package/dist/src/utils/parseKeyValueParamArray.js +21 -0
- package/dist/src/utils/parseKeyValueParamArray.js.map +1 -0
- package/package.json +41 -0
- package/template/metro.config.js +11 -0
- package/template/package.json +7 -0
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# @rock-js/plugin-metro
|
|
2
|
+
|
|
3
|
+
Metro bundler integration plugin for Rock (Rock). This package is part of the Rock ecosystem and provides integration with Metro, the default JavaScript bundler for React Native.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
For detailed documentation about Rock and its tools, visit [Rock Documentation](https://rockjs.dev)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/pluginMetro.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import filterPlatformAssetScales from '../filterPlatformAssetScales';
|
|
9
|
+
jest.dontMock('../filterPlatformAssetScales').dontMock('../assetPathUtils');
|
|
10
|
+
describe('filterPlatformAssetScales', () => {
|
|
11
|
+
test('removes everything but 2x and 3x for iOS', () => {
|
|
12
|
+
expect(filterPlatformAssetScales('ios', [1, 1.5, 2, 3, 4])).toEqual([
|
|
13
|
+
1, 2, 3,
|
|
14
|
+
]);
|
|
15
|
+
expect(filterPlatformAssetScales('ios', [3, 4])).toEqual([3]);
|
|
16
|
+
});
|
|
17
|
+
test('keeps closest largest one if nothing matches', () => {
|
|
18
|
+
expect(filterPlatformAssetScales('ios', [0.5, 4, 100])).toEqual([4]);
|
|
19
|
+
expect(filterPlatformAssetScales('ios', [0.5, 100])).toEqual([100]);
|
|
20
|
+
expect(filterPlatformAssetScales('ios', [0.5])).toEqual([0.5]);
|
|
21
|
+
expect(filterPlatformAssetScales('ios', [])).toEqual([]);
|
|
22
|
+
});
|
|
23
|
+
test('keeps all scales for unknown platform', () => {
|
|
24
|
+
expect(filterPlatformAssetScales('freebsd', [1, 1.5, 2, 3.7])).toEqual([
|
|
25
|
+
1, 1.5, 2, 3.7,
|
|
26
|
+
]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
//# sourceMappingURL=filterPlatformAssetScales-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterPlatformAssetScales-test.js","sourceRoot":"","sources":["../../../../../src/lib/bundle/__tests__/filterPlatformAssetScales-test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,yBAAyB,MAAM,8BAA8B,CAAC;AAErE,IAAI,CAAC,QAAQ,CAAC,8BAA8B,CAAC,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;AAE5E,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACzC,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;QACpD,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAClE,CAAC,EAAE,CAAC,EAAE,CAAC;SACR,CAAC,CAAC;QACH,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACxD,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACpE,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/D,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;QACjD,MAAM,CAAC,yBAAyB,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YACrE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG;SACf,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { AssetData } from 'metro';
|
|
9
|
+
export declare function cleanAssetCatalog(catalogDir: string): void;
|
|
10
|
+
type ImageSet = {
|
|
11
|
+
basePath: string;
|
|
12
|
+
files: {
|
|
13
|
+
name: string;
|
|
14
|
+
src: string;
|
|
15
|
+
scale: number;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
export declare function getImageSet(catalogDir: string, asset: AssetData, scales: ReadonlyArray<number>): ImageSet;
|
|
19
|
+
export declare function isCatalogAsset(asset: AssetData): boolean;
|
|
20
|
+
export declare function writeImageSet(imageSet: ImageSet): void;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import assetPathUtils from './assetPathUtils.js';
|
|
11
|
+
export function cleanAssetCatalog(catalogDir) {
|
|
12
|
+
const files = fs
|
|
13
|
+
.readdirSync(catalogDir)
|
|
14
|
+
.filter((file) => file.endsWith('.imageset'));
|
|
15
|
+
for (const file of files) {
|
|
16
|
+
fs.rmSync(path.join(catalogDir, file), { recursive: true, force: true });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function getImageSet(catalogDir, asset, scales) {
|
|
20
|
+
const fileName = assetPathUtils.getResourceIdentifier(asset);
|
|
21
|
+
return {
|
|
22
|
+
basePath: path.join(catalogDir, `${fileName}.imageset`),
|
|
23
|
+
files: scales.map((scale, idx) => {
|
|
24
|
+
const suffix = scale === 1 ? '' : `@${scale}x`;
|
|
25
|
+
return {
|
|
26
|
+
name: `${fileName + suffix}.${asset.type}`,
|
|
27
|
+
scale,
|
|
28
|
+
src: asset.files[idx],
|
|
29
|
+
};
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function isCatalogAsset(asset) {
|
|
34
|
+
return asset.type === 'png' || asset.type === 'jpg' || asset.type === 'jpeg';
|
|
35
|
+
}
|
|
36
|
+
export function writeImageSet(imageSet) {
|
|
37
|
+
fs.mkdirSync(imageSet.basePath, { recursive: true });
|
|
38
|
+
for (const file of imageSet.files) {
|
|
39
|
+
const dest = path.join(imageSet.basePath, file.name);
|
|
40
|
+
fs.copyFileSync(file.src, dest);
|
|
41
|
+
}
|
|
42
|
+
fs.writeFileSync(path.join(imageSet.basePath, 'Contents.json'), JSON.stringify({
|
|
43
|
+
images: imageSet.files.map((file) => ({
|
|
44
|
+
filename: file.name,
|
|
45
|
+
idiom: 'universal',
|
|
46
|
+
scale: `${file.scale}x`,
|
|
47
|
+
})),
|
|
48
|
+
info: {
|
|
49
|
+
author: 'xcode',
|
|
50
|
+
version: 1,
|
|
51
|
+
},
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=assetCatalogIOS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetCatalogIOS.js","sourceRoot":"","sources":["../../../../src/lib/bundle/assetCatalogIOS.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAEjD,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,MAAM,KAAK,GAAG,EAAE;SACb,WAAW,CAAC,UAAU,CAAC;SACvB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC;AAOD,MAAM,UAAU,WAAW,CACzB,UAAkB,EAClB,KAAgB,EAChB,MAA6B;IAE7B,MAAM,QAAQ,GAAG,cAAc,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC7D,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,QAAQ,WAAW,CAAC;QACvD,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;YAC/B,MAAM,MAAM,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC;YAC/C,OAAO;gBACL,IAAI,EAAE,GAAG,QA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) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export type PackagerAsset = Readonly<{
|
|
9
|
+
httpServerLocation: string;
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
* FIXME: using number to represent discrete scale numbers is fragile in essence because of
|
|
15
|
+
* floating point numbers imprecision.
|
|
16
|
+
*/
|
|
17
|
+
declare function getAndroidAssetSuffix(scale: number): string;
|
|
18
|
+
declare function getAndroidResourceFolderName(asset: PackagerAsset, scale: number): string;
|
|
19
|
+
declare function getResourceIdentifier(asset: PackagerAsset): string;
|
|
20
|
+
declare function getBasePath(asset: PackagerAsset): string;
|
|
21
|
+
declare const _default: {
|
|
22
|
+
drawableFileTypes: Set<string>;
|
|
23
|
+
getAndroidAssetSuffix: typeof getAndroidAssetSuffix;
|
|
24
|
+
getAndroidResourceFolderName: typeof getAndroidResourceFolderName;
|
|
25
|
+
getResourceIdentifier: typeof getResourceIdentifier;
|
|
26
|
+
getBasePath: typeof getBasePath;
|
|
27
|
+
};
|
|
28
|
+
export default _default;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* FIXME: using number to represent discrete scale numbers is fragile in essence because of
|
|
10
|
+
* floating point numbers imprecision.
|
|
11
|
+
*/
|
|
12
|
+
function getAndroidAssetSuffix(scale) {
|
|
13
|
+
switch (scale) {
|
|
14
|
+
case 0.75:
|
|
15
|
+
return 'ldpi';
|
|
16
|
+
case 1:
|
|
17
|
+
return 'mdpi';
|
|
18
|
+
case 1.5:
|
|
19
|
+
return 'hdpi';
|
|
20
|
+
case 2:
|
|
21
|
+
return 'xhdpi';
|
|
22
|
+
case 3:
|
|
23
|
+
return 'xxhdpi';
|
|
24
|
+
case 4:
|
|
25
|
+
return 'xxxhdpi';
|
|
26
|
+
default:
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// See https://developer.android.com/guide/topics/resources/drawable-resource.html
|
|
31
|
+
const drawableFileTypes = new Set([
|
|
32
|
+
'gif',
|
|
33
|
+
'jpeg',
|
|
34
|
+
'jpg',
|
|
35
|
+
'png',
|
|
36
|
+
'webp',
|
|
37
|
+
'xml',
|
|
38
|
+
]);
|
|
39
|
+
function getAndroidResourceFolderName(asset, scale) {
|
|
40
|
+
if (!drawableFileTypes.has(asset.type)) {
|
|
41
|
+
return 'raw';
|
|
42
|
+
}
|
|
43
|
+
const suffix = getAndroidAssetSuffix(scale);
|
|
44
|
+
if (!suffix) {
|
|
45
|
+
throw new Error(`Don't know which android drawable suffix to use for asset: ${JSON.stringify(asset)}`);
|
|
46
|
+
}
|
|
47
|
+
const androidFolder = `drawable-${suffix}`;
|
|
48
|
+
return androidFolder;
|
|
49
|
+
}
|
|
50
|
+
function getResourceIdentifier(asset) {
|
|
51
|
+
const folderPath = getBasePath(asset);
|
|
52
|
+
return `${folderPath}/${asset.name}`
|
|
53
|
+
.toLowerCase()
|
|
54
|
+
.replace(/\//g, '_') // Encode folder structure in file name
|
|
55
|
+
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
|
|
56
|
+
.replace(/^assets_/, ''); // Remove "assets_" prefix
|
|
57
|
+
}
|
|
58
|
+
function getBasePath(asset) {
|
|
59
|
+
let basePath = asset.httpServerLocation;
|
|
60
|
+
if (basePath[0] === '/') {
|
|
61
|
+
basePath = basePath.substr(1);
|
|
62
|
+
}
|
|
63
|
+
return basePath;
|
|
64
|
+
}
|
|
65
|
+
export default {
|
|
66
|
+
drawableFileTypes,
|
|
67
|
+
getAndroidAssetSuffix,
|
|
68
|
+
getAndroidResourceFolderName,
|
|
69
|
+
getResourceIdentifier,
|
|
70
|
+
getBasePath,
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=assetPathUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assetPathUtils.js","sourceRoot":"","sources":["../../../../src/lib/bundle/assetPathUtils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH;;;GAGG;AACH,SAAS,qBAAqB,CAAC,KAAa;IAC1C,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,IAAI;YACP,OAAO,MAAM,CAAC;QAChB,KAAK,CAAC;YACJ,OAAO,MAAM,CAAC;QAChB,KAAK,GAAG;YACN,OAAO,MAAM,CAAC;QAChB,KAAK,CAAC;YACJ,OAAO,OAAO,CAAC;QACjB,KAAK,CAAC;YACJ,OAAO,QAAQ,CAAC;QAClB,KAAK,CAAC;YACJ,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,MAAM,iBAAiB,GAAgB,IAAI,GAAG,CAAS;IACrD,KAAK;IACL,MAAM;IACN,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;CACN,CAAC,CAAC;AAEH,SAAS,4BAA4B,CACnC,KAAoB,EACpB,KAAa;IAEb,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,MAAM,GAAG,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAC5C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,8DAA8D,IAAI,CAAC,SAAS,CAC1E,KAAK,CACN,EAAE,CACJ,CAAC;IACJ,CAAC;IACD,MAAM,aAAa,GAAG,YAAY,MAAM,EAAE,CAAC;IAC3C,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAoB;IACjD,MAAM,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACtC,OAAO,GAAG,UAAU,IAAI,KAAK,CAAC,IAAI,EAAE;SACjC,WAAW,EAAE;SACb,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,uCAAuC;SAC3D,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC,uBAAuB;SACpD,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,0BAA0B;AACxD,CAAC;AAED,SAAS,WAAW,CAAC,KAAoB;IACvC,IAAI,QAAQ,GAAG,KAAK,CAAC,kBAAkB,CAAC;IACxC,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACxB,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,eAAe;IACb,iBAAiB;IACjB,qBAAqB;IACrB,4BAA4B;IAC5B,qBAAqB;IACrB,WAAW;CACZ,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { RunBuildOptions } from 'metro';
|
|
9
|
+
import type { ConfigT } from 'metro-config';
|
|
10
|
+
export type BundleCommandArgs = {
|
|
11
|
+
assetsDest?: string;
|
|
12
|
+
assetCatalogDest?: string;
|
|
13
|
+
entryFile: string;
|
|
14
|
+
resetCache: boolean;
|
|
15
|
+
resetGlobalCache: boolean;
|
|
16
|
+
transformer?: string;
|
|
17
|
+
minify?: boolean;
|
|
18
|
+
config?: string;
|
|
19
|
+
platform: string;
|
|
20
|
+
dev: boolean;
|
|
21
|
+
bundleOutput: string;
|
|
22
|
+
bundleEncoding?: 'utf8' | 'utf16le' | 'ascii';
|
|
23
|
+
maxWorkers?: string;
|
|
24
|
+
sourcemapOutput?: string;
|
|
25
|
+
sourcemapSourcesRoot?: string;
|
|
26
|
+
sourcemapUseAbsolutePath: boolean;
|
|
27
|
+
verbose: boolean;
|
|
28
|
+
unstableTransformProfile: 'hermes-stable' | 'hermes-canary' | 'default';
|
|
29
|
+
indexedRamBundle?: boolean;
|
|
30
|
+
resolverOption?: Array<string>;
|
|
31
|
+
hermes: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type Config = {
|
|
34
|
+
root: string;
|
|
35
|
+
reactNativeVersion: string;
|
|
36
|
+
reactNativePath: string;
|
|
37
|
+
platforms: Record<string, object>;
|
|
38
|
+
};
|
|
39
|
+
declare function buildBundle(options: {
|
|
40
|
+
platforms: Record<string, object>;
|
|
41
|
+
reactNativeVersion: string;
|
|
42
|
+
reactNativePath: string;
|
|
43
|
+
root: string;
|
|
44
|
+
}, args: BundleCommandArgs, bundleImpl?: RunBuildOptions['output']): Promise<void>;
|
|
45
|
+
declare function buildBundleWithConfig(args: BundleCommandArgs, config: ConfigT, bundleImpl?: RunBuildOptions['output']): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* UNSTABLE: This function is likely to be relocated and its API changed in
|
|
48
|
+
* the near future. `@react-native/community-cli-plugin` should not be directly
|
|
49
|
+
* depended on by projects or integrators -- this is exported for legacy
|
|
50
|
+
* compatibility.
|
|
51
|
+
*
|
|
52
|
+
* Create a bundle using a pre-loaded Metro config. The config can be
|
|
53
|
+
* re-used for several bundling calls if multiple platforms are being
|
|
54
|
+
* bundled.
|
|
55
|
+
*/
|
|
56
|
+
export declare const unstable_buildBundleWithConfig: typeof buildBundleWithConfig;
|
|
57
|
+
export default buildBundle;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { promises as fs } from 'fs';
|
|
9
|
+
import { runBuild } from 'metro';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import loadMetroConfig from '../../utils/loadMetroConfig.js';
|
|
12
|
+
import parseKeyValueParamArray from '../../utils/parseKeyValueParamArray.js';
|
|
13
|
+
import saveAssets from './saveAssets.js';
|
|
14
|
+
// import { styleText } from 'util'; // Not available in all Node versions
|
|
15
|
+
function styleText(style, text) {
|
|
16
|
+
const styles = {
|
|
17
|
+
red: '\x1b[31m',
|
|
18
|
+
bold: '\x1b[1m',
|
|
19
|
+
reset: '\x1b[0m',
|
|
20
|
+
};
|
|
21
|
+
const colorCode = styles[style] || '';
|
|
22
|
+
return `${colorCode}${text}${styles.reset}`;
|
|
23
|
+
}
|
|
24
|
+
async function buildBundle(options, args, bundleImpl) {
|
|
25
|
+
const config = await loadMetroConfig({
|
|
26
|
+
platforms: options.platforms,
|
|
27
|
+
reactNativeVersion: options.reactNativeVersion,
|
|
28
|
+
reactNativePath: options.reactNativePath,
|
|
29
|
+
root: options.root,
|
|
30
|
+
}, {
|
|
31
|
+
maxWorkers: args.maxWorkers,
|
|
32
|
+
resetCache: args.resetCache,
|
|
33
|
+
config: args.config,
|
|
34
|
+
});
|
|
35
|
+
return buildBundleWithConfig(args, config, bundleImpl);
|
|
36
|
+
}
|
|
37
|
+
async function buildBundleWithConfig(args, config, bundleImpl) {
|
|
38
|
+
const customResolverOptions = parseKeyValueParamArray(args.resolverOption ?? []);
|
|
39
|
+
if (config.resolver.platforms.indexOf(args.platform) === -1) {
|
|
40
|
+
console.error(`${styleText('red', 'error')}: Invalid platform ${args.platform ? `"${styleText('bold', args.platform)}" ` : ''}selected.`);
|
|
41
|
+
console.info(`Available platforms are: ${config.resolver.platforms
|
|
42
|
+
.map((x) => `"${styleText('bold', x)}"`)
|
|
43
|
+
.join(', ')}. If you are trying to bundle for an out-of-tree platform, it may not be installed.`);
|
|
44
|
+
throw new Error('Bundling failed');
|
|
45
|
+
}
|
|
46
|
+
// This is used by a bazillion of npm modules we don't control so we don't
|
|
47
|
+
// have other choice than defining it as an env variable here.
|
|
48
|
+
process.env['NODE_ENV'] = args.dev ? 'development' : 'production';
|
|
49
|
+
let sourceMapUrl = args.sourcemapOutput;
|
|
50
|
+
if (sourceMapUrl != null && !args.sourcemapUseAbsolutePath) {
|
|
51
|
+
sourceMapUrl = path.basename(sourceMapUrl);
|
|
52
|
+
}
|
|
53
|
+
const runBuildOptions = {
|
|
54
|
+
// @ts-expect-error - missing type, available in Flow types
|
|
55
|
+
bundleOut: args.bundleOutput,
|
|
56
|
+
customResolverOptions,
|
|
57
|
+
dev: args.dev,
|
|
58
|
+
entry: args.entryFile,
|
|
59
|
+
minify: args.minify !== undefined ? args.minify : !args.dev,
|
|
60
|
+
output: bundleImpl,
|
|
61
|
+
platform: args.platform,
|
|
62
|
+
sourceMap: args.sourcemapOutput != null,
|
|
63
|
+
sourceMapOut: args.sourcemapOutput,
|
|
64
|
+
sourceMapUrl,
|
|
65
|
+
unstable_transformProfile: args.unstableTransformProfile,
|
|
66
|
+
};
|
|
67
|
+
// Ensure destination directory exists before running the build
|
|
68
|
+
await fs.mkdir(path.dirname(args.bundleOutput), {
|
|
69
|
+
recursive: true,
|
|
70
|
+
mode: 0o755,
|
|
71
|
+
});
|
|
72
|
+
const result = await runBuild(config, runBuildOptions);
|
|
73
|
+
if (args.assetsDest == null) {
|
|
74
|
+
console.warn('Warning: Assets destination folder is not set, skipping...');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Save the assets of the bundle
|
|
78
|
+
// @ts-expect-error - runBuild returns result with assets
|
|
79
|
+
if (!result || !result.assets) {
|
|
80
|
+
throw new Error("Assets missing from Metro's runBuild result");
|
|
81
|
+
}
|
|
82
|
+
// @ts-expect-error - runBuild returns result with assets
|
|
83
|
+
const outputAssets = result.assets;
|
|
84
|
+
// When we're done saving bundle output and the assets, we're done.
|
|
85
|
+
await saveAssets(outputAssets, args.platform, args.assetsDest, args.assetCatalogDest);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* UNSTABLE: This function is likely to be relocated and its API changed in
|
|
89
|
+
* the near future. `@react-native/community-cli-plugin` should not be directly
|
|
90
|
+
* depended on by projects or integrators -- this is exported for legacy
|
|
91
|
+
* compatibility.
|
|
92
|
+
*
|
|
93
|
+
* Create a bundle using a pre-loaded Metro config. The config can be
|
|
94
|
+
* re-used for several bundling calls if multiple platforms are being
|
|
95
|
+
* bundled.
|
|
96
|
+
*/
|
|
97
|
+
export const unstable_buildBundleWithConfig = buildBundleWithConfig;
|
|
98
|
+
export default buildBundle;
|
|
99
|
+
//# sourceMappingURL=buildBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildBundle.js","sourceRoot":"","sources":["../../../../src/lib/bundle/buildBundle.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AAEpC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,eAAe,MAAM,gCAAgC,CAAC;AAC7D,OAAO,uBAAuB,MAAM,wCAAwC,CAAC;AAC7E,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,0EAA0E;AAC1E,SAAS,SAAS,CAAC,KAAa,EAAE,IAAY;IAC5C,MAAM,MAAM,GAAG;QACb,GAAG,EAAE,UAAU;QACf,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;KACjB,CAAC;IACF,MAAM,SAAS,GAAG,MAAM,CAAC,KAA4B,CAAC,IAAI,EAAE,CAAC;IAC7D,OAAO,GAAG,SAAS,GAAG,IAAI,GAAG,MA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C,4DAA4D,CAAC,CAAC;QAC3E,OAAO;IACT,CAAC;IAED,gCAAgC;IAChC,yDAAyD;IACzD,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IACD,yDAAyD;IACzD,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IAEnC,mEAAmE;IACnE,MAAM,UAAU,CACd,YAAY,EACZ,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,gBAAgB,CACtB,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,qBAAqB,CAAC;AAEpE,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/lib/bundle/command.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAoC9C,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,SAAS,QA0DnD"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { colorLink, intro, logger, outro, RockError, runHermes, spinner, } from '@rock-js/tools';
|
|
4
|
+
import { getReactNativeCommunityCliPlugin } from '../getReactNativeDeps.js';
|
|
5
|
+
export function registerBundleCommand(api) {
|
|
6
|
+
api.registerCommand({
|
|
7
|
+
name: 'bundle',
|
|
8
|
+
description: 'Build the bundle for the provided JavaScript entry file with Metro.',
|
|
9
|
+
action: async (args) => {
|
|
10
|
+
if (!args.platform || !args.bundleOutput || !args.entryFile) {
|
|
11
|
+
throw new RockError('"rock bundle" command requires all of these flags to bundle JavaScript with Metro: \n "--platform", "--bundle-output", "--entry-file"');
|
|
12
|
+
}
|
|
13
|
+
intro('Compiling JS bundle with Metro');
|
|
14
|
+
const root = api.getProjectRoot();
|
|
15
|
+
const reactNativeVersion = api.getReactNativeVersion();
|
|
16
|
+
const reactNativePath = api.getReactNativePath();
|
|
17
|
+
const platforms = api.getPlatforms();
|
|
18
|
+
// create the bundle output directory if it doesn't exist
|
|
19
|
+
const bundleOutputDir = path.dirname(args.bundleOutput);
|
|
20
|
+
fs.mkdirSync(bundleOutputDir, { recursive: true });
|
|
21
|
+
const { bundleCommand } = await getReactNativeCommunityCliPlugin(reactNativePath);
|
|
22
|
+
await bundleCommand.func(undefined, { root, reactNativeVersion, reactNativePath, platforms }, args);
|
|
23
|
+
if (args.hermes) {
|
|
24
|
+
const loader = spinner();
|
|
25
|
+
loader.start('Running Hermes compiler...');
|
|
26
|
+
await runHermes({
|
|
27
|
+
bundleOutputPath: args.bundleOutput,
|
|
28
|
+
sourcemapOutputPath: args.sourcemapOutput,
|
|
29
|
+
});
|
|
30
|
+
loader.stop(`Hermes bytecode bundle created at: ${colorLink(args.bundleOutput)}`);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
logger.info(`JavaScript bundle created at: ${colorLink(args.bundleOutput)}`);
|
|
34
|
+
}
|
|
35
|
+
outro('Success 🎉.');
|
|
36
|
+
},
|
|
37
|
+
options: [
|
|
38
|
+
{
|
|
39
|
+
name: '--entry-file <path>',
|
|
40
|
+
description: 'Path to the root JS file, either absolute or relative to JS root',
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: '--platform <string>',
|
|
44
|
+
description: 'Either "ios" or "android"',
|
|
45
|
+
default: 'ios',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: '--transformer <string>',
|
|
49
|
+
description: 'Specify a custom transformer to be used',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: '--dev [boolean]',
|
|
53
|
+
description: 'If false, warnings are disabled and the bundle is minified',
|
|
54
|
+
parse: (val) => val !== 'false',
|
|
55
|
+
default: true,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: '--minify [boolean]',
|
|
59
|
+
description: 'Allows overriding whether bundle is minified. This defaults to ' +
|
|
60
|
+
'false if dev is true, and true if dev is false. Disabling minification ' +
|
|
61
|
+
'can be useful for speeding up production builds for testing purposes.',
|
|
62
|
+
parse: (val) => val !== 'false',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: '--bundle-output <string>',
|
|
66
|
+
description: 'File name where to store the resulting bundle, ex. /tmp/groups.bundle',
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: '--bundle-encoding <string>',
|
|
70
|
+
description: 'Encoding the bundle should be written in (https://nodejs.org/api/buffer.html#buffer_buffer).',
|
|
71
|
+
default: 'utf8',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: '--max-workers <number>',
|
|
75
|
+
description: 'Specifies the maximum number of workers the worker-pool ' +
|
|
76
|
+
'will spawn for transforming files. This defaults to the number of the ' +
|
|
77
|
+
'cores available on your machine.',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: '--sourcemap-output <string>',
|
|
81
|
+
description: 'File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: '--sourcemap-sources-root <string>',
|
|
85
|
+
description: "Path to make sourcemap's sources entries relative to, ex. /root/dir",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: '--sourcemap-use-absolute-path',
|
|
89
|
+
description: 'Report SourceMapURL using its full path',
|
|
90
|
+
default: false,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: '--assets-dest <string>',
|
|
94
|
+
description: 'Directory name where to store assets referenced in the bundle',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: '--unstable-transform-profile <string>',
|
|
98
|
+
description: 'Experimental, transform JS for a specific JS engine. Currently supported: hermes, hermes-canary, default',
|
|
99
|
+
default: 'default',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: '--asset-catalog-dest [string]',
|
|
103
|
+
description: 'Path where to create an iOS Asset Catalog for images',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: '--reset-cache',
|
|
107
|
+
description: 'Removes cached files',
|
|
108
|
+
default: false,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: '--read-global-cache',
|
|
112
|
+
description: 'Try to fetch transformed JS code from the global cache, if configured.',
|
|
113
|
+
default: false,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: '--config <string>',
|
|
117
|
+
description: 'Path to the CLI configuration file',
|
|
118
|
+
parse: (val) => path.resolve(val),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: '--resolver-option <string...>',
|
|
122
|
+
description: 'Custom resolver options of the form key=value. URL-encoded. May be specified multiple times.',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: '--config-cmd [string]',
|
|
126
|
+
description: '[Internal] A hack for Xcode build script pointing to wrong bundle command that recognizes this flag. Do not use.',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: '--hermes',
|
|
130
|
+
description: 'Passes the output JS bundle to Hermes compiler and outputs a bytecode file.',
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../src/lib/bundle/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,SAAS,EACT,KAAK,EACL,MAAM,EACN,KAAK,EACL,SAAS,EACT,SAAS,EACT,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gCAAgC,EAAE,MAAM,0BAA0B,CAAC;AA2B5E,MAAM,UAAU,qBAAqB,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WAAW,EAAE,yCAAyC;gBACtD,OAAO,EAAE,KAAK;aACf;YACD;gBACE,IAAI,EAAE,wBAAwB;gBAC9B,WAAW,EACT,+DAA+D;aAClE;YACD;gBACE,IAAI,EAAE,uCAAuC;gBAC7C,WAAW,EACT,0GAA0G;gBAC5G,OAAO,EAAE,SAAS;aACnB;YACD;gBACE,IAAI,EAAE,+BAA+B;gBACrC,WAAW,EAAE,sDAAsD;aACpE;YACD;gBACE,IAAI,EAAE,eAAe;gBACrB,WAAW,EAAE,sBAAsB;gBACnC,OAAO,EAAE,KAAK;aACf;YACD;gBACE,IAAI,EAAE,qBAAqB;gBAC3B,WAAW,EACT,wEAAwE;gBAC1E,OAAO,EAAE,KAAK;aACf;YACD;gBACE,IAAI,EAAE,mBAAmB;gBACzB,WAAW,EAAE,oCAAoC;gBACjD,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;aAClC;YACD;gBACE,IAAI,EAAE,+BAA+B;gBACrC,WAAW,EACT,8FAA8F;aACjG;YACD;gBACE,IAAI,EAAE,uBAAuB;gBAC7B,WAAW,EACT,kHAAkH;aACrH;YACD;gBACE,IAAI,EAAE,UAAU;gBAChB,WAAW,EACT,6EAA6E;aAChF;SACF;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { AssetData } from 'metro';
|
|
9
|
+
declare function createKeepFileAsync(assets: ReadonlyArray<AssetData>, outputDirectory: string): Promise<void>;
|
|
10
|
+
export default createKeepFileAsync;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import assetPathUtils from './assetPathUtils.js';
|
|
11
|
+
async function createKeepFileAsync(assets, outputDirectory) {
|
|
12
|
+
if (!assets.length) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const assetsList = [];
|
|
16
|
+
for (const asset of assets) {
|
|
17
|
+
const prefix = assetPathUtils.drawableFileTypes.has(asset.type)
|
|
18
|
+
? 'drawable'
|
|
19
|
+
: 'raw';
|
|
20
|
+
assetsList.push(`@${prefix}/${assetPathUtils.getResourceIdentifier(asset)}`);
|
|
21
|
+
}
|
|
22
|
+
const keepPath = path.join(outputDirectory, 'raw/keep.xml');
|
|
23
|
+
const content = `<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="${assetsList.join(',')}" />\n`;
|
|
24
|
+
await fs.promises.mkdir(path.dirname(keepPath), { recursive: true });
|
|
25
|
+
await fs.promises.writeFile(keepPath, content);
|
|
26
|
+
}
|
|
27
|
+
export default createKeepFileAsync;
|
|
28
|
+
//# sourceMappingURL=createKeepFileAsync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createKeepFileAsync.js","sourceRoot":"","sources":["../../../../src/lib/bundle/createKeepFileAsync.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,cAAc,MAAM,qBAAqB,CAAC;AAEjD,KAAK,UAAU,mBAAmB,CAChC,MAAgC,EAChC,eAAuB;IAEvB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO;IACT,CAAC;IACD,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,cAAc,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;YAC7D,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,KAAK,CAAC;QACV,UAAU,CAAC,IAAI,CACb,IAAI,MAAM,IAAI,cAAc,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,CAC5D,CAAC;IACJ,CAAC;IACD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,yEAAyE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;IACtH,MAAM,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACjD,CAAC;AAED,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
declare function filterPlatformAssetScales(platform: string, scales: ReadonlyArray<number>): ReadonlyArray<number>;
|
|
9
|
+
export default filterPlatformAssetScales;
|