@@ -319,6 +319,57 @@ ${bookContent}
319
319
// MAIN EXECUTION LOGIC
320
320
// ==========================================
321
321
322
+ // Simple reusable progress manager
323
+ type ProgressState = {
324
+ completedSessions : string [ ]
325
+ sessionNotes : Record < string , string >
326
+ mainBookCreated ?: boolean
327
+ mainBookUrl ?: string
328
+ startedAt ?: string
329
+ completedAt ?: string
330
+ }
331
+
332
+ function createProgressManager ( progressFilePath : string ) {
333
+ const resolvedPath = path . resolve ( progressFilePath )
334
+
335
+ function load ( ) : ProgressState | null {
336
+ if ( ! fs . existsSync ( resolvedPath ) ) return null
337
+ try {
338
+ const data = JSON . parse ( fs . readFileSync ( resolvedPath , 'utf8' ) )
339
+ return data
340
+ } catch ( e : any ) {
341
+ console . warn ( `⚠️ Failed to load progress: ${ e . message } ` )
342
+ return null
343
+ }
344
+ }
345
+
346
+ function initFresh ( ) : ProgressState {
347
+ if ( fs . existsSync ( resolvedPath ) ) {
348
+ try { fs . unlinkSync ( resolvedPath ) } catch { }
349
+ }
350
+ return {
351
+ completedSessions : [ ] ,
352
+ sessionNotes : { } ,
353
+ startedAt : new Date ( ) . toISOString ( ) ,
354
+ }
355
+ }
356
+
357
+ function save ( progress : ProgressState ) {
358
+ try { fs . writeFileSync ( resolvedPath , JSON . stringify ( progress , null , 2 ) ) } catch { }
359
+ }
360
+
361
+ function isSessionDone ( id : string , p : ProgressState ) {
362
+ return p . completedSessions . includes ( id )
363
+ }
364
+
365
+ function markSessionDone ( id : string , noteUrl : string , p : ProgressState ) {
366
+ if ( ! p . completedSessions . includes ( id ) ) p . completedSessions . push ( id )
367
+ p . sessionNotes [ id ] = noteUrl
368
+ }
369
+
370
+ return { load, initFresh, save, isSessionDone, markSessionDone, progressFilePath : resolvedPath }
371
+ }
372
+
322
373
/**
323
374
* Main function that orchestrates the entire book mode note creation process
324
375
*/
@@ -340,9 +391,32 @@ async function main(): Promise<void> {
340
391
const sessionList = loadAndProcessSessions ( )
341
392
console . log ( `Processing ${ sessionList . length } sessions...` )
342
393
394
+ // Progress/resume support
395
+ const pm = createProgressManager ( path . join ( __dirname , 'progress.json' ) )
396
+ const RESUME_MODE = process . env . RESUME_MODE === 'true' || process . argv . includes ( '--resume' )
397
+ let progress : ProgressState | null = null
398
+ if ( RESUME_MODE ) {
399
+ progress = pm . load ( )
400
+ if ( ! progress ) {
401
+ console . error ( 'No progress.json found. Start without --resume to create it.' )
402
+ process . exit ( 1 )
403
+ }
404
+ console . log ( `🔄 Resume mode: ${ progress . completedSessions . length } sessions already created` )
405
+ } else {
406
+ progress = pm . initFresh ( )
407
+ console . log ( '🚀 Fresh run: progress initialized' )
408
+ }
409
+
343
410
// Create individual session notes
344
411
console . log ( '\n=== Creating Individual Session Notes ===' )
345
412
for ( let data of sessionList ) {
413
+ if ( pm . isSessionDone ( data . id , progress ! ) ) {
414
+ // restore URL
415
+ if ( progress ! . sessionNotes [ data . id ] ) data . noteUrl = progress ! . sessionNotes [ data . id ] . replace ( `${ getHackMDHost ( ) } /` , '' )
416
+ console . log ( `⏭️ Skip existing: ${ data . title } ` )
417
+ continue
418
+ }
419
+
346
420
const noteContent = generateSessionNoteContent ( data )
347
421
348
422
const noteData = {
@@ -355,6 +429,8 @@ async function main(): Promise<void> {
355
429
try {
356
430
const note = await api . createTeamNote ( TEAM_PATH , noteData )
357
431
data . noteUrl = note . shortId
432
+ pm . markSessionDone ( data . id , `${ getHackMDHost ( ) } /${ note . shortId } ` , progress ! )
433
+ pm . save ( progress ! )
358
434
console . log ( `✓ Created note for: ${ data . title } ` )
359
435
} catch ( error : any ) {
360
436
console . error ( `✗ Failed to create note for ${ data . title } :` , error . message )
@@ -395,6 +471,12 @@ async function main(): Promise<void> {
395
471
console . log ( `✓ Book URL: ${ hackmdHost } /${ mainBook . shortId } ` )
396
472
console . log ( '\n🎉 Book mode conference notes created successfully!' )
397
473
console . log ( `📚 Main book contains links to ${ sessionUrls . length } session notes` )
474
+ if ( progress ) {
475
+ progress . mainBookCreated = true
476
+ progress . mainBookUrl = `${ hackmdHost } /${ mainBook . shortId } `
477
+ progress . completedAt = new Date ( ) . toISOString ( )
478
+ pm . save ( progress )
479
+ }
398
480
} catch ( error : any ) {
399
481
console . error ( '✗ Failed to create main book:' , error . message )
400
482
}
0 commit comments