-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (34 loc) · 1.38 KB
/
index.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
'use strict';
var W3cAPIConverter = require('w3c-sm');
var logPath = fis.project.getProjectPath() + '/w3c-sm-change-' + (new Date()).toLocaleDateString() + '.log';
module.exports = function (content, file, conf) {
var w3cAPIConverter = new W3cAPIConverter(),
include = conf.include,
result,
logContent = (new Date()).toLocaleTimeString() + '\n',
exclude = conf.exclude;
if (file.isJsLike && fis.util.filter(file.subpath, include, exclude)) {
try {
result = w3cAPIConverter.replace(conf.patterns, content);
if (result.isReplaced) {
if (conf.log) {
logContent += file.subpath + '\n';
for (var k in result.loc) {
logContent += '\t"' + k + '" in line ';
for (var i = 0, loc = result.loc[k], len = loc.length; i < len; i++) {
logContent += '\t' + '[' + loc[i].start.line + ':' + loc[i].start.column + ']';
}
}
logContent += '\n';
fis.util.write(logPath, logContent, 'utf-8', true);
}
return result.content;
}
return content;
} catch (e) {
fis.log.error(file.subpath + ': ' + e.stack);
}
} else {
return content;
}
};