make syncer track directories

This commit is contained in:
Girish Ramakrishnan
2017-09-29 09:56:01 -07:00
parent 8b341e2bf8
commit 954224dafb
5 changed files with 418 additions and 19 deletions

33
src/test/common.js Normal file
View File

@@ -0,0 +1,33 @@
'use strict';
var fs = require('fs'),
mkdirp = require('mkdirp'),
path = require('path'),
rimraf = require('rimraf');
exports = module.exports = {
createTree: createTree
};
function createTree(root, obj) {
rimraf.sync(root);
mkdirp.sync(root);
function createSubTree(tree, curpath) {
for (var key in tree) {
if (typeof tree[key] === 'string') {
if (key.startsWith('link:')) {
fs.symlinkSync(tree[key], path.join(curpath, key.slice(5)));
} else {
fs.writeFileSync(path.join(curpath, key), tree[key], 'utf8');
}
} else {
fs.mkdirSync(path.join(curpath, key));
createSubTree(tree[key], path.join(curpath, key));
}
}
}
createSubTree(obj, root);
}