@chassis-ui/docs 0.7.0 → 0.9.0-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @chassis-ui/docs
2
2
 
3
+ ## 0.9.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - **Breaking.** The package needs `@chassis-ui/css` 0.10.0 or later: the peer range was `>=0.6.0`. css 0.10 names the font families by their job and holds every text role in one group, and it removes the old Sass names without a deprecation step, so the styles of the package read `$font-lead` in place of `$font-context-lead`, and the footer and the docs sidebar use `.font-h6` and `.font-h5` in place of `.h6` and `.h5`, which css 0.10 deprecates. The roles keep their values, so the pages look as before. css 0.10 reads its tokens from the `@chassis-ui/tokens` that a site installs, which must be 0.10 too. See [UPGRADING.md](https://github.com/chassis-ui/website/blob/main/packages/docs/UPGRADING.md#from-08-to-09) for the dependencies and the names to replace in a site's own pages and styles: `.h1` to `.h6`, `.font-text`, the `--cx-*-text-*` and `--cx-*-html-*` properties and the `$font-context-*` maps.
8
+
9
+ ## 0.8.0
10
+
11
+ ### Minor Changes
12
+
13
+ - **Breaking.** The pages load their fonts from the site's own static files, no longer from Google Fonts. `Head.astro` links `fonts/text.css`, `fonts/display.css` and `fonts/code.css` under the static path, `/static/` by default, in place of the Google Fonts stylesheet and the `preconnect` links to `fonts.googleapis.com` and `fonts.gstatic.com`. The three stylesheets and the font files they load are in the docs build of `chassis-assets`, which a site copies into `static/` already. A site moves its `vendor/assets` submodule to `acb5d2e` of `app/docs` or later, with `pnpm sync-submodules`: there the stylesheets declare Inter, Archivo Narrow and Fira Code as variable fonts, with every weight the styles use. With a commit before `77912ed` they declare four weights of each family. The Inter of the assets has an optical size axis, which the font of Google Fonts had not, and a browser follows it: text above 14 pixels is narrower, 7% at 57 pixels. A site keeps the look it had by building the assets with `--subset` of `chassis-docs vendor`, which fixes the axis at 14 from `acb5d2e` on, or by setting `font-optical-sizing: none` in its styles. A site that does not copy the docs build provides the three stylesheets itself.
14
+ - `chassis-docs vendor` and `chassis-docs sync-submodules` take `--subset <range>`, repeatable, and `--split` or `--no-split` with it. With `--subset` the fonts of the docs build of `chassis-assets` are written with the characters of the ranges only, such as `--subset latin --subset latin-ext`, and the optical size axis of Inter is fixed at 14, as `chassis-assets` sets it for the `chassis` brand. With `--split` each font is also written in a file per range, and its stylesheet names them with a `unicode-range`, so a page loads a range only when it has a character of it; without `--split` and `--no-split` the setting of `chassis-assets` decides, which is one file. With the two ranges and the split, a page in English loads `text-latin.woff2`, 69 KB, where the whole `text.woff2` is 349 KB, and `code-latin.woff2`, 43 KB, where `code.woff2` is 109 KB. A character outside the ranges is drawn with the next font of the font stack. With `--subset` the commands run `pnpm install --filter ./packages/assets --prod` in the submodule, in place of `pnpm install --ignore-workspace`, since the build loads a package to subset a font. The options need `vendor/assets` at `acb5d2e` of `app/docs` or later. Without them nothing changes.
15
+
3
16
  ## 0.7.0
4
17
 
5
18
  ### Minor Changes
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  > [!NOTE] This package is developed inside the [`chassis-website`](https://github.com/chassis-ui/website) monorepo at `packages/docs/` and published to npm. Source, issues, and pull requests live in that repository.
12
12
 
13
- Coming from 0.5? See [UPGRADING.md](UPGRADING.md).
13
+ Coming from an earlier version? See [UPGRADING.md](UPGRADING.md).
14
14
 
15
15
  ## Installation
16
16
 
@@ -23,7 +23,7 @@ pnpm add @chassis-ui/docs
23
23
  ```json
24
24
  {
25
25
  "@astrojs/markdown-remark": "^7.0.0",
26
- "@chassis-ui/css": ">=0.6.0",
26
+ "@chassis-ui/css": ">=0.10.0-next.0",
27
27
  "@pagefind/component-ui": "^1.0.0",
28
28
  "@shikijs/transformers": "^4.3.1",
29
29
  "astro": "^7.0.0",
@@ -184,18 +184,43 @@ export const collections = {
184
184
 
185
185
  The layouts link to files under `/static/`, which the site puts into `static/` of its `public` directory:
186
186
 
187
- | URL | From |
188
- | -------------------------------------------------------------------- | ----------------------------------------- |
189
- | `/static/css/chassis.css`, `/static/css/chassis.min.css` | the `dist` folder of `@chassis-ui/css` |
190
- | `/static/icons/chassis-icons.svg`, `/static/icons/chassis-icons.css` | the `icons` folder of `@chassis-ui/icons` |
191
- | `/static/images/*`: logo, favicons, social image | the docs build of `chassis-assets` |
187
+ | URL | From |
188
+ | ---------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
189
+ | `/static/css/chassis.css`, `/static/css/chassis.min.css` | the `dist` folder of `@chassis-ui/css` |
190
+ | `/static/icons/chassis-icons.svg`, `/static/icons/chassis-icons.css` | the `icons` folder of `@chassis-ui/icons` |
191
+ | `/static/images/site-logo.svg`, the logo of the navigation bar and the footer | the docs build of `chassis-assets` |
192
+ | `/static/images/favicon.png`, `favicon-16x16.png`, `favicon-32x32.png` and `apple-touch-icon.png` | the docs build of `chassis-assets` |
193
+ | `/static/images/social-image.png`, the image of a page without a `thumbnail`. The build reads its size, and fails without the file | the docs build of `chassis-assets` |
194
+ | `/static/fonts/text.css`, `/static/fonts/display.css`, `/static/fonts/code.css`, and the font files they load | the docs build of `chassis-assets` |
195
+ | `/static/images/manifest.json`, the web app manifest | the site itself. The starter has one in `static/images/` |
192
196
 
193
197
  `chassis-docs vendor` builds the docs build of `chassis-assets` in the `vendor/assets` submodule. See [Commands](#commands).
194
198
 
199
+ Nothing else of the docs build is read by the package. A site copies the whole build into `static/`, and its own pages may read more of it.
200
+
195
201
  These helpers find the folders, whether `node_modules` is in the site's root or in the root of the repository: `getChassisCSSFsPath()`, `getChassisIconsFsPath()`, `getChassisAssetsFsPath()` and `getChassisTokensFsPath()`. Each takes `{ root, dir }`.
196
202
 
197
203
  A site that type-checks with `astro check` declares the `@chassis-ui/css` module, which has no types: `declare module '@chassis-ui/css'`.
198
204
 
205
+ #### What the Chassis sites read from the docs build
206
+
207
+ The sites of the Chassis projects read these files besides, by name, from the docs build of the `chassis` brand:
208
+
209
+ | File of the docs build | Read by |
210
+ | ------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
211
+ | `icons/cx-sprite.svg` | The home page of each of the seven sites, which imports it. The build fails without it |
212
+ | `images/apple-touch-icon.png`, `images/favicon.png` | Each of the seven sites, which copies them to `/apple-touch-icon.png` and `/favicon.ico` |
213
+ | `images/android-chrome-192x192.png`, `images/android-chrome-512x512.png` | The `manifest.json` of each of the seven sites |
214
+ | `images/home/` | The home page of the website. The home page of chassis-tokens reads `comp-gallery-*` of it |
215
+ | `images/logo/chassis-{logo,icon}-{brand,white}-banner.svg` | The about page of the website |
216
+ | `images/social-image.png` | The blog of the website, for a post without an image |
217
+ | `images/site-logo.svg` | The examples of the navbar page of chassis-css. The README of `@chassis-ui/react`, by its URL on chassis-ui.com |
218
+ | `images/figma/components/` | The component pages of chassis-figma |
219
+
220
+ The vanilla HTML example, in the `vanilla-example` repository, builds the assets itself from a `vendor/assets` submodule of its own, for the brand of each of its sites, and takes `fonts/text.css`, `fonts/display.css` and `fonts/code.css`, the font files they load, the license of each font and `images/logo/chassis-icon-brand.svg`.
221
+
222
+ `contracts` in `chassis.checks.json` of `chassis-assets` names the files that a site reads, with the code that reads each, and `pnpm assets:contract` there checks a build against it.
223
+
199
224
  #### A site under a prefix
200
225
 
201
226
  A site that is served under a path of another host, such as `chassis-ui.com/css`, cannot use `/static/` there: that path belongs to the host's own site. It loads its static files under a path of its own instead:
@@ -292,6 +317,22 @@ The package installs a `chassis-docs` command with the build steps that every Ch
292
317
 
293
318
  `vendor` and `sync-submodules` work from any folder of the repository. They need Git, Git LFS and pnpm. `sync-submodules --branch <name>`, or the `SUBMODULE_BRANCH` variable, follows another branch.
294
319
 
320
+ Both take `--subset <range>`, which writes the fonts of the build with the characters of the range only, so that a page downloads smaller font files. A range is a name that `chassis-assets` knows, such as `latin` or `latin-ext`, or a range written as `U+0370-03FF`, and the option is repeatable:
321
+
322
+ ```json
323
+ {
324
+ "scripts": {
325
+ "vendor": "chassis-docs vendor --subset latin --subset latin-ext --split"
326
+ }
327
+ }
328
+ ```
329
+
330
+ A character outside the ranges is drawn with the next font of the font stack. With the option, the commands install the package of the build in the submodule, `pnpm install --filter ./packages/assets --prod`, in place of `pnpm install --ignore-workspace`: it holds the package that subsets a font.
331
+
332
+ `--subset` also fixes the axes of a variable font that `chassis-assets` names for the brand: the optical size of Inter at 14, so that text has the width it had with Google Fonts. A site that builds without `--subset` sets `font-optical-sizing: none` in its styles for the same look.
333
+
334
+ `--split`, with `--subset`, writes each font in a file per range as well, such as `text-latin.woff2` and `text-latin-ext.woff2`, and the stylesheets name them with a `unicode-range`: a page loads the file of a range only when it has a character of it. `--no-split` writes one file per font. Without either, the setting of `chassis-assets` decides, which is one file.
335
+
295
336
  Each command exits with 1 when it fails, so a script or CI job stops there.
296
337
 
297
338
  ### Validating HTML
@@ -376,6 +417,7 @@ The integration provides five modules: `virtual:chassis-docs/config`, `virtual:c
376
417
 
377
418
  | `@chassis-ui/docs` | Requires Astro | Requires `@chassis-ui/css` | Requires Node | Built with |
378
419
  | ------------------ | -------------------------- | -------------------------- | ------------- | ------------------------------------ |
420
+ | 0.8.0 | `^7.0.0` | `>=0.6.0` | `>=22.12.0` | Astro 7.3.5, css 0.7.1, tokens 0.7.0 |
379
421
  | 0.7.0 | `^7.0.0` | `>=0.6.0` | `>=22.12.0` | Astro 7.3.5, css 0.6.0, tokens 0.6.0 |
380
422
  | 0.6.3 | `^7.0.0` | `^0.5.0-0` | `>=22.12.0` | Astro 7.3.5, css 0.5.2, tokens 0.6.0 |
381
423
  | 0.6.2 | `^7.0.0` | `^0.5.0-0` | `>=22.12.0` | Astro 7.3.5, css 0.5.2, tokens 0.6.0 |
@@ -387,7 +429,7 @@ The integration provides five modules: `virtual:chassis-docs/config`, `virtual:c
387
429
  | 0.3.0 to 0.3.10 | `^7.0.0` | `>=0.3.1` to `>=0.3.4` | not declared | not recorded |
388
430
  | 0.1.0 to 0.2.0 | `^5.0.0`, 0.1.0–0.1.1 `^4` | not declared | not declared | not recorded |
389
431
 
390
- `@chassis-ui/tokens` is not a dependency of the package. The styles take the design tokens that `@chassis-ui/css` carries: css 0.5 is built on tokens 0.5, css 0.4 on tokens 0.4. A site's own version of `@chassis-ui/tokens` matters only when the site puts it on the Sass load path in place of those. Tokens 0.6 renamed and removed some tokens, listed in its changelog.
432
+ `@chassis-ui/tokens` is not a dependency of the package, but a site installs it: the default token source of `@chassis-ui/css`, `scss/vendor/_chassis-tokens.scss`, forwards `@chassis-ui/tokens/dist/web/docs/chassis/main` from the site's `node_modules`, so the site needs the tokens that its css is built on: css 0.10 on tokens 0.10, css 0.7 on tokens 0.7. A site with tokens of its own puts them on the Sass load path in place of those, as [Styles](#styles) says.
391
433
 
392
434
  Before a release, the [canary](https://github.com/chassis-ui/website/blob/main/build/canary.js) builds the site of each Chassis repository whose range accepts the new version.
393
435
 
package/UPGRADING.md CHANGED
@@ -1,5 +1,128 @@
1
1
  # Upgrading @chassis-ui/docs
2
2
 
3
+ ## From 0.8 to 0.9
4
+
5
+ 0.9.0 needs `@chassis-ui/css` 0.10.0 or later. css 0.10 names the font families by their
6
+ job, `ui` in place of `text`, and holds every text role in one group, so `$font-context-lead`
7
+ is `$font-lead` now, and `.font-h1` to `.font-h6` are the classes of the heading roles. The
8
+ styles and the layouts of the package read the new names.
9
+
10
+ ### 1. Update the dependencies
11
+
12
+ ```sh
13
+ pnpm add -D @chassis-ui/docs@^0.9.0 @chassis-ui/css@^0.10.0 @chassis-ui/tokens@^0.10.0
14
+ ```
15
+
16
+ The default token source of css, `scss/vendor/_chassis-tokens.scss`, forwards the
17
+ `@chassis-ui/tokens` that your site installs, and css 0.10 reads tokens that only tokens 0.10
18
+ has, so the three move together. css 0.10.0 has changes of its own. Read its
19
+ [changelog](https://github.com/chassis-ui/css/blob/main/packages/css/CHANGELOG.md) first.
20
+
21
+ ### 2. Rename the typography names in your own pages and styles
22
+
23
+ css 0.10 keeps `.h1` to `.h6`, `.font-text` and `--cx-font-family-text` in this minor as
24
+ deprecated names, so a site builds and looks as before without this step. The next breaking
25
+ minor of css removes them. The other old names are gone in css 0.10.
26
+
27
+ | Old | New |
28
+ | -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
29
+ | `.h1` to `.h6` | `.font-h1` to `.font-h6` |
30
+ | `.font-text` | `.font-ui` |
31
+ | `--cx-font-family-text` | `--cx-font-family-ui` |
32
+ | `--cx-font-size-text-lg`, `--cx-line-height-text-lg`, `--cx-font-weight-text-strong` and the other steps | `--cx-font-size-ui-lg`, `--cx-line-height-ui-lg`, `--cx-font-weight-ui-strong` |
33
+ | `--cx-font-size-html-h1`, `--cx-line-height-html-h1` and the other `--cx-*-html-*` properties | `--cx-font-size-h1`, `--cx-line-height-h1`; `--cx-font-family-heading` and `--cx-font-weight-heading` for the headings |
34
+ | `.font-display.font-lg` and the other display sizes | removed: a text role such as `.font-h2`, or `.font-prose.font-lg` |
35
+ | `$font-context-lead`, `$font-context-title-large` and the other `$font-context-*` maps | `$font-lead`, `$font-title-large` and the others |
36
+ | `$font-family-text` | `$font-family-ui` |
37
+
38
+ ### What changes in the package
39
+
40
+ - **The footer and the docs sidebar use `.font-h6` and `.font-h5`.** The three column
41
+ titles of the footer and the "On this page" label were `h6`, the section titles of the
42
+ sidebar `h5`. A rule of your own that matched them by class matches the new class.
43
+ - **`.cxd-subtitle` reads `$font-lead`,** the role that `$font-context-lead` was.
44
+
45
+ ### Check the result
46
+
47
+ Build the site before and after the upgrade and compare the pages in a browser. The roles
48
+ keep their values, so nothing of the package moves.
49
+
50
+ ## From 0.7 to 0.8
51
+
52
+ 0.8.0 loads the fonts from the site's own static files, no longer from Google Fonts. The
53
+ head of every page links `fonts/text.css`, `fonts/display.css` and `fonts/code.css` under
54
+ the static path, `/static/` by default. The three stylesheets and the font files they load
55
+ are in the docs build of `chassis-assets`, which a site copies into `static/` already.
56
+
57
+ ### 1. Update the dependency
58
+
59
+ ```sh
60
+ pnpm add -D @chassis-ui/docs@^0.8.0
61
+ ```
62
+
63
+ ### 2. Move the `vendor/assets` submodule
64
+
65
+ ```sh
66
+ pnpm sync-submodules
67
+ ```
68
+
69
+ The pages need `vendor/assets` at `acb5d2e` of `app/docs` or later: there the stylesheets
70
+ declare Inter, Archivo Narrow and Fira Code as variable fonts, with every weight the styles
71
+ use. With a commit before `77912ed` they declare four weights of each family. Commit the
72
+ new pointer.
73
+
74
+ A site that does not copy the docs build provides the three stylesheets itself, at the
75
+ same paths.
76
+
77
+ ### 3. Subset the fonts
78
+
79
+ Add `--subset` and `--split` to the `vendor` and `sync-submodules` scripts:
80
+
81
+ ```json
82
+ {
83
+ "scripts": {
84
+ "vendor": "chassis-docs vendor --subset latin --subset latin-ext --split",
85
+ "sync-submodules": "chassis-docs sync-submodules --subset latin --subset latin-ext --split"
86
+ }
87
+ }
88
+ ```
89
+
90
+ The step is optional, and it does two things:
91
+
92
+ - The fonts hold the characters of the ranges only, each range in a file of its own that a
93
+ page loads when it has a character of it. A page in English loads `text-latin.woff2`,
94
+ 69 KB, where the whole `text.woff2` is 349 KB. A character outside the ranges is drawn
95
+ with the next font of the font stack, so name the range of every script your pages use:
96
+ a name that `chassis-assets` knows, or a range written as `U+0370-03FF`. See
97
+ [Commands](README.md#commands) in the README.
98
+ - The optical size axis of Inter is fixed at 14. See "What changes on the pages" below.
99
+
100
+ With `--subset` the commands install the package of the build in the submodule, which
101
+ holds the package that subsets a font.
102
+
103
+ ### 4. Remove Google Fonts from your policy and your privacy page
104
+
105
+ No page requests `fonts.googleapis.com` or `fonts.gstatic.com` any more. Remove the two
106
+ hosts from a content security policy of your own, and a sentence about Google Fonts from a
107
+ privacy page. The sites under chassis-ui.com have the policy of the website, which no
108
+ longer allows the two hosts.
109
+
110
+ ### What changes on the pages
111
+
112
+ - **Inter follows its optical size axis.** The Inter of the assets has the axis, which the
113
+ font of Google Fonts had not, and a browser follows it: text above 14 pixels is narrower,
114
+ 7% at 57 pixels. Step 3 fixes the axis at 14, so text has the width it had. A site that
115
+ builds without `--subset` sets `font-optical-sizing: none` in its styles for the same
116
+ look.
117
+ - **Inter has an italic file.** Italic text was drawn by slanting the upright font.
118
+ - **The head has no `preconnect` links** to the two hosts of Google Fonts.
119
+
120
+ ### Check the result
121
+
122
+ Build the site before and after the upgrade and compare the pages in a browser. With
123
+ step 3 the text keeps its width, so nothing moves. Check in the network panel that no
124
+ request goes to `fonts.googleapis.com` or `fonts.gstatic.com`.
125
+
3
126
  ## From 0.6 to 0.7
4
127
 
5
128
  0.7.0 needs `@chassis-ui/css` 0.6.0 or later. The layouts use the CSS grid of that version,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chassis-ui/docs",
3
3
  "description": "Shared Astro components and layouts for Chassis documentation sites.",
4
- "version": "0.7.0",
4
+ "version": "0.9.0-next.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -65,12 +65,9 @@
65
65
  "engines": {
66
66
  "node": ">=22.12.0"
67
67
  },
68
- "scripts": {
69
- "astro": "astro"
70
- },
71
68
  "peerDependencies": {
72
69
  "@astrojs/markdown-remark": "^7.0.0",
73
- "@chassis-ui/css": ">=0.6.0",
70
+ "@chassis-ui/css": ">=0.10.0-next.0",
74
71
  "@pagefind/component-ui": "^1.0.0",
75
72
  "@shikijs/transformers": "^4.3.1",
76
73
  "astro": "^7.0.0",
@@ -95,8 +92,8 @@
95
92
  "clipboard": "^2.0.11",
96
93
  "github-slugger": "^2.0.0",
97
94
  "image-size": "^2.0.4",
98
- "js-yaml": "^5.4.2",
99
- "mdast-util-from-markdown": "^2.0.3",
95
+ "js-yaml": "^5.4.3",
96
+ "mdast-util-from-markdown": "^2.1.0",
100
97
  "mdast-util-mdx-jsx": "^3.2.0",
101
98
  "mdast-util-to-string": "^4.0.0",
102
99
  "medium-zoom": "^1.1.0",
@@ -106,16 +103,19 @@
106
103
  "unist-util-visit": "^5.1.0"
107
104
  },
108
105
  "devDependencies": {
109
- "@astrojs/markdown-remark": "^7.3.1",
110
- "@chassis-ui/css": "^0.6.0",
106
+ "@astrojs/markdown-remark": "^7.3.2",
107
+ "@chassis-ui/css": "0.10.0-next.0",
111
108
  "@pagefind/component-ui": "^1.5.2",
112
109
  "@shikijs/transformers": "^4.5.0",
113
- "astro": "^7.3.5",
114
- "html-validate": "^11.16.1",
110
+ "astro": "^7.3.8",
111
+ "html-validate": "^11.16.2",
115
112
  "rehype-autolink-headings": "^7.1.0",
116
113
  "remark-mdx": "^3.1.1",
117
114
  "sass": "^1.105.1",
118
115
  "vfile": "^6.0.3",
119
- "vnu-jar": "^26.10.2"
116
+ "vnu-jar": "^26.10.9"
117
+ },
118
+ "scripts": {
119
+ "astro": "astro"
120
120
  }
121
- }
121
+ }
package/src/cli/assets.js CHANGED
@@ -11,6 +11,9 @@ export const ASSETS_OUTPUT = 'dist/web/docs/chassis'
11
11
  /** The branch of chassis-assets that the docs sites follow. */
12
12
  export const DEFAULT_BRANCH = 'app/docs'
13
13
 
14
+ /** The package of the build inside the submodule, which names the packages its options load. */
15
+ export const ASSETS_PACKAGE = './packages/assets'
16
+
14
17
  /**
15
18
  * The root of the repository that contains the working directory, so that the commands
16
19
  * work from a site's folder too.
@@ -22,24 +25,34 @@ function repositoryRoot(run) {
22
25
 
23
26
  /**
24
27
  * Checks out `vendor/assets` at the commit that the repository pins, and builds it.
25
- * @param {{ root?: string, run?: typeof defaultRun }} [options]
28
+ * @param {{ root?: string, subset?: string[], split?: boolean, run?: typeof defaultRun }} [options]
26
29
  */
27
- export function buildAssets({ run = defaultRun, root = repositoryRoot(run) } = {}) {
30
+ export function buildAssets({
31
+ run = defaultRun,
32
+ root = repositoryRoot(run),
33
+ subset = [],
34
+ split
35
+ } = {}) {
36
+ const fonts = fontOptions(subset, split)
37
+
28
38
  log(`Building ${ASSETS_PATH} at the pinned commit`)
29
39
  run('git', ['submodule', 'update', '--init', ASSETS_PATH], { cwd: root })
30
- buildCheckout(root, run)
40
+ buildCheckout(root, run, fonts)
31
41
  }
32
42
 
33
43
  /**
34
44
  * Moves `vendor/assets` to the latest commit of `branch`, and builds it. The repository
35
45
  * then has a changed submodule pointer to commit.
36
- * @param {{ root?: string, branch?: string, run?: typeof defaultRun }} [options]
46
+ * @param {{ root?: string, branch?: string, subset?: string[], split?: boolean, run?: typeof defaultRun }} [options]
37
47
  */
38
48
  export function syncAssets({
39
49
  run = defaultRun,
40
50
  root = repositoryRoot(run),
41
- branch = DEFAULT_BRANCH
51
+ branch = DEFAULT_BRANCH,
52
+ subset = [],
53
+ split
42
54
  } = {}) {
55
+ const fonts = fontOptions(subset, split)
43
56
  const dir = path.join(root, ASSETS_PATH)
44
57
  const git = (args, quiet = true) => run('git', args, { cwd: dir, quiet })
45
58
 
@@ -68,7 +81,7 @@ export function syncAssets({
68
81
  }
69
82
 
70
83
  git(['pull', '--ff-only', 'origin', branch])
71
- buildCheckout(root, run)
84
+ buildCheckout(root, run, fonts)
72
85
 
73
86
  const commit = git(['rev-parse', '--short', 'HEAD']).trim()
74
87
  const moved = run('git', ['status', '--porcelain', '--', ASSETS_PATH], {
@@ -92,14 +105,49 @@ function hasLocalBranch(git, branch) {
92
105
  }
93
106
  }
94
107
 
95
- function buildCheckout(root, run) {
108
+ /**
109
+ * The options of the build for the fonts: the ranges of `--subset`, then `--split` or
110
+ * `--no-split` when the site decides it, and nothing when the fonts stay whole. Without
111
+ * either of the two, the build takes `split` of `chassis.subset` of chassis-assets.
112
+ * @param {string[]} subset
113
+ * @param {boolean} [split]
114
+ * @returns {string[]}
115
+ */
116
+ function fontOptions(subset, split) {
117
+ if (subset.length === 0) {
118
+ if (split !== undefined) {
119
+ throw new CommandError('--split and --no-split need --subset: a font is split by its ranges.')
120
+ }
121
+
122
+ return []
123
+ }
124
+
125
+ const decided = split === undefined ? [] : [split ? '--split' : '--no-split']
126
+
127
+ return ['--subset', ...subset, ...decided]
128
+ }
129
+
130
+ function buildCheckout(root, run, fonts = []) {
96
131
  const dir = path.join(root, ASSETS_PATH)
97
132
 
98
133
  // The images are stored with Git LFS. Without it they are pointer files.
99
134
  run('git', ['lfs', 'install', '--local'], { cwd: dir, quiet: true })
100
135
  run('git', ['lfs', 'pull'], { cwd: dir })
101
- run('pnpm', ['install', '--ignore-workspace'], { cwd: dir })
102
- run('pnpm', ['assets:site'], { cwd: dir })
136
+
137
+ if (fonts.length > 0) {
138
+ // The subsetter is a package that the build loads, so the package of the build is
139
+ // installed, without the tools of its tests. Where an install without the workspace
140
+ // ran before, pnpm removes its modules first, and would ask.
141
+ run(
142
+ 'pnpm',
143
+ ['install', '--filter', ASSETS_PACKAGE, '--prod', '--config.confirmModulesPurge=false'],
144
+ { cwd: dir }
145
+ )
146
+ run('pnpm', ['assets:site', ...fonts], { cwd: dir })
147
+ } else {
148
+ run('pnpm', ['install', '--ignore-workspace'], { cwd: dir })
149
+ run('pnpm', ['assets:site'], { cwd: dir })
150
+ }
103
151
 
104
152
  const output = path.join(dir, ASSETS_OUTPUT)
105
153
 
package/src/cli/main.js CHANGED
@@ -14,6 +14,14 @@ Commands:
14
14
  vendor Build vendor/assets at the commit that the repository pins
15
15
  sync-submodules Move vendor/assets to the latest commit of a branch, and build it
16
16
  --branch <name> The branch of chassis-assets (default: $SUBMODULE_BRANCH or ${DEFAULT_BRANCH})
17
+
18
+ Both builds:
19
+ --subset <range> Write the web fonts with the characters of a range only, such as
20
+ latin or U+0370-03FF. Repeatable
21
+ --split With --subset, write a font in a file per range, which a page
22
+ loads when it has a character of the range
23
+ --no-split With --subset, write a font in one file (default: the setting
24
+ of chassis-assets)
17
25
  html-validate [paths] Validate the HTML files in paths (default: _site) with html-validate
18
26
  --config <file> A JSON config of html-validate, added to the defaults
19
27
  vnu [paths] Validate paths (default: _site) with the Nu Html Checker. Needs Java
@@ -27,6 +35,21 @@ Commands:
27
35
 
28
36
  html-validate and vnu need the html-validate and vnu-jar packages in the site's devDependencies.`
29
37
 
38
+ const fontOptions = {
39
+ subset: { type: 'string', multiple: true },
40
+ split: { type: 'boolean' },
41
+ 'no-split': { type: 'boolean' }
42
+ }
43
+
44
+ // `--split` is true and `--no-split` is false. Neither leaves the decision to chassis-assets.
45
+ function splitOf(values) {
46
+ if (values.split && values['no-split']) {
47
+ throw new CommandError('Give --split or --no-split, not both.')
48
+ }
49
+
50
+ return values.split ? true : values['no-split'] ? false : undefined
51
+ }
52
+
30
53
  const ignoreOptions = {
31
54
  ignore: { type: 'string', multiple: true },
32
55
  'no-default-ignore': { type: 'boolean' }
@@ -39,16 +62,20 @@ function ignoresOf(values, paths) {
39
62
 
40
63
  const commands = {
41
64
  vendor: {
42
- options: {},
43
- run: () => {
44
- buildAssets()
65
+ options: { ...fontOptions },
66
+ run: ({ values }) => {
67
+ buildAssets({ subset: values.subset, split: splitOf(values) })
45
68
  return 0
46
69
  }
47
70
  },
48
71
  'sync-submodules': {
49
- options: { branch: { type: 'string' } },
72
+ options: { branch: { type: 'string' }, ...fontOptions },
50
73
  run: ({ values }) => {
51
- syncAssets({ branch: values.branch ?? process.env.SUBMODULE_BRANCH ?? DEFAULT_BRANCH })
74
+ syncAssets({
75
+ branch: values.branch ?? process.env.SUBMODULE_BRANCH ?? DEFAULT_BRANCH,
76
+ subset: values.subset,
77
+ split: splitOf(values)
78
+ })
52
79
  return 0
53
80
  }
54
81
  },