Skip to content

Commit

Permalink
Ship the types, in a way that works with both VS Code and Atom
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Dec 14, 2016
1 parent 867e701 commit 9b6303a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// Add your own contribution below

### 0.6.6 - 0.6.7
### 0.6.6 - 0.6.7 - 0.6.8

* Ship flow annotations with the npm module - orta

Expand Down
18 changes: 14 additions & 4 deletions scripts/create-flow-typed-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ fs.readdir("source/dsl", (err, files) => {
if (line.includes(":")) { return " declare var " + line.trim() }
}).join("\n")

fileOutput += `
const exportModule = `
declare module "danger" {
${context}
}
`
fileOutput += exportModule

// Remove all JS-y bits
fileOutput = fileOutput.split("\n").filter((line) => {
return !line.startsWith("import type") &&
Expand All @@ -43,11 +45,19 @@ declare module "danger" {
fileOutput = fileOutput.replace(/export interface/gi, "interface")

// Remove any 2 line breaks
fileOutput = fileOutput.replace(/\n\s*\n/g, "\n")
const flowTyped = fileOutput.replace(/\n\s*\n/g, "\n")

// This is so you can get it for this repo 👍
fs.writeFileSync("flow-typed/npm/danger_v0.x.x.js", fileOutput)

fs.writeFileSync("flow-typed/npm/danger_v0.x.x.js", flowTyped)
console.log("Awesome - shipped to flow-typed/npm/danger_v0.x.x.js")
console.log("This should get sent to the main repo.")

// We want to create another variant - specifically for inlining into the npm module
// This version specifically does not have the declarations, but is the original
const inlineFlow = flowTyped.replace('declare module "danger" {', "")
const inlineDefinition = inlineFlow.replace(/declare/g, "")
const withoutLastBrace = inlineDefinition.substring(0, inlineDefinition.lastIndexOf("}"))
fs.writeFileSync("distribution/danger.js.flow", withoutLastBrace)
console.log("Awesome - shipped to distribution/danger.js.flow")
console.log("This will get sent off with the npm modile.")
})
2 changes: 1 addition & 1 deletion source/danger.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// This file represents the module that is exposed as the danger API
import "babel-polyfill"

// Decide what to do with this file in the future.
// Empty on purpose

0 comments on commit 9b6303a

Please sign in to comment.