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
974f93e7
Commit
974f93e7
authored
Dec 22, 2014
by
Adeel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Importer: Adds support for CLI usage.
parent
52554b83
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
161 additions
and
2 deletions
+161
-2
node-sass
bin/node-sass
+16
-1
render.js
lib/render.js
+2
-1
cli.js
test/cli.js
+102
-0
my_custom_importer_data.js
test/fixtures/extras/my_custom_importer_data.js
+5
-0
my_custom_importer_data_cb.js
test/fixtures/extras/my_custom_importer_data_cb.js
+5
-0
my_custom_importer_file.js
test/fixtures/extras/my_custom_importer_file.js
+7
-0
my_custom_importer_file_and_data.js
test/fixtures/extras/my_custom_importer_file_and_data.js
+6
-0
my_custom_importer_file_and_data_cb.js
test/fixtures/extras/my_custom_importer_file_and_data_cb.js
+6
-0
my_custom_importer_file_cb.js
test/fixtures/extras/my_custom_importer_file_cb.js
+7
-0
expected-importer.css
test/fixtures/include-files/expected-importer.css
+5
-0
No files found.
bin/node-sass
View file @
974f93e7
...
...
@@ -5,7 +5,8 @@ var Emitter = require('events').EventEmitter,
meow
=
require
(
'meow'
),
replaceExt
=
require
(
'replace-ext'
),
stdin
=
require
(
'get-stdin'
),
render
=
require
(
'../lib/render'
);
render
=
require
(
'../lib/render'
),
fs
=
require
(
'fs'
);
/**
* Initialize CLI
...
...
@@ -39,6 +40,7 @@ var cli = meow({
' --image-path Path to prepend when using the `image-url()` helper'
,
' --precision The amount of precision allowed in decimal numbers'
,
' --stdout Print the resulting CSS to stdout'
,
' --importer Path to custom importer'
,
' --help Print usage info'
].
join
(
'
\
n'
)
},
{
...
...
@@ -107,6 +109,10 @@ function getEmitter() {
console
.
log
(
data
);
});
emitter
.
on
(
'done'
,
function
(){
process
.
exit
(
0
);
});
return
emitter
;
}
...
...
@@ -204,6 +210,15 @@ function run(options, emitter) {
}
}
if
(
options
.
importer
)
{
if
(
fs
.
existsSync
(
options
.
importer
))
{
options
.
importer
=
require
(
options
.
importer
);
}
else
{
console
.
error
(
'Could not locate importer.'
);
process
.
exit
(
1
);
}
}
if
(
options
.
watch
)
{
watch
(
options
,
emitter
);
}
else
{
...
...
lib/render.js
View file @
974f93e7
...
...
@@ -22,7 +22,8 @@ module.exports = function(options, emitter) {
sourceComments
:
options
.
sourceComments
,
sourceMapEmbed
:
options
.
sourceMapEmbed
,
sourceMapContents
:
options
.
sourceMapContents
,
sourceMap
:
options
.
sourceMap
sourceMap
:
options
.
sourceMap
,
importer
:
options
.
importer
};
if
(
options
.
src
)
{
...
...
test/cli.js
View file @
974f93e7
...
...
@@ -223,4 +223,106 @@ describe('cli', function() {
});
});
});
describe
(
'importer'
,
function
()
{
var
dest
=
fixture
(
'include-files/index.css'
);
var
src
=
fixture
(
'include-files/index.scss'
);
var
expected
=
read
(
fixture
(
'include-files/expected-importer.css'
),
'utf8'
).
trim
().
replace
(
/
\r\n
/g
,
'
\
n'
);
it
(
'should override imports and fire callback with file and contents'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'extras/my_custom_importer_file_and_data_cb.js'
)
]);
bin
.
on
(
'close'
,
function
()
{
assert
.
equal
(
read
(
dest
,
'utf8'
).
trim
(),
expected
);
fs
.
unlinkSync
(
dest
);
done
();
});
});
it
(
'should override imports and fire callback with file'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'extras/my_custom_importer_file_cb.js'
)
]);
bin
.
on
(
'close'
,
function
()
{
if
(
fs
.
existsSync
(
dest
))
{
assert
.
equal
(
read
(
dest
,
'utf8'
).
trim
(),
''
);
fs
.
unlinkSync
(
dest
);
}
done
();
});
});
it
(
'should override imports and fire callback with data'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'extras/my_custom_importer_data_cb.js'
)
]);
bin
.
on
(
'close'
,
function
()
{
assert
.
equal
(
read
(
dest
,
'utf8'
).
trim
(),
expected
);
fs
.
unlinkSync
(
dest
);
done
();
});
});
it
(
'should override imports and return file and contents'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'extras/my_custom_importer_file_and_data.js'
)
]);
bin
.
on
(
'close'
,
function
()
{
assert
.
equal
(
read
(
dest
,
'utf8'
).
trim
(),
expected
);
fs
.
unlinkSync
(
dest
);
done
();
});
});
it
(
'should override imports and return file'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'extras/my_custom_importer_file.js'
)
]);
bin
.
on
(
'close'
,
function
()
{
if
(
fs
.
existsSync
(
dest
))
{
assert
.
equal
(
read
(
dest
,
'utf8'
).
trim
(),
''
);
fs
.
unlinkSync
(
dest
);
}
done
();
});
});
it
(
'should override imports and return data'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'extras/my_custom_importer_data.js'
)
]);
bin
.
on
(
'close'
,
function
()
{
assert
.
equal
(
read
(
dest
,
'utf8'
).
trim
(),
expected
);
fs
.
unlinkSync
(
dest
);
done
();
});
});
it
(
'should return error on for invalid importer file path'
,
function
(
done
)
{
var
bin
=
spawn
(
cli
,
[
src
,
'--output'
,
path
.
dirname
(
dest
),
'--importer'
,
fixture
(
'non/existing/path'
)
]);
bin
.
on
(
'close'
,
function
(
code
)
{
assert
(
code
!==
0
);
done
();
});
});
});
});
test/fixtures/extras/my_custom_importer_data.js
0 → 100644
View file @
974f93e7
module
.
exports
=
function
()
{
return
{
contents
:
'div {color: yellow;}'
};
};
test/fixtures/extras/my_custom_importer_data_cb.js
0 → 100644
View file @
974f93e7
module
.
exports
=
function
(
file
,
prev
,
done
)
{
done
({
contents
:
'div {color: yellow;}'
});
};
test/fixtures/extras/my_custom_importer_file.js
0 → 100644
View file @
974f93e7
var
path
=
require
(
'path'
);
module
.
exports
=
function
(
file
)
{
console
.
log
(
'>>>>>>>>>>'
);
console
.
log
(
path
.
resolve
(
path
.
join
(
process
.
cwd
(),
'test/fixtures/include-files/'
,
file
+
(
path
.
extname
(
file
)
?
''
:
'.scss'
))));
return
{
file
:
path
.
resolve
(
path
.
join
(
process
.
cwd
(),
'test/fixtures/include-files/'
,
file
+
(
path
.
extname
(
file
)
?
''
:
'.scss'
)))
};
};
test/fixtures/extras/my_custom_importer_file_and_data.js
0 → 100644
View file @
974f93e7
module
.
exports
=
function
()
{
return
{
file
:
'/some/random/path/file.scss'
,
contents
:
'div {color: yellow;}'
};
};
test/fixtures/extras/my_custom_importer_file_and_data_cb.js
0 → 100644
View file @
974f93e7
module
.
exports
=
function
(
file
,
prev
,
done
)
{
done
({
file
:
'/some/random/path/file.scss'
,
contents
:
'div {color: yellow;}'
});
};
test/fixtures/extras/my_custom_importer_file_cb.js
0 → 100644
View file @
974f93e7
var
path
=
require
(
'path'
);
module
.
exports
=
function
(
file
,
/* jshint unused:false */
prev
,
done
)
{
done
({
file
:
path
.
resolve
(
path
.
join
(
process
.
cwd
(),
'test/fixtures/include-files/'
,
file
+
(
path
.
extname
(
file
)
?
''
:
'.scss'
)))
});
};
test/fixtures/include-files/expected-importer.css
0 → 100644
View file @
974f93e7
div
{
color
:
yellow
;
}
div
{
color
:
yellow
;
}
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