-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(smogontiers): fix updater and update tiers manually
- Loading branch information
Showing
4 changed files
with
110 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"lastSha":"46b4ad47685518043daea4a4081147019a321ede"} | ||
{ "lastSha": "28bf388b98cd5cc83a696a09befd7ece89a9e5e1" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,67 @@ | ||
import { writeFileAtomic, remove } from 'fs-nextra'; | ||
import fetch from 'node-fetch'; | ||
import { dirname } from 'path'; | ||
import { resolve } from 'path'; | ||
import ts from 'typescript'; | ||
|
||
export const mapToJson = (map: Map<string, unknown>) => JSON.stringify([...map]); | ||
|
||
export const needFile = async (url: string) => { | ||
const NodeModule: Module = module.constructor as Module; | ||
const request = await fetch(url); | ||
const body: string = await request.text(); | ||
const nodeModule = new NodeModule(url, module.parent); | ||
nodeModule.fileName = url; | ||
/* eslint-disable no-underscore-dangle */ | ||
nodeModule.paths = NodeModule._nodeModulePaths(dirname(url)); | ||
nodeModule._compile(body, url); | ||
|
||
/* eslint-enable no-underscore-dangle */ | ||
return nodeModule.exports; | ||
}; | ||
const body = await request.text(); | ||
|
||
export interface TierEntry { | ||
tier: string; | ||
} | ||
const result = ts.transpileModule(body, { | ||
compilerOptions: { | ||
module: ts.ModuleKind.CommonJS, | ||
newLine: ts.NewLineKind.LineFeed, | ||
moduleResolution: ts.ModuleResolutionKind.NodeJs, | ||
target: ts.ScriptTarget.ES2019, | ||
removeComments: true, | ||
declaration: false, | ||
sourceMap: false, | ||
declarationMap: false, | ||
incremental: false, | ||
importHelpers: false | ||
} | ||
}); | ||
|
||
const temporaryOutputFile = resolve(__dirname, 'tiers.ts'); | ||
|
||
await writeFileAtomic(temporaryOutputFile, result.outputText); | ||
const TiersData = (await import(resolve(__dirname, 'tiers.ts'))) as { BattleFormatsData: Record<string, SpeciesFormatsData> }; | ||
|
||
await remove(temporaryOutputFile); | ||
|
||
return TiersData; | ||
}; | ||
|
||
export interface DataJSON { | ||
lastSha: string; | ||
} | ||
|
||
export type Formats = Record<string, TierEntry>; | ||
|
||
interface Module extends Function { | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
_nodeModulePaths: any; | ||
|
||
new (url: string, parents: NodeModule | null): any; | ||
interface SpeciesFormatsData { | ||
comboMoves?: readonly string[]; | ||
doublesTier?: string; | ||
essentialMove?: string; | ||
exclusiveMoves?: readonly string[]; | ||
isNonstandard?: Nonstandard | null; | ||
maleOnlyHidden?: boolean; | ||
randomBattleMoves?: readonly string[]; | ||
randomDoubleBattleMoves?: readonly string[]; | ||
randomSets?: readonly Gen2RandomSet[]; | ||
tier?: string; | ||
unreleasedHidden?: boolean | 'Past'; | ||
} | ||
|
||
/* eslint-enable @typescript-eslint/no-explicit-any */ | ||
type Nonstandard = 'Past' | 'Future' | 'Unobtainable' | 'CAP' | 'LGPE' | 'Custom'; | ||
interface Gen2RandomSet { | ||
chance: number; | ||
item?: string[]; | ||
baseMove1?: string; | ||
baseMove2?: string; | ||
baseMove3?: string; | ||
baseMove4?: string; | ||
fillerMoves1?: string[]; | ||
fillerMoves2?: string[]; | ||
fillerMoves3?: string[]; | ||
fillerMoves4?: string[]; | ||
} |
Oops, something went wrong.