Skip to content

Commit

Permalink
refactor: verbose code
Browse files Browse the repository at this point in the history
  • Loading branch information
fujidaiti committed Aug 9, 2023
1 parent bab9666 commit 2bf567a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
45 changes: 15 additions & 30 deletions src/criteria.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import {Tag} from './report'

export type SDK = 'flutter' | 'dart'
const allSDKs = ['flutter', 'dart'] as const
const allPlatforms = [
'ios',
'android',
'windows',
'macos',
'linux',
'web'
] as const

export type Platform = 'ios' | 'android' | 'windows' | 'macos' | 'linux' | 'web'
export type SDK = (typeof allSDKs)[number]
export type Platform = (typeof allPlatforms)[number]

export type Criteria = {
supportedSDKs: SDK[]
Expand All @@ -19,35 +28,11 @@ export type Criteria = {
soundNullSafety: boolean
}

export const parseSDK = (str: string): SDK | undefined => {
switch (str) {
case 'dart':
return 'dart'
case 'flutter':
return 'flutter'
default:
return undefined
}
}
export const isSDK = (x: unknown): x is SDK =>
typeof x === 'string' && (allSDKs as readonly string[]).includes(x)

export const parsePlatform = (str: string): Platform | undefined => {
switch (str) {
case 'ios':
return 'ios'
case 'android':
return 'android'
case 'linux':
return 'linux'
case 'windows':
return 'windows'
case 'macos':
return 'macos'
case 'web':
return 'web'
default:
return undefined
}
}
export const isPlatform = (x: unknown): x is Platform =>
typeof x === 'string' && (allPlatforms as readonly string[]).includes(x)

export const platformToTag = (platform: Platform): Tag => {
switch (platform) {
Expand Down
14 changes: 7 additions & 7 deletions src/input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as core from '@actions/core'
import {Criteria, Platform, SDK, parsePlatform, parseSDK} from './criteria'
import {Criteria, Platform, SDK, isPlatform, isSDK} from './criteria'
import {Report, isTag} from './report'

const peekInput = (name: string): string | undefined => {
Expand Down Expand Up @@ -37,17 +37,17 @@ export const getReport = (): Report => {
export const getCriteria = (): Criteria => {
const supportedSDKs: SDK[] = []
for (const s of core.getInput('supported-SDKs').split(',')) {
const sdk = parseSDK(s.trim())
if (sdk === undefined) throw Error("Invalid value for 'supported-SDKs'")
supportedSDKs.push(sdk)
const maybeSdk = s.trim()
if (!isSDK(maybeSdk)) throw Error("Invalid value for 'supported-SDKs'")
supportedSDKs.push(maybeSdk)
}

const supportedPlatforms: Platform[] = []
for (const s of core.getInput('supported-platforms').split(',')) {
const platform = parsePlatform(s.trim())
if (platform === undefined)
const maybePlatform = s.trim()
if (!isPlatform(maybePlatform))
throw Error("Invalid value for 'supported-platforms'")
supportedPlatforms.push(platform)
supportedPlatforms.push(maybePlatform)
}

const panaOutput = JSON.parse(getRequiredInput('report'))
Expand Down

0 comments on commit 2bf567a

Please sign in to comment.