Skip to content

Commit

Permalink
Add «basedir» option (fix #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrmlnc committed Jun 25, 2017
1 parent 9c5b9de commit bfbc0ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Expand Down
7 changes: 6 additions & 1 deletion src/emitty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(<IScannerOptions>{
Expand Down
12 changes: 10 additions & 2 deletions src/services/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/test/services/scanner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <IOptions>{
scanner: {
depth: 30,
exclude: ['.git', '**/node_modules', '**/bower_components']
Expand Down

0 comments on commit bfbc0ea

Please sign in to comment.