react-native-asset 2.0.1 → 2.1.1

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 CHANGED
@@ -18,13 +18,27 @@
18
18
  yarn global add react-native-asset
19
19
  ```
20
20
  * Add assets to your `react-native.config.js` as you would with `react-native link`
21
- ```json
21
+ ```js
22
22
  ...
23
- "assets": [
23
+ assets: [
24
24
  "./src/font",
25
- "./src/mp3"
26
- ]
25
+ "./src/mp3",
26
+ ];
27
27
  ```
28
+ * Add platform-specific assets to your `react-native.config.js` like so:
29
+ ```js
30
+ ...
31
+ assets: [
32
+ "./src/mp3",
33
+ ],
34
+ iosAssets: [
35
+ "./src/font/ios",
36
+ ],
37
+ androidAssets: [
38
+ "./src/font/android",
39
+ ],
40
+ ```
41
+
28
42
  * Run the command and linking + unlinking is automatic!
29
43
  ```bash
30
44
  react-native-asset
package/lib/cli.js CHANGED
@@ -43,8 +43,15 @@ const {
43
43
  // Using dynamic require for config file, is written in js
44
44
  // eslint-disable-next-line import/no-dynamic-require
45
45
  const reactNativeConfig = require(path.resolve(rootPath, 'react-native.config.js'));
46
- const reactNativeConfigAssets = reactNativeConfig.assets || [];
47
- const mutualAssets = reactNativeConfigAssets.concat(assets !== undefined ? assets : []);
46
+ const mutualAssets = (reactNativeConfig.assets || []).concat(assets || []);
47
+ const mergediOSAssets = mutualAssets.concat(
48
+ reactNativeConfig.iosAssets || [],
49
+ iosAssets || [],
50
+ );
51
+ const mergedAndroidAssets = mutualAssets.concat(
52
+ reactNativeConfig.androidAssets || [],
53
+ androidAssets || [],
54
+ );
48
55
 
49
56
  linkAssets({
50
57
  rootPath,
@@ -52,11 +59,11 @@ linkAssets({
52
59
  platforms: {
53
60
  ios: {
54
61
  enabled: !(androidAssets && !iosAssets), // when given android but not ios, ok if both not
55
- assets: iosAssets || mutualAssets,
62
+ assets: mergediOSAssets,
56
63
  },
57
64
  android: {
58
65
  enabled: !(iosAssets && !androidAssets), // when given ios but not android, ok if both not
59
- assets: androidAssets || mutualAssets,
66
+ assets: mergedAndroidAssets,
60
67
  },
61
68
  },
62
69
  });
package/lib/index.js CHANGED
@@ -7,12 +7,15 @@ const cleanAssetsAndroid = require('./clean-assets/android');
7
7
  const getManifest = require('./manifest/index');
8
8
  const log = require('npmlog');
9
9
  const sha1File = require('sha1-file');
10
+ const _ = require('lodash');
10
11
  const getConfig = require('./get-config');
11
12
 
12
13
  const cwd = process.cwd();
13
14
 
14
15
  const unl = (val, otherwise) => ((val !== undefined) ? val : otherwise);
15
16
 
17
+ const clearDuplicated = files => _.uniqBy(files, f => path.parse(f.path).base);
18
+
16
19
  const filesToIgnore = [
17
20
  '.DS_Store',
18
21
  'Thumbs.db',
@@ -87,8 +90,11 @@ const linkPlatform = ({
87
90
  });
88
91
  }
89
92
  };
93
+
90
94
  assetsPaths.forEach(loadAsset);
91
95
 
96
+ assets = clearDuplicated(assets);
97
+
92
98
  const fileFilters = []
93
99
  .concat(Object.keys(linkOptionsPerExt).map(fileExt => ({
94
100
  name: fileExt,
@@ -205,8 +211,25 @@ module.exports = ({
205
211
  {},
206
212
  );
207
213
 
214
+ const imageOptions = {
215
+ android: {
216
+ path: path.resolve(androidPath, 'app', 'src', 'main', 'res', 'drawable'),
217
+ },
218
+ ios: {
219
+ addFont: false,
220
+ },
221
+ };
222
+
223
+ const imageTypes = ['png', 'jpg', 'gif'];
224
+
225
+ const imageLinkOptions = imageTypes.reduce(
226
+ (result, imageFiles) => ({ ...result, [imageFiles]: imageOptions }),
227
+ {},
228
+ );
229
+
208
230
  const linkOptionsPerExt = {
209
231
  ...fontsLinkOptions,
232
+ ...imageLinkOptions,
210
233
  mp3: {
211
234
  android: {
212
235
  path: path.resolve(androidPath, 'app', 'src', 'main', 'res', 'raw'),
@@ -253,6 +276,9 @@ module.exports = ({
253
276
  linkOptionsPerExt: {
254
277
  otf: linkOptionsPerExt.otf.android,
255
278
  ttf: linkOptionsPerExt.ttf.android,
279
+ png: linkOptionsPerExt.png.android,
280
+ jpg: linkOptionsPerExt.jpg.android,
281
+ gif: linkOptionsPerExt.gif.android,
256
282
  mp3: linkOptionsPerExt.mp3.android,
257
283
  },
258
284
  otherLinkOptions: otherLinkOptions.android,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-asset",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "Linking and unlinking of assets in your react-native app, works for fonts and sounds",
5
5
  "main": "lib/index.js",
6
6
  "bin": "lib/cli.js",
@@ -32,11 +32,12 @@
32
32
  },
33
33
  "homepage": "https://github.com/unimonkiez/react-native-asset#readme",
34
34
  "peerDependencies": {
35
- "react-native": "^0.60.0"
35
+ "react-native": ">=0.60.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "fs-extra": "^7.0.1",
39
39
  "npmlog": "^4.1.2",
40
+ "lodash": "4.17.21",
40
41
  "plist": "^3.0.1",
41
42
  "sha1-file": "^1.0.4",
42
43
  "xcode": "^2.0.0"