1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
'use strict';
// Packages
const fs = require('fs');
const prettier = require('prettier');
const sass = require('node-sass');
const less = require('less');
const stylus = require('stylus');
// Postcss
const postcss = require('postcss');
const rfs = require('../..');
const postcsstests = require('../postcss/tests.js');
// Strings
const encoding = 'utf8';
const dir = `${__dirname}/../`;
// Functions
const format = css => prettier.format(css, {parser: 'css'}).replace(/(\n)(\n)/g, '$1');
const getFileContent = (folder, id, ext) => fs.readFileSync(`${dir}${folder}/${id}.${ext}`, {encoding});
const postcsscss = getFileContent('postcss', 'main', 'css');
// Exports
module.exports = {
// Return formatted expected result
expected: id => format(getFileContent('result', id, 'css')),
// Return parsed css
sass: id => format(sass.renderSync({file: `${dir}sass/${id}.scss`}).css.toString(encoding)),
// Return parsed css
less: id => {
return less.render(getFileContent('less', id, 'less'), {paths: [dir + 'less'], syncImport: true}).then(result => {
return format(result.css);
});
},
stylus: id => {
let formattedCSS = '';
stylus.render(getFileContent('stylus', id, 'styl'), {filename: `${dir}stylus/${id}.styl`}, (err, css) => {
if (err) {
throw err;
}
formattedCSS = format(css);
});
return formattedCSS;
},
postcss: id => format(postcss(rfs(postcsstests[id])).process(postcsscss).css)
};
|