@@ -52,7 +52,6 @@ export type SearchIndexItem = {
52
52
53
53
export type Options = {
54
54
targetFilePaths : string [ ] ,
55
- exportFilePath : string ,
56
55
mainVirtualModule : string ,
57
56
modulesToHmrOnUpdate : string [ ] ,
58
57
fileVirtualModulePrefix ?: string ,
@@ -352,49 +351,6 @@ function countMarkers(markers: SearchIndexItem[]): { totalMarkers: number, total
352
351
return { totalMarkers, totalChildren } ;
353
352
}
354
353
355
- /**
356
- * 最終的なTypeScriptファイルを出力
357
- */
358
- function writeOutputFile ( outputPath : string , tsOutput : string ) : void {
359
- try {
360
- //fs.writeFileSync(outputPath, tsOutput, 'utf-8');
361
- // 強制的に出力させるためにViteロガーを使わない
362
- console . log ( `Successfully wrote search index to ${ outputPath } ` ) ;
363
- } catch ( error ) {
364
- logger . error ( '[create-search-index]: error writing output: ' , error ) ;
365
- }
366
- }
367
-
368
- /**
369
- * TypeScriptコード生成
370
- */
371
- function generateTypeScriptCode ( resolvedRootMarkers : SearchIndexItem [ ] ) : string {
372
- return `
373
- /*
374
- * SPDX-FileCopyrightText: syuilo and misskey-project
375
- * SPDX-License-Identifier: AGPL-3.0-only
376
- */
377
-
378
- // This file was automatically generated by create-search-index.
379
- // Do not edit this file.
380
-
381
- import { i18n } from '@/i18n.js';
382
-
383
- export type SearchIndexItem = {
384
- id: string;
385
- path?: string;
386
- label: string;
387
- keywords: string[];
388
- icon?: string;
389
- children?: SearchIndexItem[];
390
- };
391
-
392
- export const searchIndexes: SearchIndexItem[] = ${ customStringify ( resolvedRootMarkers ) } as const;
393
-
394
- export type SearchIndex = typeof searchIndexes;
395
- ` ;
396
- }
397
-
398
354
/**
399
355
* TypeScriptコード生成
400
356
*/
@@ -1161,32 +1117,6 @@ function parseArrayExpression(expr: string): any[] {
1161
1117
}
1162
1118
}
1163
1119
1164
- export async function analyzeVueProps ( options : Options , assigner : MarkerIdAssigner ) : Promise < void > {
1165
- initLogger ( options ) ;
1166
-
1167
- // 対象ファイルパスを glob で展開
1168
- const filePaths = options . targetFilePaths . reduce < string [ ] > ( ( acc , filePathPattern ) => {
1169
- const matchedFiles = glob . sync ( filePathPattern ) ;
1170
- return [ ...acc , ...matchedFiles ] ;
1171
- } , [ ] ) ;
1172
-
1173
- logger . info ( `Found ${ filePaths . length } matching files to analyze` ) ;
1174
- const files : [ string , string ] [ ] = filePaths . map ( filePath => {
1175
- const absolutePath = path . join ( process . cwd ( ) , filePath ) ;
1176
- const id = absolutePath . replace ( / \\ / g, '/' ) ; // 絶対パスに変換
1177
- const code = assigner . getCached ( id ) ; // options 経由でキャッシュ参照
1178
- if ( ! code ) { // キャッシュミスの場合
1179
- logger . error ( `Error: No cached code found for: ${ id } .` ) ; // エラーログ
1180
- throw new Error ( `No cached code found for: ${ id } .` ) ; // エラーを投げる
1181
- }
1182
- return [ id , code . code ] ;
1183
- } ) ;
1184
- analyzeVuePropsByFiles ( {
1185
- exportFilePath : options . exportFilePath ,
1186
- files,
1187
- } )
1188
- }
1189
-
1190
1120
export function collectFileMarkers ( files : [ id : string , code : string ] [ ] ) : AnalysisResult {
1191
1121
const allMarkers : SearchIndexItem [ ] = [ ] ;
1192
1122
for ( const [ id , code ] of files ) {
@@ -1220,12 +1150,6 @@ export function collectFileMarkers(files: [id: string, code: string][]): Analysi
1220
1150
} ;
1221
1151
}
1222
1152
1223
- export function analyzeVuePropsByFiles ( options : Pick < Options , 'exportFilePath' > & {
1224
- files : [ id : string , code : string ] [ ]
1225
- } ) : void {
1226
- writeOutputFile ( options . exportFilePath , generateTypeScriptCode ( collectSearchItemIndexes ( [ collectFileMarkers ( options . files ) ] ) ) ) ;
1227
- }
1228
-
1229
1153
interface MarkerRelation {
1230
1154
parentId ?: string ;
1231
1155
markerId : string ;
@@ -1478,27 +1402,6 @@ export class MarkerIdAssigner {
1478
1402
}
1479
1403
}
1480
1404
1481
- export async function generateSearchIndex ( options : Options , assigner : MarkerIdAssigner ) {
1482
- const filePaths = options . targetFilePaths . reduce < string [ ] > ( ( acc , filePathPattern ) => {
1483
- const matchedFiles = glob . sync ( filePathPattern ) ;
1484
- return [ ...acc , ...matchedFiles ] ;
1485
- } , [ ] ) ;
1486
-
1487
- const files : [ string , string ] [ ] = [ ] ;
1488
-
1489
- for ( const filePath of filePaths ) {
1490
- const id = path . resolve ( filePath ) ; // 絶対パスに変換
1491
- const code = fs . readFileSync ( filePath , 'utf-8' ) ; // ファイル内容を読み込む
1492
- const transformed = assigner . processFile ( normalizePath ( id ) , code ) ;
1493
- files . push ( [ id , transformed . code ] ) ;
1494
- }
1495
-
1496
- analyzeVuePropsByFiles ( {
1497
- exportFilePath : options . exportFilePath ,
1498
- files,
1499
- } )
1500
- }
1501
-
1502
1405
// Rollup プラグインとして export
1503
1406
export default function pluginCreateSearchIndex ( options : Options ) : PluginOption {
1504
1407
const assigner = new MarkerIdAssigner ( ) ;
@@ -1509,22 +1412,12 @@ export default function pluginCreateSearchIndex(options: Options): PluginOption
1509
1412
}
1510
1413
1511
1414
function createSearchIndex ( options : Options , assigner : MarkerIdAssigner ) : Plugin {
1512
- const isDevServer = process . env . NODE_ENV === 'development' ; // 開発サーバーかどうか
1513
-
1514
1415
initLogger ( options ) ; // ロガーを初期化
1515
1416
1516
1417
return {
1517
1418
name : 'createSearchIndex' ,
1518
1419
enforce : 'pre' ,
1519
1420
1520
- async buildStart ( ) {
1521
- if ( ! isDevServer ) {
1522
- return ;
1523
- }
1524
-
1525
- await generateSearchIndex ( options , assigner ) ;
1526
- } ,
1527
-
1528
1421
watchChange ( id ) {
1529
1422
assigner . onInvalidate ( id ) ;
1530
1423
} ,
@@ -1554,20 +1447,7 @@ function createSearchIndex(options: Options, assigner: MarkerIdAssigner): Plugin
1554
1447
return ;
1555
1448
}
1556
1449
1557
- // ファイルの内容が変更された場合は再処理を行う
1558
- const hasContentChanged = true ; // TODO
1559
-
1560
- const transformed = assigner . processFile ( id , code ) ;
1561
-
1562
- if ( isDevServer && hasContentChanged ) {
1563
- await analyzeVueProps ( options , assigner ) ; // ファイルが変更されたときのみ分析を実行
1564
- }
1565
-
1566
- return transformed ;
1567
- } ,
1568
-
1569
- async writeBundle ( ) {
1570
- await analyzeVueProps ( options , assigner ) ; // ビルド時にも analyzeVueProps を実行
1450
+ return assigner . processFile ( id , code ) ;
1571
1451
} ,
1572
1452
} ;
1573
1453
}
0 commit comments