forked from qmlweb/qmlweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
176 lines (154 loc) · 4.57 KB
/
gulpfile.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
const gulp = require("gulp");
const concat = require("gulp-concat");
const rename = require("gulp-rename");
const changed = require("gulp-changed");
const order = require("gulp-order");
const uglify = require("gulp-uglify");
const sourcemaps = require("gulp-sourcemaps");
const iife = require("gulp-iife");
const babel = require("gulp-babel");
const replace = require("gulp-replace");
const karma = require("karma");
const path = require("path");
const sources = [
"src/QmlWeb.js",
"src/qtbase/QObject.js",
"src/qtbase/*.js",
"src/modules/QtQml/Qt.js",
"src/engine/QML*.js",
"src/engine/*.js",
"src/modules/**/*.js"
];
const parserSources = [
"node_modules/qmlweb-parser/lib/*"
];
const licenseSources = [
"LICENSE",
"node_modules/qmlweb-parser/LICENSE"
];
// This is required because other values confuse PhantomJS, and are sometimes
// set by default by the system.
process.env.QT_QPA_PLATFORM = "";
gulp.task("license", () =>
gulp.src(licenseSources)
.pipe(order(licenseSources, { base: __dirname }))
.pipe(concat("LICENSE"))
.pipe(changed("./lib"))
.pipe(gulp.dest("./lib"))
);
gulp.task("parser", () =>
gulp.src(parserSources)
.pipe(gulp.dest("./lib"))
);
gulp.task("parser-covered", () =>
// This file is not covered here on a purpose.
// Name *.covered.js is required to autoload from qt.covered.js.
gulp.src("node_modules/qmlweb-parser/lib/qmlweb.parser.js")
.pipe(rename("qmlweb.parser.covered.js"))
.pipe(changed("./tmp"))
.pipe(gulp.dest("./tmp"))
);
gulp.task("qmlweb-covered", () =>
gulp.src(sources)
.pipe(order(sources, { base: __dirname }))
.pipe(babel({
presets: ["es2015"],
plugins: ["transform-class-properties", "istanbul"]
}))
.pipe(concat("qmlweb.covered.js"))
.pipe(changed("./tmp"))
.pipe(replace(/["']use strict["'];/g, ""))
.pipe(iife({
useStrict: false,
params: ["global"],
args: ["typeof global != \"undefined\" ? global : window"]
}))
.pipe(gulp.dest("./tmp"))
);
gulp.task("qmlweb", () =>
gulp.src(sources)
.pipe(order(sources, { base: __dirname }))
.pipe(sourcemaps.init())
.pipe(concat("qmlweb.js"))
.pipe(changed("./lib"))
.pipe(babel())
.pipe(replace(/"use strict";/g, ""))
.pipe(iife({
useStrict: false,
params: ["global"],
args: ["typeof global != \"undefined\" ? global : window"]
}))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./lib"))
);
gulp.task("qmlweb.min", ["qmlweb"], () =>
gulp.src("./lib/qmlweb.js")
.pipe(rename("qmlweb.min.js"))
.pipe(changed("./lib"))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./lib"))
);
// Legacy library name, TODO: remove
gulp.task("qt", ["qmlweb"], () =>
gulp.src("./lib/qmlweb.js")
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(concat("qt.js"))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./lib"))
);
// Legacy library name, TODO: remove
gulp.task("qt.min", ["qmlweb.min"], () =>
gulp.src("./lib/qmlweb.min.js")
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(concat("qt.min.js"))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./lib"))
);
gulp.task("build-covered", ["parser-covered", "qmlweb-covered"]);
gulp.task("build-dev", ["qmlweb", "parser", "license"]);
gulp.task("build", [
"qmlweb", "parser", "license", "qmlweb.min", "qt", "qt.min"
]);
gulp.task("watch", ["build"], () => {
gulp.watch(sources, ["qmlweb", "qmlweb.min", "qt", "qt.min"]);
gulp.watch(parserSources, ["parser"]);
gulp.watch(licenseSources, ["license"]);
});
gulp.task("watch-dev", ["build-dev"], () => {
gulp.watch(sources, ["qmlweb", "qt"]);
gulp.watch(parserSources, ["parser"]);
gulp.watch(licenseSources, ["license"]);
});
gulp.task("test", ["build-dev"], () => {
new karma.Server({
singleRun: true,
configFile: path.join(__dirname, "karma.conf.js")
}, code => {
process.exit(code);
}).start();
});
gulp.task("coverage", ["build-covered"], () => {
new karma.Server({
singleRun: true,
coverageEnabled: true,
configFile: path.join(__dirname, "karma.conf.js")
}, code => {
process.exit(code);
}).start();
});
gulp.task("test-watch", ["watch-dev"], done => {
new karma.Server({
configFile: path.join(__dirname, "karma.conf.js")
}, done).start();
});
gulp.task("test-debug", ["watch-dev"], done => {
new karma.Server({
configFile: path.join(__dirname, "karma.conf.js"),
browsers: ["PhantomJSCustom", "Chrome"],
reporters: ["progress"],
debug: true
}, done).start();
});
gulp.task("default", ["watch"]);