Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
8364ad8c
Commit
8364ad8c
authored
Oct 25, 2013
by
Andrew Nesbitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed some jshint warnings and errors
parent
49a0c0a9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
38 deletions
+34
-38
cli.js
lib/cli.js
+2
-2
middleware.js
lib/middleware.js
+31
-32
render.js
lib/render.js
+1
-4
No files found.
lib/cli.js
View file @
8364ad8c
...
...
@@ -35,8 +35,8 @@ var optimist = require('optimist')
alias
:
'help'
})
.
check
(
function
(
argv
){
if
(
argv
.
help
)
return
true
;
if
(
argv
.
_
.
length
<
1
)
return
false
;
if
(
argv
.
help
)
{
return
true
;
}
if
(
argv
.
_
.
length
<
1
)
{
return
false
;
}
});
// throttle function, used so when multiple files change at the same time
...
...
lib/middleware.js
View file @
8364ad8c
var
sass
=
require
(
'../sass'
)
,
fs
=
require
(
'fs'
)
,
url
=
require
(
'url'
)
,
basename
=
require
(
'path'
).
basename
,
dirname
=
require
(
'path'
).
dirname
,
mkdirp
=
require
(
'mkdirp'
)
,
join
=
require
(
'path'
).
join
;
var
sass
=
require
(
'../sass'
),
fs
=
require
(
'fs'
),
url
=
require
(
'url'
),
dirname
=
require
(
'path'
).
dirname
,
mkdirp
=
require
(
'mkdirp'
),
join
=
require
(
'path'
).
join
;
var
imports
=
{};
...
...
@@ -57,7 +56,7 @@ module.exports = function(options){
// Source dir required
var
src
=
options
.
src
;
if
(
!
src
)
throw
new
Error
(
'sass.middleware() requires "src" directory'
);
if
(
!
src
)
{
throw
new
Error
(
'sass.middleware() requires "src" directory'
);
}
// Default dest dir to source
var
dest
=
options
.
dest
...
...
@@ -68,20 +67,20 @@ module.exports = function(options){
// Default compile callback
options
.
compile
=
options
.
compile
||
function
(){
return
sass
return
sass
;
};
// Middleware
return
function
sass
(
req
,
res
,
next
){
if
(
'GET'
!=
req
.
method
&&
'HEAD'
!=
req
.
method
)
return
next
();
if
(
'GET'
!=
req
.
method
&&
'HEAD'
!=
req
.
method
)
{
return
next
();
}
var
path
=
url
.
parse
(
req
.
url
).
pathname
;
if
(
options
.
prefix
&&
0
===
path
.
indexOf
(
options
.
prefix
))
{
path
=
path
.
substring
(
options
.
prefix
.
length
);
}
if
(
/
\.
css$/
.
test
(
path
))
{
var
cssPath
=
join
(
dest
,
path
)
,
sassPath
=
join
(
src
,
path
.
replace
(
'.css'
,
'.scss'
))
,
sassDir
=
dirname
(
sassPath
);
var
cssPath
=
join
(
dest
,
path
)
,
sassPath
=
join
(
src
,
path
.
replace
(
'.css'
,
'.scss'
)),
sassDir
=
dirname
(
sassPath
);
if
(
root
)
{
cssPath
=
join
(
root
,
dest
,
path
.
replace
(
dest
,
''
));
...
...
@@ -97,29 +96,29 @@ module.exports = function(options){
}
// Ignore ENOENT to fall through as 404
function
error
(
err
)
{
var
error
=
function
(
err
)
{
next
(
'ENOENT'
==
err
.
code
?
null
:
err
);
}
}
;
// Force
if
(
force
)
return
compile
();
if
(
force
)
{
return
compile
();
}
// Compile to cssPath
function
compile
()
{
if
(
debug
)
log
(
'read'
,
cssPath
);
var
compile
=
function
()
{
if
(
debug
)
{
log
(
'read'
,
cssPath
);
}
fs
.
readFile
(
sassPath
,
'utf8'
,
function
(
err
,
str
){
if
(
err
)
return
error
(
err
);
if
(
err
)
{
return
error
(
err
);
}
var
style
=
options
.
compile
();
var
paths
=
[];
delete
imports
[
sassPath
];
style
.
render
(
str
,
function
(
err
,
css
){
if
(
err
)
return
next
(
err
);
if
(
debug
)
log
(
'render'
,
sassPath
);
if
(
err
)
{
return
next
(
err
);
}
if
(
debug
)
{
log
(
'render'
,
sassPath
);
}
imports
[
sassPath
]
=
paths
;
mkdirp
(
dirname
(
cssPath
),
0700
,
function
(
err
){
if
(
err
)
return
error
(
err
);
if
(
err
)
{
return
error
(
err
);
}
fs
.
writeFile
(
cssPath
,
css
,
'utf8'
,
next
);
});
},
{
...
...
@@ -127,20 +126,20 @@ module.exports = function(options){
output_style
:
options
.
output_style
||
options
.
outputStyle
});
});
}
}
;
// Re-compile on server restart, disregarding
// mtimes since we need to map imports
if
(
!
imports
[
sassPath
])
return
compile
();
if
(
!
imports
[
sassPath
])
{
return
compile
();
}
// Compare mtimes
fs
.
stat
(
sassPath
,
function
(
err
,
sassStats
){
if
(
err
)
return
error
(
err
);
if
(
err
)
{
return
error
(
err
);
}
fs
.
stat
(
cssPath
,
function
(
err
,
cssStats
){
// CSS has not been compiled, compile it!
if
(
err
)
{
if
(
'ENOENT'
==
err
.
code
)
{
if
(
debug
)
log
(
'not found'
,
cssPath
);
if
(
debug
)
{
log
(
'not found'
,
cssPath
);
}
compile
();
}
else
{
next
(
err
);
...
...
@@ -148,7 +147,7 @@ module.exports = function(options){
}
else
{
// Source has changed, compile it
if
(
sassStats
.
mtime
>
cssStats
.
mtime
)
{
if
(
debug
)
log
(
'modified'
,
cssPath
);
if
(
debug
)
{
log
(
'modified'
,
cssPath
);
}
compile
();
// Already compiled, check imports
}
else
{
...
...
@@ -167,7 +166,7 @@ module.exports = function(options){
}
else
{
next
();
}
}
}
;
};
/**
...
...
@@ -180,11 +179,11 @@ module.exports = function(options){
function
checkImports
(
path
,
fn
)
{
var
nodes
=
imports
[
path
];
if
(
!
nodes
)
return
fn
();
if
(
!
nodes
.
length
)
return
fn
();
if
(
!
nodes
)
{
return
fn
();
}
if
(
!
nodes
.
length
)
{
return
fn
();
}
var
pending
=
nodes
.
length
,
changed
=
[];
var
pending
=
nodes
.
length
,
changed
=
[];
nodes
.
forEach
(
function
(
imported
){
fs
.
stat
(
imported
.
path
,
function
(
err
,
stat
){
...
...
lib/render.js
View file @
8364ad8c
var
sass
=
require
(
'../sass'
),
colors
=
require
(
'colors'
),
fs
=
require
(
'fs'
);
var
cwd
=
process
.
cwd
();
function
render
(
options
,
emitter
)
{
sass
.
render
({
...
...
@@ -17,7 +14,7 @@ function render(options, emitter) {
emitter
.
emit
(
'warn'
,
'Rendering Complete, saving .css file...'
.
green
);
fs
.
writeFile
(
options
.
outFile
,
css
,
function
(
err
)
{
if
(
err
)
return
emitter
.
emit
(
'error'
,
(
'Error: '
+
err
).
red
);
if
(
err
)
{
return
emitter
.
emit
(
'error'
,
(
'Error: '
+
err
).
red
);
}
emitter
.
emit
(
'warn'
,
(
'Wrote CSS to '
+
options
.
outFile
).
green
);
emitter
.
emit
(
'write'
,
err
,
options
.
outFile
,
css
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment