Projekt

Obecné

Profil

Stáhnout (1.67 KB) Statistiky
| Větev: | Revize:
1
/*
2
MIT License http://www.opensource.org/licenses/mit-license.php
3
Author Tobias Koppers @sokra
4
*/
5
"use strict";
6

    
7
const DescriptionFileUtils = require("./DescriptionFileUtils");
8

    
9
module.exports = class DescriptionFilePlugin {
10
	constructor(source, filenames, target) {
11
		this.source = source;
12
		this.filenames = [].concat(filenames);
13
		this.target = target;
14
	}
15

    
16
	apply(resolver) {
17
		const target = resolver.ensureHook(this.target);
18
		resolver.getHook(this.source).tapAsync("DescriptionFilePlugin", (request, resolveContext, callback) => {
19
			const directory = request.path;
20
			DescriptionFileUtils.loadDescriptionFile(resolver, directory, this.filenames, resolveContext, (err, result) => {
21
				if(err) return callback(err);
22
				if(!result) {
23
					if(resolveContext.missing) {
24
						this.filenames.forEach((filename) => {
25
							resolveContext.missing.add(resolver.join(directory, filename));
26
						});
27
					}
28
					if(resolveContext.log) resolveContext.log("No description file found");
29
					return callback();
30
				}
31
				const relativePath = "." + request.path.substr(result.directory.length).replace(/\\/g, "/");
32
				const obj = Object.assign({}, request, {
33
					descriptionFilePath: result.path,
34
					descriptionFileData: result.content,
35
					descriptionFileRoot: result.directory,
36
					relativePath: relativePath
37
				});
38
				resolver.doResolve(target, obj, "using description file: " + result.path + " (relative path: " + relativePath + ")", resolveContext, (err, result) => {
39
					if(err) return callback(err);
40

    
41
					// Don't allow other processing
42
					if(result === undefined) return callback(null, null);
43
					callback(null, result);
44
				});
45
			});
46
		});
47
	}
48
};
(9-9/39)