-
Notifications
You must be signed in to change notification settings - Fork 10
/
gulpfile.js
57 lines (46 loc) · 1.45 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
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 WORK_DIR = process.cwd();
const DIST_DIR = path.join(WORK_DIR, './dist');
const BUILD_DIR = path.join(DIST_DIR, 'bundles');
if (!fs.existsSync(DIST_DIR)) {
throw new Error('Build ReAPI project before packing');
}
const resolveArchiveName = (suffix) =>
`${package.name}-${package.version.replace(/\./g, '')}-${suffix}.zip`;
const FILES = {
bundleArchive: resolveArchiveName('bundle'),
addonsArchive: resolveArchiveName('addons'),
resourcesArchive: resolveArchiveName('resources'),
};
const BUNDLE_FILES = [
{ name: FILES.addonsArchive },
{ name: FILES.resourcesArchive },
];
gulp.task('pack:bundles', () => {
const dirPatterns = {
all: DIST_DIR + '/**',
addons: DIST_DIR + '/addons{,/**}',
};
return merge2([
gulp.src([dirPatterns.addons]).pipe(zip(FILES.addonsArchive)),
gulp
.src([dirPatterns.all, '!' + dirPatterns.addons])
.pipe(zip(FILES.resourcesArchive)),
]).pipe(gulp.dest(BUILD_DIR));
});
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'));