-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql-diff.js
96 lines (81 loc) · 2.69 KB
/
sql-diff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"use strict";
var fs = require("fs");
var async = require("async");
var path = require("path");
var args = require("optimist").
usage("Usage: $0 --output [path] --left [path] --right [path]").
demand(["left", "right", "output"]).
describe("left", "Left folder (earlier one) to compare").
describe("right", "Right folder (later one) to compare").
describe("output", "The name of file, to which report will be generated").
describe("rd", "Path to a dictionary which holds all possible renamings - should be a JSON file, where keys are " +
"old names and values - new names").
argv;
var leftDir = args.left;
var rightDir = args.right;
var diff = require("./lib/diff");
if (leftDir === rightDir) {
console.error("Cannot compare two same directories!");
process.exit(-1);
}
async.each([leftDir, rightDir], directoryExists, function(err) {
if (err) {
console.error("The provided directory does not exists", err);
process.exit(-1);
}
async.map([leftDir, rightDir], readDir, function(err, directories) {
if (err) {
console.error("Cannot read directory", err);
process.exit(-1);
}
var leftDirectory = directories[0];
var rightDirectory = directories[1];
var renamingDictionary;
if (args.rd) {
if (fs.existsSync(args.rd)) {
renamingDictionary = JSON.parse(fs.readFileSync(args.rd));
} else {
console.warn("Path to Renaming dictionary file has been provided, but this file does not exist. Ignoring");
}
}
diff.findDifferences({
left: leftDirectory,
right: rightDirectory,
output: args.output,
renamingDictionary: renamingDictionary,
done: function () {
console.log("Job finished successfully");
}
});
});
});
function directoryExists(dirPath, done) {
fs.exists(dirPath, function (exists) {
if (exists) {
fs.stat(dirPath, function(err, stats) {
if (err) {
done(err);
return;
}
if (stats.isDirectory()) {
done();
} else {
done("Is not a directory: " + dirPath);
}
});
} else {
done("Not exist: " + dirPath);
}
});
}
function readDir(directory, done) {
fs.readdir(directory, function(err, content) {
if (err) {
done(err, null);
return;
}
done(null, content.map(function (file) {
return directory + path.sep + file;
}));
});
}