Skip to content

Commit

Permalink
adding imports generation
Browse files Browse the repository at this point in the history
  • Loading branch information
thlorenz committed Oct 31, 2013
1 parent fabfeab commit 326a9cf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
39 changes: 39 additions & 0 deletions index.js
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);
});
}

23 changes: 23 additions & 0 deletions test/imports.js
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()
});
})

0 comments on commit 326a9cf

Please sign in to comment.