forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteReadme.js
More file actions
67 lines (56 loc) · 1.57 KB
/
writeReadme.js
File metadata and controls
67 lines (56 loc) · 1.57 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
66
67
const fs = require("fs");
const path = require("path");
const spawn = require("child_process").spawn;
function getGitSha() {
return new Promise((resolve, reject) => {
const proc = spawn("git", ["log", "--format=%H", "-n", "1"]);
let version = "";
proc.stdout.on("data", data => {
version += data;
});
proc.on("close", code => resolve(version.trim()));
proc.on("error", error => {
if (error.code == "ENOENT") {
reject(new Error("Could not find git."));
return;
}
reject(error);
});
});
}
function getPackageVersion(name) {
try {
const json = require(`${name}/package.json`);
const { version } = json;
return { name, version };
} catch (ex) {
return { name, version: "n/a" };
}
}
const packageOfInterest = [
"babel-plugin-transform-es2015-modules-commonjs",
"babel-preset-react",
"react",
"react-dom",
"webpack"
];
function getInterestingPackagesVersions() {
return Promise.all(packageOfInterest.map(p => getPackageVersion(p)));
}
async function writeReadme(target) {
const buffer = [
"This is the debugger.html project output.",
"See https://github.com/devtools-html/debugger.html",
""
];
const sha = await getGitSha();
buffer.push(`Taken from upstream commit: ${sha}`, "");
const packagesVersions = await getInterestingPackagesVersions();
buffer.push("Packages:");
packagesVersions.forEach(({ name, version }) => {
buffer.push(`- ${name} @${version}`);
});
buffer.push("");
fs.writeFileSync(target, buffer.join("\n"));
}
module.exports = writeReadme;