-
Notifications
You must be signed in to change notification settings - Fork 20
/
included-file.js
79 lines (61 loc) · 1.47 KB
/
included-file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import path from 'path';
import fs from 'fs';
import sha1 from './sha1';
import pluginOptionsWrapper from './options';
const pluginOptions = pluginOptionsWrapper.options;
export default class IncludedFile {
constructor(filePath, backingInputFile) {
this.path = filePath;
this.inputFile = backingInputFile;
this.extension = path.extname(this.path);
this.basename = path.basename(this.path);
this.contents = null;
}
prepInputFile() {
this.referencedImportPaths = [];
if (!this.contents) {
this.contents = fs.readFileSync(this.path, 'utf-8');
}
if (pluginOptions.globalVariablesText) {
this.contents = `${pluginOptions.globalVariablesText}\n\n${this.contents}`;
}
this.rawContents = this.contents;
}
addJavaScript(options) {
this.inputFile.addJavaScript(options);
}
addStylesheet(options) {
this.inputFile.addStylesheet(options);
}
error(data) {
data.message = 'Explicitly imported file error: ' + data.message;
this.inputFile.error(data);
}
getArch() {
return this.inputFile.getArch();
}
getBasename() {
return this.basename;
}
getContentsAsString() {
return this.contents;
}
getDisplayPath() {
return this.path;
}
getExtension() {
return this.extension;
}
getFileOptions() {
return {};
}
getPackageName() {
return null;
}
getPathInPackage() {
return this.path;
}
getSourceHash() {
return sha1(this.getContentsAsString());
}
};