forked from gorner/broccoli-templater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate-file.js
47 lines (38 loc) · 1 KB
/
template-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
'use strict'
const fs = require('fs');
module.exports = class TemplateFile {
static fromPath(path) {
return new this(path);
}
constructor(path, _stat, _content) {
this.path = path;
this._stat = _stat;
this._content = _content;
this.__template = undefined;
}
get stat() {
if (this._stat !== undefined) {
return this._stat;
}
return (this._stat = fs.statSync(this.path))
}
equal(other) {
// key represents a other, diff the other
if (this.path === other.path &&
this.stat.mode === other.stat.mode &&
this.stat.size === other.stat.size &&
this.type === 'directory' ? true : this.stat.mtime.getTime() === other.stat.mtime.getTime()) {
return true;
}
}
get _template() {
if (this.__template) {
return this.__template;
}
const templater = require('lodash/template');
return (this.__template = templater(fs.readFileSync(this.path)));
}
template(variables) {
return this._template(variables);
}
}