-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added experimental TypeScript support
caveats: * there's barely any abstraction here (cf. inline comment), so the only reason not to use TypeScript directly is module bundling via Rollup * this plugin is getting a little bloaty, but that seems inevitable unless we wanna make some separate TypeScript plugin fork it or include hooks for a `generateTranspiler` equivalent; YAGNI for now * more significantly, stuffing everything into the `js` config section seems a little risky WRT avoiding breaking changes in future evolution * the test's sample code seems pretty silly based on earlier efforts by @tillsc
- Loading branch information
Showing
8 changed files
with
130 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "faucet-pipeline-typescript", | ||
"version": "1.0.0-beta.1", | ||
"description": "TypeScript for faucet-pipeline", | ||
"author": "FND", | ||
"contributors": [ | ||
"Till Schulte-Coerne <[email protected]>" | ||
], | ||
"license": "Apache-2.0", | ||
"homepage": "https://github.com/faucet-pipeline/faucet-pipeline-js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/faucet-pipeline/faucet-pipeline-js.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/faucet-pipeline/faucet-pipeline-js/issues" | ||
}, | ||
"dependencies": { | ||
"faucet-pipeline-js": "1.0.0-beta.1", | ||
"rollup-plugin-typescript2": "^0.11.1", | ||
"typescript": "^2.7.2" | ||
} | ||
} |
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,39 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
if(typeof global === "undefined" && typeof window !== "undefined") { | ||
window.global = window; | ||
} | ||
|
||
var LogLevel; | ||
(function (LogLevel) { | ||
LogLevel[LogLevel["Debug"] = 0] = "Debug"; | ||
LogLevel[LogLevel["Info"] = 1] = "Info"; | ||
LogLevel[LogLevel["Critical"] = 2] = "Critical"; | ||
})(LogLevel || (LogLevel = {})); | ||
function log(level, msg) { | ||
if (level === LogLevel.Critical) { | ||
console.error(msg); | ||
} | ||
else { | ||
console.log(msg); | ||
} | ||
} | ||
|
||
var generateArticle = function (params) { | ||
var title = params.title, authors = params.authors; | ||
if (typeof title !== "string") { | ||
log(LogLevel.Debug, "auto-generating title"); | ||
title = title.main + ": " + title.sub; | ||
} | ||
return title + "\n" + authors.join(", "); | ||
}; | ||
generateArticle({ | ||
title: { | ||
main: "Hello World", | ||
sub: "sup" | ||
}, | ||
authors: ["foo", "bar"] | ||
}); | ||
|
||
}()); |
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,14 @@ | ||
"use strict"; | ||
|
||
let path = require("path"); | ||
|
||
module.exports = { | ||
js: [{ | ||
source: "./src/index.ts", | ||
target: "./dist/bundle.js", | ||
typescript: true | ||
}], | ||
plugins: { | ||
js: path.resolve(__dirname, "../../..") | ||
} | ||
}; |
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,28 @@ | ||
import { log, LogLevel } from "./util"; | ||
|
||
interface ComplexTitle { | ||
main: string; | ||
sub: string; | ||
} | ||
|
||
interface ArticleInterface { | ||
title: string | ComplexTitle; | ||
authors: string[]; | ||
} | ||
|
||
let generateArticle = (params: ArticleInterface) => { | ||
let { title, authors } = params; | ||
if(typeof title !== "string") { | ||
log(LogLevel.Debug, "auto-generating title"); | ||
title = `${title.main}: ${title.sub}`; | ||
} | ||
return title + "\n" + authors.join(", "); | ||
}; | ||
|
||
generateArticle({ | ||
title: { | ||
main: "Hello World", | ||
sub: "sup" | ||
}, | ||
authors: ["foo", "bar"] | ||
}); |
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,9 @@ | ||
export enum LogLevel { Debug, Info, Critical } | ||
|
||
export function log(level: LogLevel, msg: string) { | ||
if(level === LogLevel.Critical) { | ||
console.error(msg); | ||
} else { | ||
console.log(msg); | ||
} | ||
} |