@matra/cli 0.5.2-preview.0 → 0.5.2-preview.1
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.ja.md +18 -1
- package/README.md +19 -1
- package/package.json +2 -2
- package/src/dev.mjs +14 -0
package/README.ja.md
CHANGED
|
@@ -132,9 +132,26 @@ CLI `0.5.0`では`matra init --template blog my-blog`でブログを開始でき
|
|
|
132
132
|
プレビューは設定、記事、テンプレート、部品、画像などの追加・変更・削除を監視します。
|
|
133
133
|
`basePath`と404を反映し、生成したルートとファイルだけを配信します。
|
|
134
134
|
出力先にある未追跡ファイルは配信しません。編集後はブラウザーを再読み込みしてください。
|
|
135
|
-
CLIはsite-generation
|
|
135
|
+
CLIはsite-generationとstylesに依存しますが、unifiedは同梱しません。
|
|
136
136
|
利用する場合だけ**ブログ内**で`npm install @matra/markdown-unified@^0.1.3`を実行し、`site.markdown: unified`を指定します。
|
|
137
137
|
|
|
138
|
+
### JSフック
|
|
139
|
+
|
|
140
|
+
信頼する`.mjs`を`site.hooks.module`に明示すると、`pages`・`markdown`・`assets`フックを
|
|
141
|
+
`matra site build`と`matra site dev`の両方で使えます。設定・実行順・監視方法は
|
|
142
|
+
[サイト生成の契約](../../spec/site-generation.ja.md#cliのページmarkdownフック)を参照してください。
|
|
143
|
+
`assets`と`pages`の戻り値の共通`data`は生成器`0.4.1-preview.1`から利用できます。
|
|
144
|
+
|
|
145
|
+
公開済みの生成器previewとプリセットを同じプロジェクトに入れる場合、両方の対応版を指定します。
|
|
146
|
+
安定版プリセット`0.1.3`のpeer範囲には生成器previewは含まれません。
|
|
147
|
+
|
|
148
|
+
```sh
|
|
149
|
+
npm install --save-dev @matra/site-generation@0.4.1-preview.1 @matra/markdown-unified@0.1.4-preview.1
|
|
150
|
+
npm ls @matra/site-generation @matra/markdown-unified
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`npm install`でlockfileを更新してください。`npm ci`だけでは依存関係は更新されません。
|
|
154
|
+
|
|
138
155
|
## セキュリティ上の注意
|
|
139
156
|
|
|
140
157
|
信頼できる文書のみをbuildしてください。build中に選択されたJavaScriptと
|
package/README.md
CHANGED
|
@@ -134,9 +134,27 @@ files, and Cloudflare Pages configuration for `dist/404.html`. Preview watches t
|
|
|
134
134
|
and its article, template, component and asset directories, including additions and deletions.
|
|
135
135
|
Only generated routes and files are served (including the configured `basePath` and custom 404);
|
|
136
136
|
untracked files in the output directory are not exposed. Refresh the browser after editing.
|
|
137
|
-
The CLI includes site-generation
|
|
137
|
+
The CLI includes site-generation and styles, but not unified. For the preset,
|
|
138
138
|
run `npm install @matra/markdown-unified@^0.1.3` **inside the blog**, then set `site.markdown: unified`.
|
|
139
139
|
|
|
140
|
+
### JavaScript hooks
|
|
141
|
+
|
|
142
|
+
Explicitly configure a trusted `.mjs` module as `site.hooks.module` to use `pages`, `markdown`,
|
|
143
|
+
and `assets` hooks with both `matra site build` and `matra site dev`. See the
|
|
144
|
+
[site-generation contract](../../spec/site-generation.md#cli-page-and-markdown-hooks) for configuration,
|
|
145
|
+
execution order, and watching.
|
|
146
|
+
The `assets` hook and shared `data` returned by `pages` require generator `0.4.1-preview.1` or later.
|
|
147
|
+
|
|
148
|
+
To install the published generator preview and preset in the same project, use both matching versions.
|
|
149
|
+
The stable preset `0.1.3` peer range does not include the generator preview.
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
npm install --save-dev @matra/site-generation@0.4.1-preview.1 @matra/markdown-unified@0.1.4-preview.1
|
|
153
|
+
npm ls @matra/site-generation @matra/markdown-unified
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Use `npm install` to update the lockfile; `npm ci` alone does not update dependencies.
|
|
157
|
+
|
|
140
158
|
## Security notes
|
|
141
159
|
|
|
142
160
|
Build only trusted documents: selected JavaScript and Python execute during
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matra/cli",
|
|
3
|
-
"version": "0.5.2-preview.
|
|
3
|
+
"version": "0.5.2-preview.1",
|
|
4
4
|
"description": "Matra project initialization and HTML build tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@matra/command": "0.2.0",
|
|
15
15
|
"@matra/core": "0.4.1",
|
|
16
16
|
"@matra/html": "0.4.1",
|
|
17
|
-
"@matra/site-generation": "0.4.1-preview.
|
|
17
|
+
"@matra/site-generation": "0.4.1-preview.1",
|
|
18
18
|
"@matra/styles": "0.2.1",
|
|
19
19
|
"mime-types": "^3.0.2"
|
|
20
20
|
},
|
package/src/dev.mjs
CHANGED
|
@@ -18,6 +18,7 @@ export async function startDev(
|
|
|
18
18
|
) {
|
|
19
19
|
const root = resolve(directory)
|
|
20
20
|
let snapshot
|
|
21
|
+
let routes = new Set()
|
|
21
22
|
let basePath = ""
|
|
22
23
|
let fallback
|
|
23
24
|
let failure
|
|
@@ -82,6 +83,7 @@ export async function startDev(
|
|
|
82
83
|
)
|
|
83
84
|
}
|
|
84
85
|
snapshot = entries
|
|
86
|
+
routes = new Set([...result.routes.keys()].map(route => result.basePath + route))
|
|
85
87
|
basePath = result.basePath
|
|
86
88
|
fallback = result.notFound ? entries.get(`${basePath}/404.html`) : undefined
|
|
87
89
|
failure = undefined
|
|
@@ -149,6 +151,18 @@ export async function startDev(
|
|
|
149
151
|
response.end()
|
|
150
152
|
return
|
|
151
153
|
}
|
|
154
|
+
if (
|
|
155
|
+
site &&
|
|
156
|
+
!failure &&
|
|
157
|
+
!asset &&
|
|
158
|
+
url.endsWith("/") &&
|
|
159
|
+
path.length > 1 &&
|
|
160
|
+
routes.has(path.slice(0, -1))
|
|
161
|
+
) {
|
|
162
|
+
response.writeHead(301, { Location: `${url.slice(0, -1)}${request.url.slice(url.length)}` })
|
|
163
|
+
response.end()
|
|
164
|
+
return
|
|
165
|
+
}
|
|
152
166
|
const status = failure ? 503 : !asset ? 404 : 200
|
|
153
167
|
const content = asset ?? fallback
|
|
154
168
|
const body = status === 503 ? `Build failed: ${failure}\n` : (content?.body ?? "Not found\n")
|