-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish.mjs
58 lines (44 loc) · 1.48 KB
/
publish.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
46
47
48
49
50
51
52
53
54
55
56
57
58
import cp from 'child_process';
import * as path from "path";
import * as fs from "fs";
import { fileURLToPath } from "url";
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const sdkPath = path.resolve(dirname, './src/FingerprintPro.ServerSdk');
const paths = {
sdk: sdkPath,
release: path.join(sdkPath, 'bin/Release')
}
Object.entries(paths).forEach(([key, value]) => {
if (!fs.existsSync(value)) {
throw new Error(`Path ${key} does not exist: ${value}`);
}
})
console.info('Publishing SDK to NuGet',);
console.info('Paths:', paths);
// version without "v" prefix
const version = process.env.NEW_VERSION?.replace(/^v/, '');
const apiKey = process.env.NUGET_API_KEY;
if (!version) {
throw new Error('NEW_VERSION environment variable is not set');
}
if (!apiKey) {
throw new Error('NUGET_API_KEY environment variable is not set');
}
console.info('New version:', version);
console.info('Building library...');
cp.execSync('dotnet build --configuration Release --no-restore', {
stdio: 'inherit',
cwd: paths.sdk
})
console.info('Packing library...');
cp.execSync('dotnet pack --configuration Release --no-restore', {
stdio: 'inherit',
cwd: paths.sdk
})
const fileName = `FingerprintPro.ServerSdk.${version}.nupkg`;
console.info(`Publishing ${fileName}...`);
cp.execSync(`dotnet nuget push ${fileName} --api-key ${apiKey} --source https://api.nuget.org/v3/index.json`, {
stdio: 'inherit',
cwd: paths.release
})