@c-time/frelio-data-json-generator 1.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 +349 -0
- package/dist/index.d.ts +457 -0
- package/dist/index.js +1385 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { FrelioDataJson } from '@c-time/frelio-data-json';
|
|
2
|
+
import { FrelioBuildDataRecipe, TemplateIncludes } from '@c-time/frelio-data-json-recipe';
|
|
3
|
+
import { FrelioDependencyMap } from '@c-time/frelio-dependency-map';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Type definitions for @c-time/frelio-data-json-generator
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* ファイルシステム抽象化インターフェース
|
|
11
|
+
* テスト可能にするため、実際のファイルシステムアクセスを抽象化
|
|
12
|
+
*/
|
|
13
|
+
type FileSystemPort = {
|
|
14
|
+
/**
|
|
15
|
+
* ファイルを読み込む
|
|
16
|
+
* @param path ファイルパス
|
|
17
|
+
* @returns ファイル内容
|
|
18
|
+
* @throws ファイルが存在しない場合
|
|
19
|
+
*/
|
|
20
|
+
readFile(path: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* ファイルの存在確認
|
|
23
|
+
* @param path ファイルパス
|
|
24
|
+
* @returns 存在すれば true
|
|
25
|
+
*/
|
|
26
|
+
exists(path: string): Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* glob パターンにマッチするファイル一覧を取得
|
|
29
|
+
* @param pattern glob パターン
|
|
30
|
+
* @returns マッチしたファイルパスの配列
|
|
31
|
+
*/
|
|
32
|
+
listFiles(pattern: string): Promise<string[]>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Git diff 情報
|
|
36
|
+
* git diff --name-status の出力をパースした結果
|
|
37
|
+
*/
|
|
38
|
+
type GitDiffInfo = {
|
|
39
|
+
/** 追加されたファイル (A) */
|
|
40
|
+
added: string[];
|
|
41
|
+
/** 変更されたファイル (M) */
|
|
42
|
+
modified: string[];
|
|
43
|
+
/** 削除されたファイル (D) */
|
|
44
|
+
deleted: string[];
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 生成オプション
|
|
48
|
+
*/
|
|
49
|
+
type GenerateDataJsonOptions = {
|
|
50
|
+
/**
|
|
51
|
+
* フルリビルド(差分無視で全件再生成)
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
fullRebuild?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* ドライラン(ファイル出力せず、レポートのみ生成)
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
dryRun?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* ログレベル
|
|
62
|
+
* - debug: 詳細ログ
|
|
63
|
+
* - info: 通常ログ(デフォルト)
|
|
64
|
+
* - quiet: エラーのみ
|
|
65
|
+
* @default 'info'
|
|
66
|
+
*/
|
|
67
|
+
logLevel?: 'debug' | 'info' | 'quiet';
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* generateDataJson 関数の入力パラメータ
|
|
71
|
+
*/
|
|
72
|
+
type GenerateDataJsonInput = {
|
|
73
|
+
/** ビルドデータレシピ */
|
|
74
|
+
recipe: FrelioBuildDataRecipe;
|
|
75
|
+
/** 依存マップ(スコープ選定用) */
|
|
76
|
+
dependencyMap: FrelioDependencyMap;
|
|
77
|
+
/** Git diff 情報 */
|
|
78
|
+
gitDiff: GitDiffInfo;
|
|
79
|
+
/** ファイルシステムアクセス */
|
|
80
|
+
fileSystem: FileSystemPort;
|
|
81
|
+
/** コンテンツ読み込み元パス (例: "frelio-data/site") */
|
|
82
|
+
contentRootPath: string;
|
|
83
|
+
/** 出力先ルートパス (例: "frelio-data/generated/data-json") */
|
|
84
|
+
outputRootPath: string;
|
|
85
|
+
/** 生成オプション */
|
|
86
|
+
options?: GenerateDataJsonOptions;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* 出力ファイル
|
|
90
|
+
*/
|
|
91
|
+
type OutputFile = {
|
|
92
|
+
/** 相対パス (例: "articles/my-article.json") */
|
|
93
|
+
path: string;
|
|
94
|
+
/** FrelioDataJson 形式のコンテンツ */
|
|
95
|
+
content: FrelioDataJson;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* generateDataJson 関数の出力結果
|
|
99
|
+
*/
|
|
100
|
+
type GenerateDataJsonResult = {
|
|
101
|
+
/** 生成されたファイル一覧 */
|
|
102
|
+
outputs: OutputFile[];
|
|
103
|
+
/** ビルドレポート */
|
|
104
|
+
report: GenerationReport;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* ビルド統計
|
|
108
|
+
*/
|
|
109
|
+
type GenerationStats = {
|
|
110
|
+
/** 更新されたファイル数(create/update は区別しない) */
|
|
111
|
+
updated: number;
|
|
112
|
+
/** 削除されたファイル数 */
|
|
113
|
+
deleted: number;
|
|
114
|
+
/** スキップされたファイル数 */
|
|
115
|
+
skipped: number;
|
|
116
|
+
/** エラー数 */
|
|
117
|
+
errors: number;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* ビルドレポート
|
|
121
|
+
* CMS-admin で表示するためのレポート形式
|
|
122
|
+
*/
|
|
123
|
+
type GenerationReport = {
|
|
124
|
+
/** 生成日時 (ISO 8601) */
|
|
125
|
+
generatedAt: string;
|
|
126
|
+
/** ビルドモード */
|
|
127
|
+
mode: 'incremental' | 'full-rebuild';
|
|
128
|
+
/** 差分範囲(incremental の場合) */
|
|
129
|
+
diffRange?: string;
|
|
130
|
+
/** ドライランかどうか */
|
|
131
|
+
dryRun: boolean;
|
|
132
|
+
/** 統計情報 */
|
|
133
|
+
stats: GenerationStats;
|
|
134
|
+
/** 出力ファイル一覧 */
|
|
135
|
+
outputs: GenerationOutputEntry[];
|
|
136
|
+
/** エラー一覧 */
|
|
137
|
+
errors: GenerationError[];
|
|
138
|
+
/** 警告一覧 */
|
|
139
|
+
warnings: GenerationWarning[];
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* 出力ファイルエントリ
|
|
143
|
+
*/
|
|
144
|
+
type GenerationOutputEntry = {
|
|
145
|
+
/** ファイルパス */
|
|
146
|
+
path: string;
|
|
147
|
+
/** ステータス */
|
|
148
|
+
status: 'updated' | 'deleted';
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* エラーコード
|
|
152
|
+
*/
|
|
153
|
+
type GenerationErrorCode = 'RELATION_NOT_FOUND' | 'CONTENT_NOT_FOUND' | 'INVALID_TEMPLATE_VAR' | 'INVALID_JSON' | 'FILTER_ERROR' | 'CIRCULAR_REFERENCE' | 'INVALID_OUTPUT_PATH' | 'DUPLICATE_OUTPUT_PATH';
|
|
154
|
+
/**
|
|
155
|
+
* 生成エラー
|
|
156
|
+
*/
|
|
157
|
+
type GenerationError = {
|
|
158
|
+
/** エラーコード */
|
|
159
|
+
code: GenerationErrorCode;
|
|
160
|
+
/** 対象の出力パス */
|
|
161
|
+
outputPath?: string;
|
|
162
|
+
/** 対象のコンテンツID */
|
|
163
|
+
contentId?: string;
|
|
164
|
+
/** 対象のフィールド名 */
|
|
165
|
+
field?: string;
|
|
166
|
+
/** エラーメッセージ */
|
|
167
|
+
message: string;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* 警告コード
|
|
171
|
+
*/
|
|
172
|
+
type GenerationWarningCode = 'EMPTY_LIST' | 'TRUNCATED_RELATION' | 'DEFAULT_VALUE_USED';
|
|
173
|
+
/**
|
|
174
|
+
* 生成警告
|
|
175
|
+
*/
|
|
176
|
+
type GenerationWarning = {
|
|
177
|
+
/** 警告コード */
|
|
178
|
+
code: GenerationWarningCode;
|
|
179
|
+
/** 対象の出力パス */
|
|
180
|
+
outputPath?: string;
|
|
181
|
+
/** 警告メッセージ */
|
|
182
|
+
message: string;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* 分類された変更ファイル
|
|
186
|
+
*/
|
|
187
|
+
type ClassifiedChanges = {
|
|
188
|
+
/** コンテンツファイルの変更 */
|
|
189
|
+
contents: {
|
|
190
|
+
added: string[];
|
|
191
|
+
modified: string[];
|
|
192
|
+
deleted: string[];
|
|
193
|
+
};
|
|
194
|
+
/** テンプレートの変更 */
|
|
195
|
+
templates: {
|
|
196
|
+
added: string[];
|
|
197
|
+
modified: string[];
|
|
198
|
+
deleted: string[];
|
|
199
|
+
};
|
|
200
|
+
/** コンテンツタイプ定義の変更 */
|
|
201
|
+
contentTypes: {
|
|
202
|
+
added: string[];
|
|
203
|
+
modified: string[];
|
|
204
|
+
deleted: string[];
|
|
205
|
+
};
|
|
206
|
+
/** パーツファイルの変更 */
|
|
207
|
+
parts: {
|
|
208
|
+
added: string[];
|
|
209
|
+
modified: string[];
|
|
210
|
+
deleted: string[];
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* 再生成が必要な出力パスとその理由
|
|
215
|
+
*/
|
|
216
|
+
type RegenerationTarget = {
|
|
217
|
+
/** 出力パス(パターン or 具体的パス) */
|
|
218
|
+
outputPath: string;
|
|
219
|
+
/** 再生成の理由 */
|
|
220
|
+
reason: 'content_changed' | 'template_changed' | 'schema_changed' | 'parts_changed' | 'deleted' | 'full_rebuild';
|
|
221
|
+
/** 関連するコンテンツID(detail の場合) */
|
|
222
|
+
contentId?: string;
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* パース済みコンテンツ
|
|
226
|
+
*/
|
|
227
|
+
type ParsedContent = {
|
|
228
|
+
/** コンテンツID (UUID) */
|
|
229
|
+
contentId: string;
|
|
230
|
+
/** コンテンツタイプID */
|
|
231
|
+
contentTypeId: string;
|
|
232
|
+
/** slug */
|
|
233
|
+
slug: string;
|
|
234
|
+
/** タイトル */
|
|
235
|
+
title: string;
|
|
236
|
+
/** ステータス */
|
|
237
|
+
status: string;
|
|
238
|
+
/** コンテンツデータ */
|
|
239
|
+
data: Record<string, unknown>;
|
|
240
|
+
/** 作成日時 */
|
|
241
|
+
createdAt: string;
|
|
242
|
+
/** 更新日時 */
|
|
243
|
+
updatedAt: string;
|
|
244
|
+
/** 公開日時 */
|
|
245
|
+
publishedAt: string | null;
|
|
246
|
+
/** 作成者 */
|
|
247
|
+
createdBy: string;
|
|
248
|
+
/** ファイルパス */
|
|
249
|
+
filePath: string;
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* レシピ実行コンテキスト
|
|
253
|
+
*/
|
|
254
|
+
type RecipeExecutionContext = {
|
|
255
|
+
/** コンテンツタイプ別のコンテンツ */
|
|
256
|
+
contentsByType: Map<string, ParsedContent[]>;
|
|
257
|
+
/** ファイルシステム */
|
|
258
|
+
fileSystem: FileSystemPort;
|
|
259
|
+
/** コンテンツルートパス */
|
|
260
|
+
contentRootPath: string;
|
|
261
|
+
/** 出力ルートパス */
|
|
262
|
+
outputRootPath: string;
|
|
263
|
+
/** エラー記録用 */
|
|
264
|
+
errors: GenerationError[];
|
|
265
|
+
/** 警告記録用 */
|
|
266
|
+
warnings: GenerationWarning[];
|
|
267
|
+
/** ログレベル */
|
|
268
|
+
logLevel: 'debug' | 'info' | 'quiet';
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* ロガーインターフェース
|
|
272
|
+
*/
|
|
273
|
+
type Logger = {
|
|
274
|
+
debug(message: string, ...args: unknown[]): void;
|
|
275
|
+
info(message: string, ...args: unknown[]): void;
|
|
276
|
+
error(message: string, ...args: unknown[]): void;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Main generator function
|
|
281
|
+
*
|
|
282
|
+
* FrelioBuildDataRecipe に従って FrelioDataJson を生成するメイン関数
|
|
283
|
+
*/
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* FrelioDataJson を生成
|
|
287
|
+
*
|
|
288
|
+
* @param input 入力パラメータ
|
|
289
|
+
* @returns 生成結果(outputs + report)
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* import { generateDataJson } from '@c-time/frelio-data-json-generator'
|
|
294
|
+
*
|
|
295
|
+
* const result = await generateDataJson({
|
|
296
|
+
* recipe,
|
|
297
|
+
* dependencyMap,
|
|
298
|
+
* gitDiff,
|
|
299
|
+
* fileSystem: new NodeFileSystem(),
|
|
300
|
+
* contentRootPath: 'frelio-data/site',
|
|
301
|
+
* outputRootPath: 'frelio-data/generated/data-json',
|
|
302
|
+
* options: {
|
|
303
|
+
* fullRebuild: false,
|
|
304
|
+
* dryRun: false,
|
|
305
|
+
* logLevel: 'info',
|
|
306
|
+
* },
|
|
307
|
+
* })
|
|
308
|
+
*
|
|
309
|
+
* // 結果を処理
|
|
310
|
+
* for (const output of result.outputs) {
|
|
311
|
+
* writeFile(output.path, JSON.stringify(output.content, null, 2))
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
declare function generateDataJson(input: GenerateDataJsonInput): Promise<GenerateDataJsonResult>;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Node.js implementation of FileSystemPort
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Node.js ファイルシステム実装
|
|
323
|
+
*
|
|
324
|
+
* @example
|
|
325
|
+
* ```typescript
|
|
326
|
+
* import { NodeFileSystem } from '@c-time/frelio-data-json-generator'
|
|
327
|
+
*
|
|
328
|
+
* const fileSystem = new NodeFileSystem()
|
|
329
|
+
* const content = await fileSystem.readFile('path/to/file.json')
|
|
330
|
+
* ```
|
|
331
|
+
*/
|
|
332
|
+
declare class NodeFileSystem implements FileSystemPort {
|
|
333
|
+
/**
|
|
334
|
+
* ファイルを読み込む
|
|
335
|
+
*
|
|
336
|
+
* @param path ファイルパス
|
|
337
|
+
* @returns ファイル内容(UTF-8)
|
|
338
|
+
* @throws ファイルが存在しない場合
|
|
339
|
+
*/
|
|
340
|
+
readFile(path: string): Promise<string>;
|
|
341
|
+
/**
|
|
342
|
+
* ファイルの存在確認
|
|
343
|
+
*
|
|
344
|
+
* @param path ファイルパス
|
|
345
|
+
* @returns 存在すれば true
|
|
346
|
+
*/
|
|
347
|
+
exists(path: string): Promise<boolean>;
|
|
348
|
+
/**
|
|
349
|
+
* glob パターンにマッチするファイル一覧を取得
|
|
350
|
+
*
|
|
351
|
+
* @param pattern glob パターン
|
|
352
|
+
* @returns マッチしたファイルパスの配列
|
|
353
|
+
*/
|
|
354
|
+
listFiles(pattern: string): Promise<string[]>;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Git diff utilities
|
|
359
|
+
*/
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* git diff --name-status の出力をパース
|
|
363
|
+
*
|
|
364
|
+
* @param diffText git diff --name-status の出力
|
|
365
|
+
* @returns GitDiffInfo
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* parseGitDiff(`A\tcontents/published/article/123.json
|
|
369
|
+
* M\ttemplates/index.html
|
|
370
|
+
* D\tcontents/published/article/old.json`)
|
|
371
|
+
* // => { added: [...], modified: [...], deleted: [...] }
|
|
372
|
+
*/
|
|
373
|
+
declare function parseGitDiff(diffText: string): GitDiffInfo;
|
|
374
|
+
/**
|
|
375
|
+
* 指定した範囲の git diff を取得してパース
|
|
376
|
+
*
|
|
377
|
+
* @param diffRange 差分範囲 (例: "origin/main...HEAD")
|
|
378
|
+
* @returns GitDiffInfo
|
|
379
|
+
* @throws コマンド実行に失敗した場合
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* const diff = await getGitDiff('origin/main...HEAD')
|
|
383
|
+
*/
|
|
384
|
+
declare function getGitDiff(diffRange: string): Promise<GitDiffInfo>;
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Logger utility
|
|
388
|
+
*/
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* ロガーを作成
|
|
392
|
+
*
|
|
393
|
+
* @param level ログレベル
|
|
394
|
+
* @returns Logger インスタンス
|
|
395
|
+
*/
|
|
396
|
+
declare function createLogger(level: 'debug' | 'info' | 'quiet'): Logger;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Change detector - classifies git diff by file type
|
|
400
|
+
*/
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* git diff をファイル種別に分類
|
|
404
|
+
*
|
|
405
|
+
* @param gitDiff git diff 情報
|
|
406
|
+
* @returns 分類された変更ファイル
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* classifyChangedFiles({
|
|
410
|
+
* added: ['contents/published/article/123.json'],
|
|
411
|
+
* modified: ['templates/index.html'],
|
|
412
|
+
* deleted: []
|
|
413
|
+
* })
|
|
414
|
+
*/
|
|
415
|
+
declare function classifyChangedFiles(gitDiff: GitDiffInfo): ClassifiedChanges;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Scope calculator - determines which outputs need regeneration
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* 再生成スコープを計算
|
|
423
|
+
*
|
|
424
|
+
* @param changes 分類された変更ファイル
|
|
425
|
+
* @param dependencyMap 依存マップ
|
|
426
|
+
* @param recipe ビルドレシピ
|
|
427
|
+
* @returns 再生成対象の配列
|
|
428
|
+
*/
|
|
429
|
+
declare function calculateRegenerationScope(changes: ClassifiedChanges, dependencyMap: FrelioDependencyMap, recipe: FrelioBuildDataRecipe): RegenerationTarget[];
|
|
430
|
+
/**
|
|
431
|
+
* フルリビルド用の全出力パスを取得
|
|
432
|
+
*
|
|
433
|
+
* @param dependencyMap 依存マップ
|
|
434
|
+
* @returns 全 outputPath の RegenerationTarget 配列
|
|
435
|
+
*/
|
|
436
|
+
declare function getAllOutputPaths(dependencyMap: FrelioDependencyMap): RegenerationTarget[];
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Parts expander - expands scope based on template parts changes
|
|
440
|
+
*/
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* パーツ変更の影響を拡張
|
|
444
|
+
*
|
|
445
|
+
* @param changedParts 変更されたパーツファイルのパス
|
|
446
|
+
* @param templateIncludes テンプレートインクルード設定
|
|
447
|
+
* @param dependencyMap 依存マップ
|
|
448
|
+
* @returns 影響を受ける outputPath の配列
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* // templateIncludes: { "_parts/*.html": ["*"] }
|
|
452
|
+
* // changedParts: ["templates/_parts/header.html"]
|
|
453
|
+
* // => 全 outputPath が影響を受ける
|
|
454
|
+
*/
|
|
455
|
+
declare function expandPartsAffectedScope(changedParts: string[], templateIncludes: TemplateIncludes | undefined, dependencyMap: FrelioDependencyMap): RegenerationTarget[];
|
|
456
|
+
|
|
457
|
+
export { type ClassifiedChanges, type FileSystemPort, type GenerateDataJsonInput, type GenerateDataJsonOptions, type GenerateDataJsonResult, type GenerationError, type GenerationErrorCode, type GenerationOutputEntry, type GenerationReport, type GenerationStats, type GenerationWarning, type GenerationWarningCode, type GitDiffInfo, type Logger, NodeFileSystem, type OutputFile, type ParsedContent, type RecipeExecutionContext, type RegenerationTarget, calculateRegenerationScope, classifyChangedFiles, createLogger, expandPartsAffectedScope, generateDataJson, getAllOutputPaths, getGitDiff, parseGitDiff };
|