forked from Hedgefog/cs-halloween-mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
95 lines (81 loc) · 3.61 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
const path = require('path');
const fs = require('fs');
const gulp = require('gulp');
const zip = require('gulp-zip');
const file = require('gulp-file');
const merge2 = require('merge2');
const package = require('./package.json');
const generateReadme = require('./helpers/bundle-readme.generator');
const WORK_DIR = process.cwd();
const DIST_DIR = path.join(WORK_DIR, './dist');
const BUILD_DIR = path.join(DIST_DIR, 'bundles');
const VANILLA_DIST_DIR = path.join(DIST_DIR, 'vanilla');
const REAPI_DIST_DIR = path.join(DIST_DIR, 'reapi');
if (!fs.existsSync(REAPI_DIST_DIR)) {
throw new Error('Build ReAPI project before packing');
}
const resolveArchiveName = (sufix) => `${package.name}-${package.version.replace(/\./g, '')}-${sufix}.zip`;
const FILES = {
bundleArchive: resolveArchiveName('bundle'),
srcArchive: resolveArchiveName('addons-src'),
addonsVanillaArchive: resolveArchiveName('addons'),
addonsReapiArchive: resolveArchiveName('addons-reapi'),
resourcesArchive: resolveArchiveName('resources'),
sdkArchive: resolveArchiveName('sdk'),
readme: 'README.TXT'
};
const BUNDLE_FILES = [
{ name: FILES.addonsVanillaArchive, description: 'compiled plugins and source code' },
{ name: FILES.addonsReapiArchive, description: 'compiled plugins for reapi and source code' },
{ name: FILES.resourcesArchive, description: 'mod resources' },
{ name: FILES.sdkArchive, description: 'mod sdk' }
];
gulp.task('pack:vanilla:bundles', () => {
const dirPatterns = {
all: VANILLA_DIST_DIR + '/**',
addons: VANILLA_DIST_DIR + '/addons{,/**}',
plugins: VANILLA_DIST_DIR + '/addons/amxmodx/plugins{,/**}',
modules: VANILLA_DIST_DIR + '/addons/amxmodx/modules{,/**}',
roundControl: path.join(WORK_DIR, '.thirdparty/round-control/roundcontrol_2.2/**'),
sdk: WORK_DIR + '/sdk/**'
};
return merge2([
gulp.src([dirPatterns.addons, '!' + dirPatterns.plugins, '!' + dirPatterns.modules])
.pipe(zip(FILES.srcArchive)),
gulp.src([dirPatterns.addons, dirPatterns.roundControl])
.pipe(zip(FILES.addonsVanillaArchive)),
gulp.src([dirPatterns.all, '!' + dirPatterns.addons])
.pipe(zip(FILES.resourcesArchive)),
gulp.src([dirPatterns.sdk])
.pipe(zip(FILES.sdkArchive)),
file(FILES.readme, generateReadme(BUNDLE_FILES), {src: true})
]).pipe(gulp.dest(BUILD_DIR));
});
gulp.task('pack:reapi:bundles', () => {
const dirPatterns = {
all: REAPI_DIST_DIR + '/**',
addons: REAPI_DIST_DIR + '/addons{,/**}',
plugins: REAPI_DIST_DIR + '/addons/amxmodx/plugins{,/**}',
modules: REAPI_DIST_DIR + '/addons/amxmodx/modules{,/**}',
sdk: WORK_DIR + '/sdk/**'
};
return merge2([
gulp.src([dirPatterns.addons, '!' + dirPatterns.plugins, '!' + dirPatterns.modules])
.pipe(zip(FILES.srcArchive)),
gulp.src([dirPatterns.addons])
.pipe(zip(FILES.addonsReapiArchive)),
gulp.src([dirPatterns.all, '!' + dirPatterns.addons])
.pipe(zip(FILES.resourcesArchive)),
gulp.src([dirPatterns.sdk])
.pipe(zip(FILES.sdkArchive)),
file(FILES.readme, generateReadme(BUNDLE_FILES), {src: true})
]).pipe(gulp.dest(BUILD_DIR));
});
gulp.task('pack:bundles', gulp.series('pack:reapi:bundles', 'pack:vanilla:bundles'));
gulp.task('pack:full', () => {
const bundleFiles = BUNDLE_FILES.map(file => path.join(BUILD_DIR, file.name));
return gulp.src(bundleFiles)
.pipe(zip(FILES.bundleArchive))
.pipe(gulp.dest(BUILD_DIR))
})
gulp.task('default', gulp.series('pack:bundles', 'pack:full'));