-
-
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.
Add a Danger rule about updating the d.ts
- Loading branch information
Showing
3 changed files
with
60 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,10 @@ | ||
var fs = require("fs") | ||
var fileOutput = "" | ||
const dts = require("./danger-dts") | ||
const fs = require("fs") | ||
|
||
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) => { | ||
if ((line.length === 0) || (line.includes("*"))) { return line } | ||
if (line.includes("(")) { return " function " + line.trim() } | ||
if (line.includes(":")) { return " var " + line.trim() } | ||
}).join("\n") | ||
|
||
fileOutput += context | ||
|
||
// Remove all JS-y bits | ||
fileOutput = fileOutput.split("\n").filter((line) => { | ||
return !line.startsWith("import") && | ||
!line.includes("* @type ") | ||
}).join("\n") | ||
|
||
// We don't export in the definitions files | ||
// fileOutput = fileOutput.replace(/export interface/gi, "interface") | ||
|
||
// Remove any 2 line breaks | ||
const flowTyped = fileOutput.replace(/\n\s*\n/g, "\n") | ||
const output = dts() | ||
|
||
// This is so you can get it for this repo 👍 | ||
fs.writeFileSync("source/danger.d.ts", flowTyped) | ||
fs.writeFileSync("distribution/danger.d.ts", flowTyped) | ||
console.log("Awesome - shipped to source/danger.dts") | ||
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 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,45 @@ | ||
var fs = require("fs") | ||
|
||
const createDTS = () => { | ||
var 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) => { | ||
if ((line.length === 0) || (line.includes("*"))) { return line } | ||
if (line.includes("(")) { return " function " + line.trim() } | ||
if (line.includes(":")) { return " var " + line.trim() } | ||
}).join("\n") | ||
|
||
fileOutput += context | ||
|
||
// Remove all JS-y bits | ||
fileOutput = fileOutput.split("\n").filter((line) => { | ||
return !line.startsWith("import") && | ||
!line.includes("* @type ") | ||
}).join("\n") | ||
|
||
// Remove any 2 line breaks | ||
return fileOutput.replace(/\n\s*\n/g, "\n") | ||
} | ||
|
||
module.exports = createDTS |