-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.mjs
45 lines (36 loc) · 1016 Bytes
/
build.mjs
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
import {build} from "tsup";
import fg from "fast-glob";
import path from 'path'
import fs from 'fs'
const outdir = 'artifacts'
const buildToFromMap = (glob, stripExtension = false) => {
return fg.sync(glob).reduce((acc, from) => {
const fromInfo = path.parse(from)
const [src, ...namespace] = fromInfo.dir.split('/');
let to = [...namespace, fromInfo.name].join('-').replace(/[._]/g, '-')
if (!stripExtension) {
to = to + fromInfo.ext
}
if (src === 'src'){
to = '_' + to
}
acc[to] = from
return acc
}, {})
}
await build({
entry: buildToFromMap(['./{src,tests}/**/*.k6.ts'], true),
outDir: outdir,
minify: false,
platform: 'browser',
external: ['k6'],
bundle: true,
clean: true,
noExternal: ['lodash', '@ownclouders/k6-tdk', 'zod'],
splitting: true,
sourcemap: true,
esbuildOptions: (options) => {
options.chunkNames = `__chunk/[name]-[hash]`;
}
});
fs.cpSync('data', path.resolve(path.join(outdir, 'data')), {recursive: true})