-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
100 lines (87 loc) · 2.63 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
const gulp = require('gulp');
const qml = require('./gulp-qmlweb');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();
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 = [
"qmlweb/qtbase/QObject.js",
"qmlweb/qtbase/*.js",
"qmlweb/modules/QtQml/Qt.js",
"qmlweb/engine/QML*.js",
"qmlweb/engine/*.js",
"qmlweb/modules/**/*.js",
];
const app_sources = [
"src/**/*.qml",
"src/**/*.js",
];
const qmlweb_output = './build/js/qmlweb/';
const app_output = './build/js/';
const all_sources = sources.concat(app_sources).concat(["qmlweb/QmlWeb.js"]);
// This is required because other values confuse PhantomJS, and are sometimes
// set by default by the system.
process.env.QT_QPA_PLATFORM = "";
gulp.task('app-parser', function() {
gulp.src(app_sources)
.pipe(qml({
pathFilter: (p) => {
return p.substr(p.search('/'));
}
}).on('error', (err) => console.log(err)))
.pipe(concat('app.js'))
.pipe(gulp.dest('qmlweb/'));
});
gulp.task('app', ["app-parser"], function() {
gulp.src(["qmlweb/QmlWeb.js", "qmlweb/app.js"])
.pipe(concat('app.js'))
.pipe(gulp.dest(app_output));
});
gulp.task('app.min', ["app-parser"], function() {
gulp.src([app_output + "app.js"])
.pipe(rename('app.min.js'))
.pipe(changed(app_output))
.pipe(uglify())
.pipe(gulp.dest(app_output));
});
gulp.task("qmlweb", () => {
gulp.src(sources)
.pipe(order(sources, { base: __dirname }))
.pipe(concat("qmlweb.js"))
.pipe(changed(qmlweb_output))
.pipe(babel())
.pipe(replace(/"use strict";/g, ""))
.pipe(iife({
useStrict: false,
params: ["global"],
args: ["typeof global != \"undefined\" ? global : window"]
}))
.pipe(gulp.dest(qmlweb_output));
});
gulp.task("qmlweb.min", ["qmlweb"], () =>
gulp.src(qmlweb_output + "qmlweb.js")
.pipe(rename("qmlweb.min.js"))
.pipe(changed(qmlweb_output))
.pipe(uglify())
.pipe(gulp.dest(qmlweb_output))
);
gulp.task("build-dev", ["qmlweb", "app"]);
gulp.task("build", ["qmlweb.min", "app.min"]);
gulp.task('serve', function() {
browserSync.exit()
browserSync.init({
server: "./build"
});
gulp.watch(["./build/**/*"]).on('change', browserSync.reload);
});
gulp.task("watch", ["build-dev", "serve"], () => {
gulp.watch(all_sources, ["build-dev"]);
});