Skip to content
Merged
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
34 changes: 21 additions & 13 deletions lib/process/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
20 changes: 20 additions & 0 deletions test/files/fixtures/html/index-with-style.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Document</title>
</head>
<body>
<div class="jp-block"></div>
<div class="jp-block__element"></div>
<style>
:root {
--theme: #ADD;
}

.classic-long-selector__as-element--and-modifiers {
background: var(--theme);
}
</style>
</body>
</html>
20 changes: 20 additions & 0 deletions test/files/results/html/index-with-style.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test Document</title>
</head>
<body>
<div class="a"></div>
<div class="b"></div>
<style>
:root {
--l: #ADD;
}

.m {
background: var(--l);
}
</style>
</body>
</html>
24 changes: 24 additions & 0 deletions test/processAuto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down