-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbuild.mjs
More file actions
61 lines (54 loc) · 1.67 KB
/
build.mjs
File metadata and controls
61 lines (54 loc) · 1.67 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
import {build} from 'tsup';
import path from 'path';
import fs from 'fs';
const instructions = {
root: 'src',
outdir: 'dist',
entryPoints: [
'index.ts',
'auth/index.ts',
'client/index.ts',
'endpoints/index.ts',
'values/index.ts',
'utils/index.ts',
],
packageName: '@ownclouders/k6-tdk',
packageRoot: 'lib',
formats: ['cjs', 'esm']
}
await Promise.all(instructions.formats.map(format => {
return build({
outDir: path.join(instructions.outdir, format === 'esm' ? '' : format),
external: ['k6'],
entryPoints: instructions.entryPoints.map(entryPoint => path.join(instructions.root, entryPoint)),
format: format,
packages: 'external',
bundle: true,
splitting: false,
treeShaking: true,
minify: true,
sourcemap: true,
legacyOutput: true
})
}))
instructions.entryPoints.forEach((entryPoint) => {
const entryPointInfo = path.parse(entryPoint)
const isVirtualPackage = !!entryPointInfo.dir
if (!isVirtualPackage) {
return
}
const packageFolder = path.resolve(instructions.packageRoot, entryPointInfo.dir)
const data = {
name: path.join(instructions.packageName, entryPointInfo.dir),
}
;['types', ...instructions.formats].forEach(format => {
const key = {esm: 'import', cjs: 'require'}[format] || format
const extension = {esm: 'js', cjs: 'js', types: 'd.ts'}[format]
data[key] = path.relative(
packageFolder,
path.join(instructions.outdir, format, entryPointInfo.dir, `${entryPointInfo.name}.${extension}`),
)
})
fs.mkdirSync(packageFolder, {recursive: true})
fs.writeFileSync(path.resolve(packageFolder, 'package.json'), JSON.stringify(data, undefined, 2))
})