Skip to content
This repository was archived by the owner on Oct 30, 2020. It is now read-only.

Commit 53ba3b9

Browse files
committed
Revert previous changes to cssModuleToInterface.js; replace newlines in persist.js. Make persist.js only write the files out if they have changed.
1 parent e6603cb commit 53ba3b9

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/cssModuleToInterface.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import path from 'path';
2-
import os from 'os';
32

43
const filenameToInterfaceName = (filename) => {
54
return path.basename(filename)
@@ -10,13 +9,13 @@ const filenameToInterfaceName = (filename) => {
109
const cssModuleToTypescriptInterfaceProperties = (cssModuleKeys, indent = ' ') => {
1110
return cssModuleKeys
1211
.map((key) => `${indent}'${key}': string;`)
13-
.join(os.EOL);
12+
.join('\n');
1413
};
1514

1615
const cssModuleToNamedExports = (cssModuleKeys) => {
1716
return cssModuleKeys
1817
.map((key) => `export const ${key}: string;`)
19-
.join(os.EOL);
18+
.join('\n');
2019
};
2120

2221
const allWordsRegexp = /^\w+$/i;

src/persist.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import fs from 'graceful-fs';
2-
import crypto from 'crypto';
2+
import os from 'os';
33

44
export const writeToFileIfChanged = (filename, content) => {
5-
try {
5+
if (fs.existsSync(filename)) {
66
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);
1210
}
13-
} finally {
14-
fs.writeFileSync(filename, content);
11+
} else {
12+
writeFile(filename, content);
1513
}
1614
};
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+
};

0 commit comments

Comments
 (0)