@@ -40,6 +40,17 @@ export async function generateDocs(names: string[]) {
4040 ctx . docSource = docSource ;
4141 } ,
4242 } ,
43+ {
44+ title : `Write English document` ,
45+ task : async ctx => {
46+ const { docSource } = ctx ;
47+ const dirname = path . dirname ( sourceFilePath ) ;
48+
49+ if ( docSource != null ) {
50+ await fs . writeFile ( `${ dirname } /${ name } .md` , docSource ) ;
51+ }
52+ } ,
53+ } ,
4354 {
4455 title : `Translate markdown to Korean` ,
4556 task : async ctx => {
@@ -48,37 +59,45 @@ export async function generateDocs(names: string[]) {
4859
4960 let isFileExists = false ;
5061 try {
51- await fs . access ( `${ dirname } /${ name } .md` ) ;
5262 await fs . access ( `${ dirname } /ko/${ name } .md` ) ;
5363 isFileExists = true ;
5464 } catch {
5565 isFileExists = false ;
5666 }
5767
58- if ( isFileExists && ( await fs . readFile ( `${ dirname } /${ name } .md` ) ) . toString ( ) === docSource ) {
59- return ;
68+ // Skip if Korean file already exists and English file hasn't changed
69+ if ( isFileExists ) {
70+ try {
71+ const existingEnglish = await fs . readFile ( `${ dirname } /${ name } .md` , 'utf-8' ) ;
72+ if ( existingEnglish === docSource ) {
73+ return ;
74+ }
75+ } catch {
76+ // Continue with translation if we can't read existing file
77+ }
6078 }
6179
6280 if ( docSource == null ) {
6381 throw new Error ( 'docSource is not found' ) ;
6482 }
6583
66- const translatedDoc = await translate ( docSource ) ;
67-
68- ctx . translatedDoc = translatedDoc ;
84+ try {
85+ const translatedDoc = await translate ( docSource ) ;
86+ ctx . translatedDoc = translatedDoc ;
87+ } catch ( error ) {
88+ // Log the error but don't fail the task - English doc is already saved
89+ console . warn ( `Translation failed for ${ name } : ${ error instanceof Error ? error . message : error } ` ) ;
90+ ctx . translatedDoc = null ;
91+ }
6992 } ,
7093 } ,
7194 {
72- title : `Write document files` ,
95+ title : `Write Korean document` ,
96+ skip : ctx => ctx . translatedDoc == null ,
7397 task : async ctx => {
74- const { docSource, translatedDoc } = ctx ;
75-
98+ const { translatedDoc } = ctx ;
7699 const dirname = path . dirname ( sourceFilePath ) ;
77100
78- if ( docSource != null ) {
79- await fs . writeFile ( `${ dirname } /${ name } .md` , docSource ) ;
80- }
81-
82101 if ( translatedDoc != null ) {
83102 await fs . mkdir ( `${ dirname } /ko` ) . catch ( e => {
84103 if ( e . code === 'EEXIST' ) {
@@ -92,7 +111,7 @@ export async function generateDocs(names: string[]) {
92111 } ,
93112 } ,
94113 ] ,
95- { concurrent : false , ctx : subCtx }
114+ { concurrent : false , ctx : subCtx , exitOnError : false }
96115 ) ,
97116 } ,
98117 ] ) ;
@@ -108,7 +127,8 @@ function parseJSDoc(source: string) {
108127
109128 const template = targetComment . tags . find ( tag => tag . tag === 'template' ) ;
110129
111- const description = targetComment . tags . find ( tag => tag . tag === 'description' ) ?. description ?? '' ;
130+ const description =
131+ targetComment . tags . find ( tag => tag . tag === 'description' ) ?. description ?? targetComment . description ?? '' ;
112132
113133 const params = targetComment . tags . filter ( tag => tag . tag === 'param' ) ;
114134
0 commit comments