11import { readFileSync , writeFileSync } from "node:fs" ;
22import path from "node:path" ;
33import { fetchMetadata , findLinkToLatestVersion } from "@fluffylabs/links-metadata" ;
4- import { convertToNotes } from "./convert-to-notes" ;
4+ import { convertToNotes , saveNotes } from "./convert-to-notes" ;
55
66export class MessagesLogger {
7- constructor ( private readonly roomId : string ) { }
7+ constructor (
8+ private readonly roomId : string ,
9+ private readonly notesLabels : string [ ] ,
10+ ) { }
811
912 private generatePermalink ( eventId : string ) : string {
1013 return `https://matrix.to/#/${ this . roomId } /${ eventId } ` ;
@@ -26,6 +29,8 @@ export class MessagesLogger {
2629
2730 const majorVersion = `${ versionName . split ( "." ) . slice ( 0 , 2 ) . join ( "." ) } .x` ;
2831 const outputFilename = `output/messages-${ majorVersion } .json` ;
32+ const notesOutputFilename = `output/notes-${ majorVersion } .json` ;
33+ const labels = this . notesLabels . map ( ( x ) => x . replace ( "$MAJOR_VERSION" , majorVersion ) ) ;
2934
3035 const link = this . generatePermalink ( eventId ) ;
3136 const newMessage = {
@@ -36,15 +41,18 @@ export class MessagesLogger {
3641 } ;
3742
3843 let messages = [ ] ;
44+ // read previous log file
3945 try {
4046 messages = JSON . parse ( readFileSync ( path . resolve ( outputFilename ) , "utf-8" ) ) ;
4147 } catch ( e ) { }
48+
49+ // append the new message and save.
4250 messages . push ( newMessage ) ;
4351 writeFileSync ( outputFilename , JSON . stringify ( messages ) ) ;
4452
45- const notesFilename = `output/notes-${ majorVersion } .json` ;
4653 try {
47- convertToNotes ( meta , outputFilename , notesFilename ) ;
54+ const notes = await convertToNotes ( meta , outputFilename , labels ) ;
55+ saveNotes ( notes , notesOutputFilename ) ;
4856 } catch ( e ) {
4957 console . error ( e ) ;
5058 }
0 commit comments