Refactor version data
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
import { SupplyEventData } from '../../../lib/honkai3rd/supplyEvents'
|
||||
import { readdirSync, readJsonFileSync } from '../fs'
|
||||
|
||||
export function listSupplyEventsByVersion(version: string) {
|
||||
const supplyEventsDirectoryPathname = `honkai3rd/versions/${version}/supply-events`
|
||||
|
||||
const supplyEventFileNameList = readdirSync(supplyEventsDirectoryPathname)
|
||||
const supplyEventList = supplyEventFileNameList
|
||||
.map((fileName) => {
|
||||
const filePathname = `${supplyEventsDirectoryPathname}/` + fileName
|
||||
const data = readJsonFileSync(filePathname)
|
||||
|
||||
return { ...data, id: fileName.replace(/\.json/, '') } as SupplyEventData
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return -a.id.localeCompare(b.id)
|
||||
})
|
||||
|
||||
return supplyEventList
|
||||
}
|
||||
@@ -1,41 +1,45 @@
|
||||
import { format } from 'date-fns'
|
||||
import { readdirSync, readFileSync, readJsonFileSync } from '../fs'
|
||||
import { compareVersion } from '../../../lib/string'
|
||||
import { VersionData } from '../../../lib/honkai3rd/versions'
|
||||
import yaml from 'yaml'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { omit } from 'ramda'
|
||||
|
||||
const versionDirectoryList = readdirSync('honkai3rd/versions')
|
||||
let cachedData: any = null
|
||||
export function listVersionData(locale?: string): VersionData[] {
|
||||
if (cachedData == null) {
|
||||
cachedData = yaml.parse(
|
||||
fs
|
||||
.readFileSync(path.join(process.cwd(), 'data/honkai3rd/versions.yaml'))
|
||||
.toString('utf-8')
|
||||
)
|
||||
}
|
||||
const versions = cachedData
|
||||
const localized = versions
|
||||
.map((version: any) => {
|
||||
return {
|
||||
...omit(['krName'], version),
|
||||
name: locale === 'ko-KR' ? version.krName : version.name,
|
||||
}
|
||||
})
|
||||
.sort((a: any, b: any) => {
|
||||
return compareVersion(b.version, a.version)
|
||||
})
|
||||
|
||||
const versionDataList = versionDirectoryList
|
||||
.map((directoryName) => {
|
||||
const directoryPathname = 'honkai3rd/versions/' + directoryName
|
||||
const data: VersionData = {
|
||||
version: directoryName,
|
||||
...readJsonFileSync(directoryPathname + '/version-data.json'),
|
||||
description: readFileSync(
|
||||
directoryPathname + '/description.md'
|
||||
).toString(),
|
||||
}
|
||||
|
||||
return data
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return compareVersion(b.version, a.version)
|
||||
})
|
||||
|
||||
export function listVersionData() {
|
||||
return versionDataList
|
||||
return localized
|
||||
}
|
||||
|
||||
export function getVersion(version: number | string) {
|
||||
return versionDataList.find((versionData) => {
|
||||
export function getVersion(version: number | string, locale?: string) {
|
||||
return listVersionData(locale).find((versionData) => {
|
||||
return versionData.version.toString() === version.toString()
|
||||
})
|
||||
}
|
||||
|
||||
export function getCurrentVersion() {
|
||||
export function getCurrentVersion(locale?: string) {
|
||||
const todayDateString = format(new Date(), 'yyyy-MM-dd')
|
||||
|
||||
return versionDataList.slice().find((versionData) => {
|
||||
return listVersionData(locale).find((versionData) => {
|
||||
const [startDateString] = versionData.duration
|
||||
|
||||
return startDateString.localeCompare(todayDateString) <= 0
|
||||
|
||||
Reference in New Issue
Block a user