gulp-dependents
Version:
Gulp plugin that tracks dependencies between files and adds any files that depend on the files currently in the stream, thus enabling incremental build of pcss, less, scss, sass, with extensibility points to support other file types.
70 lines (69 loc) • 3.14 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.plugin = void 0;
var path = __importStar(require("path"));
var through = __importStar(require("through2"));
var dependency_parser_1 = require("../core/dependency-parser/implementation/dependency-parser");
var dependency_tracker_1 = require("../core/dependency-tracker/implementation/dependency-tracker");
// The static dependency tracker instance.
var dependencyTracker;
/**
* 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.
*/
function plugin(parserConfig, pluginConfig) {
// Get or create the debug options.
if (!pluginConfig) {
pluginConfig = {};
}
// Get or create the dependency parser and tracker.
if (dependencyTracker == null) {
dependencyTracker = new dependency_tracker_1.DependencyTracker(new dependency_parser_1.DependencyParser(parserConfig));
}
// Return the stream transform.
return through.obj(function (file, encoding, callback) {
// Get the files that depend on the current file.
var dependentFiles = dependencyTracker.updateAndGetDependents(file, encoding);
// Should we log the dependents to the console?
if (dependentFiles != null && pluginConfig.logDependents) {
dependencyTracker.logDependents(path.normalize(file.path), true, process.cwd());
}
// 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) {
for (var _i = 0, dependentFiles_1 = dependentFiles; _i < dependentFiles_1.length; _i++) {
var dependentFile = dependentFiles_1[_i];
this.push(dependentFile);
}
}
callback();
}, function (callback) {
// Should we log the dependency map to the console?
if (pluginConfig.logDependencyMap) {
dependencyTracker.logDependencyMap(process.cwd());
}
callback();
});
}
exports.plugin = plugin;
;