@wfcd/relics 2.0.26 → 2.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,272 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import { n as Generator, t as VersionManager } from "./VersionManager-DUIsq0rq.mjs";
3
2
 
4
- // src/Generator.ts
5
- import fs from "fs/promises";
6
- import path from "path";
7
- import fetch from "node-fetch";
8
-
9
- // src/Config.ts
10
- var Config = {
11
- warframeRelicDropUrl: "https://drops.warframestat.us/data/relics.json",
12
- warframeMarketItemUrl: "https://api.warframe.market/v2/items",
13
- warframeItemsUrl: "https://api.warframestat.us/items/search/Relics?by=category",
14
- warframeRelicDropInfoUrl: "https://drops.warframestat.us/data/info.json",
15
- warframePatchlogsUrl: "https://raw.githubusercontent.com/WFCD/warframe-patchlogs/master/data/patchlogs.json"
16
- };
17
- var Config_default = Config;
18
-
19
- // src/Logger.ts
20
- import * as console from "console";
21
- var fromString = /* @__PURE__ */ __name((logLevelIsh) => {
22
- switch (logLevelIsh == null ? void 0 : logLevelIsh.toLowerCase()) {
23
- case "fatal":
24
- return -1 /* FATAL */;
25
- case "error":
26
- case "bad":
27
- return 0 /* ERROR */;
28
- case "info":
29
- case "log":
30
- return 1 /* LOG */;
31
- case "debug":
32
- return 2 /* DEBUG */;
33
- default:
34
- return -1 /* FATAL */;
35
- }
36
- }, "fromString");
37
- var _Logger = class _Logger {
38
- logLevel = fromString(process.env.LOG_LEVEL || "fatal");
39
- log(message) {
40
- if (this.logLevel >= 1 /* LOG */) console.log(message);
41
- }
42
- error(message) {
43
- if (this.logLevel >= 0 /* ERROR */) console.error(message);
44
- }
45
- debug(message) {
46
- if (this.logLevel === 2 /* DEBUG */) console.debug(message);
47
- }
48
- fatal(message) {
49
- if (this.logLevel >= -1 /* FATAL */) {
50
- console.error(`FATAL: ${message}`);
51
- throw new Error(message);
52
- }
53
- }
54
- };
55
- __name(_Logger, "Logger");
56
- var Logger = _Logger;
57
- var Logger_default = new Logger();
58
-
59
- // src/Generator.ts
60
- var _Generator = class _Generator {
61
- relicsRaw;
62
- wfcdItems;
63
- wfmItems;
64
- relics;
65
- constructor() {
66
- this.relics = [];
67
- }
68
- /**
69
- * Main function to fetch and generate the relic data
70
- * @returns {Promise<Array<TitaniaRelic>>} The Relics data array
71
- */
72
- async generate() {
73
- Logger_default.log("Starting Generation");
74
- await this.fetchRawData();
75
- this.filterWFCDRelics();
76
- this.generateTitaniaRelics();
77
- return this.relics;
78
- }
79
- /**
80
- * Fetches all required data from WFCD and WFM.
81
- */
82
- async fetchRawData() {
83
- var _a;
84
- const relicRequest = await fetch(Config_default.warframeRelicDropUrl);
85
- if (!relicRequest.ok) {
86
- Logger_default.error("Failed to fetch Warframe relics from WFCD!");
87
- return;
88
- }
89
- this.relicsRaw = (_a = await relicRequest.json()) == null ? void 0 : _a.relics;
90
- const wfmRequest = await fetch(Config_default.warframeMarketItemUrl);
91
- if (!wfmRequest.ok) {
92
- Logger_default.error("Failed to fetch items from WFM!");
93
- return;
94
- }
95
- this.wfmItems = await wfmRequest.json();
96
- const wfcdItemRequest = await fetch(Config_default.warframeItemsUrl);
97
- if (!wfcdItemRequest.ok) {
98
- Logger_default.error("Failed to fetch items from WFCD! ");
99
- return;
100
- }
101
- this.wfcdItems = await wfcdItemRequest.json();
102
- }
103
- /**
104
- * Generates the relic data
105
- * uses WFCD/warframe-drop-data to check what relics exist,
106
- * and adds information from WFCD/warframe-items and WFM
107
- */
108
- generateTitaniaRelics() {
109
- if (typeof this.relicsRaw === "undefined" || typeof this.wfmItems === "undefined") {
110
- Logger_default.log("Failed to load relics/item data");
111
- return;
112
- }
113
- const { length } = this.relicsRaw;
114
- for (let i = 0; i < length; i += 1) {
115
- const rawRelic = this.relicsRaw[i];
116
- Logger_default.debug(`[${i + 1}/${length}] ${rawRelic.tier} ${rawRelic.relicName}`);
117
- const relic = this.generateTitaniaRelic(rawRelic);
118
- this.relics.push(relic);
119
- }
120
- Logger_default.debug(`Finished parsing ${this.relics.length} relics`);
121
- }
122
- /**
123
- * Writes the fully generated data to disk.
124
- * @param {string} dataDir Directory to store the relic data in. Default: ../data/
125
- * @param {string} fileName Filename base ex: "Relics" becomes "Relics.json" and "Relics.min.json". Default: "Relics"
126
- * @param {boolean} generateMin True if a minified json should be generated too. Default: true
127
- */
128
- async writeData(dataDir, fileName, generateMin = true) {
129
- const DataDir = dataDir ?? path.join(__dirname, "..", "data");
130
- const RelicPath = fileName ? path.join(DataDir, `${fileName}.json`) : path.join(DataDir, "Relics.json");
131
- await fs.writeFile(RelicPath, JSON.stringify(this.relics, void 0, 4));
132
- if (generateMin) {
133
- const RelicMinPath = fileName ? path.join(DataDir, `${fileName}.min.json`) : path.join(DataDir, "Relics.min.json");
134
- await fs.writeFile(RelicMinPath, JSON.stringify(this.relics));
135
- }
136
- }
137
- /**
138
- * Generates a single relic from all available data
139
- * @param {WFCDRelic} rawRelic relic to pull Titania data from
140
- * @returns {TitaniaRelicReward}
141
- */
142
- generateTitaniaRelic(rawRelic) {
143
- var _a, _b;
144
- const name = `${rawRelic.tier} ${rawRelic.relicName}`;
145
- const rewards = rawRelic.rewards.map((rawReward) => {
146
- var _a2, _b2, _c;
147
- const { chance } = rawReward;
148
- const { rarity } = rawReward;
149
- const wfmInfo = (_a2 = this.wfmItems) == null ? void 0 : _a2.data.find((x) => x.i18n.en.name === rawReward.itemName);
150
- const isSpecial = ["Forma", "Kuva", "Exilus", "Riven"].find(
151
- (x) => (
152
- // eslint-disable-next-line @typescript-eslint/comma-dangle
153
- rawReward.itemName.toLowerCase().includes(x.toLowerCase())
154
- )
155
- );
156
- if (!(wfmInfo || isSpecial)) {
157
- Logger_default.debug(`Failed to find wfm item for ${rawReward.itemName}`);
158
- }
159
- const item = {
160
- name: rawReward.itemName,
161
- uniqueName: ((_c = (_b2 = this.wfcdItems) == null ? void 0 : _b2.find((x) => x.name.toLowerCase() === `${name.trim()} Intact`.toLowerCase())) == null ? void 0 : _c.uniqueName) || "",
162
- warframeMarket: void 0
163
- };
164
- if (wfmInfo) {
165
- item.warframeMarket = { id: wfmInfo.id, urlName: wfmInfo.slug };
166
- }
167
- return { rarity, chance, item };
168
- });
169
- let drops = [];
170
- const wfcdItem = (_a = this.wfcdItems) == null ? void 0 : _a.find((x) => x.name.toLowerCase() === `${name.trim()} Intact`.toLowerCase());
171
- if (!wfcdItem) {
172
- Logger_default.error(`Failed to get WFCD item for relic: ${name}`);
173
- }
174
- if (wfcdItem && wfcdItem.drops) {
175
- drops = wfcdItem.drops.map((rawDrop) => {
176
- return { rarity: rawDrop.rarity, chance: rawDrop.chance, location: rawDrop.location };
177
- });
178
- }
179
- const wfm = (_b = this.wfmItems) == null ? void 0 : _b.data.find((x) => x.i18n.en.name === `${name.trim()} Relic`);
180
- if (!wfm) {
181
- Logger_default.error(`Failed to get relic item from wfm: ${name}`);
182
- }
183
- return {
184
- name,
185
- rewards,
186
- locations: drops,
187
- uniqueName: (wfcdItem == null ? void 0 : wfcdItem.uniqueName) || "",
188
- vaultInfo: { vaulted: drops.length === 0 },
189
- ...(wfm == null ? void 0 : wfm.id) && (wfm == null ? void 0 : wfm.slug) && { warframeMarket: { id: wfm == null ? void 0 : wfm.id, urlName: wfm == null ? void 0 : wfm.slug } }
190
- };
191
- }
192
- /**
193
- * Filters WFCD's relic data to only include Intact variants, since we just need the base.
194
- */
195
- filterWFCDRelics() {
196
- var _a, _b, _c;
197
- const before = ((_a = this.relicsRaw) == null ? void 0 : _a.length) || 0;
198
- this.relicsRaw = (_b = this.relicsRaw) == null ? void 0 : _b.filter((x) => x.state === "Intact");
199
- Logger_default.log(`Filtered relics to intact variants. Before: ${before} After: ${((_c = this.relicsRaw) == null ? void 0 : _c.length) || 0}`);
200
- }
201
- };
202
- __name(_Generator, "Generator");
203
- var Generator = _Generator;
204
-
205
- // src/VersionManager.ts
206
- import path2 from "path";
207
- import fs2 from "fs/promises";
208
- import fetch2 from "node-fetch";
209
- var _VersionManager = class _VersionManager {
210
- versionPath;
211
- versionRawPath;
212
- hashPath;
213
- /**
214
- * Creates a new VersionManager instance.
215
- * @param {string} dataDir Folder to write version information to.
216
- * @constructor
217
- */
218
- constructor(dataDir) {
219
- const DataDir = dataDir ?? path2.join(__dirname, "..", "data");
220
- this.versionPath = path2.join(DataDir, "version.json");
221
- this.versionRawPath = path2.join(DataDir, "version.txt");
222
- this.hashPath = path2.join(DataDir, "hash.json");
223
- }
224
- /**
225
- * Checks if the current data needs an update
226
- */
227
- async updateNeeded() {
228
- const infoReq = await fetch2(Config_default.warframeRelicDropInfoUrl);
229
- if (!infoReq.ok) {
230
- Logger_default.fatal("Failed to fetch version info!");
231
- }
232
- const info = await infoReq.json();
233
- try {
234
- await fs2.access(this.hashPath);
235
- const infoFile = JSON.parse(await fs2.readFile(this.hashPath, "utf-8"));
236
- return infoFile.hash !== info.hash;
237
- } catch (ex) {
238
- return true;
239
- }
240
- }
241
- /**
242
- * Writes both game and drop version metadata
243
- * @param {number} timestamp Timestamp the build was started at
244
- */
245
- async writeVersion(timestamp) {
246
- const patchLogsReq = await fetch2(Config_default.warframePatchlogsUrl);
247
- if (!patchLogsReq.ok) {
248
- Logger_default.error("Failed to fetch patchlogs");
249
- return;
250
- }
251
- const patchlogs = await patchLogsReq.json();
252
- const version = patchlogs[0].name.replace(/ \+ /g, "--").replace(/[^0-9\-.]/g, "").trim();
253
- const hashReq = await fetch2(Config_default.warframeRelicDropInfoUrl);
254
- if (!hashReq.ok) {
255
- Logger_default.error("Failed to fetch hashInfo");
256
- return;
257
- }
258
- const hashInfo = await hashReq.json();
259
- const versionInfo = { version, title: patchlogs[0].name };
260
- const hashFile = { hash: hashInfo.hash, deUpdated: hashInfo.modified, timestamp };
261
- await fs2.writeFile(this.hashPath, JSON.stringify(hashFile, void 0, 2), "utf-8");
262
- await fs2.writeFile(this.versionPath, JSON.stringify(versionInfo, void 0, 2), "utf-8");
263
- await fs2.writeFile(this.versionRawPath, version, "utf-8");
264
- Logger_default.debug("Finished writing version info");
265
- }
266
- };
267
- __name(_VersionManager, "VersionManager");
268
- var VersionManager = _VersionManager;
269
- export {
270
- Generator,
271
- VersionManager
272
- };
3
+ export { Generator, VersionManager };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wfcd/relics",
3
- "version": "2.0.26",
3
+ "version": "2.0.27",
4
4
  "description": "Relic Data for Warframe",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "types": "dist/index.d.ts",
16
16
  "scripts": {
17
- "build": "tsup ./src/index.ts ./src/Build.ts",
17
+ "build": "tsdown ./src/index.ts ./src/Build.ts",
18
18
  "coverage": "npm test && nyc report --reporter=text-lcov | coveralls",
19
19
  "lint": "eslint .",
20
20
  "lint:fix": "eslint . --fix",
@@ -47,97 +47,22 @@
47
47
  "nyc": "^17.0.0",
48
48
  "precommit-hook": "^3.0.0",
49
49
  "ts-mocha": "^11.1.0",
50
- "ts-node": "^10.9.1",
51
50
  "tsconfig-paths": "^4.1.0",
52
- "tsup": "^8.0.2",
51
+ "tsdown": "^0.20.3",
52
+ "tsx": "^4.21.0",
53
53
  "typescript": "^5.0.4"
54
54
  },
55
55
  "dependencies": {
56
+ "@semantic-release/changelog": "^6.0.3",
57
+ "@semantic-release/git": "^10.0.1",
56
58
  "node-fetch": "^2.6.7",
57
59
  "warframe-patchlogs": "^2.3.3"
58
60
  },
59
- "eslintIgnore": [
60
- "dist/**"
61
- ],
62
- "eslintConfig": {
63
- "extends": [
64
- "@wfcd/eslint-config/typescript"
65
- ],
66
- "parserOptions": {
67
- "project": "tsconfig.json"
68
- }
69
- },
70
- "prettier": "@wfcd/eslint-config/prettier",
71
- "babel": {
72
- "presets": [
73
- "@babel/preset-env"
74
- ],
75
- "plugins": [
76
- "@babel/plugin-proposal-class-properties",
77
- "@babel/plugin-proposal-private-methods"
78
- ]
79
- },
80
- "release": {
81
- "plugins": [
82
- "@semantic-release/commit-analyzer",
83
- "@semantic-release/release-notes-generator",
84
- "@semantic-release/npm",
85
- "@semantic-release/github",
86
- [
87
- "@semantic-release/changelog",
88
- {
89
- "assets": [
90
- "CHANGELOG.md"
91
- ]
92
- }
93
- ],
94
- [
95
- "@semantic-release/git",
96
- {
97
- "assets": [
98
- "package.json",
99
- "package-lock.json",
100
- "CHANGELOG.md"
101
- ]
102
- }
103
- ]
104
- ],
105
- "branches": "development"
106
- },
107
- "mocha": {
108
- "exit": true,
109
- "spec": "src/spec/**/*.spec.ts",
110
- "timeout": "1000",
111
- "loader": "ts-node/esm",
112
- "extension": "ts"
113
- },
114
- "nyc": {
115
- "exclude": [
116
- "src/spec/**",
117
- "dist/**"
118
- ],
119
- "skip-full": true,
120
- "reporter": [
121
- "lcov",
122
- "text"
123
- ]
124
- },
125
61
  "pre-commit": [
126
62
  "lint",
127
63
  "test",
128
64
  "validate"
129
65
  ],
130
- "tsup": {
131
- "dts": true,
132
- "clean": true,
133
- "keepNames": true,
134
- "target": "node14",
135
- "splitting": false,
136
- "format": [
137
- "cjs",
138
- "esm"
139
- ]
140
- },
141
66
  "publishConfig": {
142
67
  "provenance": true
143
68
  }
package/dist/index.d.ts DELETED
@@ -1,244 +0,0 @@
1
- interface WarframeMarketRoot {
2
- data: Array<WarframeMarketItem>;
3
- }
4
- interface WarframeMarketItem {
5
- /**
6
- * WFM Item ID
7
- */
8
- id: string;
9
- /**
10
- * Url name for querying WFM
11
- */
12
- slug: string;
13
- /**
14
- * WFM language object
15
- */
16
- i18n: {
17
- /**
18
- * English language object
19
- */
20
- en: {
21
- /**
22
- * Item Name
23
- */
24
- name: string;
25
- /**
26
- * Thumbnail URL relative to wfm api base
27
- */
28
- thumb: string;
29
- };
30
- };
31
- }
32
- interface WFCDRelic {
33
- /**
34
- * Relic Tier (Axi, Neo, etc.)
35
- */
36
- tier: string;
37
- /**
38
- * Relic Name (A1, A10, etc.)
39
- */
40
- relicName: string;
41
- /**
42
- * Relic Refinement state
43
- */
44
- state: 'Intact' | 'Exceptional' | 'Flawless' | 'Radiant';
45
- /**
46
- * Relic Rewards
47
- */
48
- rewards: Array<WFCDRelicReward>;
49
- /**
50
- * Internal WFCD id
51
- */
52
- _id: string;
53
- }
54
- interface WFCDRelicReward {
55
- /**
56
- * Dropped Item name
57
- */
58
- itemName: string;
59
- /**
60
- * Dropchance Rarity (Uncommon/Rare ?)
61
- */
62
- rarity: 'Uncommon' | 'Rare';
63
- /**
64
- * Actual Dropchance in %
65
- */
66
- chance: number;
67
- /**
68
- * Internal ID
69
- */
70
- _id: string;
71
- }
72
- interface WFCDItem {
73
- /**
74
- * Item Name
75
- */
76
- name: string;
77
- /** Unique identifying name */
78
- uniqueName: string;
79
- /**
80
- * Item Drop Location
81
- */
82
- drops?: Array<WFCDItemDropLocation>;
83
- }
84
- interface WFCDItemDropLocation {
85
- /**
86
- * Dropchance in %
87
- */
88
- chance: number;
89
- /**
90
- * Mission location
91
- */
92
- location: string;
93
- /**
94
- * Drop rarity
95
- */
96
- rarity: string;
97
- /**
98
- * Relic Type
99
- */
100
- type: string;
101
- }
102
- interface TitaniaRelic {
103
- /**
104
- * Relic Combined Name (Ex: Axi A1)
105
- */
106
- name: string;
107
- /**
108
- * Relic Rewards when opened
109
- */
110
- rewards: Array<TitaniaRelicReward>;
111
- /**
112
- * Drop Locations for the relics
113
- */
114
- locations: Array<TitaniaRelicLocation>;
115
- /**
116
- * Warframe Market Information
117
- * undefined for untradable
118
- */
119
- warframeMarket?: TitaniaWFMInfo;
120
- /**
121
- * Relic Vault Information
122
- */
123
- vaultInfo: TitaniaRelicVaultedInfo;
124
- /** unique name for corresponding warframe-items Item */
125
- uniqueName: string;
126
- }
127
- interface TitaniaRelicReward {
128
- /**
129
- * Relic Rarity (Uncommon,Rare ?)
130
- */
131
- rarity: 'Uncommon' | 'Rare';
132
- /**
133
- * Reward Drop Chance in %
134
- */
135
- chance: number;
136
- /**
137
- * Item Information
138
- */
139
- item: TitaniaRelicRewardItem;
140
- }
141
- interface TitaniaRelicRewardItem {
142
- /**
143
- * Item Name
144
- */
145
- name: string;
146
- /** unique name for corresponding warframe-items Item */
147
- uniqueName: string;
148
- /**
149
- * WarframeMarket Info
150
- */
151
- warframeMarket?: TitaniaWFMInfo;
152
- }
153
- type Rarity = 'Uncommon' | 'Rare' | 'Legendary' | 'Common';
154
- interface TitaniaRelicLocation {
155
- /** Location Info $planet-$node (Ex: Eris - Phalan) */
156
- location: string;
157
- /**
158
- * Rarity (Uncommon, Rare ?)
159
- */
160
- rarity: Rarity;
161
- /**
162
- * Dropchance in %
163
- */
164
- chance: number;
165
- }
166
- interface TitaniaWFMInfo {
167
- /**
168
- * Warframe Market ID
169
- */
170
- id: string;
171
- /**
172
- * Warframe market URL parameter
173
- */
174
- urlName: string;
175
- }
176
- interface TitaniaRelicVaultedInfo {
177
- /**
178
- * If the relic is vaulted
179
- */
180
- vaulted: boolean;
181
- }
182
-
183
- declare class Generator {
184
- relicsRaw: Array<WFCDRelic> | undefined;
185
- wfcdItems: Array<WFCDItem> | undefined;
186
- wfmItems: WarframeMarketRoot | undefined;
187
- relics: Array<TitaniaRelic>;
188
- constructor();
189
- /**
190
- * Main function to fetch and generate the relic data
191
- * @returns {Promise<Array<TitaniaRelic>>} The Relics data array
192
- */
193
- generate(): Promise<Array<TitaniaRelic>>;
194
- /**
195
- * Fetches all required data from WFCD and WFM.
196
- */
197
- fetchRawData(): Promise<void>;
198
- /**
199
- * Generates the relic data
200
- * uses WFCD/warframe-drop-data to check what relics exist,
201
- * and adds information from WFCD/warframe-items and WFM
202
- */
203
- generateTitaniaRelics(): void;
204
- /**
205
- * Writes the fully generated data to disk.
206
- * @param {string} dataDir Directory to store the relic data in. Default: ../data/
207
- * @param {string} fileName Filename base ex: "Relics" becomes "Relics.json" and "Relics.min.json". Default: "Relics"
208
- * @param {boolean} generateMin True if a minified json should be generated too. Default: true
209
- */
210
- writeData(dataDir?: string, fileName?: string, generateMin?: boolean): Promise<void>;
211
- /**
212
- * Generates a single relic from all available data
213
- * @param {WFCDRelic} rawRelic relic to pull Titania data from
214
- * @returns {TitaniaRelicReward}
215
- */
216
- private generateTitaniaRelic;
217
- /**
218
- * Filters WFCD's relic data to only include Intact variants, since we just need the base.
219
- */
220
- private filterWFCDRelics;
221
- }
222
-
223
- declare class VersionManager {
224
- versionPath: string;
225
- versionRawPath: string;
226
- hashPath: string;
227
- /**
228
- * Creates a new VersionManager instance.
229
- * @param {string} dataDir Folder to write version information to.
230
- * @constructor
231
- */
232
- constructor(dataDir?: string);
233
- /**
234
- * Checks if the current data needs an update
235
- */
236
- updateNeeded(): Promise<boolean>;
237
- /**
238
- * Writes both game and drop version metadata
239
- * @param {number} timestamp Timestamp the build was started at
240
- */
241
- writeVersion(timestamp: number): Promise<void>;
242
- }
243
-
244
- export { Generator, type Rarity, type TitaniaRelic, type TitaniaRelicLocation, type TitaniaRelicReward, type TitaniaRelicRewardItem, type TitaniaRelicVaultedInfo, type TitaniaWFMInfo, VersionManager, type WFCDItem, type WFCDItemDropLocation, type WFCDRelic, type WFCDRelicReward, type WarframeMarketItem, type WarframeMarketRoot };
package/dist/index.js DELETED
@@ -1,308 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/index.ts
32
- var index_exports = {};
33
- __export(index_exports, {
34
- Generator: () => Generator,
35
- VersionManager: () => VersionManager
36
- });
37
- module.exports = __toCommonJS(index_exports);
38
-
39
- // src/Generator.ts
40
- var import_promises = __toESM(require("fs/promises"));
41
- var import_node_path = __toESM(require("path"));
42
- var import_node_fetch = __toESM(require("node-fetch"));
43
-
44
- // src/Config.ts
45
- var Config = {
46
- warframeRelicDropUrl: "https://drops.warframestat.us/data/relics.json",
47
- warframeMarketItemUrl: "https://api.warframe.market/v2/items",
48
- warframeItemsUrl: "https://api.warframestat.us/items/search/Relics?by=category",
49
- warframeRelicDropInfoUrl: "https://drops.warframestat.us/data/info.json",
50
- warframePatchlogsUrl: "https://raw.githubusercontent.com/WFCD/warframe-patchlogs/master/data/patchlogs.json"
51
- };
52
- var Config_default = Config;
53
-
54
- // src/Logger.ts
55
- var console = __toESM(require("console"));
56
- var fromString = /* @__PURE__ */ __name((logLevelIsh) => {
57
- switch (logLevelIsh == null ? void 0 : logLevelIsh.toLowerCase()) {
58
- case "fatal":
59
- return -1 /* FATAL */;
60
- case "error":
61
- case "bad":
62
- return 0 /* ERROR */;
63
- case "info":
64
- case "log":
65
- return 1 /* LOG */;
66
- case "debug":
67
- return 2 /* DEBUG */;
68
- default:
69
- return -1 /* FATAL */;
70
- }
71
- }, "fromString");
72
- var _Logger = class _Logger {
73
- logLevel = fromString(process.env.LOG_LEVEL || "fatal");
74
- log(message) {
75
- if (this.logLevel >= 1 /* LOG */) console.log(message);
76
- }
77
- error(message) {
78
- if (this.logLevel >= 0 /* ERROR */) console.error(message);
79
- }
80
- debug(message) {
81
- if (this.logLevel === 2 /* DEBUG */) console.debug(message);
82
- }
83
- fatal(message) {
84
- if (this.logLevel >= -1 /* FATAL */) {
85
- console.error(`FATAL: ${message}`);
86
- throw new Error(message);
87
- }
88
- }
89
- };
90
- __name(_Logger, "Logger");
91
- var Logger = _Logger;
92
- var Logger_default = new Logger();
93
-
94
- // src/Generator.ts
95
- var _Generator = class _Generator {
96
- relicsRaw;
97
- wfcdItems;
98
- wfmItems;
99
- relics;
100
- constructor() {
101
- this.relics = [];
102
- }
103
- /**
104
- * Main function to fetch and generate the relic data
105
- * @returns {Promise<Array<TitaniaRelic>>} The Relics data array
106
- */
107
- async generate() {
108
- Logger_default.log("Starting Generation");
109
- await this.fetchRawData();
110
- this.filterWFCDRelics();
111
- this.generateTitaniaRelics();
112
- return this.relics;
113
- }
114
- /**
115
- * Fetches all required data from WFCD and WFM.
116
- */
117
- async fetchRawData() {
118
- var _a;
119
- const relicRequest = await (0, import_node_fetch.default)(Config_default.warframeRelicDropUrl);
120
- if (!relicRequest.ok) {
121
- Logger_default.error("Failed to fetch Warframe relics from WFCD!");
122
- return;
123
- }
124
- this.relicsRaw = (_a = await relicRequest.json()) == null ? void 0 : _a.relics;
125
- const wfmRequest = await (0, import_node_fetch.default)(Config_default.warframeMarketItemUrl);
126
- if (!wfmRequest.ok) {
127
- Logger_default.error("Failed to fetch items from WFM!");
128
- return;
129
- }
130
- this.wfmItems = await wfmRequest.json();
131
- const wfcdItemRequest = await (0, import_node_fetch.default)(Config_default.warframeItemsUrl);
132
- if (!wfcdItemRequest.ok) {
133
- Logger_default.error("Failed to fetch items from WFCD! ");
134
- return;
135
- }
136
- this.wfcdItems = await wfcdItemRequest.json();
137
- }
138
- /**
139
- * Generates the relic data
140
- * uses WFCD/warframe-drop-data to check what relics exist,
141
- * and adds information from WFCD/warframe-items and WFM
142
- */
143
- generateTitaniaRelics() {
144
- if (typeof this.relicsRaw === "undefined" || typeof this.wfmItems === "undefined") {
145
- Logger_default.log("Failed to load relics/item data");
146
- return;
147
- }
148
- const { length } = this.relicsRaw;
149
- for (let i = 0; i < length; i += 1) {
150
- const rawRelic = this.relicsRaw[i];
151
- Logger_default.debug(`[${i + 1}/${length}] ${rawRelic.tier} ${rawRelic.relicName}`);
152
- const relic = this.generateTitaniaRelic(rawRelic);
153
- this.relics.push(relic);
154
- }
155
- Logger_default.debug(`Finished parsing ${this.relics.length} relics`);
156
- }
157
- /**
158
- * Writes the fully generated data to disk.
159
- * @param {string} dataDir Directory to store the relic data in. Default: ../data/
160
- * @param {string} fileName Filename base ex: "Relics" becomes "Relics.json" and "Relics.min.json". Default: "Relics"
161
- * @param {boolean} generateMin True if a minified json should be generated too. Default: true
162
- */
163
- async writeData(dataDir, fileName, generateMin = true) {
164
- const DataDir = dataDir ?? import_node_path.default.join(__dirname, "..", "data");
165
- const RelicPath = fileName ? import_node_path.default.join(DataDir, `${fileName}.json`) : import_node_path.default.join(DataDir, "Relics.json");
166
- await import_promises.default.writeFile(RelicPath, JSON.stringify(this.relics, void 0, 4));
167
- if (generateMin) {
168
- const RelicMinPath = fileName ? import_node_path.default.join(DataDir, `${fileName}.min.json`) : import_node_path.default.join(DataDir, "Relics.min.json");
169
- await import_promises.default.writeFile(RelicMinPath, JSON.stringify(this.relics));
170
- }
171
- }
172
- /**
173
- * Generates a single relic from all available data
174
- * @param {WFCDRelic} rawRelic relic to pull Titania data from
175
- * @returns {TitaniaRelicReward}
176
- */
177
- generateTitaniaRelic(rawRelic) {
178
- var _a, _b;
179
- const name = `${rawRelic.tier} ${rawRelic.relicName}`;
180
- const rewards = rawRelic.rewards.map((rawReward) => {
181
- var _a2, _b2, _c;
182
- const { chance } = rawReward;
183
- const { rarity } = rawReward;
184
- const wfmInfo = (_a2 = this.wfmItems) == null ? void 0 : _a2.data.find((x) => x.i18n.en.name === rawReward.itemName);
185
- const isSpecial = ["Forma", "Kuva", "Exilus", "Riven"].find(
186
- (x) => (
187
- // eslint-disable-next-line @typescript-eslint/comma-dangle
188
- rawReward.itemName.toLowerCase().includes(x.toLowerCase())
189
- )
190
- );
191
- if (!(wfmInfo || isSpecial)) {
192
- Logger_default.debug(`Failed to find wfm item for ${rawReward.itemName}`);
193
- }
194
- const item = {
195
- name: rawReward.itemName,
196
- uniqueName: ((_c = (_b2 = this.wfcdItems) == null ? void 0 : _b2.find((x) => x.name.toLowerCase() === `${name.trim()} Intact`.toLowerCase())) == null ? void 0 : _c.uniqueName) || "",
197
- warframeMarket: void 0
198
- };
199
- if (wfmInfo) {
200
- item.warframeMarket = { id: wfmInfo.id, urlName: wfmInfo.slug };
201
- }
202
- return { rarity, chance, item };
203
- });
204
- let drops = [];
205
- const wfcdItem = (_a = this.wfcdItems) == null ? void 0 : _a.find((x) => x.name.toLowerCase() === `${name.trim()} Intact`.toLowerCase());
206
- if (!wfcdItem) {
207
- Logger_default.error(`Failed to get WFCD item for relic: ${name}`);
208
- }
209
- if (wfcdItem && wfcdItem.drops) {
210
- drops = wfcdItem.drops.map((rawDrop) => {
211
- return { rarity: rawDrop.rarity, chance: rawDrop.chance, location: rawDrop.location };
212
- });
213
- }
214
- const wfm = (_b = this.wfmItems) == null ? void 0 : _b.data.find((x) => x.i18n.en.name === `${name.trim()} Relic`);
215
- if (!wfm) {
216
- Logger_default.error(`Failed to get relic item from wfm: ${name}`);
217
- }
218
- return {
219
- name,
220
- rewards,
221
- locations: drops,
222
- uniqueName: (wfcdItem == null ? void 0 : wfcdItem.uniqueName) || "",
223
- vaultInfo: { vaulted: drops.length === 0 },
224
- ...(wfm == null ? void 0 : wfm.id) && (wfm == null ? void 0 : wfm.slug) && { warframeMarket: { id: wfm == null ? void 0 : wfm.id, urlName: wfm == null ? void 0 : wfm.slug } }
225
- };
226
- }
227
- /**
228
- * Filters WFCD's relic data to only include Intact variants, since we just need the base.
229
- */
230
- filterWFCDRelics() {
231
- var _a, _b, _c;
232
- const before = ((_a = this.relicsRaw) == null ? void 0 : _a.length) || 0;
233
- this.relicsRaw = (_b = this.relicsRaw) == null ? void 0 : _b.filter((x) => x.state === "Intact");
234
- Logger_default.log(`Filtered relics to intact variants. Before: ${before} After: ${((_c = this.relicsRaw) == null ? void 0 : _c.length) || 0}`);
235
- }
236
- };
237
- __name(_Generator, "Generator");
238
- var Generator = _Generator;
239
-
240
- // src/VersionManager.ts
241
- var import_node_path2 = __toESM(require("path"));
242
- var import_promises2 = __toESM(require("fs/promises"));
243
- var import_node_fetch2 = __toESM(require("node-fetch"));
244
- var _VersionManager = class _VersionManager {
245
- versionPath;
246
- versionRawPath;
247
- hashPath;
248
- /**
249
- * Creates a new VersionManager instance.
250
- * @param {string} dataDir Folder to write version information to.
251
- * @constructor
252
- */
253
- constructor(dataDir) {
254
- const DataDir = dataDir ?? import_node_path2.default.join(__dirname, "..", "data");
255
- this.versionPath = import_node_path2.default.join(DataDir, "version.json");
256
- this.versionRawPath = import_node_path2.default.join(DataDir, "version.txt");
257
- this.hashPath = import_node_path2.default.join(DataDir, "hash.json");
258
- }
259
- /**
260
- * Checks if the current data needs an update
261
- */
262
- async updateNeeded() {
263
- const infoReq = await (0, import_node_fetch2.default)(Config_default.warframeRelicDropInfoUrl);
264
- if (!infoReq.ok) {
265
- Logger_default.fatal("Failed to fetch version info!");
266
- }
267
- const info = await infoReq.json();
268
- try {
269
- await import_promises2.default.access(this.hashPath);
270
- const infoFile = JSON.parse(await import_promises2.default.readFile(this.hashPath, "utf-8"));
271
- return infoFile.hash !== info.hash;
272
- } catch (ex) {
273
- return true;
274
- }
275
- }
276
- /**
277
- * Writes both game and drop version metadata
278
- * @param {number} timestamp Timestamp the build was started at
279
- */
280
- async writeVersion(timestamp) {
281
- const patchLogsReq = await (0, import_node_fetch2.default)(Config_default.warframePatchlogsUrl);
282
- if (!patchLogsReq.ok) {
283
- Logger_default.error("Failed to fetch patchlogs");
284
- return;
285
- }
286
- const patchlogs = await patchLogsReq.json();
287
- const version = patchlogs[0].name.replace(/ \+ /g, "--").replace(/[^0-9\-.]/g, "").trim();
288
- const hashReq = await (0, import_node_fetch2.default)(Config_default.warframeRelicDropInfoUrl);
289
- if (!hashReq.ok) {
290
- Logger_default.error("Failed to fetch hashInfo");
291
- return;
292
- }
293
- const hashInfo = await hashReq.json();
294
- const versionInfo = { version, title: patchlogs[0].name };
295
- const hashFile = { hash: hashInfo.hash, deUpdated: hashInfo.modified, timestamp };
296
- await import_promises2.default.writeFile(this.hashPath, JSON.stringify(hashFile, void 0, 2), "utf-8");
297
- await import_promises2.default.writeFile(this.versionPath, JSON.stringify(versionInfo, void 0, 2), "utf-8");
298
- await import_promises2.default.writeFile(this.versionRawPath, version, "utf-8");
299
- Logger_default.debug("Finished writing version info");
300
- }
301
- };
302
- __name(_VersionManager, "VersionManager");
303
- var VersionManager = _VersionManager;
304
- // Annotate the CommonJS export names for ESM import in node:
305
- 0 && (module.exports = {
306
- Generator,
307
- VersionManager
308
- });