forked from Plaristote/qmlweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (36 loc) · 1.3 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
var es = require('event-stream');
var gutil = require('gulp-util');
// QML Parser
require(__dirname + '/src/qtcore/qml/QMLBinding.js');
require(__dirname + '/src/qtcore/qml/lib/parser.js');
// JS Parser
require(__dirname + '/src/uglify/node.js');
require(__dirname + '/src/qtcore/qml/lib/jsparser.js');
module.exports = function (opt) {
function modifyFile(file) {
if (file.isNull()) return this.emit('data', file);
if (file.isStream()) return this.emit('error', new Error("gulp-qml: Streaming not supported"));
var data;
var src;
var str = file.contents.toString('utf8');
var dest = gutil.replaceExtension(file.path, ".js");
var gulpPath = __dirname.split('/');
gulpPath = gulpPath.splice(0, gulpPath.length - 2).join('/') + '/';
var path = file.path.substr(gulpPath.length, file.path.length);
try {
if (file.path.match(/\.qml$/) != null)
data = qmlparse(str);
else if (file.path.match(/\.js$/) != null)
data = jsparse(str);
else
data = str;
} catch (err) {
return this.emit('error', new Error(file.path + ': ' + err));
}
src = "qrc['"+path+"'] = " + JSON.stringify(data) + ';';
file.contents = new Buffer(src);
file.path = dest;
this.emit('data', file);
}
return es.through(modifyFile);
};