File tree Expand file tree Collapse file tree 4 files changed +36
-2
lines changed Expand file tree Collapse file tree 4 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ are using it within `package.json` simply write `typescript-scripts [script name
35
35
36
36
All the usual eslint flags can be passed to this script, they will be passed on to eslint.
37
37
38
+ - ` typescript-scripts format `
39
+
40
+ Formats all the files in the repository using prettier.
41
+
42
+ TODO - allow passing an argument to configure which files/folders should be formatted
43
+
38
44
- compile (TODO)
39
45
40
46
- test (TODO)
Original file line number Diff line number Diff line change 2
2
3
3
"use strict" ;
4
4
5
- import { init , lint } from "./scripts" ;
5
+ import { format , init , lint } from "./scripts" ;
6
6
7
7
const args = process . argv . slice ( 2 ) ;
8
8
const scriptName = args [ 0 ] ;
@@ -20,6 +20,11 @@ switch (scriptName) {
20
20
process . exit ( 0 ) ;
21
21
break ;
22
22
23
+ case "format" :
24
+ format ( ) ;
25
+ process . exit ( 0 ) ;
26
+ break ;
27
+
23
28
case "lint" : {
24
29
const status = lint ( ) ;
25
30
process . exit ( status ) ;
Original file line number Diff line number Diff line change
1
+ import fs from "fs" ;
2
+ import path from "path" ;
3
+ import spawn from "cross-spawn" ;
4
+
5
+ const appDirectory = fs . realpathSync ( process . cwd ( ) ) ;
6
+ // const args = process.argv.slice(3);
7
+
8
+ function format ( ) : number {
9
+ const result = spawn . sync (
10
+ path . join ( appDirectory , "./node_modules/.bin/prettier" ) ,
11
+ [ "--write" , "./**/*" ] ,
12
+ { stdio : "inherit" }
13
+ ) ;
14
+
15
+ if ( result . error ) {
16
+ console . error ( result . error ) ;
17
+ }
18
+
19
+ return typeof result . status === "number" ? result . status : 1 ;
20
+ }
21
+
22
+ export default format ;
Original file line number Diff line number Diff line change
1
+ import format from "./format" ;
1
2
import init from "./init" ;
2
3
import lint from "./lint" ;
3
4
4
- export { init , lint } ;
5
+ export { format , init , lint } ;
You can’t perform that action at this time.
0 commit comments