-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsass2stylus.js
executable file
·36 lines (34 loc) · 1.09 KB
/
sass2stylus.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
#!/usr/bin/env node
var exec = require('child_process').exec,
fs = require('fs'),
cliArg = process.argv,
filename = cliArg[2],
rawFilename = filename.replace(/.scss|.sass/, ''),
sassFile = filename.replace('.scss', '.sass'),
converter = __dirname +'/node_converter.rb',
s2s = function() {
exec('ruby '+ converter +' '+ sassFile, function(error, stdout, stderr) {
console.log('Converting Sass to Stylus');
fs.writeFileSync(rawFilename + '.styl', stdout);
if(error !== null) {
console.log(error);
}
if(sassFile.match(/.tmp/) && sassFile.match(/.tmp/).length) {
fs.unlinkSync(sassFile);
}
});
};
if(filename.match(/.scss/)) {
// Convert SCSS to Sass
sassFile = sassFile.replace('.sass', '.tmp.sass');
exec('sass-convert '+ filename +' '+ sassFile, function(error, stdout, stderr) {
s2s();
if(error !== null) {
console.log(error);
}
});
} else if(filename.match(/.sass/)) {
s2s();
} else {
console.log('You didn\'t pass a Sass (or SCSS) file.\nUsage: sass2stylus foo.scss');
}