This repository was archived by the owner on Oct 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Expand file tree Collapse file tree 2 files changed +16
-12
lines changed Original file line number Diff line number Diff line change 1
1
import path from 'path' ;
2
- import os from 'os' ;
3
2
4
3
const filenameToInterfaceName = ( filename ) => {
5
4
return path . basename ( filename )
@@ -10,13 +9,13 @@ const filenameToInterfaceName = (filename) => {
10
9
const cssModuleToTypescriptInterfaceProperties = ( cssModuleKeys , indent = ' ' ) => {
11
10
return cssModuleKeys
12
11
. map ( ( key ) => `${ indent } '${ key } ': string;` )
13
- . join ( os . EOL ) ;
12
+ . join ( '\n' ) ;
14
13
} ;
15
14
16
15
const cssModuleToNamedExports = ( cssModuleKeys ) => {
17
16
return cssModuleKeys
18
17
. map ( ( key ) => `export const ${ key } : string;` )
19
- . join ( os . EOL ) ;
18
+ . join ( '\n' ) ;
20
19
} ;
21
20
22
21
const allWordsRegexp = / ^ \w + $ / i;
Original file line number Diff line number Diff line change 1
1
import fs from 'graceful-fs' ;
2
- import crypto from 'crypto ' ;
2
+ import os from 'os ' ;
3
3
4
4
export const writeToFileIfChanged = ( filename , content ) => {
5
- try {
5
+ if ( fs . existsSync ( filename ) ) {
6
6
const currentInput = fs . readFileSync ( filename , 'utf-8' ) ;
7
- const oldHash = crypto . createHash ( 'md5' ) . update ( currentInput ) . digest ( 'hex' ) ;
8
- const newHash = crypto . createHash ( 'md5' ) . update ( content ) . digest ( 'hex' ) ;
9
- // the definitions haven't changed - ignore this
10
- if ( oldHash === newHash ) {
11
- return false ;
7
+
8
+ if ( currentInput !== content ) {
9
+ writeFile ( filename , content ) ;
12
10
}
13
- } finally {
14
- fs . writeFileSync ( filename , content ) ;
11
+ } else {
12
+ writeFile ( filename , content ) ;
15
13
}
16
14
} ;
15
+
16
+ const writeFile = ( filename , content ) => {
17
+ //Replace new lines with OS-specific new lines
18
+ content = content . replace ( / \n / g, os . EOL ) ;
19
+
20
+ fs . writeFileSync ( filename , content , 'utf8' ) ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments