1
1
const prettier = require ( 'prettier' )
2
2
const path = require ( 'path' )
3
+ const fs = require ( 'fs' )
3
4
const { execSync } = require ( 'child_process' )
4
5
const { t, yes, no } = require ( './utils' )
5
6
@@ -23,17 +24,40 @@ function format(str, options = {}) {
23
24
. trim ( )
24
25
}
25
26
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
+
26
52
function formatFixture ( name ) {
27
53
let binPath = path . resolve ( __dirname , '../node_modules/.bin/prettier' )
28
54
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 ( ) )
37
61
}
38
62
39
63
let html = [
0 commit comments