-
Notifications
You must be signed in to change notification settings - Fork 10
/
Gulpfile.js
130 lines (117 loc) · 3.5 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
// Generated on 2017-03-22 using generator-mendix 2.0.4 :: git+https://github.com/mendix/generator-mendix.git
/*jshint -W069,-W097*/
"use strict";
// In case you seem to have trouble starting Mendix through `gulp modeler`, you might have to set the path to the Mendix application, otherwise leave both values as they are
var MODELER_PATH = null;
var MODELER_ARGS = "/file:{path}";
/********************************************************************************
* Do not edit anything below, unless you know what you are doing
********************************************************************************/
var gulp = require("gulp"),
zip = require("gulp-zip"),
del = require("del"),
newer = require("gulp-newer"),
gutil = require("gulp-util"),
gulpif = require("gulp-if"),
jsonTransform = require("gulp-json-transform"),
intercept = require("gulp-intercept"),
argv = require("yargs").argv,
widgetBuilderHelper = require("widgetbuilder-gulp-helper"),
jsValidate = require("gulp-jsvalidate"),
minify = require("gulp-minify"),
fs = require("fs-extra"),
del = require("del");
var pkg = require("./package.json"),
paths = widgetBuilderHelper.generatePaths(pkg),
xmlversion = widgetBuilderHelper.xmlversion;
gulp.task("default", function() {
gulp.watch("./src/**/*", [ "compress" ]);
gulp.watch("./src/**/*.js", [ "copy:js" ]);
});
gulp.task("clean", function() {
return del([ paths.WIDGET_TEST_DEST, paths.WIDGET_DIST_DEST ], {
force : true,
});
});
gulp.task("compress", [ "clean" ], function() {
return gulp
.src("src/**/*")
.pipe(zip(pkg.name + ".mpk"))
.pipe(gulp.dest(paths.TEST_WIDGETS_FOLDER))
.pipe(gulp.dest("dist"));
});
gulp.task("copy:js", function() {
return gulp
.src([ "./src/**/*.js" ])
.pipe(jsValidate())
.pipe(newer(paths.TEST_WIDGETS_DEPLOYMENT_FOLDER))
.pipe(gulp.dest(paths.TEST_WIDGETS_DEPLOYMENT_FOLDER));
});
gulp.task("version:xml", function() {
return gulp.src(paths.PACKAGE_XML).pipe(xmlversion(argv.n)).pipe(gulp.dest("./src/"));
});
gulp.task("version:json", function() {
return gulp
.src("./package.json")
.pipe(
gulpif(
typeof argv.n !== "undefined",
jsonTransform(function(data) {
data.version = argv.n;
return data;
}, 2),
),
)
.pipe(gulp.dest("./"));
});
gulp.task("icon", function(cb) {
var icon = typeof argv.file !== "undefined" ? argv.file : "./icon.png";
console.log("\nUsing this file to create a base64 string: " + gutil.colors.cyan(icon));
gulp.src(icon).pipe(
intercept(function(file) {
console.log(
"\nCopy the following to your " +
pkg.name +
".xml (after description):\n\n" +
gutil.colors.cyan("<icon>") +
file.contents.toString("base64") +
gutil.colors.cyan("</icon>") +
"\n",
);
cb();
}),
);
});
gulp.task("folders", function() {
paths.showPaths();
return;
});
gulp.task("modeler", function(cb) {
widgetBuilderHelper.runmodeler(MODELER_PATH, MODELER_ARGS, paths.TEST_PATH, cb);
});
gulp.task("build:prod", function() {
try {
del.sync("build/**", {force: true}); // cleanup buid dir
fs.copySync("src", "build"); // copy everthing
gulp
.src([ "src/**/*.js" ]) // overwrite .js files with the minified ones.
.pipe(
minify({
ext : {
min : ".js",
},
noSource : true,
mangle : true,
}),
)
.pipe(gulp.dest("build"));
return gulp
.src("build/**/*")
.pipe(zip(pkg.name + ".mpk"))
.pipe(gulp.dest(paths.TEST_WIDGETS_FOLDER))
.pipe(gulp.dest("build"))
.pipe(gulp.dest("dist"));
} catch (e) {
console.error(e);
}
});