Skip to content

Commit 5e1da68

Browse files
committed
Refactor: prepare for rcs-core@v1
1 parent 3133024 commit 5e1da68

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

lib/process/process.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const _ = require('lodash');
4+
const fs = require('fs');
45
const rcs = require('rcs-core');
56
const path = require('path');
67
const glob = require('glob');
@@ -65,19 +66,21 @@ const rcsProcess = (pathString, options, cb) => {
6566
// call in series
6667
// not all selectors are stored, maybe some selectors are duplicated in different files
6768
async.eachSeries(filesArray, (filePath, callback) => {
68-
rcs.replace.fileCss(path.join(options.cwd, filePath), options, (err, data) => {
69+
fs.readFile(path.join(options.cwd, filePath), (err, bufferData) => {
6970
let joinedPath;
7071
let shouldOverwrite = options.overwrite;
7172

7273
if (err) return callback(err);
7374

75+
const data = rcs.replace.bufferCss(bufferData, options);
76+
7477
joinedPath = path.join(options.newPath, filePath);
7578

7679
if (!options.overwrite) {
7780
shouldOverwrite = joinedPath !== path.join(options.cwd, filePath);
7881
}
7982

80-
rcs.helper.save(joinedPath, data.data, { overwrite: shouldOverwrite }, (err) => {
83+
rcs.helper.save(joinedPath, data, { overwrite: shouldOverwrite }, (err) => {
8184
if (err) return callback(err);
8285

8386
callback();
@@ -95,19 +98,21 @@ const rcsProcess = (pathString, options, cb) => {
9598
// all selectors are collected
9699
// ⚡️ speed it up with async ⚡️
97100
async.each(filesArray, (filePath, callback) => {
98-
rcs.replace.file(path.join(options.cwd, filePath), (err, data) => {
101+
fs.readFile(path.join(options.cwd, filePath), (err, bufferData) => {
99102
let joinedPath;
100103
let shouldOverwrite = options.overwrite;
101104

102105
if (err) return callback(err);
103106

107+
const data = rcs.replace.buffer(bufferData);
108+
104109
joinedPath = path.join(options.newPath, filePath);
105110

106111
if (!options.overwrite) {
107112
shouldOverwrite = joinedPath !== path.join(options.cwd, filePath);
108113
}
109114

110-
rcs.helper.save(joinedPath, data.data, { overwrite: shouldOverwrite }, (err) => {
115+
rcs.helper.save(joinedPath, data, { overwrite: shouldOverwrite }, (err) => {
111116
if (err) return callback(err);
112117

113118
callback();

lib/process/processSync.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const fs = require('fs');
34
const rcs = require('rcs-core');
45
const path = require('path');
56
const glob = require('glob');
@@ -37,13 +38,13 @@ const processSync = (pathString, options) => {
3738
}
3839

3940
if (options.collectSelectors) {
40-
data = rcs.replace.fileCssSync(path.join(options.cwd, filePath), options);
41+
data = rcs.replace.bufferCss(fs.readFileSync(path.join(options.cwd, filePath)), options);
4142
} else {
42-
data = rcs.replace.fileSync(path.join(options.cwd, filePath), options);
43+
data = rcs.replace.buffer(fs.readFileSync(path.join(options.cwd, filePath)), options);
4344

4445
}
4546

46-
rcs.helper.saveSync(joinedPath, data.data, { overwrite: shouldOverwrite });
47+
rcs.helper.saveSync(joinedPath, data, { overwrite: shouldOverwrite });
4748
}
4849
}; // /processSync
4950

test/index.spec.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,36 @@ describe('integration tests', () => {
2828

2929
describe('processing', () => {
3030
it('should process js files', done => {
31-
rcs.replace.fileCss(fixturesCwd + '/style.css', (err, data) => {
32-
app.process('**/*.txt', {
33-
newPath: testCwd,
34-
cwd: fixturesCwd
35-
}, (err, data) => {
36-
let newFile = fs.readFileSync(testCwd + '/main.txt', 'utf8');
37-
let expectedFile = fs.readFileSync(resultsCwd + '/main.txt', 'utf8');
31+
rcs.selectorLibrary.fillLibrary(fs.readFileSync(fixturesCwd + '/style.css', 'utf8'));
3832

39-
expect(err).to.not.exist;
40-
expect(newFile).to.equal(expectedFile);
33+
app.process('**/*.txt', {
34+
newPath: testCwd,
35+
cwd: fixturesCwd
36+
}, (err, data) => {
37+
let newFile = fs.readFileSync(testCwd + '/main.txt', 'utf8');
38+
let expectedFile = fs.readFileSync(resultsCwd + '/main.txt', 'utf8');
4139

42-
done();
43-
});
40+
expect(err).to.not.exist;
41+
expect(newFile).to.equal(expectedFile);
42+
43+
done();
4444
});
4545
});
4646

4747
it('should process html files', done => {
48-
rcs.replace.fileCss(fixturesCwd + '/style.css', (err, data) => {
49-
app.process('**/*.html', {
50-
newPath: testCwd,
51-
cwd: fixturesCwd
52-
}, (err, data) => {
53-
let newFile = fs.readFileSync(testCwd + '/index.html', 'utf8');
54-
let expectedFile = fs.readFileSync(resultsCwd + '/index.html', 'utf8');
48+
rcs.selectorLibrary.fillLibrary(fs.readFileSync(fixturesCwd + '/style.css', 'utf8'));
5549

56-
expect(err).to.not.exist;
57-
expect(newFile).to.equal(expectedFile);
50+
app.process('**/*.html', {
51+
newPath: testCwd,
52+
cwd: fixturesCwd
53+
}, (err, data) => {
54+
let newFile = fs.readFileSync(testCwd + '/index.html', 'utf8');
55+
let expectedFile = fs.readFileSync(resultsCwd + '/index.html', 'utf8');
5856

59-
done();
60-
});
57+
expect(err).to.not.exist;
58+
expect(newFile).to.equal(expectedFile);
59+
60+
done();
6161
});
6262
});
6363
});

0 commit comments

Comments
 (0)