-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathget-e2e-db-schema.ts
45 lines (37 loc) · 1.21 KB
/
get-e2e-db-schema.ts
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 arg from 'arg'
import fs from 'fs-jetpack'
import { z } from 'zod'
const numberParser = z.string().regex(/\d+/)
const osParser = z.union([z.literal('macos-latest'), z.literal('ubuntu-latest'), z.literal('windows-latest')])
const getConnectionString = ({ os, nodeVersion }: { nodeVersion: string; os: string }) =>
`node_${nodeVersion}_${os.replace('-', '_')}`
const args = arg({
'--os': String,
'--node-version': String,
'--prisma-client-version': String,
'--github-env': String,
})
const schemaName = parseComboCase(
args['--node-version'] ?? '',
args['--os'] ?? '',
args['--prisma-client-version'] ?? '',
)
if (args['--github-env']) {
fs.append(args['--github-env'], `E2E_DB_SCHEMA=${schemaName}`)
} else {
process.stdout.write(schemaName)
}
//
// Helpers
//
function parseComboCase(nodeVersionInput: string, osInput: string, prismaClientInput: string): string {
const nodeVersion = numberParser.parse(nodeVersionInput)
const os = osParser.parse(osInput)
const schema = getConnectionString({ nodeVersion, os })
if (!prismaClientInput) {
return schema
} else {
const prismaClientVersion = numberParser.parse(prismaClientInput)
return [schema, prismaClientVersion].join('_')
}
}