|
@@ -66,8 +66,13 @@ class CommentsManager {
|
|
|
|
|
|
private static enqueueComment(comment: IComment, action: CommentAction): void {
|
|
|
const commentPath = `${CommentsManager.getClassDirPath(comment.root, comment.className)}/${comment.propertyName}`;
|
|
|
- if(fs.existsSync(commentPath))
|
|
|
+
|
|
|
+ action = CommentAction.Create;
|
|
|
+ const exists = fs.existsSync(commentPath);
|
|
|
+ if(exists)
|
|
|
action = CommentAction.Update;
|
|
|
+ if(exists && comment.text.length === 0)
|
|
|
+ action = CommentAction.Remove;
|
|
|
|
|
|
const queueComment: IQueueComment = Object.assign(comment, { action }) as IQueueComment;
|
|
|
|
|
@@ -97,16 +102,18 @@ class CommentsManager {
|
|
|
const commentPath = `${classDirPath}/${comment.propertyName}`;
|
|
|
|
|
|
let status = CommentUpdateStatus.Created;
|
|
|
-
|
|
|
- if (fs.existsSync(commentPath))
|
|
|
+ const exists = fs.existsSync(commentPath);
|
|
|
+ if(exists)
|
|
|
status = CommentUpdateStatus.Updated;
|
|
|
+ if(exists && comment.text.length === 0)
|
|
|
+ status = CommentUpdateStatus.Deleted;
|
|
|
|
|
|
await fs.promises.writeFile(commentPath, commentContent, { encoding: 'utf8' });
|
|
|
|
|
|
return { commentPath, status };
|
|
|
}
|
|
|
|
|
|
- public static async create(comment: IComment): Promise<CommentUpdateStatus> {
|
|
|
+ public static async update(comment: IComment): Promise<CommentUpdateStatus> {
|
|
|
if(CommentsManager.isSaving()) {
|
|
|
CommentsManager.enqueueComment(comment, CommentAction.Create);
|
|
|
return CommentUpdateStatus.Enqueued;
|
|
@@ -115,7 +122,21 @@ class CommentsManager {
|
|
|
CommentsManager.beginSave();
|
|
|
try {
|
|
|
const { commentPath, status } = await CommentsManager.createOrUpdateCommentFile(comment);
|
|
|
- const queueComment: IQueueComment = Object.assign(comment, { action: (status === CommentUpdateStatus.Created ? CommentAction.Create : CommentAction.Update) }) as IQueueComment;
|
|
|
+ let action = CommentAction.Create;
|
|
|
+
|
|
|
+ switch(status) {
|
|
|
+ case CommentUpdateStatus.Created:
|
|
|
+ action = CommentAction.Create;
|
|
|
+ break;
|
|
|
+ case CommentUpdateStatus.Updated:
|
|
|
+ action = CommentAction.Update;
|
|
|
+ break;
|
|
|
+ case CommentUpdateStatus.Deleted:
|
|
|
+ action = CommentAction.Remove;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ const queueComment: IQueueComment = Object.assign(comment, { action: action }) as IQueueComment;
|
|
|
await CommentsManager.commit([queueComment], [commentPath]);
|
|
|
CommentsManager.endSave();
|
|
|
return status;
|
|
@@ -190,7 +211,8 @@ class CommentsManager {
|
|
|
const message = `"${comment.author} ${comment.action === CommentAction.Create ? 'created' : (comment.action === CommentAction.Update ? 'updated' : 'deleted')} a comment for ${comment.root}/${comment.className}:${comment.propertyName}"`;
|
|
|
commitMessages.push(message);
|
|
|
|
|
|
- await execAsync(`git ${comment.action === CommentAction.Create || comment.action === CommentAction.Update ? 'add' : 'rm'} ${commentPath}`, { encoding: 'utf8', cwd: CommentsManager.CommentsFSRoot });
|
|
|
+ //await execAsync(`git ${comment.action === CommentAction.Create || comment.action === CommentAction.Update ? 'add' : 'rm'} ${commentPath}`, { encoding: 'utf8', cwd: CommentsManager.CommentsFSRoot });
|
|
|
+ await execAsync(`git add ${commentPath}`, { encoding: 'utf8', cwd: CommentsManager.CommentsFSRoot });
|
|
|
}
|
|
|
|
|
|
await execAsync(`git commit -m ${commitMessages.join(' -m ')}`, { encoding: 'utf8', cwd: CommentsManager.CommentsFSRoot });
|
|
@@ -213,7 +235,7 @@ class CommentsManager {
|
|
|
const comment = queueItem.comment;
|
|
|
const commentPath = queueItem.commentPath;
|
|
|
|
|
|
- switch(comment.action) {
|
|
|
+ /*switch(comment.action) {
|
|
|
case CommentAction.Create:
|
|
|
case CommentAction.Update:
|
|
|
await CommentsManager.createOrUpdateCommentFile(comment);
|
|
@@ -221,7 +243,9 @@ class CommentsManager {
|
|
|
case CommentAction.Remove:
|
|
|
await CommentsManager.deleteCommentFile(comment.root, comment.className, comment.propertyName);
|
|
|
break;
|
|
|
- }
|
|
|
+ }*/
|
|
|
+
|
|
|
+ await CommentsManager.createOrUpdateCommentFile(comment);
|
|
|
|
|
|
comments.push(comment);
|
|
|
commentsPaths.push(commentPath);
|