This repository was archived by the owner on Jun 22, 2022. It is now read-only.
forked from exercism/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecksum
More file actions
executable file
·65 lines (53 loc) · 1.91 KB
/
Copy pathchecksum
File metadata and controls
executable file
·65 lines (53 loc) · 1.91 KB
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
#!/usr/bin/env node
/**
* Run this script (from root directory): npx babel-node scripts/checksum
*
* This will check root `package.json` matches each exercise's `package.json`.
* But the catch is there are some dependencies used for build but not served to end users
* We skip those dependencies while performing checksum.
* See `SKIP_PACKAGES_FOR_CHECKSUM` in helpers.js for list of skipped packages.
*/
const shell = require("shelljs");
const helpers = require("./helpers");
const crypto = require("crypto");
const sha = (str) => crypto.createHash("md5").update(str).digest("hex");
// Helper function to check single assignment
function checksum(filename, assignment, rootChecksum) {
if (!assignment) {
return;
}
let assignmentConfig = shell
.cat(["exercises", assignment, filename].join("/"))
.toString();
if (filename === "package.json") {
const json = JSON.parse(assignmentConfig);
delete json["version"];
assignmentConfig = JSON.stringify(json, null, 2) + "\n";
}
const assignmentChecksum = sha(assignmentConfig);
if (assignmentChecksum !== rootChecksum) {
shell.echo(`[Failure] ${filename} did not match for ${assignment}`);
shell.exit(1);
}
}
// Check all assignments by default
// or single if ASSIGNMENT is given
function checkSumAll(filename, rootFileName = filename) {
const assignment = shell.env["ASSIGNMENT"];
shell.echo(`Checking integrity of ${assignment}/${filename}...`);
const config = shell.cat(rootFileName).toString();
const rootChecksum = sha(config);
if (assignment) {
checksum(filename, assignment, rootChecksum);
} else {
helpers.assignments.forEach((assignment) =>
checksum(filename, assignment, rootChecksum)
);
}
}
helpers.createExercisePackageJson();
checkSumAll("package.json", "exercise-package.json");
shell.rm("exercise-package.json");
checkSumAll("babel.config.js");
checkSumAll(".eslintrc");
checkSumAll(".npmrc");