-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
73 additions
and
87 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
12 changes: 6 additions & 6 deletions
12
src/plugin/DependencyParserConfig.ts → ...ndency-parser/dependency-parser-config.ts
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 |
---|---|---|
@@ -1,31 +1,31 @@ | ||
/** | ||
* Represents a configuration for a DependencyParser, specifying how it should parse the file type with which it is associated. | ||
*/ | ||
export default class DependencyParserConfig | ||
export interface IDependencyParserConfig | ||
{ | ||
/** | ||
* The sequence of RegExps and/or functions to use when parsing dependency paths from a source file. | ||
* Each RegExp must have the "gm" modifier and at least one capture group. Each function must accept a string and return | ||
* an array of captured strings. The strings captured by each RegExp or function will be passed to the next, thus iteratively | ||
* reducing the file content to an array of dependency file paths. | ||
*/ | ||
public parserSteps: (RegExp|((text: string) => string[]))[]; | ||
parserSteps: (RegExp|((text: string) => string[]))[]; | ||
|
||
/** | ||
* The file name prefixes to try when looking for dependency files, if the syntax does not require them to be specified | ||
* in dependency statements. This could be e.g. "_", which is often used as a naming convention for mixin files. | ||
*/ | ||
public prefixes: string[]; | ||
prefixes: string[]; | ||
|
||
/** | ||
* The file name postfixes to try when looking for dependency files, if the syntax does not require it to be specified | ||
* in dependency statements. This could be e.g. the file name extension, which is often allowed to be omitted. | ||
*/ | ||
public postfixes: string[]; | ||
postfixes: string[]; | ||
|
||
/** | ||
* The additional base paths to try when looking for dependency files referenced using relative paths, if the compiler | ||
* allows alternative base paths to be specified. | ||
*/ | ||
public basePaths: string[]; | ||
} | ||
basePaths: string[]; | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import Plugin from "./plugin/Plugin"; | ||
import {plugin} from "./plugin/Plugin"; | ||
|
||
// Export the plugin function that will be used in the gulp pipeline. | ||
export = Plugin.create; | ||
export = plugin; |
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 |
---|---|---|
@@ -1,75 +1,67 @@ | ||
import * as util from "gulp-util"; | ||
import * as path from "path"; | ||
import * as through from "through2"; | ||
import PluginConfig from "./PluginConfig"; | ||
import DependencyParser from "./DependencyParser"; | ||
import DependencyTracker from "./DependencyTracker"; | ||
import {IPluginConfig} from "./plugin-config"; | ||
import {DependencyParser} from "../core/dependency-parser/implementation/dependency-parser"; | ||
import {DependencyTracker} from "../core/dependency-tracker/implementation/dependency-tracker"; | ||
|
||
// The static dependency tracker instance. | ||
let dependencyTracker: DependencyTracker; | ||
|
||
/** | ||
* Represents the plugin. | ||
* Creates a new instance of the plugin. | ||
* @param parserConfig The parser configuration use, null, undefined or empty string to use the default configuration, or an instance of a custom IDependencyParser. | ||
* @param pluginConfig The debug configuration use, or null or undefined to disable all debug options. | ||
*/ | ||
export default class Plugin | ||
export function plugin(parserConfig?: {}, pluginConfig?: IPluginConfig): NodeJS.ReadWriteStream | ||
{ | ||
/** | ||
* The static dependency tracker instance. | ||
*/ | ||
private static dependencyTracker: DependencyTracker; | ||
// Get or create the debug options. | ||
if (!pluginConfig) | ||
{ | ||
pluginConfig = {}; | ||
} | ||
|
||
/** | ||
* Creates a new instance of the plugin. | ||
* @param parserConfig The parser configuration use, null, undefined or empty string to use the default configuration, or an instance of a custom IDependencyParser. | ||
* @param pluginConfig The debug configuration use, or null or undefined to disable all debug options. | ||
*/ | ||
public static create(parserConfig?: {}, pluginConfig?: PluginConfig): NodeJS.ReadWriteStream | ||
// Get or create the dependency parser and tracker. | ||
|
||
if (dependencyTracker == null) | ||
{ | ||
// Get or create the debug options. | ||
if (!pluginConfig) | ||
{ | ||
pluginConfig = new PluginConfig(); | ||
} | ||
dependencyTracker = new DependencyTracker(new DependencyParser(parserConfig)); | ||
} | ||
|
||
// Get or create the dependency parser and tracker. | ||
// Return the stream transform. | ||
return through.obj(function (file: util.File, encoding: string, callback: (err?: any, data?: any) => void) | ||
{ | ||
// Get the files that depend on the current file. | ||
let dependentFiles = dependencyTracker.updateAndGetDependents(file, encoding); | ||
|
||
if (Plugin.dependencyTracker == null) | ||
// Should we log the dependents to the console? | ||
if (dependentFiles != null && pluginConfig.logDependents) | ||
{ | ||
Plugin.dependencyTracker = new DependencyTracker(new DependencyParser(parserConfig)); | ||
dependencyTracker.logDependents(path.normalize(file.path), true, process.cwd()); | ||
} | ||
|
||
// Return the stream transform. | ||
return through.obj(function (file: util.File, encoding: string, callback: (err?: any, data?: any) => void) | ||
{ | ||
// Get the files that depend on the current file. | ||
let dependentFiles = Plugin.dependencyTracker.updateAndGetDependents(file, encoding); | ||
|
||
// Should we log the dependents to the console? | ||
if (dependentFiles != null && pluginConfig.logDependents) | ||
{ | ||
Plugin.dependencyTracker.logDependents(path.normalize(file.path), true, process.cwd()); | ||
} | ||
|
||
// Push the current file to the stream. | ||
this.push(file); | ||
// Push the current file to the stream. | ||
this.push(file); | ||
|
||
// If the current file is tracked, add its dependents to the stream. | ||
if (dependentFiles != null) | ||
// If the current file is tracked, add its dependents to the stream. | ||
if (dependentFiles != null) | ||
{ | ||
for (let dependentFile of dependentFiles) | ||
{ | ||
for (let dependentFile of dependentFiles) | ||
{ | ||
this.push(dependentFile); | ||
} | ||
this.push(dependentFile); | ||
} | ||
} | ||
|
||
callback(); | ||
}, | ||
function (callback) | ||
callback(); | ||
}, | ||
function (callback) | ||
{ | ||
// Should we log the dependency map to the console? | ||
if (pluginConfig.logDependencyMap) | ||
{ | ||
// Should we log the dependency map to the console? | ||
if (pluginConfig.logDependencyMap) | ||
{ | ||
Plugin.dependencyTracker.logDependencyMap(process.cwd()); | ||
} | ||
dependencyTracker.logDependencyMap(process.cwd()); | ||
} | ||
|
||
callback(); | ||
}); | ||
} | ||
} | ||
callback(); | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
/** | ||
* Represents the plugin configuration. | ||
*/ | ||
export default class PluginConfig | ||
export interface IPluginConfig | ||
{ | ||
/** | ||
* True to log the dependents of each file to the console; otherwise false. | ||
*/ | ||
public logDependents: boolean; | ||
logDependents?: boolean; | ||
|
||
/** | ||
* True to log the state of the dependency map to the console at the end of the stream; otherwise false. | ||
*/ | ||
public logDependencyMap: boolean; | ||
logDependencyMap?: boolean; | ||
} |