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
Show 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')
...
@@ -35,8 +35,8 @@ var optimist = require('optimist')
alias
:
'help'
alias
:
'help'
})
})
.
check
(
function
(
argv
){
.
check
(
function
(
argv
){
if
(
argv
.
help
)
return
true
;
if
(
argv
.
help
)
{
return
true
;
}
if
(
argv
.
_
.
length
<
1
)
return
false
;
if
(
argv
.
_
.
length
<
1
)
{
return
false
;
}
});
});
// throttle function, used so when multiple files change at the same time
// throttle function, used so when multiple files change at the same time
...
...
lib/middleware.js
View file @
8364ad8c
var
sass
=
require
(
'../sass'
)
var
sass
=
require
(
'../sass'
),
,
fs
=
require
(
'fs'
)
fs
=
require
(
'fs'
),
,
url
=
require
(
'url'
)
url
=
require
(
'url'
),
,
basename
=
require
(
'path'
).
basename
dirname
=
require
(
'path'
).
dirname
,
,
dirname
=
require
(
'path'
).
dirname
mkdirp
=
require
(
'mkdirp'
),
,
mkdirp
=
require
(
'mkdirp'
)
join
=
require
(
'path'
).
join
;
,
join
=
require
(
'path'
).
join
;
var
imports
=
{};
var
imports
=
{};
...
@@ -57,7 +56,7 @@ module.exports = function(options){
...
@@ -57,7 +56,7 @@ module.exports = function(options){
// Source dir required
// Source dir required
var
src
=
options
.
src
;
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
// Default dest dir to source
var
dest
=
options
.
dest
var
dest
=
options
.
dest
...
@@ -68,20 +67,20 @@ module.exports = function(options){
...
@@ -68,20 +67,20 @@ module.exports = function(options){
// Default compile callback
// Default compile callback
options
.
compile
=
options
.
compile
||
function
(){
options
.
compile
=
options
.
compile
||
function
(){
return
sass
return
sass
;
};
};
// Middleware
// Middleware
return
function
sass
(
req
,
res
,
next
){
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
;
var
path
=
url
.
parse
(
req
.
url
).
pathname
;
if
(
options
.
prefix
&&
0
===
path
.
indexOf
(
options
.
prefix
))
{
if
(
options
.
prefix
&&
0
===
path
.
indexOf
(
options
.
prefix
))
{
path
=
path
.
substring
(
options
.
prefix
.
length
);
path
=
path
.
substring
(
options
.
prefix
.
length
);
}
}
if
(
/
\.
css$/
.
test
(
path
))
{
if
(
/
\.
css$/
.
test
(
path
))
{
var
cssPath
=
join
(
dest
,
path
)
var
cssPath
=
join
(
dest
,
path
)
,
,
sassPath
=
join
(
src
,
path
.
replace
(
'.css'
,
'.scss'
))
sassPath
=
join
(
src
,
path
.
replace
(
'.css'
,
'.scss'
)),
,
sassDir
=
dirname
(
sassPath
);
sassDir
=
dirname
(
sassPath
);
if
(
root
)
{
if
(
root
)
{
cssPath
=
join
(
root
,
dest
,
path
.
replace
(
dest
,
''
));
cssPath
=
join
(
root
,
dest
,
path
.
replace
(
dest
,
''
));
...
@@ -97,29 +96,29 @@ module.exports = function(options){
...
@@ -97,29 +96,29 @@ module.exports = function(options){
}
}
// Ignore ENOENT to fall through as 404
// Ignore ENOENT to fall through as 404
function
error
(
err
)
{
var
error
=
function
(
err
)
{
next
(
'ENOENT'
==
err
.
code
next
(
'ENOENT'
==
err
.
code
?
null
?
null
:
err
);
:
err
);
}
}
;
// Force
// Force
if
(
force
)
return
compile
();
if
(
force
)
{
return
compile
();
}
// Compile to cssPath
// Compile to cssPath
function
compile
()
{
var
compile
=
function
()
{
if
(
debug
)
log
(
'read'
,
cssPath
);
if
(
debug
)
{
log
(
'read'
,
cssPath
);
}
fs
.
readFile
(
sassPath
,
'utf8'
,
function
(
err
,
str
){
fs
.
readFile
(
sassPath
,
'utf8'
,
function
(
err
,
str
){
if
(
err
)
return
error
(
err
);
if
(
err
)
{
return
error
(
err
);
}
var
style
=
options
.
compile
();
var
style
=
options
.
compile
();
var
paths
=
[];
var
paths
=
[];
delete
imports
[
sassPath
];
delete
imports
[
sassPath
];
style
.
render
(
str
,
function
(
err
,
css
){
style
.
render
(
str
,
function
(
err
,
css
){
if
(
err
)
return
next
(
err
);
if
(
err
)
{
return
next
(
err
);
}
if
(
debug
)
log
(
'render'
,
sassPath
);
if
(
debug
)
{
log
(
'render'
,
sassPath
);
}
imports
[
sassPath
]
=
paths
;
imports
[
sassPath
]
=
paths
;
mkdirp
(
dirname
(
cssPath
),
0700
,
function
(
err
){
mkdirp
(
dirname
(
cssPath
),
0700
,
function
(
err
){
if
(
err
)
return
error
(
err
);
if
(
err
)
{
return
error
(
err
);
}
fs
.
writeFile
(
cssPath
,
css
,
'utf8'
,
next
);
fs
.
writeFile
(
cssPath
,
css
,
'utf8'
,
next
);
});
});
},
{
},
{
...
@@ -127,20 +126,20 @@ module.exports = function(options){
...
@@ -127,20 +126,20 @@ module.exports = function(options){
output_style
:
options
.
output_style
||
options
.
outputStyle
output_style
:
options
.
output_style
||
options
.
outputStyle
});
});
});
});
}
}
;
// Re-compile on server restart, disregarding
// Re-compile on server restart, disregarding
// mtimes since we need to map imports
// mtimes since we need to map imports
if
(
!
imports
[
sassPath
])
return
compile
();
if
(
!
imports
[
sassPath
])
{
return
compile
();
}
// Compare mtimes
// Compare mtimes
fs
.
stat
(
sassPath
,
function
(
err
,
sassStats
){
fs
.
stat
(
sassPath
,
function
(
err
,
sassStats
){
if
(
err
)
return
error
(
err
);
if
(
err
)
{
return
error
(
err
);
}
fs
.
stat
(
cssPath
,
function
(
err
,
cssStats
){
fs
.
stat
(
cssPath
,
function
(
err
,
cssStats
){
// CSS has not been compiled, compile it!
// CSS has not been compiled, compile it!
if
(
err
)
{
if
(
err
)
{
if
(
'ENOENT'
==
err
.
code
)
{
if
(
'ENOENT'
==
err
.
code
)
{
if
(
debug
)
log
(
'not found'
,
cssPath
);
if
(
debug
)
{
log
(
'not found'
,
cssPath
);
}
compile
();
compile
();
}
else
{
}
else
{
next
(
err
);
next
(
err
);
...
@@ -148,7 +147,7 @@ module.exports = function(options){
...
@@ -148,7 +147,7 @@ module.exports = function(options){
}
else
{
}
else
{
// Source has changed, compile it
// Source has changed, compile it
if
(
sassStats
.
mtime
>
cssStats
.
mtime
)
{
if
(
sassStats
.
mtime
>
cssStats
.
mtime
)
{
if
(
debug
)
log
(
'modified'
,
cssPath
);
if
(
debug
)
{
log
(
'modified'
,
cssPath
);
}
compile
();
compile
();
// Already compiled, check imports
// Already compiled, check imports
}
else
{
}
else
{
...
@@ -167,7 +166,7 @@ module.exports = function(options){
...
@@ -167,7 +166,7 @@ module.exports = function(options){
}
else
{
}
else
{
next
();
next
();
}
}
}
}
;
};
};
/**
/**
...
@@ -180,11 +179,11 @@ module.exports = function(options){
...
@@ -180,11 +179,11 @@ module.exports = function(options){
function
checkImports
(
path
,
fn
)
{
function
checkImports
(
path
,
fn
)
{
var
nodes
=
imports
[
path
];
var
nodes
=
imports
[
path
];
if
(
!
nodes
)
return
fn
();
if
(
!
nodes
)
{
return
fn
();
}
if
(
!
nodes
.
length
)
return
fn
();
if
(
!
nodes
.
length
)
{
return
fn
();
}
var
pending
=
nodes
.
length
var
pending
=
nodes
.
length
,
,
changed
=
[];
changed
=
[];
nodes
.
forEach
(
function
(
imported
){
nodes
.
forEach
(
function
(
imported
){
fs
.
stat
(
imported
.
path
,
function
(
err
,
stat
){
fs
.
stat
(
imported
.
path
,
function
(
err
,
stat
){
...
...
lib/render.js
View file @
8364ad8c
var
sass
=
require
(
'../sass'
),
var
sass
=
require
(
'../sass'
),
colors
=
require
(
'colors'
),
colors
=
require
(
'colors'
),
fs
=
require
(
'fs'
);
fs
=
require
(
'fs'
);
var
cwd
=
process
.
cwd
();
function
render
(
options
,
emitter
)
{
function
render
(
options
,
emitter
)
{
sass
.
render
({
sass
.
render
({
...
@@ -17,7 +14,7 @@ function render(options, emitter) {
...
@@ -17,7 +14,7 @@ function render(options, emitter) {
emitter
.
emit
(
'warn'
,
'Rendering Complete, saving .css file...'
.
green
);
emitter
.
emit
(
'warn'
,
'Rendering Complete, saving .css file...'
.
green
);
fs
.
writeFile
(
options
.
outFile
,
css
,
function
(
err
)
{
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
(
'warn'
,
(
'Wrote CSS to '
+
options
.
outFile
).
green
);
emitter
.
emit
(
'write'
,
err
,
options
.
outFile
,
css
);
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