Skip to content

Commit 6b3446f

Browse files
committed
update not to overwrite origins
1 parent 272d9ed commit 6b3446f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,17 @@ renameCssSelectors.process = (pathString, options, cb) => {
7676
async.eachSeries(filesArray, (filePath, callback) => {
7777
rcs.replace.fileCss(path.join(options.cwd, filePath), options, (err, data) => {
7878
let joinedPath;
79+
let shouldOverwrite = options.overwrite;
7980

8081
if (err) callback(err);
8182

8283
joinedPath = path.join(options.newPath, filePath);
8384

84-
rcs.helper.save(joinedPath, data.data, (err) => {
85+
if (!options.overwrite) {
86+
shouldOverwrite = joinedPath !== path.join(options.cwd, filePath);
87+
}
88+
89+
rcs.helper.save(joinedPath, data.data, { overwrite: shouldOverwrite }, (err) => {
8590
if (err) callback(err);
8691

8792
callback();
@@ -101,12 +106,17 @@ renameCssSelectors.process = (pathString, options, cb) => {
101106
async.each(filesArray, (filePath, callback) => {
102107
rcs.replace.file(path.join(options.cwd, filePath), (err, data) => {
103108
let joinedPath;
109+
let shouldOverwrite = options.overwrite;
104110

105111
if (err) callback(err);
106112

107113
joinedPath = path.join(options.newPath, filePath);
108114

109-
rcs.helper.save(joinedPath, data.data, (err) => {
115+
if (!options.overwrite) {
116+
shouldOverwrite = joinedPath !== path.join(options.cwd, filePath);
117+
}
118+
119+
rcs.helper.save(joinedPath, data.data, { overwrite: shouldOverwrite }, (err) => {
110120
if (err) callback(err);
111121

112122
callback();

test/index.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,18 @@ describe('app.js', () => {
161161
});
162162
});
163163

164+
it('should not overwrite original files', done => {
165+
app.process(['**/style.css', '**/style2.css'], {
166+
collectSelectors: true,
167+
newPath: fixturesCwd,
168+
cwd: fixturesCwd
169+
}, err => {
170+
expect(err.message).to.equal('File exist and cannot be overwritten. Set the option overwrite to true to overwrite files.');
171+
172+
done();
173+
});
174+
});
175+
164176
it('should fail', done => {
165177
app.process('path/**/with/nothing/in/it', err => {
166178
expect(err).to.be.an('object');

0 commit comments

Comments
 (0)