Skip to content

Commit

Permalink
Add watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored May 29, 2022
1 parent afe8be5 commit 30d35c0
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 20 deletions.
116 changes: 109 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@octokit/plugin-throttling": "^3.5.2",
"@octokit/rest": "18.0.0",
"colors": "1.4.0",
"cross-platform-file-watch": "^3.5.2",
"ec2-spot-notification": "^2.0.3",
"exponential-backoff": "^3.1.0",
"form-data": "^3.0.1",
Expand Down
3 changes: 0 additions & 3 deletions report.md

This file was deleted.

27 changes: 17 additions & 10 deletions src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const globby = require('globby');
const git = require('simple-git')('./');
const path = require('path');
const fs = require('fs');
const chokidar = require('chokidar');

const winston = require('winston');

Expand All @@ -22,8 +23,6 @@ const GITHUB = 'github';
const GITLAB = 'gitlab';
const BB = 'bitbucket';

const paths = new Set();

const uriNoTrailingSlash = (uri) => {
return uri.endsWith('/') ? uri.substr(0, uri.length - 1) : uri;
};
Expand Down Expand Up @@ -171,7 +170,21 @@ class CML {
const { remark } = await import('remark');
const { visit } = await import('unist-util-visit');

paths.add(markdownfile);
const watcher = chokidar.watch(markdownfile, {
persistent: true,

awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 100
}
});

if (watch) {
watcher.on('all', () => {
console.log('updating report...');
this.commentCreate({ ...opts, update: true, watch: false });
});
}

const publishLocalFiles = () => async (tree) => {
const nodes = [];
Expand All @@ -186,7 +199,7 @@ class CML {
return;
}
node.url = await this.publish({ ...opts, path: node.url });
paths.add(node.url);
watcher.add(node.url);
}
};

Expand All @@ -196,12 +209,6 @@ class CML {
if (publish)
report = String(await remark().use(publishLocalFiles).process(report));

if (watch)
setInterval(() => {
console.log('updating report...');
this.commentCreate({ ...opts, update: true, watch: false });
}, 16384); // TODO: use a proper file watcher on the `paths` set

let comment;
const updatableComment = (comments) => {
return comments.reverse().find(({ body }) => {
Expand Down

0 comments on commit 30d35c0

Please sign in to comment.