Skip to content

Commit 7e4c318

Browse files
committed
added processCss
1 parent db635af commit 7e4c318

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

lib/cli.js

+22
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,25 @@ cli.process = (pathString, options, cb) => {
128128
}
129129
});
130130
};
131+
132+
/**
133+
* process over all css files - set and replace
134+
* does exactly the same as cli.process, but set the collectSelectors option to true
135+
*
136+
* @param {pathString} pathString this pathString can be either an expression for `glob` or a filepath
137+
* @param {processOptions} options
138+
* @param {Function} cb the callback
139+
* @return {Function} cb
140+
*/
141+
cli.processCss = (pathString, options, cb) => {
142+
// set cb if options are not set
143+
if (typeof cb !== 'function') {
144+
cb = options;
145+
options = {};
146+
}
147+
148+
// set the css power for cli.process
149+
options.collectSelectors = true;
150+
151+
cli.process(pathString, options, cb);
152+
}

test/cli.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ describe('cli.js', () => {
3838
});
3939
});
4040

41+
// duplicated code from the test before
42+
// but another function - especially for css
43+
it('should process css files with processCss', done => {
44+
cli.processCss('**/*.css', {
45+
newPath: 'test/files/testCache',
46+
cwd: 'test/files/fixtures'
47+
}, (err, data) => {
48+
let newFile = fs.readFileSync('test/files/testCache/style.css', 'utf8');
49+
let newFile2 = fs.readFileSync('test/files/testCache/style2.css', 'utf8');
50+
let newFile3 = fs.readFileSync('test/files/testCache/subdirectory/style.css', 'utf8');
51+
let expectedFile = fs.readFileSync('test/files/results/style.css', 'utf8');
52+
let expectedFile2 = fs.readFileSync('test/files/results/style2.css', 'utf8');
53+
let expectedFile3 = fs.readFileSync('test/files/results/subdirectory/style.css', 'utf8');
54+
55+
expect(err).to.not.exist;
56+
expect(newFile).to.equal(expectedFile);
57+
expect(newFile2).to.equal(expectedFile2);
58+
expect(newFile3).to.equal(expectedFile3);
59+
60+
done();
61+
});
62+
});
63+
64+
4165
it('should process css files and flatten the directories', done => {
4266
cli.process('**/*.css', {
4367
collectSelectors: true,

0 commit comments

Comments
 (0)