Skip to content

Commit 13d24a8

Browse files
Add files watch
1 parent b0b8b78 commit 13d24a8

7 files changed

Lines changed: 30 additions & 16 deletions

File tree

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"scripts": {
88
"start": "yarn start:client & yarn start:server",
99
"start:client": "cd src/public && webpack --progress --colors --watch --env dev",
10-
"start:server": "nodemon --inspect ./src/server/index.js"
10+
"start:server": "nodemon --inspect ./src/server/index.js",
11+
"start:demo": "node ./src/server/index.js"
1112
},
1213
"dependencies": {
1314
"antd": "^3.5.0",
@@ -18,9 +19,11 @@
1819
"babel-plugin-transform-react-jsx": "^6.24.1",
1920
"babel-traverse": "^6.26.0",
2021
"babylon": "^6.18.0",
22+
"chokidar": "^2.0.3",
2123
"css-loader": "^0.28.11",
2224
"d3-flextree": "^2.1.1",
2325
"directory-tree": "^2.1.0",
26+
"lodash.debounce": "^4.0.8",
2427
"madge": "^3.0.1",
2528
"react": "^16.3.2",
2629
"react-dom": "^16.3.2",

src/public/dist/bundle.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66779,12 +66779,13 @@ var SourceTree = function (_React$Component) {
6677966779
_createClass(SourceTree, [{
6678066780
key: 'componentDidMount',
6678166781
value: function componentDidMount() {
66782-
this.svgDraw = (0, _svg2.default)(this.svgMountNode).size(500, 500); //TODO: props for size
66782+
this.svgDraw = (0, _svg2.default)(this.svgMountNode).size(1000, 800); //TODO: props for size
6678366783
this.drawTree(this.props.treeData, this.svgDraw);
6678466784
}
6678566785
}, {
6678666786
key: 'componentDidUpdate',
6678766787
value: function componentDidUpdate() {
66788+
this.svgDraw.clear();
6678866789
this.drawTree(this.props.treeData, this.svgDraw);
6678966790
}
6679066791

@@ -66978,10 +66979,8 @@ var d3test = function d3test(treeData) {
6697866979
});
6697966980
};
6698066981

66981-
astTest();
66982-
6698366982
exports.default = function (p) {
66984-
astTest();
66983+
//astTest();
6698566984
//d3test(p);
6698666985
};
6698766986

src/public/dist/bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/js/components/tree-diagram/SourceTree.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ class SourceTree extends React.Component {
1111
}
1212

1313
componentDidMount() {
14-
this.svgDraw = SVG(this.svgMountNode).size(500, 500); //TODO: props for size
14+
this.svgDraw = SVG(this.svgMountNode).size(1000, 800); //TODO: props for size
1515
this.drawTree(this.props.treeData, this.svgDraw);
1616
}
1717

1818
componentDidUpdate() {
19+
this.svgDraw.clear();
1920
this.drawTree(this.props.treeData, this.svgDraw);
2021
}
2122

src/public/js/utils/dev-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ const d3test = treeData => {
5151
});
5252
};
5353

54-
astTest();
55-
5654
export default p => {
57-
astTest();
55+
//astTest();
5856
//d3test(p);
5957
};

src/server/project-source-watcher.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const directoryTree = require('directory-tree');
22
const codecrumbs = require('./codecrumbs/codecrumbs');
33
const file = require('./utils/file');
44
const madge = require('madge');
5+
const chokidar = require('chokidar');
6+
const debounce = require('lodash.debounce');
57

68
const getDirFiles = projectDir => {
79
const filesList = [];
@@ -21,7 +23,7 @@ const getDependenciesList = (projectDir, entryPoint) => {
2123
return madge(projectDir + entryPoint).then(res => res.obj());
2224
};
2325

24-
const getProjectSourceStats = (projectDir, entryPoint) => {
26+
const grabProjectSourceState = (projectDir, entryPoint) => {
2527
const dirFiles = getDirFiles(projectDir);
2628

2729
return Promise.all([
@@ -41,11 +43,22 @@ const getProjectSourceStats = (projectDir, entryPoint) => {
4143
}));
4244
};
4345

44-
const subscribeOnChange = (projectDir, entryPoint, fn) => {
45-
//first response on registration
46-
getProjectSourceStats(projectDir, entryPoint).then(fn);
46+
const createWatcher = (dir, fn) => {
47+
const DELAY = 500;
48+
49+
const watcher = chokidar.watch(dir);
50+
watcher.on('all', debounce(fn, DELAY));
4751

48-
//watch changes here and trigger fn()
52+
return watcher;
53+
};
54+
55+
const subscribeOnChange = (projectDir, entryPoint, fn) => {
56+
//use watcher.close(); to stop watching
57+
return createWatcher(projectDir, () => {
58+
console.log('Update project source state...');
59+
//TODO: add more specific handling, to re-draw only changed files
60+
grabProjectSourceState(projectDir, entryPoint).then(fn);
61+
});
4962
};
5063

5164
module.exports = {

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,7 @@ chardet@^0.4.0:
12051205
version "0.4.2"
12061206
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2"
12071207

1208-
chokidar@^2.0.2:
1208+
chokidar@^2.0.2, chokidar@^2.0.3:
12091209
version "2.0.3"
12101210
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.0.3.tgz#dcbd4f6cbb2a55b4799ba8a840ac527e5f4b1176"
12111211
dependencies:

0 commit comments

Comments
 (0)