-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
172 lines (159 loc) · 4.9 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
const gulp = require('gulp');
const tsc = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const merge_stream = require('merge-stream');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const tsify = require('tsify');
// const gulp_concat = require('gulp-concat');
// const gulp_clean_css = require('gulp-clean-css');
// const gulp_javascript_obfuscator = require('gulp-javascript-obfuscator');
//
const { src, dest } = require('gulp');
const { series } = require('gulp');
//
var fs = require('fs');
//
const output_dist = 'public/dist';
//const output_test = 'public/test';
/**
* Delete **all folder, subfolder and files** in a specific path. (this is a recursive function)
* @param {string} path Path to the folder to delete
*/
function rmdir(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) {
// recursive function
rmdir(curPath);
} else {
// remove the file
fs.unlinkSync(curPath);
}
});
// remove the empty directory
fs.rmdirSync(path);
}
}
/**
* Clean
*/
function clean(cb) {
rmdir(output_dist);
cb();
}
function obfuscator(options) {
const obfuscator_options = ((options) ? options : {
compact: true,
controlFlowFlattening: false,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: false,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
identifierNamesGenerator: 'mangled',
log: false,
renameGlobals: false,
rotateStringArray: false,
selfDefending: false,
stringArray: false,
stringArrayEncoding: 'base64',
stringArrayThreshold: 0.75,
transformObjectKeys: false,
unicodeEscapeSequence: false,
seed: 164823597130, // TODO: Add a random seed (timestamp) ?
});
return gulp_javascript_obfuscator(obfuscator_options);
}
function obfuscate(source, target, cb) {
const obfuscator_options = {
compact: true,
controlFlowFlattening: false,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: false,
deadCodeInjectionThreshold: 0.4,
debugProtection: false,
debugProtectionInterval: false,
disableConsoleOutput: true,
identifierNamesGenerator: 'mangled',
log: false,
renameGlobals: false,
rotateStringArray: false,
selfDefending: false,
stringArray: false,
stringArrayEncoding: 'base64',
stringArrayThreshold: 0.75,
transformObjectKeys: false,
unicodeEscapeSequence: false,
seed: 164823597130, // TODO: Add a random seed (timestamp) ?
};
gulp.src(source)
.pipe(gulp_javascript_obfuscator(obfuscator_options))
.pipe(gulp.dest(target))
.on("end", () => {
cb();
});
}
/**
* MAKE dist/game/*.js
*/
function make_game(cb) {
// const tsProject = tsc.createProject('tsconfig.json');
// var tsResult = gulp.src(['src/**/*.ts'])
// .pipe(sourcemaps.init())
// .pipe(tsProject());
// return merge_stream(tsResult, tsResult.js)
// .pipe(sourcemaps.write('.'))
// .pipe(gulp.dest(`${output_dist}/game`));
return browserify({
basedir: '.',
debug: true,
entries: ['src/main.ts'],
cache: {},
packageCache: {}
})
.plugin(tsify)
.bundle()
.pipe(source('game.js'))
.pipe(dest(`${output_dist}`));
}
/**
* COPY 3pp libraries
*/
function copy_lib(cb) {
src([
'lib/pixi_v5.1.1/pixi.min.js',
'lib/pixi_v5.1.1/pixi.min.js.map',
'lib/pixi-sound_v3.0.3/pixi-sound.js',
'lib/pixi-sound_v3.0.3/pixi-sound.js.map',
'lib/various/scaleToWindow.js',
]).pipe(dest(`${output_dist}/lib`));
cb();
}
/**
* COPY resources
*/
function copy_res(cb) {
src('res/**/*').pipe(dest(`${output_dist}/res`));
cb();
}
//
exports.clean = clean;
//
exports.copy_lib = copy_lib;
exports.copy_res = copy_res;
exports.make_game = make_game;
//
exports.dist = series(clean, make_game, copy_lib, copy_res);
//
exports.default = exports.make_game;
/**
* Watch task: look for changes in ts file and recompile it if necessary
*/
exports.watch = function() {
gulp.watch(['lib/**/*.*'], exports.copy_lib);
gulp.watch(['res/**/*.*'], exports.copy_res);
gulp.watch(['src/**/*.ts'], exports.make_game);
}