Skip to content

Commit 7cf25a1

Browse files
committed
Convert our Dangerfile to be a TypeScript file
1 parent beffc2e commit 7cf25a1

8 files changed

+42
-27
lines changed

.travis.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ cache:
33
yarn: true
44
directories:
55
- node_modules
6+
67
matrix:
78
include:
89
- node_js: node
910
before_script:
10-
- npm run build
11-
- npm run link
11+
- yarn tsc
12+
- ls
13+
- chmod +x distribution/commands/danger.js
14+
- npm link
1215
- danger
1316
- node_js: '6'
1417
- node_js: '7'
1518

1619
script:
17-
- npm run lint
18-
- npm test -- --coverage --no-cache && rm ./coverage/coverage-final.json
20+
- yarn lint
21+
- yarn test -- --coverage --no-cache && rm ./coverage/coverage-final.json
1922

2023
after_success:
2124
- bash <(curl -s https://codecov.io/bash)

dangerfile.circle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
message("this worked")
1+
// This is currently empty. Maybe it can do something in the future, but for now it's 👍 to be empty.

dangerfile.js renamed to dangerfile.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import fs from "fs"
1+
import {DangerDSL} from "./source/dsl/DangerDSL"
2+
declare var danger: DangerDSL
3+
declare function warn(params: string): void
4+
declare function fail(params: string): void
5+
6+
import * as fs from "fs"
27
import includes from "lodash.includes"
38

49
// Request a CHANGELOG entry if not declared #trivial
@@ -29,6 +34,6 @@ const currentDTS = dtsGenerator()
2934
const savedDTS = fs.readFileSync("source/danger.d.ts").toString()
3035
if (currentDTS !== savedDTS) {
3136
const message = "There are changes to the Danger DSL which are not reflected in the current danger.d.ts."
32-
const idea = "Please run <code>node ./scripts/create-danger-dts.js</code> and update this PR."
37+
const idea = "Please run <code>yarn declarations</code> and update this PR."
3338
fail(`${message} - <i>${idea}</i>`)
3439
}

package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@
5252
"test:watch": "jest --watch",
5353
"lint": "tslint \"source/**/*.ts\"",
5454
"lint:fix": "tslint \"source/**/*.ts\" --fix",
55-
"prepublish": "in-publish && npm run build && node ./scripts/create-danger-dts.js || not-in-publish",
55+
"prepublish": "in-publish && npm run build && yarn declarations || not-in-publish",
5656
"build": "shx rm -rf ./distribution && tsc && madge ./distribution --circular",
5757
"build:watch": "tsc -w",
58-
"link": "npm run build ; chmod +x distribution/commands/danger.js ; npm link"
58+
"link": "npm run build && chmod +x distribution/commands/danger.js && npm link",
59+
"declarations": "ts-node ./scripts/create-danger-dts.ts"
5960
},
6061
"repository": {
6162
"type": "git",
@@ -89,7 +90,7 @@
8990
"madge": "^1.4.4",
9091
"shx": "^0.2.1",
9192
"ts-jest": "^19.0.0",
92-
"ts-node": "^2.0.0",
93+
"ts-node": "^2.1.0",
9394
"tslint": "^4.4.0",
9495
"typescript": "2.2.1"
9596
},
@@ -98,9 +99,9 @@
9899
"chalk": "^1.1.1",
99100
"commander": "^2.9.0",
100101
"debug": "^2.6.0",
102+
"jest-config": "^18.0.0",
101103
"jest-environment-node": "^18.1.0",
102104
"jest-runtime": "^18.0.0",
103-
"jest-config": "^18.0.0",
104105
"jsome": "^2.3.25",
105106
"lodash.find": "^4.6.0",
106107
"lodash.includes": "^4.3.0",

scripts/create-danger-dts.js renamed to scripts/create-danger-dts.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
const dts = require("./danger-dts")
2-
const fs = require("fs")
1+
import dts from "./danger-dts"
2+
import * as fs from "fs"
3+
4+
// This could need to exist
5+
if (!fs.existsSync("distribution")) {
6+
fs.mkdirSync("distribution")
7+
}
38

49
const output = dts()
510

scripts/danger-dts.js renamed to scripts/danger-dts.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
var fs = require("fs")
1+
import * as fs from "fs"
22

33
const createDTS = () => {
4-
var fileOutput = ""
4+
let fileOutput = ""
55

66
const extras = ["source/platforms/messaging/violation.ts"]
77
const dslFiles = fs.readdirSync("source/dsl").map(f => `source/dsl/${f}`)
@@ -24,10 +24,11 @@ const createDTS = () => {
2424
const moduleContext = allDangerfile.split("/// Start of Danger DSL definition")[1].split("/// End of Danger DSL definition")[0]
2525

2626
// we need to add either `declare function` or `declare var` to the interface
27-
const context = moduleContext.split("\n").map((line) => {
27+
const context = moduleContext.split("\n").map((line: string) => {
2828
if ((line.length === 0) || (line.includes("*"))) { return line }
2929
if (line.includes("(")) { return " function " + line.trim() }
3030
if (line.includes(":")) { return " var " + line.trim() }
31+
return ""
3132
}).join("\n")
3233

3334
fileOutput += context
@@ -41,5 +42,5 @@ const createDTS = () => {
4142
// Remove any 2 line breaks
4243
return fileOutput.replace(/\n\s*\n/g, "\n")
4344
}
44-
45-
module.exports = createDTS
45+
46+
export default createDTS

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"pretty": true,
1717
"target": "es5",
1818
"outDir": "distribution",
19-
"lib": ["es5", "es2015.promise"]
19+
"lib": ["es5", "es2015.promise", "es2016.array.include", "es2015.core"]
2020
},
2121
"formatCodeOptions": {
2222
"indentSize": 2,

yarn.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -1105,14 +1105,14 @@ [email protected]:
11051105
dependencies:
11061106
boom "2.x.x"
11071107

1108-
[email protected], "cssom@>= 0.3.2 < 0.4.0":
1109-
version "0.3.2"
1110-
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b"
1111-
1112-
"cssom@>= 0.3.0 < 0.4.0":
1108+
[email protected], "cssom@>= 0.3.0 < 0.4.0":
11131109
version "0.3.1"
11141110
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.1.tgz#c9e37ef2490e64f6d1baa10fda852257082c25d3"
11151111

1112+
"cssom@>= 0.3.2 < 0.4.0":
1113+
version "0.3.2"
1114+
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b"
1115+
11161116
"cssstyle@>= 0.2.36 < 0.3.0", "cssstyle@>= 0.2.37 < 0.3.0":
11171117
version "0.2.37"
11181118
resolved "https://registry.yarnpkg.com/cssstyle/-/cssstyle-0.2.37.tgz#541097234cb2513c83ceed3acddc27ff27987d54"
@@ -3968,9 +3968,9 @@ ts-jest@^19.0.0:
39683968
source-map-support "^0.4.4"
39693969
yargs "^6.1.1"
39703970

3971-
ts-node@^2.0.0:
3972-
version "2.0.0"
3973-
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-2.0.0.tgz#16e4fecc949088238b4cbf1c39c9582526b66f74"
3971+
ts-node@^2.1.0:
3972+
version "2.1.0"
3973+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-2.1.0.tgz#aa2bf4b2e25c5fb6a7c54701edc3666d3a9db25d"
39743974
dependencies:
39753975
arrify "^1.0.0"
39763976
chalk "^1.1.1"

0 commit comments

Comments
 (0)