-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from danger/bullet-ts
TypeScript support, + danger.d.ts, + danger DSL change
- Loading branch information
Showing
22 changed files
with
799 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// This is currently empty. Maybe it can do something in the future, but for now it's 👍 to be empty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import dts from "./danger-dts" | ||
import * as fs from "fs" | ||
|
||
// This could need to exist | ||
if (!fs.existsSync("distribution")) { | ||
fs.mkdirSync("distribution") | ||
} | ||
|
||
const output = dts() | ||
|
||
// This is so you can get it for this repo 👍 | ||
fs.writeFileSync("source/danger.d.ts", output) | ||
fs.writeFileSync("distribution/danger.d.ts", output) | ||
|
||
console.log("Awesome - shipped to source/danger.d.ts and distribution/danger.d.ts") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as fs from "fs" | ||
|
||
const createDTS = () => { | ||
let fileOutput = "" | ||
|
||
const extras = ["source/platforms/messaging/violation.ts"] | ||
const dslFiles = fs.readdirSync("source/dsl").map(f => `source/dsl/${f}`) | ||
|
||
dslFiles.concat(extras).forEach(file => { | ||
// Sometimes they have more stuff, in those cases | ||
// offer a way to crop the file. | ||
const content = fs.readFileSync(file).toString() | ||
if (content.includes("/// End of Danger DSL definition")) { | ||
fileOutput += content.split("/// End of Danger DSL definition")[0] | ||
} else { | ||
fileOutput += content | ||
} | ||
fileOutput += "\n" | ||
}) | ||
|
||
// The definition of all the exposed vars is inside | ||
// the Dangerfile.js file. | ||
const allDangerfile = fs.readFileSync("source/runner/Dangerfile.ts").toString() | ||
const moduleContext = allDangerfile.split("/// Start of Danger DSL definition")[1].split("/// End of Danger DSL definition")[0] | ||
|
||
// we need to add either `declare function` or `declare var` to the interface | ||
const context = moduleContext.split("\n").map((line: string) => { | ||
if ((line.length === 0) || (line.includes("*"))) { return line } | ||
if (line.includes("(")) { return " function " + line.trim() } | ||
if (line.includes(":")) { return " const " + line.trim() } | ||
return "" | ||
}).join("\n") | ||
|
||
fileOutput += `declare namespace danger { | ||
${context} | ||
} | ||
`// last extra line is EOF | ||
|
||
// Remove all JS-y bits | ||
fileOutput = fileOutput.split("\n").filter((line) => { | ||
return !line.startsWith("import") && | ||
!line.includes("* @type ") | ||
}).join("\n") | ||
|
||
return fileOutput.replace(/\n\s*\n\s*\n/g, "\n") | ||
} | ||
|
||
export default createDTS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
let mockDangerfilePath = "" | ||
jest.mock("fs", () => { return { existsSync: (p) => p === mockDangerfilePath } }) | ||
|
||
import { dangerfilePath } from "../file-utils" | ||
|
||
describe("dangerfilePath", () => { | ||
|
||
it("should return anything passed into the program's dangerfile", () => { | ||
expect(dangerfilePath({ dangerfile: "123"})).toEqual("123") | ||
}) | ||
|
||
it("should find a dangerfile.js if there is no program, and the .js file exists", () => { | ||
mockDangerfilePath = "dangerfile.js" | ||
expect(dangerfilePath({})).toEqual("dangerfile.js") | ||
}) | ||
|
||
it("should find a dangerfile.ts if there is no program, and the .js file does not exist", () => { | ||
mockDangerfilePath = "dangerfile.ts" | ||
expect(dangerfilePath({})).toEqual("dangerfile.ts") | ||
}) | ||
|
||
it("should raise if nothing exists", () => { | ||
mockDangerfilePath = "dangerfile.tsjs" | ||
expect(() => dangerfilePath({}) ).toThrow() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { existsSync } from "fs" | ||
|
||
/** | ||
* Returns a the typical Dangerfile, depending on it's location | ||
* taking into account whether it JS or TS by whether those exists. | ||
* | ||
* Will throw if it isn't found. | ||
*/ | ||
export function dangerfilePath(program: any): string { | ||
if (program.dangerfile) { return program.dangerfile } | ||
if (existsSync("dangerfile.ts")) { return "dangerfile.ts" } | ||
if (existsSync("dangerfile.js")) { return "dangerfile.js" } | ||
|
||
throw new Error("Could not find a `dangerfile.js` or `dangerfile.ts` in the current working directory.") | ||
} |
Oops, something went wrong.