From 5e80998301d7fa5c9c3e4ecceb4f415d5e84cf53 Mon Sep 17 00:00:00 2001 From: epikem Date: Mon, 19 Jul 2021 17:53:45 +0900 Subject: [PATCH] fix failing github actions - use readdirSync tagHandler sometimes receives undefined tag node and i gues this is because of readdir --- scripts/blog-updater/src/handle.js | 75 ++++++++++++++---------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/scripts/blog-updater/src/handle.js b/scripts/blog-updater/src/handle.js index 682b0f16..9fe32fc0 100644 --- a/scripts/blog-updater/src/handle.js +++ b/scripts/blog-updater/src/handle.js @@ -32,53 +32,50 @@ fs.mkdirSync(writeDir, { recursive: true, }); -fs.readdir(IN_DIR, (err, filenames) => { - if(err) { - throw err; - } +const files = fs.readdirSync(IN_DIR); - filenames.forEach(filename => { - let filenameinfo = path.parse(filename); +files.forEach(filename => { + let filenameinfo = path.parse(filename); - if(filenameinfo.ext != '.md') { - console.info('skip file', filename); - return; - } + if(filenameinfo.ext != '.md') { + console.info('skip file', filename); + return; + } - const readFilePath = path.join(IN_DIR, filename); - - const file_info = { - // NOTE: USING FILENAME AS DATE, 다른 로그 할때는 변경할것. - date: filenameinfo.name.slice(0,10), - private: filenameinfo.name.slice(-2) == '-p' - }; - - if(file_info.private){ - console.warn('private. skipping', filename); - return; - } + const readFilePath = path.join(IN_DIR, filename); + + const file_info = { + // NOTE: USING FILENAME AS DATE, 다른 로그 할때는 변경할것. + date: filenameinfo.name.slice(0,10), + private: filenameinfo.name.slice(-2) == '-p' + }; + + if(file_info.private){ + console.warn('private. skipping', filename); + return; + } - const readFile = fs.readFileSync(readFilePath, { - encoding: 'utf8' - }); + const readFile = fs.readFileSync(readFilePath, { + encoding: 'utf8' + }); - // PROCESS - const result = processFile(readFile, { - ...file_info, - }); + // PROCESS + const result = processFile(readFile, { + ...file_info, + }); - console.info('done', filename); - // console.info('done', filename, 'result DATA: ', result); + console.info('done', filename); + // console.info('done', filename, 'result DATA: ', result); - const writeFilePath = path.join(writeDir, file_info.date + '-' + result.data.title.split(/\s/g).join('-') + '.md'); + const writeFilePath = path.join(writeDir, file_info.date + '-' + result.data.title.split(/\s/g).join('-') + '.md'); + + fs.writeFileSync(writeFilePath, result.runData.toString({ + encoding: 'utf-8' + }), { + encoding: 'utf-8' + }); +}); - fs.writeFileSync(writeFilePath, result.runData.toString({ - encoding: 'utf-8' - }), { - encoding: 'utf-8' - }); - }) -}) // define a unified js process that does: // 1. parses markdown to tree