11const fs = require ( 'fs-extra' )
22const path = require ( 'path' )
33const ejs = require ( 'ejs' )
4+ const prettier = require ( 'prettier' )
45const getAllPlugin = require ( './plugin-get-all' )
56
6- function generatePluginConfig ( ) {
7- const targetPath = path . resolve ( __dirname , '../../src/config/stage/plugin.js' )
8- const pluginsPath = path . resolve ( __dirname , '../../src/plugin' )
9- const templatePath = path . resolve ( __dirname , '../template/plugin-stage-config.js.ejs' )
7+ const targetPath = path . resolve ( __dirname , '../../src/config/stage/plugin.js' )
8+ const pluginsPath = path . resolve ( __dirname , '../../src/plugin' )
9+ const templatePath = path . resolve ( __dirname , '../template/plugin-stage-config.js.ejs' )
1010
11+ async function renderPluginConfig ( plugins ) {
1112 const template = fs . readFileSync ( templatePath , 'utf8' )
12- const plugins = getAllPlugin ( pluginsPath )
1313 const result = ejs . render ( template , { plugins } )
14+ const prettierConfig = ( await prettier . resolveConfig ( targetPath ) ) || { }
15+
16+ return prettier . format ( result , {
17+ ...prettierConfig ,
18+ filepath : targetPath ,
19+ } )
20+ }
21+
22+ async function generatePluginConfig ( ) {
23+ const plugins = getAllPlugin ( pluginsPath )
24+ const result = await renderPluginConfig ( plugins )
1425
1526 fs . outputFileSync ( targetPath , result )
1627
@@ -22,3 +33,4 @@ function generatePluginConfig() {
2233}
2334
2435module . exports = generatePluginConfig
36+ module . exports . renderPluginConfig = renderPluginConfig
0 commit comments