-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtsup.config.ts
More file actions
68 lines (58 loc) · 1.7 KB
/
tsup.config.ts
File metadata and controls
68 lines (58 loc) · 1.7 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
import replaceInFile from 'replace-in-file';
import semver from 'semver';
import { type Options, defineConfig } from 'tsup';
import packageJson from './package.json';
async function injectSdkDetails(dist: string) {
const anticipatedVersion = getAnticipatedVersion();
console.log(`[build] anticipated version tag: ${anticipatedVersion}`);
try {
await replaceInFile({
files: `${dist}/**/*`,
from: /__SDK_NAME__/g,
to: packageJson.name,
});
await replaceInFile({
files: `${dist}/**/*`,
from: /__SDK_VERSION__/g,
to: anticipatedVersion,
});
} catch (error) {
console.error('[injectSdkDetails]:', error);
}
}
function getAnticipatedVersion(): string {
const current = packageJson.version;
console.log(`[build] current version tag: ${current}`);
if (process.env.MINOR === 'true') {
console.log(`[build] bumping minor`);
return semver.inc(current, 'minor')!;
}
if (process.env.PATCH === 'true') {
console.log(`[build] bumping patch`);
return semver.inc(current, 'patch')!;
}
if (process.env.PRERELEASE === 'true') {
console.log(`[build] bumping prerelease`);
return semver.inc(current, 'prerelease', 'alpha')!;
}
console.log(`[build] no env release type found, skipping bump`);
return current;
}
export function config(opts: Options): Options {
return {
banner: {
js: '#!/usr/bin/env node',
},
entry: opts.entry,
format: ['cjs', 'esm'],
target: ['node16'], // Only targeting Node.js 16+
outDir: 'dist',
dts: true,
sourcemap: true,
clean: true,
async onSuccess() {
await injectSdkDetails('dist');
},
};
}
export default defineConfig([config({ entry: ['src/index.ts'] })]);