@applicaster/quick-brick-assets 0.0.0-stage → 16.0.0-rc.123
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 +89 -2
- package/assets/local-storage-favourites-action/action/flavour_1.png +0 -0
- package/assets/local-storage-favourites-action/action/flavour_1_active.png +0 -0
- package/assets/local-storage-favourites-action/action/flavour_1_default.png +0 -0
- package/assets/local-storage-favourites-action/action/flavour_2.png +0 -0
- package/assets/local-storage-favourites-action/action/flavour_2_active.png +0 -0
- package/assets/local-storage-favourites-action/action/flavour_2_default.png +0 -0
- package/assets/local-storage-favourites-action/button/flavour_1.png +0 -0
- package/assets/local-storage-favourites-action/button/flavour_1_active.png +0 -0
- package/assets/local-storage-favourites-action/button/flavour_1_default.png +0 -0
- package/assets/local-storage-favourites-action/button/flavour_2.png +0 -0
- package/assets/local-storage-favourites-action/button/flavour_2_active.png +0 -0
- package/assets/local-storage-favourites-action/button/flavour_2_default.png +0 -0
- package/assets/mute_unmute_action/action/flavour_1/mute.png +0 -0
- package/assets/mute_unmute_action/action/flavour_1/unmute.png +0 -0
- package/assets/mute_unmute_action/action/flavour_2/mute.png +0 -0
- package/assets/mute_unmute_action/action/flavour_2/unmute.png +0 -0
- package/assets/mute_unmute_action/button/flavour_1/mute.png +0 -0
- package/assets/mute_unmute_action/button/flavour_1/unmute.png +0 -0
- package/assets/mute_unmute_action/button/flavour_2/mute.png +0 -0
- package/assets/mute_unmute_action/button/flavour_2/unmute.png +0 -0
- package/index.ts +39 -0
- package/package.json +29 -3
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @applicaster/quick-brick-assets
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Static assets that Quick Brick ships with the app. Only `assets/` and the generated `index.ts` are published.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
assets/
|
|
7
|
+
{plugin_identifier}/
|
|
8
|
+
...
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
| Plugin identifier | Content |
|
|
12
|
+
| -------------------- | --------------------------------------------------------------- |
|
|
13
|
+
| `mute_unmute_action` | Default mute / unmute icons for cell actions and mobile buttons |
|
|
14
|
+
|
|
15
|
+
## Using an asset
|
|
16
|
+
|
|
17
|
+
Look the asset up by plugin identifier and path relative to the plugin folder:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { getQuickBrickAsset } from "@applicaster/zapp-react-native-utils/quickBrickAssets";
|
|
21
|
+
|
|
22
|
+
const source = getQuickBrickAsset("mute_unmute_action", "action/flavour_1/mute.png");
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
- It returns the same value as a static `require` would (a number on native, a URL on web).
|
|
26
|
+
- Both arguments are type-checked against the files in `assets/`: an unknown plugin identifier or path is a compile error.
|
|
27
|
+
- Density variants (`@2x` / `@3x`) aren't supported: webpack's `asset/resource` only follows literal paths, so `generate` fails on them. Use one file per asset.
|
|
28
|
+
- Platform variants (`.ios.png` / `.android.png`) aren't supported.
|
|
29
|
+
|
|
30
|
+
## How it works
|
|
31
|
+
|
|
32
|
+
Bundlers only include assets that are `require`d with a static string. `scripts/generate.ts` writes `index.ts`, the package `main`, which maps each `{plugin_identifier}/{path}` to a static `require` of that file under `assets/`:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const assets = {
|
|
36
|
+
"mute_unmute_action/action/flavour_1/mute.png": require("./assets/mute_unmute_action/action/flavour_1/mute.png"),
|
|
37
|
+
// one entry per file
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type QuickBrickAssetKey = keyof typeof assets;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- `index.ts` is committed and published. Metro and webpack compile it like any other `@applicaster/*` TS source, so there's no bundler config to add.
|
|
44
|
+
- `getQuickBrickAsset` imports the map, and its parameter types come from `QuickBrickAssetKey`. The types and the runtime map are the same object, so they can't disagree.
|
|
45
|
+
- `scripts/` and `__tests__/` are TypeScript sources for maintaining the package and aren't published.
|
|
46
|
+
- In Jest, `tests/quickBrickAssetsMock.js` replaces the map with one that keeps the real keys and uses each key as its value.
|
|
47
|
+
|
|
48
|
+
The native and web app entries also import `@applicaster/quick-brick-assets`, so `react-native bundle --assets-dest res` (native) and webpack (web) export every file even if nothing looks it up.
|
|
49
|
+
|
|
50
|
+
## Contributing: adding assets
|
|
51
|
+
|
|
52
|
+
1. **Put the files under `assets/{plugin_identifier}/`.**
|
|
53
|
+
- `{plugin_identifier}` is the identifier of the plugin or feature that owns the assets (e.g. `mute_unmute_action`). Never put customer-specific assets here.
|
|
54
|
+
- Group files in subfolders as you like. The path relative to the plugin folder is the lookup key, so treat it as a public API: renaming or moving a file is a breaking change for its callers.
|
|
55
|
+
- Use a file type from Metro's `assetExts` (e.g. `png`, `jpg`). If the asset is also used on web, stick to types that the web template's image rule handles (`png`, `svg`, `jpg`, `jpeg`, `gif`, `mp4`). Every file except dotfiles gets a `require`, so don't put anything else (READMEs, sources) under `assets/`. It would break the bundle.
|
|
56
|
+
|
|
57
|
+
2. **Regenerate the index:**
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
yarn workspace @applicaster/quick-brick-assets generate
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This rewrites `index.ts`, so the new file is bundled and its key is accepted by `getQuickBrickAsset`. It doesn't run on `yarn install`. A running `yarn start` picks up the change without a restart.
|
|
64
|
+
|
|
65
|
+
3. **Use it** through the helper, never with a `require` of a path into this package:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
getQuickBrickAsset("my_plugin", "icons/icon.png");
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
In Jest the helper returns the key itself (see `tests/quickBrickAssetsMock.js`), so tests can assert which asset was picked.
|
|
72
|
+
|
|
73
|
+
4. **Add the plugin identifier to the table** at the top of this README if it's a new folder.
|
|
74
|
+
|
|
75
|
+
5. **Check and commit:**
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
jest ./packages/quick-brick-assets --config=./tests/jest.unit.config.js
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This fails if `index.ts` is out of date with `assets/`. Commit the assets together with `index.ts`, and never edit `index.ts` by hand.
|
|
82
|
+
|
|
83
|
+
To confirm a file reaches `res/`, bundle a prepared app with `--assets-dest`. Then look for files named `*quickbrickassets_assets_{plugin_identifier}_*` in the `drawable-*` folders:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# from development-app/, after `yarn zapplicaster prepare -a <app_id>`
|
|
87
|
+
mkdir -p /tmp/qb/res && npx react-native bundle --platform android --dev false --entry-file development-app/index.js --bundle-output /tmp/qb/index.bundle --assets-dest /tmp/qb/res
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Removing or renaming an asset works the same way: run `generate` again, and the type checker shows every call site that still uses the old key.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Generated by scripts/generate.ts. Do not edit.
|
|
2
|
+
// Run `yarn workspace @applicaster/quick-brick-assets generate` after changing assets/.
|
|
3
|
+
// Static requires make the bundler include every asset (and export it with --assets-dest).
|
|
4
|
+
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
const assets = {
|
|
7
|
+
"local-storage-favourites-action/action/flavour_1.png": require("./assets/local-storage-favourites-action/action/flavour_1.png"),
|
|
8
|
+
"local-storage-favourites-action/action/flavour_1_active.png": require("./assets/local-storage-favourites-action/action/flavour_1_active.png"),
|
|
9
|
+
"local-storage-favourites-action/action/flavour_1_default.png": require("./assets/local-storage-favourites-action/action/flavour_1_default.png"),
|
|
10
|
+
"local-storage-favourites-action/action/flavour_2.png": require("./assets/local-storage-favourites-action/action/flavour_2.png"),
|
|
11
|
+
"local-storage-favourites-action/action/flavour_2_active.png": require("./assets/local-storage-favourites-action/action/flavour_2_active.png"),
|
|
12
|
+
"local-storage-favourites-action/action/flavour_2_default.png": require("./assets/local-storage-favourites-action/action/flavour_2_default.png"),
|
|
13
|
+
"local-storage-favourites-action/button/flavour_1.png": require("./assets/local-storage-favourites-action/button/flavour_1.png"),
|
|
14
|
+
"local-storage-favourites-action/button/flavour_1_active.png": require("./assets/local-storage-favourites-action/button/flavour_1_active.png"),
|
|
15
|
+
"local-storage-favourites-action/button/flavour_1_default.png": require("./assets/local-storage-favourites-action/button/flavour_1_default.png"),
|
|
16
|
+
"local-storage-favourites-action/button/flavour_2.png": require("./assets/local-storage-favourites-action/button/flavour_2.png"),
|
|
17
|
+
"local-storage-favourites-action/button/flavour_2_active.png": require("./assets/local-storage-favourites-action/button/flavour_2_active.png"),
|
|
18
|
+
"local-storage-favourites-action/button/flavour_2_default.png": require("./assets/local-storage-favourites-action/button/flavour_2_default.png"),
|
|
19
|
+
"mute_unmute_action/action/flavour_1/mute.png": require("./assets/mute_unmute_action/action/flavour_1/mute.png"),
|
|
20
|
+
"mute_unmute_action/action/flavour_1/unmute.png": require("./assets/mute_unmute_action/action/flavour_1/unmute.png"),
|
|
21
|
+
"mute_unmute_action/action/flavour_2/mute.png": require("./assets/mute_unmute_action/action/flavour_2/mute.png"),
|
|
22
|
+
"mute_unmute_action/action/flavour_2/unmute.png": require("./assets/mute_unmute_action/action/flavour_2/unmute.png"),
|
|
23
|
+
"mute_unmute_action/button/flavour_1/mute.png": require("./assets/mute_unmute_action/button/flavour_1/mute.png"),
|
|
24
|
+
"mute_unmute_action/button/flavour_1/unmute.png": require("./assets/mute_unmute_action/button/flavour_1/unmute.png"),
|
|
25
|
+
"mute_unmute_action/button/flavour_2/mute.png": require("./assets/mute_unmute_action/button/flavour_2/mute.png"),
|
|
26
|
+
"mute_unmute_action/button/flavour_2/unmute.png": require("./assets/mute_unmute_action/button/flavour_2/unmute.png"),
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** `{plugin_identifier}/{path}` of every asset in this package. */
|
|
30
|
+
export type QuickBrickAssetKey = keyof typeof assets;
|
|
31
|
+
|
|
32
|
+
/** What `require` returns for an asset: a number on native, a URL on web. */
|
|
33
|
+
export type QuickBrickAssetSource = number | string;
|
|
34
|
+
|
|
35
|
+
type QuickBrickAssets = Readonly<
|
|
36
|
+
Record<QuickBrickAssetKey, QuickBrickAssetSource>
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
export default assets as QuickBrickAssets;
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/quick-brick-assets",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "16.0.0-rc.123",
|
|
4
|
+
"description": "Static assets bundled by Quick Brick, grouped by plugin identifier",
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"assets",
|
|
8
|
+
"index.ts"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"generate": "yarn run -T ts-node -P ../../scripts/tsconfig.json scripts/generate.ts"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"Applicaster",
|
|
15
|
+
"Zapp",
|
|
16
|
+
"Quick-Brick",
|
|
17
|
+
"assets"
|
|
18
|
+
],
|
|
19
|
+
"author": "Applicaster",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+ssh://git@github.com/applicaster/quickbrick.git"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/applicaster/quickbrick/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/applicaster/quickbrick#readme"
|
|
6
32
|
}
|