forked from microsoft/TypeScript-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.ts
68 lines (55 loc) · 2.32 KB
/
dangerfile.ts
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
68
// This Dangerfile only runs on same-repo PRs
// You can test it by running
// yarn danger pr https://github.com/microsoft/TypeScript-Website/pull/115
import { danger, message, markdown } from "danger"
import { basename } from "path"
import { readFileSync } from "fs"
import spellcheck from "danger-plugin-spellcheck"
import lighthouse from "danger-plugin-lighthouse"
// Spell check all the things
spellcheck({
settings: "artsy/[email protected]",
codeSpellCheck: ["Examples/**/*.ts", "Examples/**/*.js"],
})
// Print out the PR url
const deployURL = `https://typescript-v2-${danger.github.pr.number}.ortam.now.sh`
message(
`Deployed to [a PR branch](${deployURL}) - [playground](${deployURL}/play) [tsconfig](${deployURL}/tsconfig) [old handbook](${deployURL}/docs/handbook/integrating-with-build-tools.html)`
)
// Look for new snapshots and show in a HTML table
const snapshots = danger.git.fileMatch("packages/typescriptlang-org/_tests/backstop_data/bitmaps_reference/*.png")
if (snapshots.modified) {
const oldSha = danger.github.pr.base.sha
const newSha = danger.github.pr.head.sha
const tables = snapshots.getKeyedPaths().modified.map(p => {
const oldURL = `https://raw.githubusercontent.com/microsoft/TypeScript-Website/${oldSha}/${p}`
const newURL = `https://raw.githubusercontent.com/microsoft/TypeScript-Website/${newSha}/${p}`
return `
###### \`${basename(p)}\`
Before | After
:-------------------------:|:-------------------------:
![](${oldURL}) | ![](${newURL})
`
})
markdown(`## Snapshots updated\n\n ${tables.join("\n\n")}`)
}
import * as glob from "glob"
// Make sure that all the versioning is accurate across the packages
const pgkPaths = glob.sync("packages/*/package.json")
const packages = pgkPaths.map(p => JSON.parse(readFileSync(p, "utf8")))
const inWorkspace = (dep: string) => {
return packages.find(p => p.name === dep)
}
packages.forEach(p => {
const deps = [p.devDependencies || {}, p.dependencies || {}]
deps.forEach(d => {
const keysInWorkSpace = Object.keys(d).filter(dep => inWorkspace(dep))
keysInWorkSpace.forEach(key => {
const version = packages.find(p => p.name === key).version
if (d[key] !== version) {
fail(`${p.name} has the wrong dependency for: ${key}. Expected ${version} got ${d[key]}`)
}
})
})
})
lighthouse()