forked from luffah/Terminus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·188 lines (174 loc) · 4.54 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
/*jshint esversion: 6 */
/*
* Copyright (C) 2017 luffah<[email protected]>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//require("es6-promise").polyfill();
//const fs = require('fs');
const gulp = require("gulp");
const file = require('gulp-file');
const del = require("del");
const concat = require("gulp-concat");
const inject = require('gulp-inject');
const htmlminifier = require("gulp-html-minifier");
const uglify = require('gulp-uglify');
const postcss = require("gulp-postcss");
var postcss_plugins = [
require("autoprefixer"),
require("cssnano")
];
const po2json = require('po2json');
var languages=['fr','en'];
function _make_all(){
// var clean=false;
// while (!clean){
// try {
// fs.statSync('tmp');
// fs.statSync('webroot');
// console.log('Waiting _clean to finish');
// } catch (e) {
// clean=true;
// }
// }
var dialogs=_dialogs(languages);
var js=_js();
var css=_css();
var images=_images();
var sounds=_sounds();
for (i in dialogs){
_html(i,dialogs[i],images,js,css);
}
}
function _js(){
/*
* JS (without dialogs)
*/
var jssrc=[
'src/js/engine/howler.core.js',
'src/js/engine/js.js',
'src/js/engine/Gettext.js',
'src/js/engine/Cookie.js',
'src/js/engine/GameState.js',
'src/js/engine/EventTarget.js',
'src/js/engine/Sound.js',
'src/js/engine/Music.js',
'src/js/engine/ReturnSequence.js',
'src/js/engine/VTerm.js',
'src/js/engine/User.js',
'src/js/engine/Parse.js',
'src/js/engine/Command.js',
'src/js/engine/Commands.js',
'src/js/engine/Pic.js',
'src/js/engine/Item.js',
'src/js/engine/Room.js',
'src/js/terminus.init.js',
'src/js/terminus.assets.js',
'src/js/terminus.utils.js',
'src/js/terminus.gamestart.js',
'src/js/terminus.level1.js',
'src/js/terminus.level2.js',
'src/js/terminus.run.js',
];
/* uncomment this for debuging */
gulp.src(jssrc)
.pipe(concat('min.js'))
.pipe(gulp.dest("./"))
;
/* --------------------------- */
return gulp.src(jssrc)
.pipe(concat('min.js'))
.pipe(uglify());
}
function _css(){
/*
* CSS
*/
return gulp.src("src/css/terminus.css")
.pipe(concat('min.css'))
.pipe(postcss(postcss_plugins));
}
function _images(){
/*
* Images
*/
return gulp.src('src/img/*')
.pipe(gulp.dest('webroot/img/'));
}
function _sounds(){
/*
* Sounds
*/
return gulp.src('src/snd/*.wav')
.pipe(gulp.dest('webroot/snd/'));
}
function _filter_dialogs(jsonData){
var ret={};
for (j in jsonData){
if (i) {
ret[j]=jsonData[j][1];
}
}
return ret;
}
function _dialogs(tlang){
/*
* Translations / text
*/
var data = {};
for (i in tlang){
try {
data[tlang[i]] = 'var dialog=' + JSON.stringify(
_filter_dialogs(
po2json.parseFileSync('src/lang/terminus.'+tlang[i]+'.po')
)
) +';';
file("terminus.dialog."+tlang[i]+".js",
"//Warning this file is autogenerated \n"+data[tlang[i]]+"\nconst APP_NAME='terminus';const LANG='"+tlang[i]+"';",
{src:true})
.pipe(gulp.dest('src/js/_build'));
} catch (e) {
console.log(e);
}
}
return data;
}
function _html(lang,dialogs,images,js,css){
/*
* HTML
*/
var inject_def_css = { transform:
function (filePath, file) {
return '<style>'+file.contents.toString('utf8')+'</style>'; }
};
var inject_def_js = { transform:
function (filePath, file) {
return '<script>' + dialogs +
file.contents.toString('utf8') +
'</script>';
}
};
gulp.src('src/*.html')
.pipe(htmlminifier({collapseWhitespace: true}))
.pipe(inject(css, inject_def_css))
.pipe(inject(js, inject_def_js))
.pipe(concat("terminus."+lang+".html"))
.pipe(gulp.dest("webroot/"));
return true;
}
function _clean(){
return del.sync(['webroot']);
}
gulp.task('clean', _clean);
gulp.task('makeall', ['clean'], _make_all);
gulp.task('default', ['makeall']);