forked from alain-bertrand/Dot-World-Maker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
205 lines (178 loc) · 5.84 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/// <binding BeforeBuild='compile' Clean='clean' ProjectOpened='default' />
"use strict";
var gulp = require("gulp");
var rimraf = require("rimraf");
var typescript = require("gulp-typescript");
var less = require("gulp-less");
var util = require("gulp-util");
var sourcemaps = require('gulp-sourcemaps');
function clean(path)
{
var fs = require("fs");
if (fs.existsSync(path))
fs.unlinkSync(path);
}
function swallowError(error)
{
// If you want details of the error in the console
console.log(error.toString())
this.emit('end')
}
var tsMaker = typescript.createProject({
out: "maker.js",
module: "system",
target: "es5",
experimentalDecorators: true,
sourceMap: true,
});
var tsRuntime = typescript.createProject({
outFile: "runtime.js",
module: "system",
target: "es5",
experimentalDecorators: true,
sourceMap: true,
});
gulp.task("default", function ()
{
process.chdir(__dirname);
console.log("Hi there Dot World Maker Developer!");
console.log("I will watch for you all the TS and LESS files and compile them as needed.");
console.log(" ");
gulp.watch(["public/Engine/**/*.ts", "!public/Engine/**/version.ts"], gulp.series(compileMaker, compileRuntime));
gulp.watch("server/**/*.ts", compileServer);
gulp.watch("public/**/*.less", compileLess);
cb();
});
gulp.task("clean", gulp.series(cleanJS, cleanCSS));
gulp.task("compile", gulp.series(compileLess, compileServer, compileMaker, compileRuntime));
gulp.task("increase-version", updateVersion);
gulp.task("compile:less", compileLess);
function compileLess(cb)
{
process.chdir(__dirname);
return gulp.src(['./public/Less/engine.less']).pipe(less({})).pipe(gulp.dest('./public/Less')).on('error', swallowError);
}
function cleanCSS(cb)
{
process.chdir(__dirname);
clean('./public/Less/engine.css');
clean('./public/Less/home.css');
cb();
}
function cleanJS(cb)
{
process.chdir(__dirname);
clean('./public/maker.js');
clean('./public/maker.js.map');
clean('./public/home.js');
clean('./public/home.js.map');
clean('./public/help/help.js');
clean('./public/help/help.js.map');
clean('./app.js');
clean('./app.js.map');
cb();
}
function compileServer(cb)
{
process.chdir(__dirname);
return gulp.src(['server/**/*.ts','typings/node.d.ts'])
.pipe(sourcemaps.init())
.pipe(sourcemaps.identityMap())
.pipe(typescript({
out: "app.js",
module: "system",
target: "es2017",
experimentalDecorators: true,
sourceMap: true,
}))
.pipe(sourcemaps.write(".", { includeContent: false, addComment: true }))
.pipe(gulp.dest("."))
.on('error', swallowError)
.on('finish', function ()
{
util.log(util.colors.cyan("Server compilation complete"));
});
}
function updateVersion()
{
return new Promise(function (ok, err)
{
process.chdir(__dirname + "/public");
var fs = require("fs");
fs.readFile("./Engine/Module/About/version.ts", "utf8", function (err2, data)
{
var lastBuild = data;
if (err2)
{
err(err2)
return;
}
var m = lastBuild.match(/engineVersion\s*=\s*"([^"]+)"/i);
var version = m[1].split('.');
version[version.length - 1] = "" + (parseInt(version[version.length - 1]) + 1);
var newVersion = "var engineVersion = \"" + version.join(".") + "\";\n";
newVersion += "var engineBuild = \"" + (new Date).toUTCString() + "\";\n";
fs.writeFile("./Engine/Module/About/version.ts", newVersion, "utf8", function (err3)
{
if (err3)
{
err(err3);
return;
}
console.log("end");
ok();
});
});
});
}
function compileMaker(cb)
{
process.chdir(__dirname + "/public");
return gulp.src(['./Engine/**/*.ts'])
.pipe(sourcemaps.init())
.pipe(sourcemaps.identityMap())
.pipe(typescript({
out: "maker.js",
module: "system",
target: "es5",
experimentalDecorators: true,
sourceMap: true,
}))
.pipe(sourcemaps.write(".", {
includeContent: false, addComment: true
}))
.pipe(gulp.dest("."))
.on('error', swallowError)
.on('finish', function ()
{
util.log(util.colors.cyan("Maker compilation complete"));
//gulp.start('compile:maker:mini');
});
}
function compileRuntime(cb)
{
process.chdir(__dirname + "/public");
return gulp.src(['./Engine/Logic/**/*.ts', './Engine/Module/MapEditor/MapEditorData.ts', './Engine/Module/ZoneEditor/ZoneEditorData.ts', './Engine/GUI/**/*.ts', './Engine/Libs/**/*.ts', './Engine/*.ts', './Engine/Module/Play/*.ts', './Engine/Module/GameList/*.ts', './Engine/Module/Logout/*.ts'])
.pipe(sourcemaps.init({ largeFile: true }))
.pipe(sourcemaps.identityMap())
.pipe(typescript({
outFile: "runtime.js",
module: "system",
target: "es5",
experimentalDecorators: true
}))
.pipe(sourcemaps.write(".", { includeContent: false, addComment: true }))
.pipe(gulp.dest("."))
.on('error', swallowError)
.on('finish', function ()
{
util.log(util.colors.cyan("Runtime compilation complete"));
//gulp.start('compile:runtime:mini');
});
}
gulp.task("clean:css", cleanCSS);
gulp.task("clean:js", cleanJS);
gulp.task("compile:client", gulp.series(compileMaker, compileRuntime));
gulp.task('compile:maker', compileMaker);
gulp.task('compile:runtime', compileRuntime);
gulp.task('compile:server', compileServer);