react-native-asset 2.0.0 → 2.1.0
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 +19 -5
- package/lib/cli.js +13 -5
- package/lib/index.js +27 -0
- package/lib/react-native-lib/ios/getPlistPath.js +2 -2
- package/package.json +3 -2
- package/.history/README_20190618130513.md +0 -43
- package/.history/README_20190719184449.md +0 -41
- package/.history/README_20190719184543.md +0 -44
- package/.history/package_20190618130521.json +0 -47
- package/.history/package_20190719184302.json +0 -50
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
|
-
```
|
|
21
|
+
```js
|
|
22
22
|
...
|
|
23
|
-
|
|
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
|
|
@@ -41,4 +55,4 @@ Instead this library writes `link-assets-manifest.json` to the root of `android`
|
|
|
41
55
|
* `-n-u, --no-unlink` - Not to unlink assets which not longer exists, not recommanded.
|
|
42
56
|
|
|
43
57
|
## Backward compatability
|
|
44
|
-
* to use react-native 0.59 and below, use version 1.
|
|
58
|
+
* to use react-native 0.59 and below, use version 1.1.4
|
package/lib/cli.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const fs = require('fs-extra');
|
|
3
2
|
const path = require('path');
|
|
4
3
|
const linkAssets = require('./index');
|
|
5
4
|
const getCliArgs = require('./cli-args');
|
|
@@ -41,9 +40,18 @@ const {
|
|
|
41
40
|
androidAssets,
|
|
42
41
|
} = cliArgs;
|
|
43
42
|
|
|
43
|
+
// Using dynamic require for config file, is written in js
|
|
44
|
+
// eslint-disable-next-line import/no-dynamic-require
|
|
44
45
|
const reactNativeConfig = require(path.resolve(rootPath, 'react-native.config.js'));
|
|
45
|
-
const
|
|
46
|
-
const
|
|
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
|
+
);
|
|
47
55
|
|
|
48
56
|
linkAssets({
|
|
49
57
|
rootPath,
|
|
@@ -51,11 +59,11 @@ linkAssets({
|
|
|
51
59
|
platforms: {
|
|
52
60
|
ios: {
|
|
53
61
|
enabled: !(androidAssets && !iosAssets), // when given android but not ios, ok if both not
|
|
54
|
-
assets:
|
|
62
|
+
assets: mergediOSAssets,
|
|
55
63
|
},
|
|
56
64
|
android: {
|
|
57
65
|
enabled: !(iosAssets && !androidAssets), // when given ios but not android, ok if both not
|
|
58
|
-
assets:
|
|
66
|
+
assets: mergedAndroidAssets,
|
|
59
67
|
},
|
|
60
68
|
},
|
|
61
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,
|
|
@@ -137,6 +143,7 @@ const linkPlatform = ({
|
|
|
137
143
|
});
|
|
138
144
|
|
|
139
145
|
manifest.write(assets
|
|
146
|
+
.filter(filterFilesToIgnore)
|
|
140
147
|
.map(asset => Object.assign(
|
|
141
148
|
{},
|
|
142
149
|
asset,
|
|
@@ -204,8 +211,25 @@ module.exports = ({
|
|
|
204
211
|
{},
|
|
205
212
|
);
|
|
206
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
|
+
|
|
207
230
|
const linkOptionsPerExt = {
|
|
208
231
|
...fontsLinkOptions,
|
|
232
|
+
...imageLinkOptions,
|
|
209
233
|
mp3: {
|
|
210
234
|
android: {
|
|
211
235
|
path: path.resolve(androidPath, 'app', 'src', 'main', 'res', 'raw'),
|
|
@@ -252,6 +276,9 @@ module.exports = ({
|
|
|
252
276
|
linkOptionsPerExt: {
|
|
253
277
|
otf: linkOptionsPerExt.otf.android,
|
|
254
278
|
ttf: linkOptionsPerExt.ttf.android,
|
|
279
|
+
png: linkOptionsPerExt.png.android,
|
|
280
|
+
jpg: linkOptionsPerExt.jpg.android,
|
|
281
|
+
gif: linkOptionsPerExt.gif.android,
|
|
255
282
|
mp3: linkOptionsPerExt.mp3.android,
|
|
256
283
|
},
|
|
257
284
|
otherLinkOptions: otherLinkOptions.android,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-asset",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
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": "
|
|
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"
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# react-native-asset
|
|
2
|
-
[](https://badge.fury.io/js/react-native-asset)[](https://travis-ci.org/unimonkiez/react-native-asset)
|
|
3
|
-
|
|
4
|
-
## Link and unlink assets to your react-native project with ease!
|
|
5
|
-
|
|
6
|
-
## Advantages
|
|
7
|
-
* `react-native link` only supports font files, this tool supports all assets.
|
|
8
|
-
* Unlinking is automatic when you delete an asset, with `react-native link`, you need to unlink the files manually.
|
|
9
|
-
* Proper link (and unlink) for `mp3` (to use with [`react-native-sound`](https://github.com/zmxv/react-native-sound#basic-usage)) and `ttf` files.
|
|
10
|
-
|
|
11
|
-
### [Check out this starter-kit to use your assets with even more simplicity.](https://github.com/unimonkiez/react-platformula-boilerplate)
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
* Install
|
|
15
|
-
```bash
|
|
16
|
-
npm install -g react-native-asset
|
|
17
|
-
# or yarn
|
|
18
|
-
yarn global add react-native-asset
|
|
19
|
-
```
|
|
20
|
-
* Add assets to you package json as you would with `react-native link`
|
|
21
|
-
```json
|
|
22
|
-
...
|
|
23
|
-
"rnpm": {
|
|
24
|
-
"assets": [
|
|
25
|
-
"./src/font",
|
|
26
|
-
"./src/mp3"
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
* Run the command and linking + unlinking is automatic!
|
|
31
|
-
```bash
|
|
32
|
-
react-native-asset
|
|
33
|
-
```
|
|
34
|
-
## Explanation
|
|
35
|
-
With `react-native link` you have to unlink the files manually, which is hard work.
|
|
36
|
-
Instead this library writes `link-assets-manifest.json` to the root of `android` and `ios` folders to keep track of the files which it added, for later removing it for you if missing from your `assets`!
|
|
37
|
-
|
|
38
|
-
## Parameters
|
|
39
|
-
* `-p, --path` - path to project, defaults to cwd.
|
|
40
|
-
* `-a, --assets` - assets paths, for example `react-native-asset -a ./src/font ./src/mp3`.
|
|
41
|
-
* `-ios-a, --ios-assets` - ios assets paths, will disable android linking
|
|
42
|
-
* `-android-a, --android-assets` - android assets paths, will disable ios linking.
|
|
43
|
-
* `-n-u, --no-unlink` - Not to unlink assets which not longer exists, not recommanded.
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# react-native-asset
|
|
2
|
-
[](https://badge.fury.io/js/react-native-asset)[](https://travis-ci.org/unimonkiez/react-native-asset)
|
|
3
|
-
|
|
4
|
-
## Link and unlink assets to your react-native project with ease!
|
|
5
|
-
|
|
6
|
-
## Advantages
|
|
7
|
-
* `react-native link` only supports font files, this tool supports all assets.
|
|
8
|
-
* Unlinking is automatic when you delete an asset, with `react-native link`, you need to unlink the files manually.
|
|
9
|
-
* Proper link (and unlink) for `mp3` (to use with [`react-native-sound`](https://github.com/zmxv/react-native-sound#basic-usage)) and `ttf` files.
|
|
10
|
-
|
|
11
|
-
### [Check out this starter-kit to use your assets with even more simplicity.](https://github.com/unimonkiez/react-platformula-boilerplate)
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
* Install
|
|
15
|
-
```bash
|
|
16
|
-
npm install -g react-native-asset
|
|
17
|
-
# or yarn
|
|
18
|
-
yarn global add react-native-asset
|
|
19
|
-
```
|
|
20
|
-
* Add assets to your `react-native.config.js` as you would with `react-native link`
|
|
21
|
-
```json
|
|
22
|
-
...
|
|
23
|
-
"assets": [
|
|
24
|
-
"./src/font",
|
|
25
|
-
"./src/mp3"
|
|
26
|
-
]
|
|
27
|
-
```
|
|
28
|
-
* Run the command and linking + unlinking is automatic!
|
|
29
|
-
```bash
|
|
30
|
-
react-native-asset
|
|
31
|
-
```
|
|
32
|
-
## Explanation
|
|
33
|
-
With `react-native link` you have to unlink the files manually, which is hard work.
|
|
34
|
-
Instead this library writes `link-assets-manifest.json` to the root of `android` and `ios` folders to keep track of the files which it added, for later removing it for you if missing from your `assets`!
|
|
35
|
-
|
|
36
|
-
## Parameters
|
|
37
|
-
* `-p, --path` - path to project, defaults to cwd.
|
|
38
|
-
* `-a, --assets` - assets paths, for example `react-native-asset -a ./src/font ./src/mp3`.
|
|
39
|
-
* `-ios-a, --ios-assets` - ios assets paths, will disable android linking
|
|
40
|
-
* `-android-a, --android-assets` - android assets paths, will disable ios linking.
|
|
41
|
-
* `-n-u, --no-unlink` - Not to unlink assets which not longer exists, not recommanded.
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# react-native-asset
|
|
2
|
-
[](https://badge.fury.io/js/react-native-asset)[](https://travis-ci.org/unimonkiez/react-native-asset)
|
|
3
|
-
|
|
4
|
-
## Link and unlink assets to your react-native project with ease!
|
|
5
|
-
|
|
6
|
-
## Advantages
|
|
7
|
-
* `react-native link` only supports font files, this tool supports all assets.
|
|
8
|
-
* Unlinking is automatic when you delete an asset, with `react-native link`, you need to unlink the files manually.
|
|
9
|
-
* Proper link (and unlink) for `mp3` (to use with [`react-native-sound`](https://github.com/zmxv/react-native-sound#basic-usage)) and `ttf` files.
|
|
10
|
-
|
|
11
|
-
### [Check out this starter-kit to use your assets with even more simplicity.](https://github.com/unimonkiez/react-platformula-boilerplate)
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
* Install
|
|
15
|
-
```bash
|
|
16
|
-
npm install -g react-native-asset
|
|
17
|
-
# or yarn
|
|
18
|
-
yarn global add react-native-asset
|
|
19
|
-
```
|
|
20
|
-
* Add assets to your `react-native.config.js` as you would with `react-native link`
|
|
21
|
-
```json
|
|
22
|
-
...
|
|
23
|
-
"assets": [
|
|
24
|
-
"./src/font",
|
|
25
|
-
"./src/mp3"
|
|
26
|
-
]
|
|
27
|
-
```
|
|
28
|
-
* Run the command and linking + unlinking is automatic!
|
|
29
|
-
```bash
|
|
30
|
-
react-native-asset
|
|
31
|
-
```
|
|
32
|
-
## Explanation
|
|
33
|
-
With `react-native link` you have to unlink the files manually, which is hard work.
|
|
34
|
-
Instead this library writes `link-assets-manifest.json` to the root of `android` and `ios` folders to keep track of the files which it added, for later removing it for you if missing from your `assets`!
|
|
35
|
-
|
|
36
|
-
## Parameters
|
|
37
|
-
* `-p, --path` - path to project, defaults to cwd.
|
|
38
|
-
* `-a, --assets` - assets paths, for example `react-native-asset -a ./src/font ./src/mp3`.
|
|
39
|
-
* `-ios-a, --ios-assets` - ios assets paths, will disable android linking
|
|
40
|
-
* `-android-a, --android-assets` - android assets paths, will disable ios linking.
|
|
41
|
-
* `-n-u, --no-unlink` - Not to unlink assets which not longer exists, not recommanded.
|
|
42
|
-
|
|
43
|
-
## Backward compatability
|
|
44
|
-
* to use react-native 0.59 and below, use version 1.14.0
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-native-asset",
|
|
3
|
-
"version": "1.1.4",
|
|
4
|
-
"description": "Linking and unlinking of assets in your react-native app, works for fonts and sounds",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"bin": "lib/cli.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"lint": "eslint --ext .js,.jsx .",
|
|
9
|
-
"lint:error": "npm run lint -- --quiet",
|
|
10
|
-
"lint:fix": "npm run lint -- --fix",
|
|
11
|
-
"lint:report": "npm run lint -- --format html -o ./report.html",
|
|
12
|
-
"test": "jest",
|
|
13
|
-
"test:watch": "npm test -- --watch"
|
|
14
|
-
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/unimonkiez/react-native-asset.git"
|
|
18
|
-
},
|
|
19
|
-
"keywords": [
|
|
20
|
-
"react-native",
|
|
21
|
-
"react",
|
|
22
|
-
"native",
|
|
23
|
-
"js",
|
|
24
|
-
"asset",
|
|
25
|
-
"assets",
|
|
26
|
-
"link"
|
|
27
|
-
],
|
|
28
|
-
"author": "Yuval Saraf",
|
|
29
|
-
"license": "ISC",
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/unimonkiez/react-native-asset/issues"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/unimonkiez/react-native-asset#readme",
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"fs-extra": "^7.0.1",
|
|
36
|
-
"npmlog": "^4.1.2",
|
|
37
|
-
"plist": "^3.0.1",
|
|
38
|
-
"sha1-file": "^1.0.4",
|
|
39
|
-
"xcode": "^2.0.0"
|
|
40
|
-
},
|
|
41
|
-
"devDependencies": {
|
|
42
|
-
"eslint": "^4.16.0",
|
|
43
|
-
"eslint-config-airbnb-base": "^12.1.0",
|
|
44
|
-
"eslint-plugin-import": "^2.8.0",
|
|
45
|
-
"jest": "^22.1.4"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-native-asset",
|
|
3
|
-
"version": "1.1.4",
|
|
4
|
-
"description": "Linking and unlinking of assets in your react-native app, works for fonts and sounds",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"bin": "lib/cli.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"lint": "eslint --ext .js,.jsx .",
|
|
9
|
-
"lint:error": "npm run lint -- --quiet",
|
|
10
|
-
"lint:fix": "npm run lint -- --fix",
|
|
11
|
-
"lint:report": "npm run lint -- --format html -o ./report.html",
|
|
12
|
-
"test": "jest",
|
|
13
|
-
"test:watch": "npm test -- --watch"
|
|
14
|
-
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "git+https://github.com/unimonkiez/react-native-asset.git"
|
|
18
|
-
},
|
|
19
|
-
"keywords": [
|
|
20
|
-
"react-native",
|
|
21
|
-
"react",
|
|
22
|
-
"native",
|
|
23
|
-
"js",
|
|
24
|
-
"asset",
|
|
25
|
-
"assets",
|
|
26
|
-
"link"
|
|
27
|
-
],
|
|
28
|
-
"author": "Yuval Saraf",
|
|
29
|
-
"license": "ISC",
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/unimonkiez/react-native-asset/issues"
|
|
32
|
-
},
|
|
33
|
-
"homepage": "https://github.com/unimonkiez/react-native-asset#readme",
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"react-native": "^0.60.0"
|
|
36
|
-
},
|
|
37
|
-
"dependencies": {
|
|
38
|
-
"fs-extra": "^7.0.1",
|
|
39
|
-
"npmlog": "^4.1.2",
|
|
40
|
-
"plist": "^3.0.1",
|
|
41
|
-
"sha1-file": "^1.0.4",
|
|
42
|
-
"xcode": "^2.0.0"
|
|
43
|
-
},
|
|
44
|
-
"devDependencies": {
|
|
45
|
-
"eslint": "^4.16.0",
|
|
46
|
-
"eslint-config-airbnb-base": "^12.1.0",
|
|
47
|
-
"eslint-plugin-import": "^2.8.0",
|
|
48
|
-
"jest": "^22.1.4"
|
|
49
|
-
}
|
|
50
|
-
}
|