Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: async issues solved #9

Merged
merged 3 commits into from
Aug 16, 2023
Merged

fix: async issues solved #9

merged 3 commits into from
Aug 16, 2023

Conversation

Quasimurdock
Copy link
Owner

merge mkanki-dev to mkanki

@Quasimurdock Quasimurdock requested a review from serifold August 15, 2023 04:42
@Quasimurdock Quasimurdock changed the title [fix] async issues solved fix: async issues solved Aug 15, 2023
@Quasimurdock Quasimurdock added bug Something isn't working enhancement New feature or request labels Aug 15, 2023
.forEach((ele) => {
front += $(ele).html() + "<hr color='grey'>";
});
const back = $("body").html();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some HTML file could be empty, we could throw a warn:

                if (!front || !back) {
                  writeToLog(`[WARN] The file ${file} is empty`);
                }

Or just reject() the blank file's generation. I prefer reject it, cause generating a blank card seems meaningless.

src/mkanki.js Outdated
// addNote()
});
const result = await Promise.allSettled(files.map(addNote));
console.log(`[INFO] addNotes() result: ${JSON.stringify(result)}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These results are too long, we don't need all of them. We only care about errors.

    result.forEach((e, i) => {
      if (e.status === "rejected") {
        writeToLog(
          `[ERR] ADD ${files[i].match(/^(.+)\.html$/)[1]} FAILED: ${e.reason}`
        );
      }
    });

src/mkanki.js Outdated
tagResult
)
);
console.log(`[INFO] ${++cnt}/${files.length} CURRENT WORD: ${file.match(/^(.+)\.html$/)[1]}`);
Copy link
Collaborator

@serifold serifold Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we put common.css in src/output/html, then the number of HTML files should minus 1:

                console.log(
                  `[INFO] ${++cnt}/${files.length - 1} CURRENT WORD: ${
                    file.match(/^(.+)\.html$/)[1]
                  }`
                );

Or we could move common.css to a src/css folder, it isn't a HTML file after all.

callerName = "anonymous arrow function";
}
const logMessage = `[${new Date().toLocaleString()}] - ${message} - [${callerName}]\n`;
console.log(logMessage);
fs.appendFile("src/output/log/" + LOG_FILE, logMessage, (err) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The src/output/log/log_html2notes.txt doesn't exist by default now. We should create a log folder, or also create a blank log_html2notes.txt in the log folder.

const LOG_FILE_PATH = "src/output/log/" + LOG_FILE;

  if (!fs.existsSync(LOG_FILE_PATH)) {
    fs.writeFile(LOG_FILE_PATH, "", (err) => {
      if (err) {
        console.log(`[ERR] Failed to create ${LOG_FILE}:`, err);
      }
    });
  }

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also create a blank log_html2notes.txt in the log folder

fs.appendFile actually creates a new file if it doesn't exist:

Asynchronously append data to a file, creating the file if it does not yet exist. (ref)

But the directory of log is needed. I've added in the latest commit.

@Quasimurdock
Copy link
Owner Author

Quasimurdock commented Aug 16, 2023

@serifold Hi appreciate ur suggestions.

Can u give organize and make a PR for them after I merging this one? Thx a lot!

Never mind. I'll try to see if I can make a new commit to this PR.

@serifold
Copy link
Collaborator

serifold commented Aug 16, 2023

@serifold Hi appreciate ur suggestions.

Can u give organize and make a PR for them after I merging this one? Thx a lot!

Never mind. I'll try to see if I can make a new commit to this PR.

Excuse me, I'm not familiar with github merge, do you mean I could Merge pull request first (by default 'Create a merge commit'):

(I thought you could merge too after PR approved, did I figure out something incorrectly?)

then commit these changes I mentioned above to mkanki-dev, and make a PR to merge these changes to mkanki, finally you'll merge mkanki to main?

If I understood correctly, sure, I'll do that.

@Quasimurdock
Copy link
Owner Author

I thought you could merge too after PR approved

Yeah. I've pushed a new commit to this PR.

@Quasimurdock Quasimurdock merged commit 91c52d9 into mkanki Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants