11const prettier = require ( 'prettier' )
22const path = require ( 'path' )
3+ const fs = require ( 'fs' )
34const { execSync } = require ( 'child_process' )
45const { t, yes, no } = require ( './utils' )
56
@@ -23,17 +24,40 @@ function format(str, options = {}) {
2324 . trim ( )
2425}
2526
27+ function allowFixtureFormatting ( callback ) {
28+ let renames = [
29+ {
30+ from : __dirname + '/../.prettierignore' ,
31+ to : __dirname + '/../.prettierignore.testing' ,
32+ } ,
33+ {
34+ from : __dirname + '/../prettier.config.js' ,
35+ to : __dirname + '/../prettier.config.js.testing' ,
36+ } ,
37+ ]
38+
39+ for ( const { from, to } of renames ) {
40+ fs . renameSync ( from , to )
41+ }
42+
43+ try {
44+ return callback ( )
45+ } finally {
46+ for ( const { from, to } of renames ) {
47+ fs . renameSync ( to , from )
48+ }
49+ }
50+ }
51+
2652function formatFixture ( name ) {
2753 let binPath = path . resolve ( __dirname , '../node_modules/.bin/prettier' )
2854 let filePath = path . resolve ( __dirname , `fixtures/${ name } /index.html` )
29- return execSync (
30- `${ binPath } ${ filePath } --plugin-search-dir ${ __dirname } --plugin ${ path . resolve (
31- __dirname ,
32- '..' ,
33- ) } `,
34- )
35- . toString ( )
36- . trim ( )
55+ let cmd = `${ binPath } ${ filePath } --plugin-search-dir ${ __dirname } --plugin ${ path . resolve (
56+ __dirname ,
57+ '..' ,
58+ ) } `
59+
60+ return allowFixtureFormatting ( ( ) => execSync ( cmd ) . toString ( ) . trim ( ) )
3761}
3862
3963let html = [
0 commit comments