-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.mjs
More file actions
98 lines (81 loc) · 2.68 KB
/
gulpfile.mjs
File metadata and controls
98 lines (81 loc) · 2.68 KB
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
import { loadConfig, build as rslibBuild } from '@rslib/core';
import esbuild from 'esbuild';
import fs from 'fs';
import gulp, { series } from 'gulp';
import zip from 'gulp-zip';
import path from 'path';
import packageJson from './package.json' with { type: 'json' };
const folder = (packageJson.author + '_' + packageJson.name).toLowerCase().replace(' ', '-');
const filesToCopy = [
'package.json',
'LICENSE',
'README.md',
'default.gamecontroller.amgp'
];
async function buildTask() {
// Build main extension (Node.js)
const nodeBuild = esbuild.build({
bundle: true,
entryPoints: ['./src/extension.ts'],
outfile: './dist/extension.js',
platform: 'node',
external: ['flashpoint-launcher'],
});
const config = await loadConfig('./rslib.config.ts');
await Promise.all([nodeBuild, rslibBuild({
...config.content,
mode: 'development'
})])
.catch(console.error)
}
async function watchTask() {
const ctx = await esbuild.context({
bundle: true,
entryPoints: ['./src/extension.ts'],
outfile: './dist/extension.js',
platform: 'node',
external: ['flashpoint-launcher', '*.css'],
});
const config = await loadConfig('./rslib.config.ts');
const renderer = rslibBuild({
...config.content,
mode: 'development',
watch: true
});
await Promise.all([ctx.watch(), renderer])
.catch(console.error);
}
function clean(cb) {
fs.rm('./package', { recursive: true }, (err) => {
if (err) { console.log('Clean', err); }
cb();
});
}
async function stage() {
// Ensure base directory exists
await fs.promises.mkdir(`package/${folder}`, { recursive: true });
const copyTasks = [];
// Copy individual files
for (const file of filesToCopy) {
if (fs.existsSync(file)) {
copyTasks.push(
fs.promises.cp(file, path.join(`package/${folder}`, file))
);
}
}
// Copy dist directory
copyTasks.push(packagePathTask('AntiMicroX', (src) => !src.includes('antimicrox_settings.ini')));
copyTasks.push(packagePathTask('dist'));
copyTasks.push(packagePathTask('static'));
await Promise.all(copyTasks);
}
function packagePathTask(src, filter) {
const dest = `package/${folder}/${src}`;
return fs.promises.cp(src, dest, { recursive: true, filter });
}
function packageExtTask() {
return gulp.src('package/**/*', { encoding: false }).pipe(zip(packageJson.artifactName)).pipe(gulp.dest('.'));
}
export const build = series(buildTask);
export const watch = series(watchTask);
export const packageExt = series(clean, build, stage, packageExtTask);