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

Added option EOL which add feature to change EOL for css.d.ts files #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ These can be accessed using the object literal syntax; eg styles['delete'] inste
// Prefix banner to CSS module
cssModuleDefinition = query.banner + '\n' + cssModuleDefinition;
}
persist.writeToFileIfChanged(cssModuleInterfaceFilename, cssModuleDefinition);
persist.writeToFileIfChanged(cssModuleInterfaceFilename, cssModuleDefinition, query);
// mock async step 3 - make `async` return the actual callback again before calling the 'real' css-loader
delegateToCssLoader(this, input, callback);
};
Expand Down
10 changes: 5 additions & 5 deletions src/persist.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import fs from 'graceful-fs';
import os from 'os';

export const writeToFileIfChanged = (filename, content) => {
export const writeToFileIfChanged = (filename, content, options) => {
if (fs.existsSync(filename)) {
const currentInput = fs.readFileSync(filename, 'utf-8');

if (currentInput !== content) {
writeFile(filename, content);
writeFile(filename, content, options);
}
} else {
writeFile(filename, content);
writeFile(filename, content, options);
}
};

const writeFile = (filename, content) => {
const writeFile = (filename, content, options) => {
//Replace new lines with OS-specific new lines
content = content.replace(/\n/g, os.EOL);
content = content.replace(/\n/g, options.EOL || os.EOL);

fs.writeFileSync(filename, content, 'utf8');
};