-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
.forEach((ele) => { | ||
front += $(ele).html() + "<hr color='grey'>"; | ||
}); | ||
const back = $("body").html(); |
There was a problem hiding this comment.
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)}`); |
There was a problem hiding this comment.
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]}`); |
There was a problem hiding this comment.
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.
src/utils/logger.js
Outdated
callerName = "anonymous arrow function"; | ||
} | ||
const logMessage = `[${new Date().toLocaleString()}] - ${message} - [${callerName}]\n`; | ||
console.log(logMessage); | ||
fs.appendFile("src/output/log/" + LOG_FILE, logMessage, (err) => { |
There was a problem hiding this comment.
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);
}
});
}
There was a problem hiding this comment.
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.
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 (I thought you could merge too after PR approved, did I figure out something incorrectly?) then commit these changes I mentioned above to If I understood correctly, sure, I'll do that. |
Yeah. I've pushed a new commit to this PR. |
merge mkanki-dev to mkanki