@@ -19,6 +19,10 @@ import { IBasePluginData } from "../definitions/plugins";
1919import { injector } from "../common/yok" ;
2020import { EOL } from "os" ;
2121import { IOptions } from "../declarations" ;
22+ import {
23+ format as prettierFormat ,
24+ resolveConfig as resolvePrettierConfig ,
25+ } from "prettier" ;
2226import semver = require( "semver/preload" ) ;
2327
2428export class ProjectConfigService implements IProjectConfigService {
@@ -161,7 +165,10 @@ export default {
161165 return _ . get ( this . readConfig ( ) , key ) ;
162166 }
163167
164- public setValue ( key : string , value : SupportedConfigValues ) : boolean {
168+ public async setValue (
169+ key : string ,
170+ value : SupportedConfigValues
171+ ) : Promise < boolean > {
165172 const { hasTS, configJSFilePath, configTSFilePath } = this . detectInfo ( ) ;
166173 const configFilePath = configTSFilePath || configJSFilePath ;
167174
@@ -188,7 +195,24 @@ export default {
188195 configContent
189196 ) ;
190197 const newContent = transformer . setValue ( key , value ) ;
191- this . $fs . writeFile ( configFilePath , newContent ) ;
198+ const prettierOptions = ( await resolvePrettierConfig (
199+ this . projectHelper . projectDir ,
200+ { editorconfig : true }
201+ ) ) || {
202+ semi : false ,
203+ singleQuote : true ,
204+ } ;
205+ this . $logger . trace (
206+ "updating config, prettier options: " ,
207+ prettierOptions
208+ ) ;
209+ this . $fs . writeFile (
210+ configFilePath ,
211+ prettierFormat ( newContent , {
212+ ...prettierOptions ,
213+ parser : "typescript" ,
214+ } )
215+ ) ;
192216 } catch ( error ) {
193217 this . $logger . error ( `Failed to update config.` + error ) ;
194218 } finally {
0 commit comments