Welcome to mirror list, hosted at ThFree Co, Russian Federation.

result.js « lib « test - github.com/twbs/rfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e891b8f5c1872e1ef006ae43ba28ff89197c4e1d (plain)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';

// Packages
const fs = require('fs');
const path = require('path');
const prettier = require('prettier');
const libSass = require('node-sass');
const dartSass = require('sass');
const less = require('less');
const less3 = require('less3');
const stylus = require('stylus');

// Postcss
const postcss = require('postcss');
const rfs = require('../..');
const postcssTests = require('../postcss/tests.js');

// Functions
function format(css) {
  return prettier.format(css, {parser: 'css'}).replace(/(\n)(\n)/g, '$1');
}

function getFileContent(folder, id, ext) {
  return fs.readFileSync(path.join(__dirname, `../${folder}/${id}.${ext}`), 'utf8');
}

const postcssCss = getFileContent('postcss', 'main', 'css');

// Exports
module.exports = {
  // Return formatted expected result
  expected: id => format(getFileContent('expected', id, 'css')),

  // Return parsed css
  dartsass: id => {
    return format(dartSass.renderSync({
      file: path.join(__dirname, `../sass/${id}.scss`)
    }).css.toString('utf8'));
  },

  // Return parsed css
  libsass: id => {
    return format(libSass.renderSync({
      file: path.join(__dirname, `../sass/${id}.scss`)
    }).css.toString('utf8'));
  },

  // Return parsed css
  less: id => {
    return less.render(getFileContent('less', id, 'less'), {
      paths: [path.join(__dirname, '../less')],
      syncImport: true
    }).then(result => {
      return format(result.css);
    });
  },

  // Return parsed css
  less3: id => {
    return less3.render(getFileContent('less', id, 'less'), {
      paths: [path.join(__dirname, '../less')],
      syncImport: true
    }).then(result => {
      return format(result.css);
    });
  },

  stylus: id => {
    let formattedCSS = '';
    stylus.render(getFileContent('stylus', id, 'styl'), {
      filename: path.join(__dirname, `../stylus/${id}.styl`)
    }, (err, css) => {
      if (err) {
        throw err;
      }

      formattedCSS = format(css);
    });
    return formattedCSS;
  },

  postcss: id => {
    return format(postcss(rfs(postcssTests[id])).process(postcssCss).css);
  }
};