forked from xerdnu/react-native-blasted-image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blastedAssets.js
66 lines (55 loc) · 2.26 KB
/
blastedAssets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const { withDangerousMod, withXcodeProject } = require('@expo/config-plugins');
const fs = require('fs-extra');
const path = require('path');
function copyAssets(srcDir, destDir, platform) {
try {
if (fs.existsSync(srcDir)) {
console.log(`[BlastedImage][${platform}] Copying assets from ${srcDir} to ${destDir}`);
fs.ensureDirSync(destDir);
fs.copySync(srcDir, destDir);
console.log(`[BlastedImage][${platform}] Assets copied successfully!`);
} else {
console.log(`[BlastedImage][${platform}] The source directory ${srcDir} does not exist. As a result, no assets will be bundled with BlastedImage. (Check documentation for more information)`);
}
} catch (err) {
console.error(`[BlastedImage][${platform}] Error copying assets:`, err);
}
}
const blastedAssets = (config) => {
config = withDangerousMod(config, [
'android',
(config) => {
const androidDir = path.join(
config.modRequest.platformProjectRoot,
'app',
'src',
'main',
'assets',
'blasted-image'
);
const absoluteSrcPath = path.resolve('assets', 'blasted-image');
copyAssets(absoluteSrcPath, androidDir, 'Android');
return config;
},
]);
config = withXcodeProject(config, async (config) => {
const { projectRoot } = config.modRequest;
const iosDir = path.join(projectRoot, 'ios');
const resourcesDir = path.join(iosDir, 'Resources');
const blastedImageDir = path.join(resourcesDir, 'blasted-image');
const absoluteSrcPath = path.resolve('assets', 'blasted-image');
fs.ensureDirSync(resourcesDir);
copyAssets(absoluteSrcPath, path.join(resourcesDir, 'blasted-image'), 'iOS');
const project = config.modResults;
const mainGroup = project.getFirstProject().firstProject.mainGroup;
let resourcesGroup = project.pbxGroupByName('Resources');
if (!resourcesGroup) {
resourcesGroup = project.addPbxGroup([], 'Resources', 'Resources');
project.addToPbxGroup(resourcesGroup.uuid, mainGroup);
}
project.addResourceFile(blastedImageDir, { target: project.getFirstTarget().uuid }, resourcesGroup.uuid);
return config;
});
return config;
};
module.exports = blastedAssets;