-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathwithAndroidDrawables.js
49 lines (41 loc) · 1.45 KB
/
withAndroidDrawables.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
const { withDangerousMod } = require('@expo/config-plugins');
const fs = require('fs');
const path = require('path');
/**
* This config plugin copies files from the specified paths, like the assets
* directory, to the Android drawable directory.
*/
function withAndroidDrawables(config, { drawableFiles }) {
return withDangerousMod(config, [
'android',
(config) => {
// Validate drawableFiles
if (!Array.isArray(drawableFiles)) {
throw new Error('drawableFiles must be an array of file paths');
}
// Define the target drawable directory
const drawableDir = path.join(
config.modRequest.projectRoot,
'android/app/src/main/res/drawable',
);
// Create the drawable directory if it doesn't exist
if (!fs.existsSync(drawableDir)) {
fs.mkdirSync(drawableDir, { recursive: true });
}
// Copy each drawable file to the drawable directory
drawableFiles.forEach((filePath) => {
const sourcePath = path.resolve(config.modRequest.projectRoot, filePath);
const fileName = path.basename(filePath);
const destPath = path.join(drawableDir, fileName);
if (!fs.existsSync(sourcePath)) {
console.warn(`Warning: Drawable file not found: ${sourcePath}`);
return;
}
// Copy the file
fs.copyFileSync(sourcePath, destPath);
});
return config;
},
]);
}
module.exports = withAndroidDrawables;