@@ -5,6 +5,11 @@ const path = require('path');
55const assert = require ( 'assert' ) ;
66
77const babel = require ( '@babel/core' ) ;
8+ const prettier = require ( 'prettier' ) ;
9+
10+ const prettierConfig = JSON . parse (
11+ fs . readFileSync ( require . resolve ( '../.prettierrc' ) , 'utf-8' ) ,
12+ ) ;
813
914const { readdirRecursive, showDirStats } = require ( './utils' ) ;
1015
@@ -20,10 +25,10 @@ if (require.main === module) {
2025 fs . mkdirSync ( path . dirname ( destPath ) , { recursive : true } ) ;
2126 if ( filepath . endsWith ( '.js' ) ) {
2227 const flowBody = '// @flow strict\n' + fs . readFileSync ( srcPath , 'utf-8' ) ;
23- fs . writeFileSync ( destPath + '.flow' , flowBody ) ;
28+ writeGeneratedFile ( destPath + '.flow' , flowBody ) ;
2429
2530 const cjs = babelBuild ( srcPath , { envName : 'cjs' } ) ;
26- fs . writeFileSync ( destPath , cjs ) ;
31+ writeGeneratedFile ( destPath , cjs ) ;
2732 } else if ( filepath . endsWith ( '.d.ts' ) ) {
2833 fs . copyFileSync ( srcPath , destPath ) ;
2934 }
@@ -81,3 +86,8 @@ function buildPackageJSON() {
8186
8287 return packageJSON ;
8388}
89+
90+ function writeGeneratedFile ( filepath , body ) {
91+ const formatted = prettier . format ( body , { filepath, ...prettierConfig } ) ;
92+ fs . writeFileSync ( filepath , formatted ) ;
93+ }
0 commit comments