-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
var resolveSassPaths = require('./lib/resolve-sass-paths'); | ||
|
||
exports = module.exports = function (root, cb) { | ||
|
||
} | ||
|
||
/** | ||
* Resolves paths to all .scss files from the current package and its dependencies. | ||
* The location of these sass files is indicated in the "sass" field inside packags.json. | ||
* | ||
* @name resolveSassPaths | ||
* @function | ||
* @param root {String} full path to the project whose sass files to resolve | ||
* @param cb {Function} called back with a list of paths to .scss files or an error if one occurred | ||
*/ | ||
exports.paths = resolveSassPaths; | ||
|
||
/** | ||
* Resolves all paths of all .scss files of this project and its dependencies and | ||
* generates the sass imports for them | ||
* | ||
* @name imports | ||
* @function | ||
* @param root {String} full path to the project whose sass files to resolve | ||
* @param cb {Function} called back with imports for the .scss files or an error if one occurred | ||
*/ | ||
exports.imports = function (root, cb) { | ||
resolveSassPaths(root, function (err, scssFiles) { | ||
if (err) return cb(err); | ||
var imports = scssFiles.map(function (f) { | ||
return '@import "' + f + '";'; | ||
}).join('\n'); | ||
|
||
cb(null, imports); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
/*jshint asi: true */ | ||
|
||
var test = require('tap').test | ||
var path = require('path') | ||
var imports = require('../').imports | ||
var fixtures = path.join(__dirname, 'fixtures'); | ||
|
||
test('\nwhen createing imports from fixture', function (t) { | ||
imports(fixtures, function (err, res) { | ||
if (err) return t.fail(err); | ||
var relImports = res.replace(new RegExp(fixtures, 'g'), '').split('\n'); | ||
|
||
[ '@import "/node_modules/foo/sass/index.scss";' | ||
, '@import "/node_modules/foo/node_modules/fooz/sass/index.scss";' | ||
, '@import "/node_modules/bar/node_modules/baz/sass/index.scss";' | ||
, '@import "/sass/index.scss";'].forEach(function (imp) { | ||
|
||
t.ok(~relImports.indexOf(imp), 'resolves ' + imp) | ||
}); | ||
t.end() | ||
}); | ||
}) |