-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathnode.js
More file actions
81 lines (65 loc) · 1.71 KB
/
node.js
File metadata and controls
81 lines (65 loc) · 1.71 KB
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
/*
* CSSLint Node.js Command Line Interface
*/
/* jshint node:true */
/* global cli */
/* exported CSSLint */
"use strict";
var fs = require("fs"),
path = require("path"),
CSSLint = require("./csslint-node").CSSLint;
cli({
args: process.argv.slice(2),
print: function(message) {
fs.writeSync(1, message + "\n");
},
quit: function(code) {
process.exit(code || 0);
},
isDirectory: function(name) {
try {
return fs.statSync(name).isDirectory();
} catch (ex) {
return false;
}
},
getFiles: function(dir) {
var files = [];
try {
fs.statSync(dir);
} catch (ex) {
return [];
}
function traverse(dir, stack) {
stack.push(dir);
fs.readdirSync(stack.join("/")).forEach(function(file) {
var path = stack.concat([file]).join("/"),
stat = fs.statSync(path);
if (file[0] === ".") {
return;
} else if (stat.isFile() && /\.css$/.test(file)) {
files.push(path);
} else if (stat.isDirectory()) {
traverse(file, stack);
}
});
stack.pop();
}
traverse(dir, []);
return files;
},
getWorkingDirectory: function() {
return process.cwd();
},
getFullPath: function(filename) {
return path.resolve(process.cwd(), filename);
},
readFile: function(filename) {
try {
return fs.readFileSync(filename, "utf-8");
} catch (ex) {
return "";
}
},
isNode: true
});