@@ -5,6 +5,11 @@ const path = require('path');
5
5
const assert = require ( 'assert' ) ;
6
6
7
7
const babel = require ( '@babel/core' ) ;
8
+ const prettier = require ( 'prettier' ) ;
9
+
10
+ const prettierConfig = JSON . parse (
11
+ fs . readFileSync ( require . resolve ( '../.prettierrc' ) , 'utf-8' ) ,
12
+ ) ;
8
13
9
14
const { readdirRecursive, showDirStats } = require ( './utils' ) ;
10
15
@@ -20,10 +25,10 @@ if (require.main === module) {
20
25
fs . mkdirSync ( path . dirname ( destPath ) , { recursive : true } ) ;
21
26
if ( filepath . endsWith ( '.js' ) ) {
22
27
const flowBody = '// @flow strict\n' + fs . readFileSync ( srcPath , 'utf-8' ) ;
23
- fs . writeFileSync ( destPath + '.flow' , flowBody ) ;
28
+ writeGeneratedFile ( destPath + '.flow' , flowBody ) ;
24
29
25
30
const cjs = babelBuild ( srcPath , { envName : 'cjs' } ) ;
26
- fs . writeFileSync ( destPath , cjs ) ;
31
+ writeGeneratedFile ( destPath , cjs ) ;
27
32
} else if ( filepath . endsWith ( '.d.ts' ) ) {
28
33
fs . copyFileSync ( srcPath , destPath ) ;
29
34
}
@@ -81,3 +86,8 @@ function buildPackageJSON() {
81
86
82
87
return packageJSON ;
83
88
}
89
+
90
+ function writeGeneratedFile ( filepath , body ) {
91
+ const formatted = prettier . format ( body , { filepath, ...prettierConfig } ) ;
92
+ fs . writeFileSync ( filepath , formatted ) ;
93
+ }
0 commit comments