push the uni-demo project
This commit is contained in:
190
uni-demo/node_modules/sass-graph/CHANGELOG.md
generated
vendored
Normal file
190
uni-demo/node_modules/sass-graph/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,190 @@
|
||||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [next]
|
||||
### BREAKING CHANGES
|
||||
|
||||
### Features
|
||||
|
||||
### Fixes
|
||||
|
||||
### Tests
|
||||
|
||||
### Dependencies
|
||||
|
||||
## [3.0.5]
|
||||
### Fixes
|
||||
|
||||
- Remove .css from default extensions in readme.md (@dosentmatter, #106)
|
||||
- Expand Travis CI test matrix (@xzyfer)
|
||||
|
||||
### Tests
|
||||
|
||||
- Test yargs version support in CI (@xzyfer)
|
||||
|
||||
### Dependencies
|
||||
|
||||
- Bump yargs@^13.3.2 (@xzyfer, #108)
|
||||
|
||||
## [3.0.4]
|
||||
### Fixes
|
||||
|
||||
- don't crash on non-atomic saves (@adnelson, #101)
|
||||
|
||||
## [3.0.3]
|
||||
### Dependencies
|
||||
|
||||
- yargs@^12.0.2 (@patricksmms, #97)
|
||||
- mocha@^5.2.0 (@patricksmms, #97)
|
||||
- nyc@^13.1.0 (@patricksmms, #97)
|
||||
|
||||
## [3.0.2]
|
||||
### Dependencies
|
||||
|
||||
- lodash@^4.17.11 (@patricksmms, #95)
|
||||
|
||||
## [3.0.1]
|
||||
### Fixes
|
||||
|
||||
- Add MIT license (@char0n, #93)
|
||||
|
||||
## [3.0.0]
|
||||
### BREAKING CHANGES
|
||||
|
||||
- Drop support Node < 6 (@realityking, #88, @xzyfer 3b2ec74)
|
||||
- Don't add .css imports to the graph by default (@xzyfer, #91)
|
||||
|
||||
### Features
|
||||
|
||||
- Add option to exclude files based on regular expression (@Iambecomeroot, #86)
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fix broken bounds check in CLI (@xzyfer, 5dd065e)
|
||||
|
||||
### Dependencies
|
||||
|
||||
- yargs@^10.0.3 (@realityking, #88)
|
||||
- chai@^4.1.2 (@realityking, #88)
|
||||
- coveralls@^3.0.0 (@realityking, #88)
|
||||
- mocha@^4.0.1 (@realityking, #88)
|
||||
- nyc@^11.2.1 (@realityking, #88)
|
||||
- scss-tokenizer@^0.3.0 (@xzyfer, 3b2ec74)
|
||||
|
||||
## [2.2.4]
|
||||
### Dependencies
|
||||
|
||||
- yargs@^7.0.0 (@alan-agius4, #84)
|
||||
|
||||
## [2.2.3]
|
||||
### Dependencies
|
||||
|
||||
- scss-tokenizer@^0.2.3 (@xzyfer)
|
||||
|
||||
## [2.2.2]
|
||||
### Fixes
|
||||
|
||||
- Babel runtime error messages (@xzyfer, #76 #77)
|
||||
|
||||
### Dependencies
|
||||
|
||||
- scss-tokenizer@^0.2.1 (@xzyfer)
|
||||
|
||||
## [2.2.1]
|
||||
### Fixes
|
||||
|
||||
- Babel runtime error messages (@STRML, #76 #77)
|
||||
|
||||
### Dependencies
|
||||
|
||||
- scss-tokenizer@^0.2.0
|
||||
|
||||
## [2.2.0]
|
||||
### Features
|
||||
|
||||
- Replace `@import` regexes with [scss-tokenizer](https://www.npmjs.com/package/scss-tokenizer) (@xzyfer, #68)
|
||||
- Add support for the old indented (`.sass`) syntax (@xzyfer, #31)
|
||||
- Add an option to follow symbolic links (@ludwiktrammer, #74)
|
||||
|
||||
### Fixes
|
||||
|
||||
- Replaces deprecated `fs.existsSync` (@martinheidegger, #29)
|
||||
|
||||
### Tests
|
||||
|
||||
- Significantly clean up test suite (@xzyfer, #69)
|
||||
|
||||
### Dependencies
|
||||
|
||||
- yargs@^6.6.0
|
||||
- mocha@^3.2.0
|
||||
|
||||
## [2.1.2]
|
||||
### Fixes
|
||||
|
||||
- Remove non-essential files from npm package (@jorrit, #48)
|
||||
- Update yargs to version 4.7.1 (@greenkeeperio-bot, #46)
|
||||
- Update glob to version 7.0.0 (@greenkeeperio-bot, #36)
|
||||
|
||||
## [2.1.1]
|
||||
### Fixes
|
||||
|
||||
- Don't add directory `@import`s to graph - [@niksy](https://github.com/niksy)
|
||||
|
||||
## [2.1.0]
|
||||
### Features
|
||||
|
||||
- Update to lodash 4 - [@nightwolfz](https://github.com/nightwolfz)
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fixed directories with extensions being treated as files - [@niksy](https://github.com/niksy)
|
||||
|
||||
## [2.0.1]
|
||||
### Fixes
|
||||
- Fixed tests for Windows - [@pleunv](https://github.com/pleunv)
|
||||
|
||||
## [2.0.0]
|
||||
### BREAKING CHANGES
|
||||
- `.sass` files are not included in the graph by default. Use the `-e .sass` flag.
|
||||
|
||||
### Features
|
||||
- Configurable file extensions - [@dannymidnight](https://github.com/dannymidnight), [@xzyfer](https://github.com/xzyfer)
|
||||
|
||||
### Fixes
|
||||
- Prioritize cwd when resolving load paths - [@schnerd](https://github.com/schnerd)
|
||||
|
||||
### Tests
|
||||
- Added test for prioritizing cwd when resolving load paths - [@xzyfer](https://github.com/xzyfer)
|
||||
|
||||
## [1.3.0]
|
||||
### Features
|
||||
- Add support for indented syntax - [@vegetableman](https://github.com/vegetableman)
|
||||
|
||||
## [1.2.0]
|
||||
### Features
|
||||
- Add support for custom imports - [@kevin-smets](https://github.com/kevin-smets)
|
||||
|
||||
## [1.1.0] - 2015-03-18
|
||||
### Fixes
|
||||
- Only strip extension for css, scss, sass files - [@nervo](https://github.com/nervo)
|
||||
|
||||
## [1.0.4] - 2015-03-03
|
||||
### Tests
|
||||
- Added a test for nested imports - [@kevin-smets](https://github.com/kevin-smets)
|
||||
|
||||
## [1.0.3] - 2015-02-02
|
||||
### Fixes
|
||||
- Replace incorrect usage of `for..in` loops with simple `for` loops
|
||||
|
||||
## [1.0.2] - 2015-02-02
|
||||
### Fixes
|
||||
- Don't iterate over inherited object properties
|
||||
|
||||
## [1.0.1] - 2015-01-05
|
||||
### Fixes
|
||||
- Handle errors in the visitor
|
||||
|
||||
## [1.0.0] - 2015-01-05
|
||||
|
||||
Initial stable release
|
||||
7
uni-demo/node_modules/sass-graph/LICENSE
generated
vendored
Normal file
7
uni-demo/node_modules/sass-graph/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright 2014 Michael Mifsud
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
122
uni-demo/node_modules/sass-graph/bin/sassgraph
generated
vendored
Normal file
122
uni-demo/node_modules/sass-graph/bin/sassgraph
generated
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env node
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
|
||||
var command, directory, file;
|
||||
|
||||
var yargs = require('yargs')
|
||||
.usage('Usage: $0 <command> [options] <dir> [file]')
|
||||
// .demand(1)
|
||||
|
||||
.command('ancestors', 'Output the ancestors')
|
||||
.command('descendents', 'Output the descendents')
|
||||
|
||||
.example('$0 ancestors -I src src/ src/_footer.scss', 'outputs the ancestors of src/_footer.scss')
|
||||
|
||||
.option('I', {
|
||||
alias: 'load-path',
|
||||
default: [process.cwd()],
|
||||
describe: 'Add directories to the sass load path',
|
||||
type: 'array',
|
||||
})
|
||||
|
||||
.option('e', {
|
||||
alias: 'extensions',
|
||||
default: ['scss', 'sass'],
|
||||
describe: 'File extensions to include in the graph',
|
||||
type: 'array',
|
||||
})
|
||||
|
||||
.option('f', {
|
||||
alias: 'follow',
|
||||
default: false,
|
||||
describe: 'Follow symbolic links',
|
||||
type: 'bool',
|
||||
})
|
||||
|
||||
.option('j', {
|
||||
alias: 'json',
|
||||
default: false,
|
||||
describe: 'Output the index in json',
|
||||
type: 'bool',
|
||||
})
|
||||
|
||||
.version()
|
||||
.alias('v', 'version')
|
||||
|
||||
.help('h')
|
||||
.alias('h', 'help');
|
||||
|
||||
var argv = yargs.argv;
|
||||
|
||||
if (argv._.length === 0) {
|
||||
yargs.showHelp();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (['ancestors', 'descendents'].indexOf(argv._[0]) !== -1) {
|
||||
command = argv._.shift();
|
||||
}
|
||||
|
||||
if (argv._.length && path.extname(argv._[0]) === '') {
|
||||
directory = argv._.shift();
|
||||
}
|
||||
|
||||
if (argv._.length && path.extname(argv._[0])) {
|
||||
file = argv._.shift();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
if (!directory) {
|
||||
throw new Error('Missing directory');
|
||||
}
|
||||
|
||||
if (!command && !argv.json) {
|
||||
throw new Error('Missing command');
|
||||
}
|
||||
|
||||
if (!file && (command === 'ancestors' || command === 'descendents')) {
|
||||
throw new Error(command + ' command requires a file');
|
||||
}
|
||||
|
||||
var loadPaths = argv.loadPath;
|
||||
if(process.env.SASS_PATH) {
|
||||
loadPaths = loadPaths.concat(process.env.SASS_PATH.split(/:/).map(function(f) {
|
||||
return path.resolve(f);
|
||||
}));
|
||||
}
|
||||
|
||||
var graph = require('../').parseDir(directory, {
|
||||
extensions: argv.extensions,
|
||||
loadPaths: loadPaths,
|
||||
follow: argv.follow,
|
||||
});
|
||||
|
||||
if(argv.json) {
|
||||
console.log(JSON.stringify(graph.index, null, 4));
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
if (command === 'ancestors') {
|
||||
graph.visitAncestors(path.resolve(file), function(f) {
|
||||
console.log(f);
|
||||
});
|
||||
}
|
||||
|
||||
if (command === 'descendents') {
|
||||
graph.visitDescendents(path.resolve(file), function(f) {
|
||||
console.log(f);
|
||||
});
|
||||
}
|
||||
} catch(e) {
|
||||
if (e.code === 'ENOENT') {
|
||||
console.error('Error: no such file or directory "' + e.path + '"');
|
||||
}
|
||||
else {
|
||||
console.log('Error: ' + e.message);
|
||||
}
|
||||
|
||||
// console.log(e.stack);
|
||||
process.exit(1);
|
||||
}
|
||||
41
uni-demo/node_modules/sass-graph/package.json
generated
vendored
Normal file
41
uni-demo/node_modules/sass-graph/package.json
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"name": "sass-graph",
|
||||
"version": "4.0.0",
|
||||
"description": "Parse sass files and extract a graph of imports",
|
||||
"license": "MIT",
|
||||
"repository": "xzyfer/sass-graph",
|
||||
"author": "xzyfer",
|
||||
"main": "sass-graph.js",
|
||||
"directories": {
|
||||
"bin": "./bin"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "nyc mocha",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls"
|
||||
},
|
||||
"keywords": [
|
||||
"sass",
|
||||
"graph"
|
||||
],
|
||||
"dependencies": {
|
||||
"glob": "^7.0.0",
|
||||
"lodash": "^4.17.11",
|
||||
"scss-tokenizer": "^0.3.0",
|
||||
"yargs": "^17.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"assert": "^1.3.0",
|
||||
"chai": "^4.1.2",
|
||||
"coveralls": "^3.0.0",
|
||||
"mocha": "^5.2.0",
|
||||
"nyc": "^13.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"files": [
|
||||
"bin",
|
||||
"parse-imports.js",
|
||||
"sass-graph.js"
|
||||
]
|
||||
}
|
||||
64
uni-demo/node_modules/sass-graph/parse-imports.js
generated
vendored
Normal file
64
uni-demo/node_modules/sass-graph/parse-imports.js
generated
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
var tokenizer = require('scss-tokenizer');
|
||||
|
||||
function parseImports(content, isIndentedSyntax) {
|
||||
var tokens = tokenizer.tokenize(content);
|
||||
var results = [];
|
||||
var tmp = '';
|
||||
var inImport = false;
|
||||
var inParen = false;
|
||||
var prevToken = tokens[0];
|
||||
|
||||
var i, token;
|
||||
for (i = 1; i < tokens.length; i++) {
|
||||
token = tokens[i];
|
||||
|
||||
if (inImport && !inParen && token[0] === 'string') {
|
||||
results.push(token[1]);
|
||||
}
|
||||
else if (token[1] === 'import' && prevToken[1] === '@') {
|
||||
if (inImport && !isIndentedSyntax) {
|
||||
throw new Error('Encountered invalid @import syntax.');
|
||||
}
|
||||
|
||||
inImport = true;
|
||||
}
|
||||
else if (inImport && !inParen && (token[0] === 'ident' || token[0] === '/')) {
|
||||
tmp += token[1];
|
||||
}
|
||||
else if (inImport && !inParen && (token[0] === 'space' || token[0] === 'newline')) {
|
||||
if (tmp !== '') {
|
||||
results.push(tmp);
|
||||
tmp = '';
|
||||
|
||||
if (isIndentedSyntax) {
|
||||
inImport = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (inImport && token[0] === ';') {
|
||||
inImport = false;
|
||||
|
||||
if (tmp !== '') {
|
||||
results.push(tmp);
|
||||
tmp = '';
|
||||
}
|
||||
}
|
||||
else if (inImport && token[0] === '(') {
|
||||
inParen = true;
|
||||
tmp = '';
|
||||
}
|
||||
else if (inParen && token[0] === ')') {
|
||||
inParen = false;
|
||||
}
|
||||
|
||||
prevToken = token;
|
||||
}
|
||||
|
||||
if (tmp !== '') {
|
||||
results.push(tmp);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
module.exports = parseImports;
|
||||
130
uni-demo/node_modules/sass-graph/readme.md
generated
vendored
Normal file
130
uni-demo/node_modules/sass-graph/readme.md
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
# Sass Graph
|
||||
|
||||
Parses Sass files in a directory and exposes a graph of dependencies
|
||||
|
||||
[](https://travis-ci.org/xzyfer/sass-graph)
|
||||
[](https://coveralls.io/github/xzyfer/sass-graph?branch=master)
|
||||
[](http://badge.fury.io/js/sass-graph)
|
||||
[](https://david-dm.org/xzyfer/sass-graph)
|
||||
[](https://david-dm.org/xzyfer/sass-graph#info=devDependencies)
|
||||
|
||||
## Install
|
||||
|
||||
Install with [npm](https://npmjs.org/package/sass-graph)
|
||||
|
||||
```
|
||||
npm install --save-dev sass-graph
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Usage as a Node library:
|
||||
|
||||
```js
|
||||
var sassGraph = require('./sass-graph');
|
||||
```
|
||||
|
||||
Usage as a command line tool:
|
||||
|
||||
The command line tool will parse a graph and then either display ancestors, descendents or both.
|
||||
|
||||
```
|
||||
$ ./bin/sassgraph --help
|
||||
Usage: bin/sassgraph <command> [options] <dir> [file]
|
||||
|
||||
Commands:
|
||||
ancestors Output the ancestors
|
||||
descendents Output the descendents
|
||||
|
||||
Options:
|
||||
-I, --load-path Add directories to the sass load path
|
||||
-e, --extensions File extensions to include in the graph
|
||||
-j, --json Output the index in json
|
||||
-h, --help Show help
|
||||
-v, --version Show version number
|
||||
|
||||
Examples:
|
||||
./bin/sassgraph descendents test/fixtures test/fixtures/a.scss
|
||||
/path/to/test/fixtures/b.scss
|
||||
/path/to/test/fixtures/_c.scss
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
#### parseDir
|
||||
|
||||
Parses a directory and builds a dependency graph of all requested file extensions.
|
||||
|
||||
#### parseFile
|
||||
|
||||
Parses a file and builds its dependency graph.
|
||||
|
||||
## Options
|
||||
|
||||
#### loadPaths
|
||||
|
||||
Type: `Array`
|
||||
Default: `[process.cwd]`
|
||||
|
||||
Directories to use when resolved `@import` directives.
|
||||
|
||||
#### extensions
|
||||
|
||||
Type: `Array`
|
||||
Default: `['scss', 'sass']`
|
||||
|
||||
File types to be parsed.
|
||||
|
||||
#### follow
|
||||
|
||||
Type: `Boolean`
|
||||
Default: `false`
|
||||
|
||||
Follow symbolic links.
|
||||
|
||||
#### exclude
|
||||
|
||||
Type: `RegExp`
|
||||
Default: `undefined`
|
||||
|
||||
Exclude files matching regular expression.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var sassGraph = require('./sass-graph');
|
||||
console.log(sassGraph.parseDir('test/fixtures'));
|
||||
|
||||
//{ index: {,
|
||||
// '/path/to/test/fixtures/a.scss': {
|
||||
// imports: ['b.scss'],
|
||||
// importedBy: [],
|
||||
// },
|
||||
// '/path/to/test/fixtures/b.scss': {
|
||||
// imports: ['_c.scss'],
|
||||
// importedBy: ['a.scss'],
|
||||
// },
|
||||
// '/path/to/test/fixtures/_c.scss': {
|
||||
// imports: [],
|
||||
// importedBy: ['b/scss'],
|
||||
// },
|
||||
//}}
|
||||
```
|
||||
|
||||
## Running Mocha tests
|
||||
|
||||
You can run the tests by executing the following commands:
|
||||
|
||||
```
|
||||
npm install
|
||||
npm test
|
||||
```
|
||||
|
||||
## Authors
|
||||
|
||||
Sass graph was originally written by [Lachlan Donald](http://lachlan.me).
|
||||
It is now maintained by [Michael Mifsud](http://twitter.com/xzyfer).
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
171
uni-demo/node_modules/sass-graph/sass-graph.js
generated
vendored
Normal file
171
uni-demo/node_modules/sass-graph/sass-graph.js
generated
vendored
Normal file
@@ -0,0 +1,171 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var _ = require('lodash');
|
||||
var glob = require('glob');
|
||||
var parseImports = require('./parse-imports');
|
||||
|
||||
// resolve a sass module to a path
|
||||
function resolveSassPath(sassPath, loadPaths, extensions) {
|
||||
// trim sass file extensions
|
||||
var re = new RegExp('(\.('+extensions.join('|')+'))$', 'i');
|
||||
var sassPathName = sassPath.replace(re, '');
|
||||
// check all load paths
|
||||
var i, j, length = loadPaths.length, scssPath, partialPath;
|
||||
for (i = 0; i < length; i++) {
|
||||
for (j = 0; j < extensions.length; j++) {
|
||||
scssPath = path.normalize(loadPaths[i] + '/' + sassPathName + '.' + extensions[j]);
|
||||
try {
|
||||
if (fs.lstatSync(scssPath).isFile()) {
|
||||
return scssPath;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// special case for _partials
|
||||
for (j = 0; j < extensions.length; j++) {
|
||||
scssPath = path.normalize(loadPaths[i] + '/' + sassPathName + '.' + extensions[j]);
|
||||
partialPath = path.join(path.dirname(scssPath), '_' + path.basename(scssPath));
|
||||
try {
|
||||
if (fs.lstatSync(partialPath).isFile()) {
|
||||
return partialPath;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
// File to import not found or unreadable so we assume this is a custom import
|
||||
return false;
|
||||
}
|
||||
|
||||
function Graph(options, dir) {
|
||||
this.dir = dir;
|
||||
this.extensions = options.extensions || [];
|
||||
this.exclude = options.exclude instanceof RegExp ? options.exclude : null;
|
||||
this.index = {};
|
||||
this.follow = options.follow || false;
|
||||
this.loadPaths = _(options.loadPaths).map(function(p) {
|
||||
return path.resolve(p);
|
||||
}).value();
|
||||
|
||||
if (dir) {
|
||||
var graph = this;
|
||||
_.each(glob.sync(dir+'/**/*.@('+this.extensions.join('|')+')', { dot: true, nodir: true, follow: this.follow }), function(file) {
|
||||
try {
|
||||
graph.addFile(path.resolve(file));
|
||||
} catch (e) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// add a sass file to the graph
|
||||
Graph.prototype.addFile = function(filepath, parent) {
|
||||
if (this.exclude !== null && this.exclude.test(filepath)) return;
|
||||
|
||||
var entry = this.index[filepath] = this.index[filepath] || {
|
||||
imports: [],
|
||||
importedBy: [],
|
||||
modified: fs.statSync(filepath).mtime
|
||||
};
|
||||
|
||||
var resolvedParent;
|
||||
var isIndentedSyntax = path.extname(filepath) === '.sass';
|
||||
var imports = parseImports(fs.readFileSync(filepath, 'utf-8'), isIndentedSyntax);
|
||||
var cwd = path.dirname(filepath);
|
||||
|
||||
var i, length = imports.length, loadPaths, resolved;
|
||||
for (i = 0; i < length; i++) {
|
||||
loadPaths = _([cwd, this.dir]).concat(this.loadPaths).filter().uniq().value();
|
||||
resolved = resolveSassPath(imports[i], loadPaths, this.extensions);
|
||||
if (!resolved) continue;
|
||||
|
||||
// check exclcude regex
|
||||
if (this.exclude !== null && this.exclude.test(resolved)) continue;
|
||||
|
||||
// recurse into dependencies if not already enumerated
|
||||
if (!_.includes(entry.imports, resolved)) {
|
||||
entry.imports.push(resolved);
|
||||
this.addFile(fs.realpathSync(resolved), filepath);
|
||||
}
|
||||
}
|
||||
|
||||
// add link back to parent
|
||||
if (parent) {
|
||||
resolvedParent = _(parent).intersection(this.loadPaths).value();
|
||||
|
||||
if (resolvedParent) {
|
||||
resolvedParent = parent.substr(parent.indexOf(resolvedParent));
|
||||
} else {
|
||||
resolvedParent = parent;
|
||||
}
|
||||
|
||||
// check exclcude regex
|
||||
if (!(this.exclude !== null && this.exclude.test(resolvedParent))) {
|
||||
entry.importedBy.push(resolvedParent);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// visits all files that are ancestors of the provided file
|
||||
Graph.prototype.visitAncestors = function(filepath, callback) {
|
||||
this.visit(filepath, callback, function(err, node) {
|
||||
if (err || !node) return [];
|
||||
return node.importedBy;
|
||||
});
|
||||
};
|
||||
|
||||
// visits all files that are descendents of the provided file
|
||||
Graph.prototype.visitDescendents = function(filepath, callback) {
|
||||
this.visit(filepath, callback, function(err, node) {
|
||||
if (err || !node) return [];
|
||||
return node.imports;
|
||||
});
|
||||
};
|
||||
|
||||
// a generic visitor that uses an edgeCallback to find the edges to traverse for a node
|
||||
Graph.prototype.visit = function(filepath, callback, edgeCallback, visited) {
|
||||
filepath = fs.realpathSync(filepath);
|
||||
var visited = visited || [];
|
||||
if (!this.index.hasOwnProperty(filepath)) {
|
||||
edgeCallback('Graph doesn\'t contain ' + filepath, null);
|
||||
}
|
||||
var edges = edgeCallback(null, this.index[filepath]);
|
||||
|
||||
var i, length = edges.length;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (!_.includes(visited, edges[i])) {
|
||||
visited.push(edges[i]);
|
||||
callback(edges[i], this.index[edges[i]]);
|
||||
this.visit(edges[i], callback, edgeCallback, visited);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function processOptions(options) {
|
||||
return Object.assign({
|
||||
loadPaths: [process.cwd()],
|
||||
extensions: ['scss', 'sass'],
|
||||
}, options);
|
||||
}
|
||||
|
||||
module.exports.parseFile = function(filepath, options) {
|
||||
if (fs.lstatSync(filepath).isFile()) {
|
||||
filepath = path.resolve(filepath);
|
||||
options = processOptions(options);
|
||||
var graph = new Graph(options);
|
||||
graph.addFile(filepath);
|
||||
return graph;
|
||||
}
|
||||
// throws
|
||||
};
|
||||
|
||||
module.exports.parseDir = function(dirpath, options) {
|
||||
if (fs.lstatSync(dirpath).isDirectory()) {
|
||||
dirpath = path.resolve(dirpath);
|
||||
options = processOptions(options);
|
||||
var graph = new Graph(options, dirpath);
|
||||
return graph;
|
||||
}
|
||||
// throws
|
||||
};
|
||||
Reference in New Issue
Block a user