-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·46 lines (36 loc) · 1.06 KB
/
index.js
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
'use strict'
const YAML = require('yamljs')
const fs = require('fs')
const stream = require('stream')
const through = require('through2')
// Midnight oil <3
const howCanWeSleepWhileOurBedsAreBurning = {}
function jsonToLessVars (obj) {
let lessVars = ''
for (let i in obj) {
lessVars += '@' + obj[i].label + ': ~"' + obj[i].mediaQuery + '";\n'
}
return lessVars
}
howCanWeSleepWhileOurBedsAreBurning.read = function (path) {
let rs = stream.Readable()
let breakpoints = YAML.load(path)
rs._read = function () {
rs.push(jsonToLessVars(breakpoints))
rs.push(null)
}
return rs
}
howCanWeSleepWhileOurBedsAreBurning.write = function (path) {
let lessFile = fs.createWriteStream(path)
return lessFile
}
howCanWeSleepWhileOurBedsAreBurning.ymlToLess = function () {
return through.obj(function (file, enc, cb) {
var content = file.contents.toString('utf8')
var parsedYaml = YAML.parse(content)
file.contents = new Buffer(String(jsonToLessVars(parsedYaml)))
cb(null, file)
})
}
module.exports = howCanWeSleepWhileOurBedsAreBurning