From dcc9e2d3b58767578006ffacaca198da69fa3832 Mon Sep 17 00:00:00 2001 From: ewgenius Date: Tue, 14 Oct 2014 11:09:38 +0400 Subject: [PATCH] Add TypeScript support --- README.md | 2 +- examples/simple-jsbeautifyrc/test.ts | 8 ++++++++ lib/langs/typescript-beautify.coffee | 12 ++++++++++++ lib/language-options.coffee | 5 +++++ package.json | 6 ++++-- 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 examples/simple-jsbeautifyrc/test.ts create mode 100644 lib/langs/typescript-beautify.coffee diff --git a/README.md b/README.md index 1ad5b3f..61a32f8 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,12 @@ Or Settings/Preferences ➔ Packages ➔ Search for `atom-beautify` - Requires [Uncrustify](http://sourceforge.net/projects/uncrustify/) - [x] [Vala](https://github.com/Glavin001/atom-beautify/issues/57) - Requires [Uncrustify](http://sourceforge.net/projects/uncrustify/) +- [x] [TypeScript](https://github.com/Glavin001/atom-beautify/issues/49) ### Road Map #### Language support -- [ ] [TypeScript](https://github.com/Glavin001/atom-beautify/issues/49) - [ ] [Perl](https://github.com/Glavin001/atom-beautify/issues/33) diff --git a/examples/simple-jsbeautifyrc/test.ts b/examples/simple-jsbeautifyrc/test.ts new file mode 100644 index 0000000..04410f2 --- /dev/null +++ b/examples/simple-jsbeautifyrc/test.ts @@ -0,0 +1,8 @@ +module TestModule { + export class A { + constructor(private a: string) { + } + } + export class B extends A { + } +}; diff --git a/lib/langs/typescript-beautify.coffee b/lib/langs/typescript-beautify.coffee new file mode 100644 index 0000000..77ecef5 --- /dev/null +++ b/lib/langs/typescript-beautify.coffee @@ -0,0 +1,12 @@ +"use strict" +TF = require("typescript-formatter/typescript-toolbox/lib/formatter") + +module.exports = (text, options, callback) -> + opts = TF.createDefaultFormatCodeOptions() + + opts.TabSize = options.tab_width + opts.IndentSize = options.indent_size + + result = TF.applyFormatterToContent(text, opts) + callback result + result diff --git a/lib/language-options.coffee b/lib/language-options.coffee index dedf87a..e75f9a5 100644 --- a/lib/language-options.coffee +++ b/lib/language-options.coffee @@ -18,6 +18,7 @@ beautifyCoffeeScript = null uncrustifyBeautifier = null beautifyHTMLERB = null beautifyMarkdown = null +beautifyTypeScript = null Analytics = null # Misc @@ -50,6 +51,7 @@ module.exports = "d" "pawn" "vala" + "typescript" ] # Default options per language @@ -233,6 +235,9 @@ module.exports = options.languageOverride = "JAVA" uncrustifyBeautifier ?= require("./langs/uncrustify/") uncrustifyBeautifier text, options, beautifyCompleted + when "TypeScript" + beautifyTypeScript ?= require("./langs/typescript-beautify") + beautifyTypeScript text, self.getOptions("js", allOptions), beautifyCompleted else unsupportedGrammar = true diff --git a/package.json b/package.json index 400f556..e9e7a21 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "main": "./lib/beautify", "version": "0.13.4", "private": true, - "description": "Beautify HTML, CSS, JavaScript, PHP, Python, Ruby, Java, C, C++, C#, Objective-C, CoffeeScript, and SQL in Atom", + "description": "Beautify HTML, CSS, JavaScript, PHP, Python, Ruby, Java, C, C++, C#, Objective-C, CoffeeScript, TypeScript, and SQL in Atom", "repository": { "type": "git", "url": "https://github.com/Glavin001/atom-beautify" @@ -63,6 +63,7 @@ "python", "ruby", "coffeescript", + "typescript", "c", "c++", "cpp", @@ -94,6 +95,7 @@ "coffee-formatter": "git+https://github.com/Glavin001/Coffee-Formatter.git", "atom-message-panel": "^1.1.1", "editorconfig": "^0.11.4", - "loophole": "^1.0.0" + "loophole": "^1.0.0", + "typescript-formatter": "~0.1.4" } }