-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.ts
72 lines (58 loc) · 1.95 KB
/
gulpfile.ts
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
/* eslint-disable @typescript-eslint/no-require-imports */
const gulp = require('gulp');
const ts = require('gulp-typescript');
const path = require('path');
const fs = require('fs');
const archiver = require('archiver');
const project = ts.createProject('tsconfig.json');
const {execSync} = require('child_process');
gulp.task('package', async () => {
return new Promise((resolve) => {
const packageParth = path.resolve(process.cwd(), 'package');
fs.rmSync(packageParth, {
recursive: true,
force: true,
});
fs.mkdirSync(packageParth);
const zipName = `module.zip`;
const zipFile = fs.createWriteStream(path.join('package', zipName));
const zip = archiver('zip', { zlib: { level: 9 } });
zipFile.on('close', () => {
console.log(zip.pointer() + ' total bytes');
console.log(`Zip file ${zipName} has been written`);
});
zip.pipe(zipFile);
zip.directory('dist/', '.');
zip.finalize();
gulp.src('dist/module.json').pipe(gulp.dest('package/'));
resolve('finished');
});
});
gulp.task('compile', () => {
return gulp.src('src/**/*.ts').pipe(project()).pipe(gulp.dest('dist/'));
});
gulp.task('copy', async () => {
return new Promise((resolve) => {
gulp.src(['static/**', '!static/module.json']).pipe(gulp.dest('dist/'));
const manifestPath = path.resolve(
process.cwd(),
'static',
'module.json'
);
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
const gitVersionString = execSync(
'git describe --tags --always',
{
encoding: 'utf8',
}
);
const version = gitVersionString.trim();
manifest.version = version;
manifest.manifest =
'https://github.com/Kulkodar/shared-compendia/releases/latest/download/module.json';
manifest.download = `https://github.com/Kulkodar/shared-compendia/releases/download/${version}/module.zip`;
fs.writeFileSync('dist/module.json', JSON.stringify(manifest), 'utf-8');
resolve('finished');
});
});
gulp.task('build', gulp.parallel('compile', 'copy'));