diff --git a/lib/process/process.js b/lib/process/process.js index db8ed78..aa743c7 100644 --- a/lib/process/process.js +++ b/lib/process/process.js @@ -51,16 +51,20 @@ const rcsProcess = (pathString, opts, cb) => { } // sort in case of 'auto' - const cssFiles = filesArray.filter(file => fileExt.css.includes(path.extname(file))); + const cssHtmlFiles = filesArray.filter(file => ( + fileExt.css.includes(path.extname(file)) + || fileExt.html.includes(path.extname(file)) + )); + const fillLibraryFiles = options.type === 'auto' - ? cssFiles + ? cssHtmlFiles : filesArray; // call in series // not all selectors are stored, maybe some selectors are duplicated in different files return async.eachSeries(fillLibraryFiles, (filePath, asyncCb) => { // skip if it is not meant to fill the library - if (options.type !== 'auto' && options.type !== 'css') { + if (options.type !== 'auto' && options.type !== 'css' && options.type !== 'html') { return asyncCb(); } @@ -69,16 +73,20 @@ const rcsProcess = (pathString, opts, cb) => { return asyncCb(errReadFile); } - const availableOptions = { - prefix: options.prefix, - suffix: options.suffix, - replaceKeyframes: options.replaceKeyframes, - preventRandomName: options.preventRandomName, - ignoreAttributeSelectors: options.ignoreAttributeSelectors, - ignoreCssVariables: options.ignoreCssVariables, - }; - - rcs.fillLibraries(bufferData.toString(), availableOptions); + const isHtml = fileExt.html.includes(path.extname(filePath)); + + rcs.fillLibraries( + bufferData.toString(), + { + prefix: options.prefix, + suffix: options.suffix, + replaceKeyframes: options.replaceKeyframes, + preventRandomName: options.preventRandomName, + ignoreAttributeSelectors: options.ignoreAttributeSelectors, + ignoreCssVariables: options.ignoreCssVariables, + codeType: isHtml ? 'html' : 'css', + }, + ); return asyncCb(); }); diff --git a/package.json b/package.json index 7810217..4fa3429 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "glob": "^7.1.1", "json-extra": "^0.5.0", "lodash.merge": "^4.6.1", - "rcs-core": "^2.5.1", + "rcs-core": "^2.6.0", "universalify": "^0.1.2" }, "devDependencies": { diff --git a/test/files/fixtures/html/index-with-style.html b/test/files/fixtures/html/index-with-style.html new file mode 100644 index 0000000..ffdf687 --- /dev/null +++ b/test/files/fixtures/html/index-with-style.html @@ -0,0 +1,20 @@ + + + + + Test Document + + +
+
+ + + diff --git a/test/files/results/html/index-with-style.html b/test/files/results/html/index-with-style.html new file mode 100644 index 0000000..9c857e1 --- /dev/null +++ b/test/files/results/html/index-with-style.html @@ -0,0 +1,20 @@ + + + + + Test Document + + +
+
+ + + diff --git a/test/processAuto.js b/test/processAuto.js index 613ca79..4326484 100644 --- a/test/processAuto.js +++ b/test/processAuto.js @@ -141,3 +141,27 @@ test.cb('should not process auto file with css variables', (t) => { t.end(); }); }); + +test.cb('should fillLibraries from html and css | issue #38', (t) => { + rcs.process.auto(['**/*.{js,html}', 'css/style.css'], { + newPath: testCwd, + cwd: fixturesCwd, + }, (err) => { + const newFile = fs.readFileSync(path.join(testCwd, '/html/index-with-style.html'), 'utf8'); + const newFile2 = fs.readFileSync(path.join(testCwd, '/css/style.css'), 'utf8'); + const expectedFile = fs.readFileSync(path.join(resultsCwd, '/html/index-with-style.html'), 'utf8'); + const expectedFile2 = fs.readFileSync(path.join(resultsCwd, '/css/style.css'), 'utf8'); + + t.falsy(err); + t.is( + minify(newFile, { collapseWhitespace: true }), + minify(expectedFile, { collapseWhitespace: true }), + ); + t.is( + minify(newFile2, { collapseWhitespace: true }), + minify(expectedFile2, { collapseWhitespace: true }), + ); + + t.end(); + }); +}); diff --git a/yarn.lock b/yarn.lock index 47aa8ec..97200c6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4003,10 +4003,10 @@ rc@^1.0.1, rc@^1.1.6, rc@^1.2.7: minimist "^1.2.0" strip-json-comments "~2.0.1" -rcs-core@^2.5.1: - version "2.5.1" - resolved "https://registry.yarnpkg.com/rcs-core/-/rcs-core-2.5.1.tgz#69b77e4a53f7cd7710f2423717a9c28de1f7f778" - integrity sha512-1qIboUKvb8AJta2sWTGC3dmqfhVFjZ3vFNtqHuj5QW43VDMWhnX3C/mQ611U7wZva61BVK1ZA/GVjMNA5TYwTg== +rcs-core@^2.6.0: + version "2.6.0" + resolved "https://registry.yarnpkg.com/rcs-core/-/rcs-core-2.6.0.tgz#169d5e32d5e52ea8a7ec1368be24e265a5d2fb5f" + integrity sha512-CDl+q1vLmTNvQkWlbpzzH/mJ1yy9TUC0jkolcOcCB3PoI5L+8oNkFqwZae2C94PJ6nGhI/C56zPrDdf8rJ34/A== dependencies: array-includes "^3.0.2" ast-traverse "^0.1.1"