forked from sass/node-sass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsass.js
95 lines (77 loc) · 2.94 KB
/
sass.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
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
86
87
88
89
90
91
92
93
94
95
var binding;
var fs = require('fs');
var path = require('path');
var v8 = 'v8-' + /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0];
var modPath = path.join(__dirname, 'bin', process.platform + '-' + process.arch + '-' + v8, 'binding');
try {
if (fs.realpathSync(__dirname + '/build')) {
// use the build version if it exists
binding = require(__dirname + '/build/Release/binding');
}
} catch (e) {
try {
fs.realpathSync(modPath + '.node');
binding = require(modPath);
} catch (ex) {
// No binary!
throw new Error('`'+ modPath + '.node` is missing. Try reinstalling `node-sass`?');
}
}
var SASS_OUTPUT_STYLE = {
nested: 0,
expanded: 1,
compact: 2,
compressed: 3
};
var SASS_SOURCE_COMMENTS = {
none: 0,
// This is called default in libsass, but is a reserved keyword here
normal: 1,
map: 2
};
var prepareOptions = function(options) {
var paths, style;
var options = typeof options !== 'object' ? {} : options;
var paths = options.include_paths || options.includePaths || [];
var style = SASS_OUTPUT_STYLE[options.output_style || options.outputStyle] || 0;
var comments = SASS_SOURCE_COMMENTS[options.source_comments || options.sourceComments] || 0;
return {
paths: paths,
style: style,
comments: comments
};
};
var deprecatedRender = function(css, callback, options) {
options = prepareOptions(options);
return binding.oldRender(css, callback, options.paths.join(':'), options.style, options.comments);
};
var deprecatedRenderSync = function(css, options) {
options = prepareOptions(options);
return binding.renderSync(css, options.paths.join(':'), options.style, options.comments);
};
exports.render = function(options) {
var newOptions;
if (typeof arguments[0] === 'string') {
return deprecatedRender.apply(this, arguments);
}
newOptions = prepareOptions(options);
options.error = options.error || function(){};
if (options.file !== undefined && options.file !== null) {
return binding.renderFile(options.file, options.success, options.error, newOptions.paths.join(path.delimiter), newOptions.style, newOptions.comments);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
return binding.render(options.data, options.success, options.error, newOptions.paths.join(path.delimiter), newOptions.style);
};
exports.renderSync = function(options) {
var newOptions;
if (typeof arguments[0] === 'string') {
return deprecatedRenderSync.apply(this, arguments);
}
newOptions = prepareOptions(options);
if (options.file !== undefined && options.file !== null) {
return binding.renderFileSync(options.file, newOptions.paths.join(path.delimiter), newOptions.style, newOptions.comments);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
return binding.renderSync(options.data, newOptions.paths.join(path.delimiter), newOptions.style);
};
exports.middleware = require('./lib/middleware');