react-manifest-rails 0.2.1 → 0.2.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +74 -285
- data/lib/react-manifest-rails.rb +1 -0
- data/lib/react_manifest/configuration.rb +9 -0
- data/lib/react_manifest/railtie.rb +46 -0
- data/lib/react_manifest/version.rb +1 -1
- data/lib/react_manifest/watcher.rb +1 -0
- data/tasks/react_manifest.rake +12 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '028416e61e2a4c385387c10267366155e596d434660c362c3f3e190ff984fa5d'
|
|
4
|
+
data.tar.gz: 7ab4143a3fee1f071da1450f28ba76a423986568a17401560dc68169539d390b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b24e547c5d9483781cf32fd081e897096907c81cf5de5e15cb1524917fba6766994def31416c7d50375c19c419c1d8168d5b3037df4004d28cafd876cdacc3f3
|
|
7
|
+
data.tar.gz: d94259f332e1fa63d9f2a37f9993576498d99eeac8f7338c7c3c5c236fcdd40e92a0aeabc900da34f0a953c8bbddcdf8367df121d9e13dd7143e761f1036ef44
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.3] - 2026-04-15
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Compatibility entrypoint (`lib/react-manifest-rails.rb`) so default Bundler auto-require reliably loads the Railtie and rake tasks.
|
|
12
|
+
- Development boot-time sync that generates missing `ux_*.js` manifests once on server start.
|
|
13
|
+
- Configurable stdout logging with `config.stdout_logging` for visible generation events in development.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Streamlined README into a concise development-first quickstart with direct troubleshooting for missing tasks and watcher behavior.
|
|
17
|
+
- Improved `react_manifest:generate` diagnostics when `ux_root` is missing or no controller bundles are detected.
|
|
18
|
+
- Watcher and boot-time generation now emit clearer runtime status lines for easier debugging.
|
|
19
|
+
|
|
20
|
+
## [0.2.2] - 2026-04-15
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- Lowered required Ruby version from >= 3.2.0 to >= 3.0.0
|
|
24
|
+
|
|
8
25
|
## [0.1.0] - 2026-04-13
|
|
9
26
|
|
|
10
27
|
### Added
|
data/README.md
CHANGED
|
@@ -1,353 +1,142 @@
|
|
|
1
1
|
# react-manifest-rails
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generate per-controller Sprockets manifests for React code in Rails.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This gem creates `ux_*.js` bundles and includes them with `react_bundle_tag`.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## Quick Start (Development)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- **Smart file watching**: Automatically regenerates bundles when files change in development
|
|
11
|
-
- **Intelligent bundle resolution**: The `react_bundle_tag` view helper automatically selects the correct bundles for each controller
|
|
12
|
-
- **Namespace-aware**: Handles nested controllers and namespaces gracefully (e.g., `admin/users` → `ux_admin_users`)
|
|
13
|
-
- **Shared bundles**: Automatically extracts shared dependencies into a `ux_shared` bundle
|
|
14
|
-
- **Always-include bundles**: Configure bundles that should be loaded on every page
|
|
15
|
-
- **Production-ready**: Integrates seamlessly with `assets:precompile` for CI/production deployments
|
|
16
|
-
- **Zero configuration**: Works out-of-the-box with sensible defaults for standard Rails projects
|
|
17
|
-
|
|
18
|
-
## Advantages
|
|
19
|
-
|
|
20
|
-
### 1. Smaller Bundle Sizes
|
|
21
|
-
Instead of a single monolithic `application.js` that loads all React components for the entire app, each controller gets its own lean bundle containing only the components it needs. This means:
|
|
22
|
-
- **Faster page loads**: Users only download what they need
|
|
23
|
-
- **Better caching**: Components unchanged on their page won't bust the cache
|
|
24
|
-
- **Reduced bandwidth**: Particularly beneficial for mobile users
|
|
25
|
-
|
|
26
|
-
### 2. Simplified Development
|
|
27
|
-
- **Automatic regeneration**: Changes to component files are automatically bundled—no manual build steps
|
|
28
|
-
- **No configuration needed**: Works with standard Rails directory structures immediately
|
|
29
|
-
- **Easy integration**: Drop the gem in and it works with your existing `react-rails` setup
|
|
30
|
-
|
|
31
|
-
### 3. Production Reliability
|
|
32
|
-
- **CI/CD friendly**: Integrates with `assets:precompile` for automated deployments
|
|
33
|
-
- **Deterministic builds**: Consistent bundle generation across environments
|
|
34
|
-
- **Safety checks**: Warns about oversized bundles to catch potential issues
|
|
35
|
-
|
|
36
|
-
### 4. Developer Experience
|
|
37
|
-
- **Per-controller organization**: Bundle structure mirrors your Rails controller layout
|
|
38
|
-
- **Smart bundle selection**: View helper automatically picks the right bundles—no manual tag management
|
|
39
|
-
- **Clear visibility**: Built-in reporter shows exactly what's in each bundle
|
|
40
|
-
|
|
41
|
-
## Installation
|
|
42
|
-
|
|
43
|
-
Add the gem to your `Gemfile`:
|
|
9
|
+
1. Add gems:
|
|
44
10
|
|
|
45
11
|
```ruby
|
|
46
|
-
|
|
12
|
+
# Gemfile
|
|
13
|
+
gem "react-manifest-rails"
|
|
14
|
+
|
|
15
|
+
group :development do
|
|
16
|
+
gem "listen", "~> 3.0"
|
|
17
|
+
end
|
|
47
18
|
```
|
|
48
19
|
|
|
49
|
-
|
|
20
|
+
2. Install:
|
|
50
21
|
|
|
51
22
|
```bash
|
|
52
23
|
bundle install
|
|
53
24
|
```
|
|
54
25
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
### 1. Create your UX directory structure
|
|
58
|
-
|
|
59
|
-
By default, the gem expects your React components to live in `app/assets/javascripts/ux/`. You should organize it like this:
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
app/assets/javascripts/ux/
|
|
63
|
-
├── app/ # Per-controller components (becomes ux_*.js bundles)
|
|
64
|
-
│ ├── users/
|
|
65
|
-
│ │ ├── UserCard.jsx
|
|
66
|
-
│ │ └── UserList.jsx
|
|
67
|
-
│ ├── products/
|
|
68
|
-
│ │ └── ProductGrid.jsx
|
|
69
|
-
│ └── dashboard/
|
|
70
|
-
│ └── Dashboard.jsx
|
|
71
|
-
├── shared/ # Shared utilities (becomes ux_shared)
|
|
72
|
-
│ ├── api.js
|
|
73
|
-
│ └── utils.js
|
|
74
|
-
└── components/ # Global components (becomes ux_shared)
|
|
75
|
-
└── Navigation.jsx
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
### 2. Configure the gem (Optional)
|
|
79
|
-
|
|
80
|
-
Create an initializer at `config/initializers/react_manifest.rb`:
|
|
26
|
+
3. Add initializer:
|
|
81
27
|
|
|
82
28
|
```ruby
|
|
29
|
+
# config/initializers/react_manifest.rb
|
|
30
|
+
require "react_manifest"
|
|
31
|
+
|
|
83
32
|
ReactManifest.configure do |config|
|
|
84
|
-
# Where your UX root lives (default: "app/assets/javascripts/ux")
|
|
85
33
|
config.ux_root = "app/assets/javascripts/ux"
|
|
86
|
-
|
|
87
|
-
# Subdir within ux_root containing per-controller components (default: "app")
|
|
88
34
|
config.app_dir = "app"
|
|
89
|
-
|
|
90
|
-
# Where generated manifests are written (default: "app/assets/javascripts")
|
|
91
35
|
config.output_dir = "app/assets/javascripts"
|
|
92
|
-
|
|
93
|
-
# Name of the shared bundle (default: "ux_shared")
|
|
94
36
|
config.shared_bundle = "ux_shared"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
# Directories within app_dir to ignore (default: [])
|
|
100
|
-
# config.ignore = ["internal_tools"]
|
|
101
|
-
|
|
102
|
-
# Warn if any bundle exceeds this size in KB (default: 500, 0 to disable)
|
|
37
|
+
config.always_include = []
|
|
38
|
+
config.ignore = []
|
|
39
|
+
config.exclude_paths = ["react", "react_dev", "vendor"]
|
|
103
40
|
config.size_threshold_kb = 500
|
|
41
|
+
config.dry_run = false
|
|
42
|
+
config.verbose = false
|
|
43
|
+
config.stdout_logging = true
|
|
104
44
|
end
|
|
105
45
|
```
|
|
106
46
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
In your layout template (`app/views/layouts/application.html.erb` or similar):
|
|
110
|
-
|
|
111
|
-
```erb
|
|
112
|
-
<head>
|
|
113
|
-
<%= javascript_include_tag "application" %>
|
|
114
|
-
<%= react_bundle_tag defer: true %>
|
|
115
|
-
</head>
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
The `react_bundle_tag` helper automatically:
|
|
119
|
-
1. Includes the shared bundle (`ux_shared`)
|
|
120
|
-
2. Includes any bundles in `config.always_include`
|
|
121
|
-
3. Includes the controller-specific bundle (e.g., `ux_users` for UsersController)
|
|
122
|
-
4. Returns an empty string gracefully if there's no matching bundle
|
|
123
|
-
|
|
124
|
-
## How It Works
|
|
125
|
-
|
|
126
|
-
### Bundle Generation
|
|
127
|
-
|
|
128
|
-
The gem scans your `app/assets/javascripts/ux/` directory and generates Sprockets manifests:
|
|
129
|
-
|
|
130
|
-
- **Controller-specific bundles**: Each directory under `ux/app/` becomes a bundle
|
|
131
|
-
- `ux/app/users/` → `ux_users.js`
|
|
132
|
-
- `ux/app/admin/reports/` → `ux_admin_reports.js`
|
|
133
|
-
|
|
134
|
-
- **Shared bundle**: Everything outside `ux/app/` (e.g., `shared/`, `components/`) automatically goes into `ux_shared.js`
|
|
135
|
-
|
|
136
|
-
- **Dependency tracking**: The gem analyzes dependencies to prevent duplication across bundles
|
|
47
|
+
4. Put React files under:
|
|
137
48
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
### Production
|
|
146
|
-
|
|
147
|
-
The gem integrates with Rails' `assets:precompile` task:
|
|
148
|
-
|
|
149
|
-
```bash
|
|
150
|
-
rails assets:precompile
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
This ensures all bundles are generated before deployment.
|
|
154
|
-
|
|
155
|
-
## View Helper Usage
|
|
156
|
-
|
|
157
|
-
### Basic usage
|
|
158
|
-
|
|
159
|
-
```erb
|
|
160
|
-
<%= react_bundle_tag %>
|
|
49
|
+
```text
|
|
50
|
+
app/assets/javascripts/ux/
|
|
51
|
+
app/
|
|
52
|
+
users/
|
|
53
|
+
users_index.jsx
|
|
54
|
+
components/
|
|
55
|
+
nav.jsx
|
|
161
56
|
```
|
|
162
57
|
|
|
163
|
-
|
|
58
|
+
5. Include bundles in your layout:
|
|
164
59
|
|
|
165
60
|
```erb
|
|
166
|
-
<%= react_bundle_tag defer: true
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### Automatic resolution
|
|
170
|
-
|
|
171
|
-
The helper automatically resolves bundles based on `controller_path`:
|
|
172
|
-
|
|
173
|
-
| Controller | Resolved Bundles |
|
|
174
|
-
|-----------|------------------|
|
|
175
|
-
| UsersController | ux_shared + ux_users |
|
|
176
|
-
| Admin::ReportsController | ux_shared + ux_admin_reports (or ux_admin if not found) |
|
|
177
|
-
| Pages::LandingController | ux_shared + ux_pages_landing (or ux_pages, or ux_landing) |
|
|
178
|
-
|
|
179
|
-
## Rake Tasks
|
|
180
|
-
|
|
181
|
-
### Generate bundles (one-time)
|
|
182
|
-
|
|
183
|
-
```bash
|
|
184
|
-
rails react_manifest:generate
|
|
61
|
+
<%= react_bundle_tag defer: true %>
|
|
185
62
|
```
|
|
186
63
|
|
|
187
|
-
|
|
64
|
+
6. Start server:
|
|
188
65
|
|
|
189
66
|
```bash
|
|
190
|
-
rails
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Show bundle contents
|
|
194
|
-
|
|
195
|
-
```bash
|
|
196
|
-
rails react_manifest:report
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
## Configuration Reference
|
|
200
|
-
|
|
201
|
-
| Option | Default | Description |
|
|
202
|
-
|--------|---------|-------------|
|
|
203
|
-
| `ux_root` | `"app/assets/javascripts/ux"` | Root directory of your React components |
|
|
204
|
-
| `app_dir` | `"app"` | Subdirectory of `ux_root` for per-controller components |
|
|
205
|
-
| `output_dir` | `"app/assets/javascripts"` | Where generated manifests are written |
|
|
206
|
-
| `shared_bundle` | `"ux_shared"` | Name of the shared bundle |
|
|
207
|
-
| `always_include` | `[]` | Array of bundle names to load on every page |
|
|
208
|
-
| `ignore` | `[]` | Directories to skip during scanning |
|
|
209
|
-
| `exclude_paths` | `["react", "react_dev", "vendor"]` | Top-level directories to exclude |
|
|
210
|
-
| `size_threshold_kb` | `500` | Warn if a bundle exceeds this size (0 = disabled) |
|
|
211
|
-
| `dry_run` | `false` | Print what would change without writing files |
|
|
212
|
-
| `verbose` | `false` | Enable extra logging |
|
|
213
|
-
|
|
214
|
-
## Troubleshooting
|
|
215
|
-
|
|
216
|
-
### Bundle not being generated
|
|
217
|
-
- Check that your components are in the correct directory structure (`app/assets/javascripts/ux/app/...`)
|
|
218
|
-
- Run `rails react_manifest:report` to see what bundles were detected
|
|
219
|
-
- Check Rails logs for any file watcher errors
|
|
220
|
-
|
|
221
|
-
### Components not loading
|
|
222
|
-
- Verify `react_bundle_tag` is in your layout
|
|
223
|
-
- Check that the bundle name matches your controller path
|
|
224
|
-
- Make sure components are in the `ux/` directory, not elsewhere
|
|
225
|
-
|
|
226
|
-
### Size warnings
|
|
227
|
-
- The gem warns when bundles exceed 500KB
|
|
228
|
-
- Consider splitting large bundles into smaller, more focused ones
|
|
229
|
-
- Adjust `config.size_threshold_kb` in your initializer if needed
|
|
230
|
-
|
|
231
|
-
## TypeScript / Custom Extensions
|
|
232
|
-
|
|
233
|
-
By default the gem scans `*.js` and `*.jsx` files. To add TypeScript support:
|
|
234
|
-
|
|
235
|
-
```ruby
|
|
236
|
-
ReactManifest.configure do |config|
|
|
237
|
-
config.extensions = %w[js jsx ts tsx]
|
|
238
|
-
end
|
|
67
|
+
bundle exec rails s
|
|
239
68
|
```
|
|
240
69
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
To enable watching, add `listen` to the development group in your app's `Gemfile`:
|
|
70
|
+
In development:
|
|
71
|
+
- If expected `ux_*.js` files are missing, the gem generates them once on boot.
|
|
72
|
+
- If `listen` is installed, file changes regenerate manifests automatically.
|
|
73
|
+
- If `listen` is missing, run `bundle exec rails react_manifest:generate` manually.
|
|
74
|
+
- Set `config.stdout_logging = false` to silence ReactManifest console lines while keeping Rails logger output.
|
|
248
75
|
|
|
249
|
-
|
|
250
|
-
gem "listen", "~> 3.0", group: :development
|
|
251
|
-
```
|
|
76
|
+
## What Gets Generated
|
|
252
77
|
|
|
253
|
-
|
|
78
|
+
- `ux_shared.js`: shared files outside `ux/app/`
|
|
79
|
+
- `ux_<controller>.js`: one bundle per directory under `ux/app/`
|
|
254
80
|
|
|
255
|
-
|
|
81
|
+
Example:
|
|
82
|
+
- `ux/app/users/...` -> `ux_users.js`
|
|
83
|
+
- `ux/app/admin/...` -> `ux_admin.js`
|
|
256
84
|
|
|
257
|
-
|
|
85
|
+
## Commands
|
|
258
86
|
|
|
259
|
-
|
|
87
|
+
- Generate manifests now:
|
|
260
88
|
|
|
261
89
|
```bash
|
|
262
|
-
rails react_manifest:
|
|
90
|
+
bundle exec rails react_manifest:generate
|
|
263
91
|
```
|
|
264
92
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
**Step 2 — Preview changes:**
|
|
93
|
+
- Watch in foreground (debugging only; not required in normal dev):
|
|
268
94
|
|
|
269
95
|
```bash
|
|
270
|
-
|
|
96
|
+
bundle exec rails react_manifest:watch
|
|
271
97
|
```
|
|
272
98
|
|
|
273
|
-
|
|
99
|
+
- Print bundle size report:
|
|
274
100
|
|
|
275
101
|
```bash
|
|
276
|
-
rails react_manifest:
|
|
102
|
+
bundle exec rails react_manifest:report
|
|
277
103
|
```
|
|
278
104
|
|
|
279
|
-
A `.bak` backup is created next to each modified file before any write.
|
|
280
|
-
|
|
281
|
-
**Step 4 — Generate bundles and verify:**
|
|
282
|
-
|
|
283
|
-
```bash
|
|
284
|
-
rails react_manifest:generate
|
|
285
|
-
rails assets:precompile # or just start the dev server
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
**Rolling back:** Simply restore the `.bak` file and remove the generated `ux_*.js` manifests.
|
|
289
|
-
|
|
290
105
|
## Troubleshooting
|
|
291
106
|
|
|
292
|
-
###
|
|
293
|
-
- Verify components live under `ux/app/<controller>/` (not directly under `ux/`)
|
|
294
|
-
- Run `rails react_manifest:report` to see detected bundles
|
|
295
|
-
- Check Rails logs for file watcher errors
|
|
107
|
+
### `react_manifest:generate` is not recognized
|
|
296
108
|
|
|
297
|
-
|
|
298
|
-
- Confirm `react_bundle_tag` is present in your layout
|
|
299
|
-
- Check that the bundle name matches your controller path
|
|
300
|
-
- Run `rails react_manifest:generate` to force regeneration
|
|
109
|
+
Run:
|
|
301
110
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
### Watcher stops responding
|
|
306
|
-
- This is usually resolved by restarting the development server
|
|
307
|
-
- Ensure the `listen` gem is installed (see above)
|
|
111
|
+
```bash
|
|
112
|
+
bundle exec rails -T | grep react_manifest
|
|
113
|
+
```
|
|
308
114
|
|
|
309
|
-
|
|
310
|
-
-
|
|
311
|
-
-
|
|
115
|
+
If nothing appears:
|
|
116
|
+
- Confirm the gem is in `Gemfile` and installed (`bundle show react-manifest-rails`).
|
|
117
|
+
- Ensure the gem is not disabled with `require: false`.
|
|
118
|
+
- Restart Spring/server (`bin/spring stop`, then re-run command).
|
|
312
119
|
|
|
313
|
-
###
|
|
314
|
-
- The gem warns when bundles exceed `config.size_threshold_kb` (default 500 KB)
|
|
315
|
-
- Consider splitting large controller directories or moving shared code into the shared bundle
|
|
316
|
-
- Adjust the threshold: `config.size_threshold_kb = 1000`
|
|
120
|
+
### Server starts but nothing happens
|
|
317
121
|
|
|
318
|
-
|
|
122
|
+
Check these in order:
|
|
123
|
+
- `app/assets/javascripts/ux` exists.
|
|
124
|
+
- Your controller files are under `ux/app/<controller>/`.
|
|
125
|
+
- Your layout includes `<%= react_bundle_tag %>`.
|
|
126
|
+
- Run `bundle exec rails react_manifest:generate` once and check for generated `ux_*.js` in `app/assets/javascripts`.
|
|
319
127
|
|
|
320
|
-
|
|
321
|
-
|----------|-------------|
|
|
322
|
-
| Initial generation (small project, ~20 controllers) | < 1 s |
|
|
323
|
-
| Initial generation (large project, ~100 controllers) | 2–5 s |
|
|
324
|
-
| Watcher debounce (regeneration after file change) | ~300 ms |
|
|
325
|
-
| Memory overhead (symbol index, large project) | < 10 MB |
|
|
128
|
+
### Auto-watch in dev does not run
|
|
326
129
|
|
|
327
|
-
|
|
130
|
+
- Ensure `listen` is in the development group.
|
|
131
|
+
- Restart the Rails server after adding `listen`.
|
|
132
|
+
- If you choose not to install `listen`, manual generation is the supported fallback.
|
|
328
133
|
|
|
329
134
|
## Compatibility
|
|
330
135
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
| Rails / Railties | 6.1 – 8.x |
|
|
335
|
-
| Sprockets | 3.x, 4.x |
|
|
336
|
-
| listen (optional) | ~> 3.0 |
|
|
337
|
-
|
|
338
|
-
> **Pre-1.0 notice:** The public API (configuration keys, rake task names, view helper signature) may change in minor versions until 1.0 is released. Pin to a patch version if stability is critical: `gem "react-manifest-rails", "~> 0.1.0"`.
|
|
339
|
-
|
|
340
|
-
## Requirements
|
|
341
|
-
|
|
342
|
-
- Ruby >= 3.2
|
|
343
|
-
- Rails >= 6.1
|
|
344
|
-
- Sprockets
|
|
345
|
-
- react-rails
|
|
136
|
+
- Ruby: 3.2+
|
|
137
|
+
- Rails/Railties: 7.x to 8.x
|
|
138
|
+
- Asset pipeline: Sprockets
|
|
346
139
|
|
|
347
140
|
## License
|
|
348
141
|
|
|
349
|
-
MIT
|
|
350
|
-
|
|
351
|
-
## Contributing
|
|
352
|
-
|
|
353
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/olivernoonan/react-manifest-rails.
|
|
142
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "react_manifest_rails"
|
|
@@ -41,6 +41,10 @@ module ReactManifest
|
|
|
41
41
|
# Extra logging
|
|
42
42
|
attr_accessor :verbose
|
|
43
43
|
|
|
44
|
+
# Emit ReactManifest status lines to stdout in development
|
|
45
|
+
# (independent from Rails.logger output)
|
|
46
|
+
attr_accessor :stdout_logging
|
|
47
|
+
|
|
44
48
|
def initialize
|
|
45
49
|
@ux_root = "app/assets/javascripts/ux"
|
|
46
50
|
@app_dir = "app"
|
|
@@ -53,6 +57,7 @@ module ReactManifest
|
|
|
53
57
|
@extensions = %w[js jsx]
|
|
54
58
|
@dry_run = false
|
|
55
59
|
@verbose = false
|
|
60
|
+
@stdout_logging = true
|
|
56
61
|
end
|
|
57
62
|
|
|
58
63
|
def dry_run?
|
|
@@ -63,6 +68,10 @@ module ReactManifest
|
|
|
63
68
|
!!@verbose
|
|
64
69
|
end
|
|
65
70
|
|
|
71
|
+
def stdout_logging?
|
|
72
|
+
!!@stdout_logging
|
|
73
|
+
end
|
|
74
|
+
|
|
66
75
|
# Glob fragment used by Dir.glob, e.g. "*.{js,jsx}" or "*.{js,jsx,ts,tsx}"
|
|
67
76
|
def extensions_glob
|
|
68
77
|
"*.{#{extensions.join(',')}}"
|
|
@@ -2,6 +2,35 @@ require "rails/railtie"
|
|
|
2
2
|
|
|
3
3
|
module ReactManifest
|
|
4
4
|
class Railtie < Rails::Railtie
|
|
5
|
+
# ----------------------------------------------------------------
|
|
6
|
+
# In development, generate once on boot if expected manifests are missing.
|
|
7
|
+
# This makes first-run setup deterministic even before any file change event.
|
|
8
|
+
# ----------------------------------------------------------------
|
|
9
|
+
initializer "react_manifest.ensure_manifests" do
|
|
10
|
+
next unless Rails.env.development?
|
|
11
|
+
|
|
12
|
+
config = ReactManifest.configuration
|
|
13
|
+
missing = self.class.missing_manifest_bundles(config)
|
|
14
|
+
next if missing.empty?
|
|
15
|
+
|
|
16
|
+
message = "[ReactManifest] Missing manifests on boot: #{missing.join(', ')}. Generating now..."
|
|
17
|
+
Rails.logger&.info(message)
|
|
18
|
+
$stdout.puts(message) if config.stdout_logging?
|
|
19
|
+
|
|
20
|
+
begin
|
|
21
|
+
results = ReactManifest::Generator.new(config).run!
|
|
22
|
+
written = results.count { |r| r[:status] == :written }
|
|
23
|
+
unchanged = results.count { |r| r[:status] == :unchanged }
|
|
24
|
+
done = "[ReactManifest] Boot generation complete: #{written} written, #{unchanged} unchanged"
|
|
25
|
+
Rails.logger&.info(done)
|
|
26
|
+
$stdout.puts(done) if config.stdout_logging?
|
|
27
|
+
rescue StandardError => e
|
|
28
|
+
error = "[ReactManifest] Could not generate manifests on boot: #{e.message}"
|
|
29
|
+
Rails.logger&.warn(error)
|
|
30
|
+
$stdout.puts(error) if config.stdout_logging?
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
5
34
|
# Expose config as Rails.application.config.react_manifest
|
|
6
35
|
config.react_manifest = ReactManifest.configuration
|
|
7
36
|
|
|
@@ -12,6 +41,7 @@ module ReactManifest
|
|
|
12
41
|
if Rails.env.development? && !ReactManifest::Watcher.running?
|
|
13
42
|
begin
|
|
14
43
|
ReactManifest::Watcher.start(ReactManifest.configuration)
|
|
44
|
+
Rails.logger&.info("[ReactManifest] Development watcher is active") if ReactManifest.configuration.verbose?
|
|
15
45
|
rescue StandardError => e
|
|
16
46
|
Rails.logger.warn "[ReactManifest] Could not start file watcher: #{e.message}"
|
|
17
47
|
end
|
|
@@ -42,5 +72,21 @@ module ReactManifest
|
|
|
42
72
|
Rake::Task["assets:precompile"].enhance(["react_manifest:generate"])
|
|
43
73
|
end
|
|
44
74
|
end
|
|
75
|
+
|
|
76
|
+
class << self
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def missing_manifest_bundles(config)
|
|
80
|
+
output_dir = config.abs_output_dir
|
|
81
|
+
expected_manifest_bundles(config).reject do |bundle_name|
|
|
82
|
+
File.exist?(File.join(output_dir, "#{bundle_name}.js"))
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def expected_manifest_bundles(config)
|
|
87
|
+
classification = ReactManifest::TreeClassifier.new(config).classify
|
|
88
|
+
([config.shared_bundle] + classification.controller_dirs.map { |ctrl| ctrl[:bundle_name] }).uniq
|
|
89
|
+
end
|
|
90
|
+
end
|
|
45
91
|
end
|
|
46
92
|
end
|
data/tasks/react_manifest.rake
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
namespace :react_manifest do
|
|
2
2
|
desc "Generate all ux_*.js Sprockets manifests from the ux/ directory tree"
|
|
3
3
|
task generate: :environment do
|
|
4
|
-
|
|
4
|
+
config = ReactManifest.configuration
|
|
5
|
+
|
|
6
|
+
unless Dir.exist?(config.abs_ux_root)
|
|
7
|
+
puts "[ReactManifest] ux_root not found: #{config.abs_ux_root}"
|
|
8
|
+
puts "[ReactManifest] Create it (for example: app/assets/javascripts/ux) then run this task again."
|
|
9
|
+
next
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
results = ReactManifest::Generator.new(config).run!
|
|
5
13
|
|
|
6
14
|
written = results.count { |r| r[:status] == :written }
|
|
7
15
|
unchanged = results.count { |r| r[:status] == :unchanged }
|
|
@@ -12,6 +20,9 @@ namespace :react_manifest do
|
|
|
12
20
|
puts "[ReactManifest] DRY-RUN complete: #{dry} manifest(s) would be written"
|
|
13
21
|
else
|
|
14
22
|
puts "[ReactManifest] Done: #{written} written, #{unchanged} unchanged, #{skipped} skipped"
|
|
23
|
+
if (written + unchanged + skipped).zero?
|
|
24
|
+
puts "[ReactManifest] No manifests generated. Ensure ux/app/<controller>/ contains .js or .jsx files."
|
|
25
|
+
end
|
|
15
26
|
end
|
|
16
27
|
|
|
17
28
|
# Print any scanner warnings
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: react-manifest-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oliver Noonan
|
|
@@ -134,6 +134,7 @@ extra_rdoc_files: []
|
|
|
134
134
|
files:
|
|
135
135
|
- CHANGELOG.md
|
|
136
136
|
- README.md
|
|
137
|
+
- lib/react-manifest-rails.rb
|
|
137
138
|
- lib/react_manifest.rb
|
|
138
139
|
- lib/react_manifest/application_analyzer.rb
|
|
139
140
|
- lib/react_manifest/application_migrator.rb
|
|
@@ -166,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
166
167
|
requirements:
|
|
167
168
|
- - ">="
|
|
168
169
|
- !ruby/object:Gem::Version
|
|
169
|
-
version: 3.
|
|
170
|
+
version: 3.0.0
|
|
170
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
172
|
requirements:
|
|
172
173
|
- - ">="
|