Skip to content

Commit e47707f

Browse files
committed
initial commit
0 parents  commit e47707f

3 files changed

Lines changed: 119 additions & 0 deletions

File tree

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
13+
# Directory for instrumented libs generated by jscoverage/JSCover
14+
lib-cov
15+
16+
# Coverage directory used by tools like istanbul
17+
coverage
18+
19+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
20+
.grunt
21+
22+
# node-waf configuration
23+
.lock-wscript
24+
25+
# Compiled binary addons (http://nodejs.org/api/addons.html)
26+
build/Release
27+
28+
# Dependency directory
29+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
30+
node_modules
31+

index.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
(function (module) {
3+
var _ = require('lodash');
4+
var fs = require('fs');
5+
6+
var exporter = module.exports = function (path, name) {
7+
var out = {};
8+
out[exporter.interface(name)] = exporter.function(path);
9+
return out;
10+
};
11+
12+
exporter.get_value = function get_value(a) {
13+
var value, i;
14+
switch (a.constructor.name) {
15+
case 'SassList':
16+
value = [];
17+
for (i = 0; i < a.getLength(); i++) {
18+
value.push(get_value(a.getValue(i)));
19+
}
20+
break;
21+
case 'SassMap':
22+
value = {};
23+
for (i = 0; i < a.getLength(); i++) {
24+
value[a.getKey(i).getValue()] = get_value(a.getValue(i));
25+
}
26+
break;
27+
case 'SassColor':
28+
if (1 === a.getA()) {
29+
value = 'rgb(' + a.getR() + ', ' + a.getG() + ', ' + a.getB() + ')';
30+
}
31+
else {
32+
value = 'rgba(' + a.getR() + ', ' + a.getG() + ', ' + a.getB() + ', ' + a.getA() + ')';
33+
}
34+
break;
35+
case 'SassNumber':
36+
value = a.getValue();
37+
if (a.getUnit()) {
38+
value += a.getUnit();
39+
}
40+
break;
41+
default:
42+
value = a.getValue();
43+
}
44+
return value;
45+
};
46+
47+
exporter.function = function (path) {
48+
return function (file, value, options) {
49+
var opt = _.defaults(exporter.get_value(options), {prefix: '', suffix: '', extend: false});
50+
var output = exporter.get_value(value);
51+
if (opt.extend && 'SassMap' === value.constructor.name) {
52+
try {
53+
_.defaults(output, JSON.parse(fs.readFileSync(path + file.getValue())));
54+
}
55+
catch (e) {
56+
console.log(e);
57+
}
58+
}
59+
fs.writeFileSync(path + file.getValue(), opt.prefix + JSON.stringify(output, null, ' ') + opt.suffix);
60+
return value;
61+
}
62+
};
63+
64+
exporter.interface = function (name) {
65+
name = name || 'export';
66+
return name + '($file, $value, $options:())';
67+
};
68+
})(module);

package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "node-sass-export",
3+
"version": "0.0.1",
4+
"description": "lightweight extension that allows you to export an encoded Sass variables (map, list, etc) into an external JSON file",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [
10+
"sass",
11+
"json",
12+
"export"
13+
],
14+
"author": "punkundead",
15+
"license": "BSD-2-Clause",
16+
"dependencies": {
17+
"fs": "0.0.2",
18+
"lodash": "~3.10.1"
19+
}
20+
}

0 commit comments

Comments
 (0)