11'use strict' ;
22
33const _ = require ( 'lodash' ) ;
4+ const fs = require ( 'fs' ) ;
45const rcs = require ( 'rcs-core' ) ;
56const path = require ( 'path' ) ;
67const 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 ( ) ;
0 commit comments