DEV Community

Cover image for Refactoring?!

Posted on


My Github project repo: Repo
Commit: Commit


In this time's lab, 5 purpose is for students to do refactoring themselves opensource project. When I saw this lab 5, actually I was being happy because honestly after 3 times working with my collaborators the API's code is getting un-efficient and long. It doesn't mean my classmate's work is useless it was enough helpful, but just need to remodeling :)

What is changed..?

So, after reading this I quickly started to work for it. I separated 3part of to-do things for refactoring each refactoring are..

added start function to handle promise error

I realized that the try and catch function has a promise error, so I changed it like this

async function start() {
    try {
        const { argv } = getParams();
        const {
            input: fileOrDirectory,
            output: outputDir,
            stylesheet: cssUrl,
            config: config,
        } = argv;
        if(!fileOrDirectory && !config) {
            throw new Error("Please include an input filename or folder");

        await convertFilesToHTML(fileOrDirectory, cssUrl, lang, outputDir, config);
    } catch (err) {

Enter fullscreen mode Exit fullscreen mode

organized files

I separated some functions into another file.
Image description

reduced duplicated part

const convertToHTML part was duplicated, so I divided them as await getParamsData and await getFileData

exports.convertFilesToHTML = async (filename, cssUrl, lang = "en", outputDir = "dist", config) => {
    const paramsData = await getParamsData(filename, cssUrl, lang = "en", outputDir, config);

    const fileInfos = await getFileData(paramsData.input);

    //function part for generating an index file to go to sample pages.
    await createIndex(paramsData, fileInfos);    
Enter fullscreen mode Exit fullscreen mode

Combine all commit to one..

After finishing all refactoring part(currently) I merged all of the commits to one commit from lab 5's instruction(used squash)

commit 10b5254e98ca6dbbfd4982dc671ec14487164821 (HEAD -> master, refactoring)
Author: jsong89 <>
Date:   Thu Oct 14 20:14:47 2021 -0400

    Refactoring ssg to improve code maintainability:
      * added start function to handle promise error
      * organized files
      * reduced duplicated part
Enter fullscreen mode Exit fullscreen mode


After this lab, I realized how much important that before we are going to commit something should not commit every each of the small things. It will make other developers confuse what is the point of the commit and distracting them because too many lists are there. So, I will not commit every moment will carefully committing the essential part.

Discussion (0)