@asd14/vblocks 5.3.0 → 6.0.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 +114 -69
- package/bin/vblocks +120 -0
- package/bin/vblocks.d/build +145 -0
- package/bin/vblocks.d/eject +38 -0
- package/bin/vblocks.d/init +274 -0
- package/bin/vblocks.d/lib.sh +569 -0
- package/bin/vblocks.d/serve +100 -0
- package/bin/vblocks.d/vblocks.sh +92 -0
- package/bin/vblocks.d/webpack.sh +130 -0
- package/package.json +2 -2
- package/src/types/client.d.ts +19 -0
- package/src/webpack.config.js +32 -21
- package/template/plain/post-init-app.sh +10 -0
- package/template/xyflow/app/src/details.tsx +74 -0
- package/template/xyflow/app/src/diagram.tsx +148 -0
- package/template/xyflow/app/src/index.tsx +26 -111
- package/template/xyflow/app/src/utils/grid.ts +44 -0
- package/template/xyflow/post-init-app.sh +5 -0
- package/template/xyflow-tabs/app/postcss.config.js +13 -0
- package/template/xyflow-tabs/app/src/index.css +3 -0
- package/template/xyflow-tabs/app/src/index.tsx +90 -0
- package/template/xyflow-tabs/app/src/pages/build/details.tsx +74 -0
- package/template/xyflow-tabs/app/src/pages/build/diagram.tsx +151 -0
- package/template/xyflow-tabs/app/src/pages/serve/details.tsx +33 -0
- package/template/xyflow-tabs/app/src/pages/serve/diagram.tsx +173 -0
- package/template/xyflow-tabs/app/src/ui/zoom-level.tsx +29 -0
- package/template/xyflow-tabs/app/src/utils/grid.ts +44 -0
- package/template/xyflow-tabs/post-init-app.sh +16 -0
- package/bin/vblocks.sh +0 -685
package/README.md
CHANGED
|
@@ -48,11 +48,16 @@ to write, read or fix
|
|
|
48
48
|
- [Replace a default config](#replace-a-default-config)
|
|
49
49
|
- [Style with Tailwind](#style-with-tailwind)
|
|
50
50
|
- [Add VBlocks to an existing project](#add-vblocks-to-an-existing-project)
|
|
51
|
-
- [
|
|
52
|
-
- [
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
- [References](#references)
|
|
52
|
+
- [Commands](#commands)
|
|
53
|
+
- [`vblocks init`](#vblocks-init)
|
|
54
|
+
- [`vblocks serve`](#vblocks-serve)
|
|
55
|
+
- [`vblocks build`](#vblocks-build)
|
|
56
|
+
- [`vblocks eject`](#vblocks-eject)
|
|
57
|
+
- [Templates](#templates)
|
|
58
|
+
- [`plain`](#plain)
|
|
59
|
+
- [`xyflow`](#xyflow)
|
|
60
|
+
- [`xyflow-tabs`](#xyflow-tabs)
|
|
56
61
|
- [License](#license)
|
|
57
62
|
|
|
58
63
|
<!-- vim-markdown-toc -->
|
|
@@ -67,23 +72,18 @@ Order this README by three principles. Each settles one decision:
|
|
|
67
72
|
- **Colocation**, the place of a fact. A caveat sits on the step or option it
|
|
68
73
|
limits, in a NOTE when it is tangential or points at another section
|
|
69
74
|
|
|
70
|
-
Each section is one Diátaxis type (https://diataxis.fr):
|
|
71
|
-
|
|
75
|
+
Each section is one Diátaxis type (https://diataxis.fr):
|
|
76
|
+
- Quick Start -> Tutorial
|
|
77
|
+
- How to -> How-to guides
|
|
78
|
+
- Vocabulary, Commands and Templates -> Reference
|
|
72
79
|
-->
|
|
73
80
|
|
|
74
81
|
## Quick Start
|
|
75
82
|
|
|
76
|
-
<!--
|
|
77
|
-
Diátaxis: tutorial. The fewest steps to a working bundle. It shows enough of
|
|
78
|
-
VBlocks for the reader to decide whether VBlocks fits their project.
|
|
79
|
-
-->
|
|
80
|
-
|
|
81
83
|
<!--
|
|
82
84
|
Using "scaffold", the field's word for what `init` does, eg. Yeoman and
|
|
83
85
|
create-vite use it.
|
|
84
|
-
-->
|
|
85
86
|
|
|
86
|
-
<!--
|
|
87
87
|
Using the `my-vblocks-` prefix, the package name, so a reader who tries several
|
|
88
88
|
scaffolders spots the folder at a glance, as with `vite-project` and
|
|
89
89
|
`nuxt-app`.
|
|
@@ -149,10 +149,7 @@ Several apps, eg. demos or MVP sketches, can share one `package.json` and one
|
|
|
149
149
|
```diff
|
|
150
150
|
sketches/
|
|
151
151
|
+ ├─ flow-diagram/
|
|
152
|
-
+ │ ├─ src/
|
|
153
|
-
+ │ │ ├─ index.tsx
|
|
154
|
-
+ │ │ ├─ index.html
|
|
155
|
-
+ │ │ └─ index.css
|
|
152
|
+
+ │ ├─ src/ # the files of the xyflow template
|
|
156
153
|
+ │ ├─ postcss.config.js
|
|
157
154
|
+ │ └─ tsconfig.json
|
|
158
155
|
├─ .gitignore
|
|
@@ -168,24 +165,22 @@ Several apps, eg. demos or MVP sketches, can share one `package.json` and one
|
|
|
168
165
|
## Vocabulary
|
|
169
166
|
|
|
170
167
|
<!--
|
|
171
|
-
Vocabulary
|
|
172
|
-
|
|
173
|
-
them.
|
|
168
|
+
Keep Vocabulary after Quick Start since the reader has no context to place
|
|
169
|
+
the definitions in.
|
|
174
170
|
-->
|
|
175
171
|
|
|
176
172
|
| Term | Means |
|
|
177
173
|
| :----------------- | :------------------------------------------------------------ |
|
|
174
|
+
| **Plumbing** | The project files `init` writes: `package.json`, `.gitignore` |
|
|
178
175
|
| **Project folder** | The folder with `package.json` |
|
|
179
176
|
| **App folder** | The folder with `src/index.tsx` and `src/index.html` |
|
|
180
|
-
| **Plumbing** | The project files `init` writes: `package.json`, `.gitignore` |
|
|
181
177
|
| **Bundle** | The files `build` writes to `dist/` |
|
|
182
178
|
|
|
183
179
|
## How to
|
|
184
180
|
|
|
185
181
|
<!--
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
another reader, eg. one with an existing app, goes last.
|
|
182
|
+
Each ### names a pain as the task that relieves it. Order the guides by how
|
|
183
|
+
early the Quick Start reader has the pain.
|
|
189
184
|
-->
|
|
190
185
|
|
|
191
186
|
### Use environment variables
|
|
@@ -229,12 +224,12 @@ import { Component } from "@self/components"
|
|
|
229
224
|
> The `tsconfig.json` that [`vblocks init`](#vblocks-init) writes already has
|
|
230
225
|
> it. Otherwise, add:
|
|
231
226
|
>
|
|
232
|
-
> ```
|
|
233
|
-
>
|
|
234
|
-
>
|
|
235
|
-
>
|
|
236
|
-
>
|
|
237
|
-
>
|
|
227
|
+
> ```diff
|
|
228
|
+
> {
|
|
229
|
+
> "compilerOptions": {
|
|
230
|
+
> + "paths": { "@self/*": ["./src/*"] }
|
|
231
|
+
> }
|
|
232
|
+
> }
|
|
238
233
|
> ```
|
|
239
234
|
|
|
240
235
|
### Use CSS Modules
|
|
@@ -263,7 +258,7 @@ import { Component } from "@self/components"
|
|
|
263
258
|
|
|
264
259
|
> [!NOTE]
|
|
265
260
|
> The [client types](src/types/client.d.ts) declare `.css`, image and font
|
|
266
|
-
> imports
|
|
261
|
+
> imports.
|
|
267
262
|
|
|
268
263
|
### Replace a default config
|
|
269
264
|
|
|
@@ -280,7 +275,8 @@ Each config in your app folder replaces the default of the same name:
|
|
|
280
275
|
1. **[Eject](#vblocks-eject) the default into your app folder**
|
|
281
276
|
|
|
282
277
|
```sh
|
|
283
|
-
|
|
278
|
+
cd flow-diagram
|
|
279
|
+
npx vblocks eject swc > .swcrc
|
|
284
280
|
```
|
|
285
281
|
|
|
286
282
|
2. **Update the ejected file**
|
|
@@ -292,18 +288,14 @@ Each config in your app folder replaces the default of the same name:
|
|
|
292
288
|
> - `.swcrc -> jsc.transform.react.refresh`: VBlocks adds the React Refresh
|
|
293
289
|
> transform when `serve` runs in `development` mode
|
|
294
290
|
|
|
295
|
-
> [!NOTE]
|
|
296
|
-
> VBlocks passes [`build --single-file`](#vblocks-build) and
|
|
297
|
-
> [`serve --analyze`](#vblocks-serve) to your `webpack.config.js` as
|
|
298
|
-
> `env.single` and `env.analyze`.
|
|
299
|
-
|
|
300
291
|
### Style with Tailwind
|
|
301
292
|
|
|
302
293
|
VBlocks does not include Tailwind. Add it through a `postcss.config.js` in your
|
|
303
294
|
app folder:
|
|
304
295
|
|
|
305
296
|
> [!NOTE]
|
|
306
|
-
> The `xyflow`
|
|
297
|
+
> The `xyflow` and `xyflow-tabs` templates of [`vblocks init`](#vblocks-init)
|
|
298
|
+
> have this setup.
|
|
307
299
|
|
|
308
300
|
1. **Install Tailwind and the Tailwind plugin for PostCSS**
|
|
309
301
|
|
|
@@ -363,51 +355,58 @@ app folder:
|
|
|
363
355
|
npm install --save-dev @asd14/vblocks # needs react and react-dom ^18 or ^19
|
|
364
356
|
```
|
|
365
357
|
|
|
366
|
-
2. **
|
|
358
|
+
2. **Add the [client types](src/types/client.d.ts) and the
|
|
359
|
+
[`@self`](#stop-using--everywhere) alias to your `tsconfig.json`**
|
|
360
|
+
|
|
361
|
+
```diff
|
|
362
|
+
{
|
|
363
|
+
"compilerOptions": {
|
|
364
|
+
+ "types": ["@asd14/vblocks/client"],
|
|
365
|
+
+ "paths": { "@self/*": ["./src/*"] }
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
3. **Ensure `index.tsx` and `index.html` are in `src/`**
|
|
367
371
|
|
|
368
372
|
> [!NOTE]
|
|
369
373
|
> VBlocks builds `dist/index.html` from `src/index.html` and adds the script and
|
|
370
374
|
> stylesheet tags to it. Drop the tag that loads your entry, eg. Vite's
|
|
371
375
|
> `<script type="module" src="/src/main.tsx"></script>`.
|
|
372
376
|
|
|
373
|
-
|
|
377
|
+
4. **Start a development server**
|
|
374
378
|
|
|
375
379
|
```sh
|
|
376
380
|
npx vblocks serve
|
|
377
381
|
```
|
|
378
382
|
|
|
379
|
-
##
|
|
383
|
+
## References
|
|
380
384
|
|
|
381
|
-
|
|
382
|
-
Diátaxis: reference. Mirror SYNOPSIS and OPTIONS of `vblocks --help`, in the
|
|
383
|
-
same words. The SYNOPSIS puts one option per line, with its values, so it fits
|
|
384
|
-
the width of GitHub. Below it, each option is a bullet with its default, and
|
|
385
|
-
its description in sub-bullets.
|
|
386
|
-
-->
|
|
385
|
+
### Commands
|
|
387
386
|
|
|
388
|
-
|
|
387
|
+
#### `vblocks init`
|
|
389
388
|
|
|
390
389
|
Write a template's plumbing, app, or both into `<directory>`.
|
|
391
390
|
|
|
392
391
|
```text
|
|
393
392
|
vblocks init <directory>
|
|
394
|
-
[--template <plain|xyflow>]
|
|
393
|
+
[--template <plain|xyflow|xyflow-tabs>]
|
|
395
394
|
[--only <app|plumbing>]
|
|
396
395
|
```
|
|
397
396
|
|
|
398
397
|
- `<directory>`
|
|
399
398
|
- The folder to write into. It must be missing or empty
|
|
400
399
|
- `--template` (default: `plain`)
|
|
401
|
-
-
|
|
400
|
+
- The template to write, see [Templates](#templates)
|
|
402
401
|
- `--only` (default: both)
|
|
403
402
|
- Write one part of the template
|
|
404
403
|
- `plumbing`: `package.json`, `.gitignore`
|
|
405
404
|
- `app`: `src/`, `tsconfig.json` and the template's configs. `init` adds the
|
|
406
405
|
template's dependencies to the `package.json` of the
|
|
407
|
-
[project folder](#vocabulary), the
|
|
408
|
-
`package.json
|
|
406
|
+
[project folder](#vocabulary), the parent of `<directory>`. Without a
|
|
407
|
+
`package.json` there, `init` fails
|
|
409
408
|
|
|
410
|
-
|
|
409
|
+
#### `vblocks serve`
|
|
411
410
|
|
|
412
411
|
Start the development server.
|
|
413
412
|
|
|
@@ -422,7 +421,7 @@ vblocks serve
|
|
|
422
421
|
[--prefix <directory>]
|
|
423
422
|
[--analyze]
|
|
424
423
|
[--log-level <error|warn|info|verbose>]
|
|
425
|
-
[<webpack option>...]
|
|
424
|
+
[-- <webpack option>...]
|
|
426
425
|
```
|
|
427
426
|
|
|
428
427
|
- `--mode` (default: `development`)
|
|
@@ -433,12 +432,13 @@ vblocks serve
|
|
|
433
432
|
- `--analyze`
|
|
434
433
|
- Run the bundle analyzer, on a free port
|
|
435
434
|
- `--log-level` (default: `warn`)
|
|
436
|
-
- How much Webpack
|
|
437
|
-
-
|
|
438
|
-
- Any
|
|
439
|
-
|
|
435
|
+
- How much Webpack and its development server print
|
|
436
|
+
- `-- <webpack option>...`
|
|
437
|
+
- Any [`webpack serve`](https://webpack.js.org/api/cli/) option
|
|
438
|
+
- `serve` passes each one to Webpack unchanged
|
|
439
|
+
- eg. `-- --host 0.0.0.0`, to listen on the network
|
|
440
440
|
|
|
441
|
-
|
|
441
|
+
#### `vblocks build`
|
|
442
442
|
|
|
443
443
|
Build the app into a bundle in the `dist/` of the app folder.
|
|
444
444
|
|
|
@@ -447,8 +447,8 @@ By default, `build`:
|
|
|
447
447
|
- Writes JS and CSS files with content-hashed names
|
|
448
448
|
- Writes a `react` chunk, and a `vendors` chunk when your other dependencies
|
|
449
449
|
total over 20 KB (10 KB in `development`)
|
|
450
|
-
- Inlines `jpg`, `gif`, `png` and `svg` files up to 10 KB
|
|
451
|
-
|
|
450
|
+
- Inlines `jpg`, `gif`, `png` and `svg` files up to 10 KB
|
|
451
|
+
- Writes larger images to `dist/` with content-hashed names
|
|
452
452
|
- Writes `woff`, `woff2`, `ttf` and `eot` files to `dist/fonts/`
|
|
453
453
|
- Copies `src/public/favicon.svg` and `src/public/robots.txt` of your app, or
|
|
454
454
|
the defaults of VBlocks
|
|
@@ -459,7 +459,7 @@ vblocks build
|
|
|
459
459
|
[--prefix <directory>]
|
|
460
460
|
[--single-file]
|
|
461
461
|
[--log-level <error|warn|info|verbose>]
|
|
462
|
-
[<webpack option>...]
|
|
462
|
+
[-- <webpack option>...]
|
|
463
463
|
```
|
|
464
464
|
|
|
465
465
|
- `--mode` (default: `production`)
|
|
@@ -475,12 +475,13 @@ vblocks build
|
|
|
475
475
|
- Keep the route in the URL hash
|
|
476
476
|
- On `file://`, `history.pushState` to another path throws
|
|
477
477
|
- `--log-level` (default: `warn`)
|
|
478
|
-
- How much Webpack
|
|
479
|
-
-
|
|
480
|
-
- Any
|
|
481
|
-
|
|
478
|
+
- How much Webpack prints
|
|
479
|
+
- `-- <webpack option>...`
|
|
480
|
+
- Any [`webpack build`](https://webpack.js.org/api/cli/) option
|
|
481
|
+
- `build` passes each one to Webpack unchanged
|
|
482
|
+
- eg. `-- --devtool source-map`, to write source maps
|
|
482
483
|
|
|
483
|
-
|
|
484
|
+
#### `vblocks eject`
|
|
484
485
|
|
|
485
486
|
Print a default config to stdout.
|
|
486
487
|
|
|
@@ -491,7 +492,7 @@ vblocks eject <webpack|postcss|swc>
|
|
|
491
492
|
- `<webpack|postcss|swc>`
|
|
492
493
|
- The config to print
|
|
493
494
|
|
|
494
|
-
|
|
495
|
+
Run it in your app folder and save the output there, to
|
|
495
496
|
[replace the default](#replace-a-default-config):
|
|
496
497
|
|
|
497
498
|
```sh
|
|
@@ -500,6 +501,50 @@ npx vblocks eject postcss > postcss.config.js
|
|
|
500
501
|
npx vblocks eject swc > .swcrc
|
|
501
502
|
```
|
|
502
503
|
|
|
504
|
+
### Templates
|
|
505
|
+
|
|
506
|
+
All templates scaffold `src/index.html`, `src/index.css` and `tsconfig.json`.
|
|
507
|
+
|
|
508
|
+
#### `plain`
|
|
509
|
+
|
|
510
|
+
"Hello World!" in `src/index.tsx`.
|
|
511
|
+
|
|
512
|
+
- Adds no packages
|
|
513
|
+
|
|
514
|
+
#### `xyflow`
|
|
515
|
+
|
|
516
|
+
One diagram, and a details panel for the selected node or edge.
|
|
517
|
+
|
|
518
|
+
- Adds `@xyflow/react`, `tailwindcss` and `@tailwindcss/postcss` to the
|
|
519
|
+
`package.json` of the project folder
|
|
520
|
+
- Writes a `postcss.config.js` that configures Tailwind
|
|
521
|
+
|
|
522
|
+
```text
|
|
523
|
+
src/
|
|
524
|
+
├── index.tsx # the layout: header, diagram, details panel, the selected id
|
|
525
|
+
├── diagram.tsx # the nodes and edges, placed and sized in grid cells
|
|
526
|
+
├── details.tsx # the panel for the selected node or edge
|
|
527
|
+
└── utils/grid.ts # CELL_SIZE and toPixels
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
#### `xyflow-tabs`
|
|
531
|
+
|
|
532
|
+
One tab per diagram, each with its own details panel.
|
|
533
|
+
|
|
534
|
+
- Adds the same packages and `postcss.config.js` as `xyflow`
|
|
535
|
+
|
|
536
|
+
```text
|
|
537
|
+
src/
|
|
538
|
+
├── index.tsx # the layout: header, tab bar, details panel, the selected id
|
|
539
|
+
├── pages/
|
|
540
|
+
│ ├── build/
|
|
541
|
+
│ │ ├── diagram.tsx # the nodes and edges of one tab, in grid cells
|
|
542
|
+
│ │ └── details.tsx # the panel for its selected node or edge
|
|
543
|
+
│ └── serve/ # the same two files
|
|
544
|
+
├── ui/zoom-level.tsx # the zoom level, and a Reset to 100%
|
|
545
|
+
└── utils/grid.ts # CELL_SIZE and toPixels
|
|
546
|
+
```
|
|
547
|
+
|
|
503
548
|
## License
|
|
504
549
|
|
|
505
550
|
MIT
|
package/bin/vblocks
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
set -eu
|
|
4
|
+
|
|
5
|
+
# NAME
|
|
6
|
+
# vblocks - Write a project or an app, then serve or build it with Webpack
|
|
7
|
+
#
|
|
8
|
+
# SYNOPSIS
|
|
9
|
+
# vblocks init <directory>
|
|
10
|
+
# [--template <plain|xyflow|xyflow-tabs>]
|
|
11
|
+
# [--only <app|plumbing>]
|
|
12
|
+
# vblocks serve
|
|
13
|
+
# [--mode <development|production>]
|
|
14
|
+
# [--prefix <directory>]
|
|
15
|
+
# [--analyze]
|
|
16
|
+
# [--log-level <error|warn|info|verbose>]
|
|
17
|
+
# [-- <webpack option>...]
|
|
18
|
+
# vblocks build
|
|
19
|
+
# [--mode <development|production>]
|
|
20
|
+
# [--prefix <directory>]
|
|
21
|
+
# [--single-file]
|
|
22
|
+
# [--log-level <error|warn|info|verbose>]
|
|
23
|
+
# [-- <webpack option>...]
|
|
24
|
+
# vblocks eject <webpack|postcss|swc>
|
|
25
|
+
# vblocks -h | --help
|
|
26
|
+
#
|
|
27
|
+
# DESCRIPTION
|
|
28
|
+
# The app folder holds src/index.tsx and src/index.html. A config in it,
|
|
29
|
+
# webpack.config.js, postcss.config.js or .swcrc, replaces the VBlocks
|
|
30
|
+
# default of the same name.
|
|
31
|
+
#
|
|
32
|
+
# init Write a template into <directory>, which must be missing or
|
|
33
|
+
# empty. A template has two parts: the plumbing, which holds
|
|
34
|
+
# the files of the project folder, and the app. Without --only,
|
|
35
|
+
# write both.
|
|
36
|
+
# After each part, run its post-init hooks in <directory>.
|
|
37
|
+
# Print each file it adds, updates or drops, then the next
|
|
38
|
+
# steps.
|
|
39
|
+
# serve Start the development server
|
|
40
|
+
# build Build the app into dist/ in the app folder. Print each file
|
|
41
|
+
# in dist/, its size and the total
|
|
42
|
+
# eject Print a default config, to save in the app folder
|
|
43
|
+
#
|
|
44
|
+
# serve and build pass every option after -- to Webpack, unchanged.
|
|
45
|
+
#
|
|
46
|
+
# OPTIONS
|
|
47
|
+
# --template <name> init: plain, xyflow or xyflow-tabs (default: plain)
|
|
48
|
+
# --only <app|plumbing> init: write only the app or only the plumbing.
|
|
49
|
+
# With app, init adds the app's dependencies to
|
|
50
|
+
# the package.json in the parent folder of
|
|
51
|
+
# <directory>. Without that file, init exits 3
|
|
52
|
+
# --mode <mode> serve, build: the Webpack mode, development or
|
|
53
|
+
# production (default: development for serve,
|
|
54
|
+
# production for build)
|
|
55
|
+
# --prefix <directory> serve, build: the app folder (default: the
|
|
56
|
+
# current folder)
|
|
57
|
+
# --single-file build: one standalone dist/index.html, every
|
|
58
|
+
# asset inlined
|
|
59
|
+
# --analyze serve: run the bundle analyzer, on a free port
|
|
60
|
+
# --log-level <level> serve, build: how much Webpack and its dev server
|
|
61
|
+
# print: error, warn, info or verbose (default:
|
|
62
|
+
# warn)
|
|
63
|
+
# -h, --help Print this help
|
|
64
|
+
#
|
|
65
|
+
# ENVIRONMENT
|
|
66
|
+
# NO_COLOR When non-empty, print without color, the tool icons or the
|
|
67
|
+
# header
|
|
68
|
+
#
|
|
69
|
+
# EXAMPLE
|
|
70
|
+
# npx @asd14/vblocks init my-app
|
|
71
|
+
# npx @asd14/vblocks init demos --only plumbing
|
|
72
|
+
# npx @asd14/vblocks init demos/flow --template xyflow --only app
|
|
73
|
+
# cd demos && npx vblocks build --prefix flow --single-file
|
|
74
|
+
# npx vblocks serve -- --host 0.0.0.0
|
|
75
|
+
# npx vblocks eject postcss > postcss.config.js
|
|
76
|
+
#
|
|
77
|
+
# EXIT CODES
|
|
78
|
+
# 0 Done
|
|
79
|
+
# 2 Invalid usage, or Webpack rejected an option or the config
|
|
80
|
+
# 3 Could not run: a missing tool or parent package.json, a folder init
|
|
81
|
+
# could not add, or a failed copy, hook or Webpack run
|
|
82
|
+
#
|
|
83
|
+
# SEE ALSO
|
|
84
|
+
# node, npm, webpack
|
|
85
|
+
|
|
86
|
+
# npm links the command to this file, so "$0" names the link. realpath follows
|
|
87
|
+
# it to the package, where vblocks.d/ holds the commands
|
|
88
|
+
_SCRIPT_DIR="$(dirname "$(realpath "$0")")/vblocks.d"
|
|
89
|
+
# shellcheck source=vblocks.d/vblocks.sh
|
|
90
|
+
. "$_SCRIPT_DIR/vblocks.sh"
|
|
91
|
+
|
|
92
|
+
# ╭───
|
|
93
|
+
# │ Bootstrap
|
|
94
|
+
# ╰───
|
|
95
|
+
|
|
96
|
+
case "${1:-}" in
|
|
97
|
+
-h | --help)
|
|
98
|
+
_show_help "$0"
|
|
99
|
+
exit 0
|
|
100
|
+
;;
|
|
101
|
+
"")
|
|
102
|
+
_show_help "$0" >&2
|
|
103
|
+
exit 2
|
|
104
|
+
;;
|
|
105
|
+
esac
|
|
106
|
+
|
|
107
|
+
# ╭───
|
|
108
|
+
# │ Main
|
|
109
|
+
# ╰───
|
|
110
|
+
|
|
111
|
+
_COMMAND=$1
|
|
112
|
+
shift
|
|
113
|
+
|
|
114
|
+
case "$_COMMAND" in
|
|
115
|
+
init | serve | build | eject) ;;
|
|
116
|
+
*) _fail 2 -v command "$_COMMAND" -v available_commands "init,serve,build,eject" "Unknown command" ;;
|
|
117
|
+
esac
|
|
118
|
+
|
|
119
|
+
# sh runs the command file, whatever mode npm gave it
|
|
120
|
+
exec sh "$_SCRIPT_DIR/$_COMMAND" "$@"
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# vblocks build [OPTIONS] [-- <webpack option>...]
|
|
4
|
+
#
|
|
5
|
+
# Build the app into dist/ in the app folder, then print
|
|
6
|
+
# each file in it. vblocks runs this file. Never call it directly.
|
|
7
|
+
|
|
8
|
+
set -eu
|
|
9
|
+
|
|
10
|
+
_SCRIPT_DIR=$(dirname "$0")
|
|
11
|
+
# shellcheck source=vblocks.sh
|
|
12
|
+
. "$_SCRIPT_DIR/vblocks.sh"
|
|
13
|
+
# shellcheck source=webpack.sh
|
|
14
|
+
. "$_SCRIPT_DIR/webpack.sh"
|
|
15
|
+
|
|
16
|
+
# ╭───
|
|
17
|
+
# │ Settings
|
|
18
|
+
# ╰───
|
|
19
|
+
|
|
20
|
+
_PREFIX_DIR="" # --prefix, the app folder
|
|
21
|
+
_MODE="production" # --mode: development or production
|
|
22
|
+
_LOG_LEVEL="warn" # --log-level: error, warn, info or verbose
|
|
23
|
+
_IS_SINGLE_FILE="" # --single-file, "true" or ""
|
|
24
|
+
|
|
25
|
+
# ╭───
|
|
26
|
+
# │ Domain primitives
|
|
27
|
+
# ╰───
|
|
28
|
+
|
|
29
|
+
# _print_build_files <app-dir>
|
|
30
|
+
#
|
|
31
|
+
# Print each file in the dist/ of <app-dir> as $APP_DIR/dist/..., a tab and its
|
|
32
|
+
# size, then the total size. Webpack empties dist/ before each build, so every
|
|
33
|
+
# file there is from the last build.
|
|
34
|
+
_print_build_files() {
|
|
35
|
+
# An ejected config can write elsewhere
|
|
36
|
+
[ -d "$1/dist" ] || return 0
|
|
37
|
+
|
|
38
|
+
(cd -- "$1/dist" && find . -type f | LC_ALL=C sort) \
|
|
39
|
+
| while IFS= read -r pbf_file; do
|
|
40
|
+
printf '%s\t%s\n' "$(wc -c <"$1/dist/$pbf_file")" "${pbf_file#./}"
|
|
41
|
+
done \
|
|
42
|
+
| awk -F '\t' -v gray="$_GRAY" -v bold="$_BOLD" -v reset="$_RESET" '
|
|
43
|
+
function format_size(bytes) {
|
|
44
|
+
if (bytes < 1024) return bytes " B"
|
|
45
|
+
if (bytes < 1024 * 1024) return sprintf("%.1f KiB", bytes / 1024)
|
|
46
|
+
return sprintf("%.1f MiB", bytes / 1024 / 1024)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
{
|
|
50
|
+
total += $1
|
|
51
|
+
printf "$APP_DIR/dist/%s\t%s%s%s\n", $2, gray, format_size($1), reset
|
|
52
|
+
}
|
|
53
|
+
END { printf "\n%sTotal%s\t%s\n", bold, reset, format_size(total) }
|
|
54
|
+
'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
# ╭───
|
|
58
|
+
# │ Flags and positionals
|
|
59
|
+
# ╰───
|
|
60
|
+
|
|
61
|
+
while [ "$#" -gt 0 ]; do
|
|
62
|
+
case "$1" in
|
|
63
|
+
--prefix)
|
|
64
|
+
[ "$#" -lt 2 ] && _fail 2 "--prefix needs a folder"
|
|
65
|
+
_PREFIX_DIR=$2
|
|
66
|
+
shift 2
|
|
67
|
+
;;
|
|
68
|
+
--mode)
|
|
69
|
+
_guard_mode "${2:-}"
|
|
70
|
+
_MODE=$2
|
|
71
|
+
shift 2
|
|
72
|
+
;;
|
|
73
|
+
--log-level)
|
|
74
|
+
_guard_log_level "${2:-}"
|
|
75
|
+
_LOG_LEVEL=$2
|
|
76
|
+
shift 2
|
|
77
|
+
;;
|
|
78
|
+
--single-file | --single)
|
|
79
|
+
_IS_SINGLE_FILE="true"
|
|
80
|
+
shift
|
|
81
|
+
;;
|
|
82
|
+
--analyze)
|
|
83
|
+
_fail 2 "--analyze works only with serve"
|
|
84
|
+
;;
|
|
85
|
+
--)
|
|
86
|
+
shift
|
|
87
|
+
break
|
|
88
|
+
;;
|
|
89
|
+
-?*)
|
|
90
|
+
_fail 2 -v flag "$1" "Unknown flag. For Webpack options, place them after --"
|
|
91
|
+
;;
|
|
92
|
+
*)
|
|
93
|
+
_fail 2 -v argument "$1" "build takes no positional"
|
|
94
|
+
;;
|
|
95
|
+
esac
|
|
96
|
+
done
|
|
97
|
+
|
|
98
|
+
if [ -n "$_PREFIX_DIR" ] && [ ! -d "$_PREFIX_DIR" ]; then
|
|
99
|
+
_fail 2 -v prefix "$_PREFIX_DIR" "--prefix is not a folder"
|
|
100
|
+
fi
|
|
101
|
+
|
|
102
|
+
# node runs webpack-cli
|
|
103
|
+
_require_cmd node
|
|
104
|
+
_export_version
|
|
105
|
+
|
|
106
|
+
# ╭───
|
|
107
|
+
# │ Main
|
|
108
|
+
# ╰───
|
|
109
|
+
|
|
110
|
+
_APP_DIR=$(cd -- "${_PREFIX_DIR:-.}" && pwd)
|
|
111
|
+
_WEBPACK_CONFIG=$(_pick_config "$_APP_DIR" webpack.config.js)
|
|
112
|
+
_POSTCSS_CONFIG=$(_pick_config "$_APP_DIR" postcss.config.js)
|
|
113
|
+
_SWC_CONFIG=$(_pick_config "$_APP_DIR" .swcrc)
|
|
114
|
+
# A single file has no robots.txt next to it. Webpack drops an --env with an
|
|
115
|
+
# empty value, so the config gets no robotsPath
|
|
116
|
+
_ROBOTS_FILE=""
|
|
117
|
+
if [ -z "$_IS_SINGLE_FILE" ]; then
|
|
118
|
+
_ROBOTS_FILE=$(_pick_file \
|
|
119
|
+
"$_APP_DIR/src/public/robots.txt" "$_VB_DIR/src/public/robots.txt")
|
|
120
|
+
fi
|
|
121
|
+
_FAVICON_FILE=$(_pick_file \
|
|
122
|
+
"$_APP_DIR/src/public/favicon.svg" "$_VB_DIR/src/public/favicon.svg")
|
|
123
|
+
|
|
124
|
+
_ARTIFACT="SPA bundle"
|
|
125
|
+
if [ -n "$_IS_SINGLE_FILE" ]; then
|
|
126
|
+
_ARTIFACT="single file"
|
|
127
|
+
fi
|
|
128
|
+
|
|
129
|
+
_print_header "$VB_VERSION" "${_BOLD}build${_RESET}: $_MODE, $_ARTIFACT" >&2
|
|
130
|
+
_print_summary "$_APP_DIR" "$_WEBPACK_CONFIG" "$_POSTCSS_CONFIG" "$_SWC_CONFIG" \
|
|
131
|
+
"$_ROBOTS_FILE" "$_FAVICON_FILE"
|
|
132
|
+
|
|
133
|
+
# The default Webpack config reads env.single. An ejected config supports
|
|
134
|
+
# --single-file only if it reads env.single too
|
|
135
|
+
_run_webpack build "$_WEBPACK_CONFIG" \
|
|
136
|
+
--env "entryDir=$_APP_DIR" \
|
|
137
|
+
--env "postcssConfigPath=$_POSTCSS_CONFIG" \
|
|
138
|
+
--env "swcConfigPath=$_SWC_CONFIG" \
|
|
139
|
+
--env "robotsPath=$_ROBOTS_FILE" \
|
|
140
|
+
--env "faviconPath=$_FAVICON_FILE" \
|
|
141
|
+
--env "logLevel=$_LOG_LEVEL" \
|
|
142
|
+
--mode "$_MODE" ${_IS_SINGLE_FILE:+--env single} "$@"
|
|
143
|
+
printf '\n'
|
|
144
|
+
_print_build_files "$_APP_DIR"
|
|
145
|
+
exit 0
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
# vblocks eject <webpack|postcss|swc>
|
|
4
|
+
#
|
|
5
|
+
# Print a default config, to save in the app folder. vblocks runs this file.
|
|
6
|
+
# Never call it directly.
|
|
7
|
+
|
|
8
|
+
set -eu
|
|
9
|
+
|
|
10
|
+
_SCRIPT_DIR=$(dirname "$0")
|
|
11
|
+
# shellcheck source=vblocks.sh
|
|
12
|
+
. "$_SCRIPT_DIR/vblocks.sh"
|
|
13
|
+
|
|
14
|
+
# ╭───
|
|
15
|
+
# │ Settings
|
|
16
|
+
# ╰───
|
|
17
|
+
|
|
18
|
+
_EJECT_CONFIG="" # eject <config>
|
|
19
|
+
|
|
20
|
+
# ╭───
|
|
21
|
+
# │ Flags and positionals
|
|
22
|
+
# ╰───
|
|
23
|
+
|
|
24
|
+
[ "$#" -ne 1 ] && _fail 2 -v available_configs "webpack,postcss,swc" "eject needs one config"
|
|
25
|
+
|
|
26
|
+
case "$1" in
|
|
27
|
+
webpack) _EJECT_CONFIG="webpack.config.js" ;;
|
|
28
|
+
postcss) _EJECT_CONFIG="postcss.config.js" ;;
|
|
29
|
+
swc) _EJECT_CONFIG=".swcrc" ;;
|
|
30
|
+
*) _fail 2 -v config "$1" -v available_configs "webpack,postcss,swc" "Unknown config" ;;
|
|
31
|
+
esac
|
|
32
|
+
|
|
33
|
+
# ╭───
|
|
34
|
+
# │ Main
|
|
35
|
+
# ╰───
|
|
36
|
+
|
|
37
|
+
cat -- "$_VB_DIR/src/$_EJECT_CONFIG"
|
|
38
|
+
exit 0
|