diff --git a/README.md b/README.md index 4d5f8c4..330c66e 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ Passes continue to stream only those files that need to be compiled. | `log` | `Function` | `console.log` | + | The function that will be called if the file needs to be compiled. | | `cleanupInterval` | `Number` | `null` | - | Time interval over which the Storage will be cleared of obsolete items. Recommended for projects very big projects. | | `makeVinylFile` | `Boolean` | `false` | + | You can use `gulp.src('patterns', { read: false })` to reduce access for filesystem. This option creates a Vinyl file within a Stream. | +| `basedir` | `String` | `null` | - | The root directory of all absolute inclusion. | | `scanner.depth` | `Number` | `30` | - | The maximum number of nested directories to scan. | | `scanner.exclude` | `String[]` | `['.git', '**/node_modules', '**/bower_components']` | - | List of Glob-patterns for directories that are excluded when scanning. | diff --git a/src/emitty.ts b/src/emitty.ts index 5aa9ce6..88c5ca2 100644 --- a/src/emitty.ts +++ b/src/emitty.ts @@ -44,6 +44,10 @@ export interface IOptions { * Creates a Vinyl file for the file which should be compiled. */ makeVinylFile?: boolean; + /** + * The root directory of all absolute inclusion. + */ + basedir?: string; } export interface IEmittyApi { @@ -96,7 +100,8 @@ export function setup(root: string, language: string | ILanguage, options?: IOpt snapshot: {}, cleanupInterval: null, log: () => console.log, - vinylFile: false + vinylFile: false, + basedir: null }, options); options.scanner = Object.assign({ diff --git a/src/services/scanner.ts b/src/services/scanner.ts index 3fa3ebf..698d7ab 100644 --- a/src/services/scanner.ts +++ b/src/services/scanner.ts @@ -127,10 +127,10 @@ export class Scanner { base: '_' + parsedPath.base })); - dependencies.push(join(entryDir, buildedPath)); + dependencies.push(this.makeDependencyPath(entryDir, buildedPath)); } - dependencies.push(join(entryDir, filepath)); + dependencies.push(this.makeDependencyPath(entryDir, filepath)); } item.dependencies = dependencies; @@ -139,6 +139,14 @@ export class Scanner { }); } + private makeDependencyPath(entryDir: string, filepath: string): string { + if (filepath.startsWith('/') && this.options.basedir) { + return join(this.options.basedir, filepath); + } + + return join(entryDir, filepath); + } + private makeEntryFile(filepath: string, ctime: Date): IFile { return { filepath, diff --git a/src/test/services/scanner.spec.ts b/src/test/services/scanner.spec.ts index 190c470..74b9bf0 100644 --- a/src/test/services/scanner.spec.ts +++ b/src/test/services/scanner.spec.ts @@ -6,7 +6,9 @@ import { Storage } from '../../services/storage'; import { Config } from '../../services/config'; import { Scanner } from '../../services/scanner'; -const options = { +import { IOptions } from '../../emitty'; + +const options = { scanner: { depth: 30, exclude: ['.git', '**/node_modules', '**/bower_components']