Skip to content
This repository was archived by the owner on Sep 21, 2019. It is now read-only.

Commit e181d38

Browse files
committed
Pass printed sfile to prettier
1 parent 394ae32 commit e181d38

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"commander": "^2.10.0",
3737
"glob": "^7.1.2",
3838
"lodash": "^4.17.4",
39+
"prettier": "^1.10.2",
3940
"typescript": "^2.6.2"
4041
},
4142
"devDependencies": {
@@ -45,11 +46,11 @@
4546
"@types/jest": "^20.0.2",
4647
"@types/lodash": "^4.14.93",
4748
"@types/node": "^8.0.2",
49+
"@types/prettier": "^1.10.0",
4850
"@types/react": "^15.0.31",
4951
"husky": "^0.14.3",
5052
"jest": "^20.0.4",
5153
"lint-staged": "^6.0.1",
52-
"prettier": "^1.10.2",
5354
"ts-jest": "^20.0.6",
5455
"ts-node": "^3.1.0",
5556
"tslint": "^5.2.0"

src/compiler.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import * as ts from 'typescript';
22
import * as chalk from 'chalk';
3+
import * as prettier from 'prettier';
34

45
import { TransformFactoryFactory } from '.';
56

67
/**
78
* Compile and return result TypeScript
89
* @param filePath Path to file to compile
910
*/
10-
export function compile(filePath: string, factoryFactories: TransformFactoryFactory[]) {
11+
export function compile(
12+
filePath: string,
13+
factoryFactories: TransformFactoryFactory[],
14+
prettierOptions: prettier.Options = {},
15+
) {
1116
const compilerOptions: ts.CompilerOptions = {
1217
target: ts.ScriptTarget.ES2017,
1318
module: ts.ModuleKind.ES2015,
@@ -42,5 +47,6 @@ export function compile(filePath: string, factoryFactories: TransformFactoryFact
4247
const printer = ts.createPrinter();
4348

4449
// TODO: fix the index 0 access... What if program have multiple source files?
45-
return printer.printNode(ts.EmitHint.SourceFile, result.transformed[0], sourceFiles[0]);
50+
const printed = printer.printNode(ts.EmitHint.SourceFile, result.transformed[0], sourceFiles[0]);
51+
return prettier.format(printed, prettierOptions);
4652
}

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
version "8.5.9"
4545
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.5.9.tgz#7155cfb4ae405bca4dd8df1a214c339e939109bf"
4646

47+
"@types/prettier@^1.10.0":
48+
version "1.10.0"
49+
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.10.0.tgz#5abf1ec0a6e904fe2490cc2068f36a38e4a63c42"
50+
4751
"@types/react@^15.0.31":
4852
version "15.6.11"
4953
resolved "https://registry.yarnpkg.com/@types/react/-/react-15.6.11.tgz#c61440937ccf970446cb3ef77007b450ab1e2f91"

0 commit comments

Comments
 (0)