-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
92 lines (69 loc) · 2.33 KB
/
index.js
File metadata and controls
92 lines (69 loc) · 2.33 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
var through = require('through2'),
gutil = require('gulp-util'),
File = gutil.File,
path = require("path");
module.exports = function(fileName, options) {
options = options || {
prefix: "Vtb.template",
dirName: false
};
var firstFile = null;
var contentFile;
var header = "var Vtb = Vtb || {};\n(function () {\n'use strict';"
var footer = "\n})();"
var text = header;
function bufferContents(file, enc, callback) {
// ignore empty files
if (file.isNull()) {
callback();
return;
}
if (!firstFile) {
firstFile = file;
}
var methodName = path.basename(file.path).split('.');
if(options.dirName) {
var dirName = file.base.split("templates/")[1].split("/");
var dj = dirName.length - 2;
}
if(options.dirName) {
text += "\n\t" + options.prefix + "." + dirName[dj] + "." + methodName[0] + " = '";
} else {
text += "\n\t" + options.prefix + "." + methodName[0] + " = '";
}
text += "<script>" + file.contents.toString().replace(/(\r\n|\n|\r|\t)/gm,"").replace(/\s{2,}/g, ' ') + "</script>";
text += "';";
// minify(file.path, function(error, data) {
// if (error) {
// console.error(error.message);
// } else {
// console.log(data);
// text += data;
// // console.log(text);
// // console.log("------");
// }
// });
// console.log(compileText);
callback();
};
function endStream(callback) {
// console.log(text += footer);
// exportFile.relative = "test.js";
// exportFile.contents = text + footer;
// console.log(exportFile);
// this.push(text + footer);
//Configure outgoing file.
var joinedPath = path.join(firstFile.base, fileName);
var joinedFile = new File({
cwd: firstFile.cwd
,base: firstFile.base
,path: joinedPath
,contents: new Buffer(text + footer)
});
// console.log(joinedFile);
this.push(joinedFile);
callback();
}
return through.obj(bufferContents, endStream);
};