Skip to content

Commit 052a1ce

Browse files
committed
[Dev] Updates the flow definition, and adds it to CI
1 parent 3c54f9f commit 052a1ce

15 files changed

+62
-13
lines changed

.flowconfig

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
[ignore]
2-
distribution
3-
.*/_tests/.*
4-
.*dangerfile.js
5-
node_modules/jest*/**/**
2+
.*/source/.*
3+
.*/node_modules/.*
64

75
[include]
6+
dangerfile.flow.js
87

98
[libs]
10-
flow-typed/
9+
distribution/danger.js.flow
10+
11+
[lints]
1112

1213
[options]
13-
unsafe.enable_getters_and_setters=true
14+
15+
[strict]

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ docs/js_ref_dsl_docs.json
4747
types/index.d.ts
4848
.jest/
4949
test-results.json
50+
51+
# Flowgen stuff
52+
source/_danger.d.tse
53+
source/_danger.d.ts

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ matrix:
1414
after_script:
1515
- rm -rf node_modules/@types/babel-*
1616
- rm -rf node_modules/@types/babylon
17+
- echo "Testing that the Danger d.ts file lints"
1718
- yarn docs
1819
- yarn add [email protected]
1920
- yarn dts-lint
21+
- echo "Testing Flow definition file"
22+
- yarn build:flow-types
23+
- yarn flow check
2024

2125
# Checks every example dangerfile can run in `danger runner`.
2226
- node_js: '8.4'

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
## Master
1515

16+
* Improvements to the Flow definition file. [@orta][]
17+
1618
## 3.1.7
1719

1820
* Minor error reporting improvements. [@orta][]

dangerfile.flow.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file isn't used anywhere, but it is used as a part of `yarn flow check`
2+
// to validate that flow typings work correctly for JS Dangerfiles
3+
4+
// @flow
5+
6+
import { danger } from "danger"
7+
8+
danger.github.pr

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"build": "shx rm -rf ./distribution && tsc -p tsconfig.production.json && madge ./distribution --circular",
4747
"build:fast": "tsc -p tsconfig.production.json",
4848
"build:flow-types":
49-
"cp source/danger.d.ts source/_danger.d.ts; sed -ie 's/api: GitHub/api: any/g' source/_danger.d.ts; npx flowgen source/_danger.d.ts -o distribution/danger.js.flow; node scripts/update_flow_types.js",
49+
"cp source/danger.d.ts source/_danger.d.ts && sed -ie 's/api: GitHub/api: any/g' source/_danger.d.ts && npx -p github:orta/flowgen#union_Strings flowgen source/_danger.d.ts -o distribution/danger.js.flow && node scripts/update_flow_types.js",
5050
"build:watch": "tsc -w",
5151
"link": "yarn run build && chmod +x distribution/commands/danger.js && npm link",
5252
"declarations": "ts-node ./scripts/create-danger-dts.ts",
@@ -89,6 +89,7 @@
8989
"danger-plugin-jest": "^1.0.1",
9090
"danger-plugin-yarn": "^1.2.1",
9191
"date-fns": "^1.29.0",
92+
"flow-bin": "^0.66.0",
9293
"husky": "^0.14.0",
9394
"jest": "22.1.4",
9495
"jest-json-reporter": "^1.2.2",

scripts/update_flow_types.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@ exportedLines.forEach(line => {
2727
const newLine = "declare export " + line
2828
flowDef = flowDef.replace(find, newLine)
2929
})
30-
fs.writeFileSync("distribution/danger.js.flow", flowDef)
30+
31+
const prefix = `
32+
// This is generated in danger/danger-js/scripts/update_flow_types.js
33+
34+
import type { GitHub } from "@octokit/rest"
35+
`
36+
37+
fs.writeFileSync("distribution/danger.js.flow", prefix + flowDef)

source/danger.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ declare module "danger" {
3434
/** ISO6801 date string */
3535
date: string
3636
}
37+
38+
// Please don't have includes in here that aren't inside the DSL folder, or the d.ts/flow defs break
3739
/**
3840
* The shape of the JSON passed between Danger and a subprocess. It's built
3941
* to be expanded in the future.
@@ -700,6 +702,19 @@ declare module "danger" {
700702
*/
701703
message: string
702704
}
705+
706+
/**
707+
* Describes the possible arguments that
708+
* could be used when calling the CLI
709+
*/
710+
interface CliArgs {
711+
base: string
712+
verbose: string
713+
externalCiProvider: string
714+
textOnly: string
715+
dangerfile: string
716+
id: string
717+
}
703718
/** A function with a callback function, which Danger wraps in a Promise */
704719
type CallbackableFn = (callback: (done: any) => void) => void
705720

source/dsl/DangerDSL.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// Please don't have includes in here that aren't inside the DSL folder, or the d.ts/flow defs break
2+
13
import { GitDSL, GitJSONDSL } from "../dsl/GitDSL"
24
import { GitHubDSL } from "../dsl/GitHubDSL"
35
import { DangerUtilsDSL } from "./DangerUtilsDSL"
4-
import { CliArgs } from "../runner/cli-args"
6+
import { CliArgs } from "../dsl/cli-args"
57

68
/**
79
* The shape of the JSON passed between Danger and a subprocess. It's built
File renamed without changes.

0 commit comments

Comments
 (0)