-
Notifications
You must be signed in to change notification settings - Fork 0
/
stamp.js
41 lines (35 loc) · 999 Bytes
/
stamp.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
// @ts-check
const path = require("path");
const { runner } = require("codestamp");
main().catch((error) => {
console.error(error);
process.exit(1);
});
async function main() {
const shouldWrite = process.argv.includes("--write");
const result = await runner({
targetFilePath: "output.json",
shouldWrite,
dependencyGlobList: ["../source.json", "codegen.js"],
initialStampPlacer: ({ content, stamp }) => {
// Insert the stamp as a JSON field
const stampedJsonObject = {
...JSON.parse(content),
stamp,
};
return JSON.stringify(stampedJsonObject, null, 2);
},
fileTransformerForHashing: ({ content, absoluteFilePath }) => {
// Ignore spacing and new lines in JSON
if (path.extname(absoluteFilePath) === ".json") {
return JSON.stringify(JSON.parse(content));
}
return content;
},
cwd: __dirname,
silent: false,
});
if (result.shouldFatalIfDesired) {
process.exit(1);
}
}