-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.js
executable file
·66 lines (57 loc) · 1.54 KB
/
index.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
#!/usr/bin/env node
const chalk = require("chalk");
const finder = require("find-root");
const jsonfile = require("jsonfile");
const fs = require("fs-extra");
const {
dependencyBuilder,
compare,
copyChanges,
writeLockFile,
deleteCache,
deleteChanges,
writeChanges
} = require("./lib/utils");
const log = console.log;
try {
const root = finder(process.cwd()).toString();
if (process.argv[2] == "push") {
const name = jsonfile.readFileSync(root + "/package.json").name;
dependencyBuilder(name, root);
let changes = compare(name, root);
if (changes.length) {
console.log("> Detected " + changes.length + " changes:");
} else {
console.log("> No changes detected.");
deleteChanges(root);
deleteCache();
return;
}
changes.forEach(function(entry) {
console.log("\t" + chalk.red(entry.relativePath));
});
copyChanges(changes, root);
writeLockFile(changes, root);
deleteCache();
console.log(chalk.green("> Successfuly saved changes!"));
return;
}
if (!fs.existsSync(root + "/__quickfix__/quickfix.lock")) {
console.log(
chalk.red(
"> Couldn't locate quickfix.lock. Try adding changes with `quickfix push`."
)
);
return;
}
let changes = jsonfile.readFileSync(root + "/__quickfix__/quickfix.lock");
writeChanges(root, changes);
} catch (err) {
if (err.message == "package.json not found in path") {
log(
chalk.red(`> Couldn't find any dependencies. Try creating a package.json`)
);
} else {
throw err;
}
}