|
1 | 1 | import { createContext } from 'react'; |
2 | | -import { useFetchNodeReleases } from '../hooks/useFetchNodeReleases'; |
| 2 | +import { getNodeReleaseStatus } from '../util/nodeRelease'; |
| 3 | +import NodeReleasesJSON from '../public/node-releases-data.json'; |
3 | 4 | import type { FC, PropsWithChildren } from 'react'; |
4 | 5 | import type { NodeRelease } from '../types'; |
5 | 6 |
|
| 7 | +type NodeReleaseJSON = { |
| 8 | + major: number; |
| 9 | + version: string; |
| 10 | + codename?: string; |
| 11 | + currentStart: string; |
| 12 | + ltsStart?: string; |
| 13 | + maintenanceStart?: string; |
| 14 | + endOfLife: string; |
| 15 | + npm?: string; |
| 16 | + v8?: string; |
| 17 | + releaseDate?: string; |
| 18 | + modules?: string; |
| 19 | +}; |
| 20 | + |
6 | 21 | export const NodeReleasesContext = createContext<NodeRelease[]>([]); |
7 | 22 |
|
8 | 23 | export const NodeReleasesProvider: FC<PropsWithChildren> = ({ children }) => { |
9 | | - const releases = useFetchNodeReleases(); |
| 24 | + const data: NodeReleaseJSON[] = NodeReleasesJSON; |
| 25 | + const now = new Date(); |
| 26 | + |
| 27 | + const releases = data.map(raw => { |
| 28 | + const support = { |
| 29 | + currentStart: raw.currentStart, |
| 30 | + ltsStart: raw.ltsStart, |
| 31 | + maintenanceStart: raw.maintenanceStart, |
| 32 | + endOfLife: raw.endOfLife, |
| 33 | + }; |
| 34 | + |
| 35 | + const status = getNodeReleaseStatus(now, support); |
| 36 | + |
| 37 | + return { |
| 38 | + ...support, |
| 39 | + major: raw.major, |
| 40 | + version: raw.version, |
| 41 | + versionWithPrefix: `v${raw.version}`, |
| 42 | + codename: raw.codename || '', |
| 43 | + isLts: status === 'Active LTS' || status === 'Maintenance LTS', |
| 44 | + status: status, |
| 45 | + npm: raw.npm || '', |
| 46 | + v8: raw.v8 || '', |
| 47 | + releaseDate: raw.releaseDate || '', |
| 48 | + modules: raw.modules || '', |
| 49 | + }; |
| 50 | + }); |
10 | 51 |
|
11 | 52 | return ( |
12 | 53 | <NodeReleasesContext.Provider value={releases}> |
|
0 commit comments