Refactor scripts (#2465)

* Refactor all kinds of scripts

* Update docs to ensure linter passes
This commit is contained in:
Isiah Meadows 2019-07-27 15:12:49 -04:00 committed by GitHub
parent 62172cbe08
commit 48e7fd1711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1695 additions and 340 deletions

37
scripts/_upstream.js Normal file
View file

@ -0,0 +1,37 @@
/* eslint-disable no-process-exit */
"use strict"
const {execFileSync} = require("child_process")
const remoteInfo = execFileSync("git", ["remote", "-v"], {
windowsHide: true,
stdio: ["inherit", "pipe", "inherit"],
encoding: "utf-8",
}).trim().split(/\r\n?|\n/g)
function find(type) {
const regexp = new RegExp(
"\t(?:" +
"(?:(?:git+)?https?|git|ssh)://(?:[^@\\s]+@)?github\\.com/|" +
"git@github\\.com:" +
")" +
`MithrilJS/mithril\\.js\\.git \\(${type}\\)$`
)
const line = remoteInfo.find((line) => regexp.test(line))
if (line == null) {
console.error(
"An upstream must be configured with both fetch and push!"
)
process.exit(1)
}
return {
branch: line.slice(0, line.indexOf("\t")),
repo: line.slice(line.lastIndexOf("\t") + 1, -(type.length + 3)),
}
}
exports.fetch = find("fetch")
exports.push = find("push")