From 17269f7b52b148c124a959bbdeef4c5cf72b018e Mon Sep 17 00:00:00 2001 From: AyAyEm <42449362+AyAyEm@users.noreply.github.com> Date: Mon, 28 Nov 2022 22:46:09 -0300 Subject: [PATCH] feat: warframe-items build refactor to esm --- build/.eslintrc.yaml | 1 + build/{build.js => build.mjs} | 58 ++++++++++--------- build/{dedupe.js => dedupe.mjs} | 6 +- build/{hashManager.js => hashManager.mjs} | 16 ++--- build/{objectsort.js => objectsort.mjs} | 4 +- build/{parser.js => parser.mjs} | 32 +++++----- build/{progress.js => progress.mjs} | 7 +-- build/readJson.mjs | 16 +++++ build/{scraper.js => scraper.mjs} | 48 ++++++++------- build/{stringify.js => stringify.mjs} | 6 +- build/{tradable.js => tradable.mjs} | 4 +- ...kiaDataScraper.js => WikiaDataScraper.mjs} | 20 +++---- build/wikia/scrapers/ModScraper.js | 11 ---- build/wikia/scrapers/ModScraper.mjs | 8 +++ build/wikia/scrapers/VersionScraper.js | 11 ---- build/wikia/scrapers/VersionScraper.mjs | 8 +++ build/wikia/scrapers/WarframeScraper.js | 11 ---- build/wikia/scrapers/WarframeScraper.mjs | 8 +++ .../{WeaponScraper.js => WeaponScraper.mjs} | 9 +-- .../{elements.js => elements.mjs} | 4 +- .../{polarities.js => polarities.mjs} | 4 +- .../{transformMod.js => transformMod.mjs} | 4 +- ...sformPolarity.js => transformPolarity.mjs} | 6 +- ...ansformVersion.js => transformVersion.mjs} | 4 +- ...sformWarframe.js => transformWarframe.mjs} | 9 ++- ...transformWeapon.js => transformWeapon.mjs} | 8 +-- package-lock.json | 31 +++++----- package.json | 4 +- test/index.regression.spec.mjs | 2 +- test/index.spec.mjs | 2 +- 30 files changed, 180 insertions(+), 182 deletions(-) rename build/{build.js => build.mjs} (87%) mode change 100755 => 100644 rename build/{dedupe.js => dedupe.mjs} (86%) rename build/{hashManager.js => hashManager.mjs} (77%) rename build/{objectsort.js => objectsort.mjs} (90%) rename build/{parser.js => parser.mjs} (97%) mode change 100755 => 100644 rename build/{progress.js => progress.mjs} (83%) mode change 100755 => 100644 create mode 100644 build/readJson.mjs rename build/{scraper.js => scraper.mjs} (88%) mode change 100755 => 100644 rename build/{stringify.js => stringify.mjs} (91%) mode change 100755 => 100644 rename build/{tradable.js => tradable.mjs} (97%) rename build/wikia/{WikiaDataScraper.js => WikiaDataScraper.mjs} (94%) mode change 100755 => 100644 delete mode 100644 build/wikia/scrapers/ModScraper.js create mode 100644 build/wikia/scrapers/ModScraper.mjs delete mode 100644 build/wikia/scrapers/VersionScraper.js create mode 100644 build/wikia/scrapers/VersionScraper.mjs delete mode 100755 build/wikia/scrapers/WarframeScraper.js create mode 100644 build/wikia/scrapers/WarframeScraper.mjs rename build/wikia/scrapers/{WeaponScraper.js => WeaponScraper.mjs} (61%) mode change 100755 => 100644 rename build/wikia/transformers/{elements.js => elements.mjs} (86%) rename build/wikia/transformers/{polarities.js => polarities.mjs} (77%) rename build/wikia/transformers/{transformMod.js => transformMod.mjs} (88%) rename build/wikia/transformers/{transformPolarity.js => transformPolarity.mjs} (88%) rename build/wikia/transformers/{transformVersion.js => transformVersion.mjs} (89%) rename build/wikia/transformers/{transformWarframe.js => transformWarframe.mjs} (88%) mode change 100755 => 100644 rename build/wikia/transformers/{transformWeapon.js => transformWeapon.mjs} (96%) mode change 100755 => 100644 diff --git a/build/.eslintrc.yaml b/build/.eslintrc.yaml index 12642778c..f5498cee4 100644 --- a/build/.eslintrc.yaml +++ b/build/.eslintrc.yaml @@ -1,3 +1,4 @@ +extends: '@wfcd/eslint-config/esm' rules: no-console: off import/no-extraneous-dependencies: off diff --git a/build/build.js b/build/build.mjs old mode 100755 new mode 100644 similarity index 87% rename from build/build.js rename to build/build.mjs index ed3266325..a5631ff46 --- a/build/build.js +++ b/build/build.mjs @@ -1,20 +1,22 @@ -'use strict'; - -const fs = require('fs/promises'); -const path = require('path'); -const crypto = require('crypto'); -const minify = require('imagemin'); -const minifyPng = require('imagemin-pngquant'); -const minifyJpeg = require('imagemin-jpegtran'); -const fetch = require('node-fetch'); -const sharp = require('sharp'); -const Progress = require('./progress'); -const stringify = require('./stringify'); -const scraper = require('./scraper'); -const parser = require('./parser'); -const hashManager = require('./hashManager'); -const imageCache = require('../data/cache/.images.json'); -const exportCache = require('../data/cache/.export.json'); +import fs from 'node:fs/promises'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import crypto from 'crypto'; +import minify from 'imagemin'; +import minifyPng from 'imagemin-pngquant'; +import minifyJpeg from 'imagemin-jpegtran'; +import fetch from 'node-fetch'; +import sharp from 'sharp'; + +import Progress from './progress.mjs'; +import stringify from './stringify.mjs'; +import scraper from './scraper.mjs'; +import parser from './parser.mjs'; +import hashManager from './hashManager.mjs'; +import readJson from './readJson.mjs'; + +const imageCache = await readJson(new URL('../data/cache/.images.json', import.meta.url)); +const exportCache = await readJson(new URL('../data/cache/.export.json', import.meta.url)); const allowedCustomCategories = ['SentinelWeapons']; @@ -125,15 +127,15 @@ class Build { const data = categories[category].sort(sort); all = all.concat(data); await fs.writeFile( - path.join(__dirname, `../data/json/${category}.json`), + new URL(`../data/json/${category}.json`, import.meta.url), JSON.stringify(JSON.parse(stringify(data))) ); } // All.json (all items in one file) all.sort(sort); - await fs.writeFile(path.join(__dirname, '../data/json/All.json'), stringify(all)); - await fs.writeFile(path.join(__dirname, '../data/json/i18n.json'), stringify(i18n)); + await fs.writeFile(new URL('../data/json/All.json', import.meta.url), stringify(all)); + await fs.writeFile(new URL('../data/json/i18n.json', import.meta.url), stringify(i18n)); return all; } @@ -160,7 +162,7 @@ class Build { * @param {Warnings} warnings warnings to save to file */ async saveWarnings(warnings) { - return fs.writeFile(path.join(__dirname, '../data/warnings.json'), stringify(warnings)); + return fs.writeFile(new URL('../data/warnings.json', import.meta.url), stringify(warnings)); } /** @@ -194,11 +196,14 @@ class Build { // write the manifests after images have all succeeded exportCache.Manifest.hash = manifestHash; - await fs.writeFile(path.join(__dirname, '../data/cache/.export.json'), JSON.stringify(exportCache, undefined, 1)); + await fs.writeFile( + new URL('../data/cache/.export.json', import.meta.url), + JSON.stringify(exportCache, undefined, 1) + ); // Write new cache to disk await fs.writeFile( - path.join(__dirname, '../data/cache/.images.json'), + new URL('../data/cache/.images.json', import.meta.url), JSON.stringify( imageCache.filter((i) => i.hash), undefined, @@ -220,7 +225,7 @@ class Build { if (!imageBase) return; const imageStub = imageBase.textureLocation.replace(/\\/g, '/').replace('xport/', ''); const imageUrl = `https://content.warframe.com/PublicExport/${imageStub}`; - const basePath = path.join(__dirname, '../data/img/'); + const basePath = fileURLToPath(new URL('../data/img/', import.meta.url)); const filePath = path.join(basePath, item.imageName); const hash = manifest.find((i) => i.uniqueName === item.uniqueName).fileTime; const cached = imageCache.find((c) => c.uniqueName === item.uniqueName); @@ -293,14 +298,13 @@ class Build { * @param {module:warframe-patchlogs.Patchlogs} patchlogs for pulling the latest update */ async updateReadme(patchlogs) { - // eslint-disable-next-line import/no-dynamic-require - const logob64 = require(path.join(__dirname, '../data/logo.json')); + const logob64 = await readJson(new URL('../data/logo.json', import.meta.url)); const version = patchlogs.posts[0].name .replace(/ \+ /g, '--') .replace(/[^0-9\-.]/g, '') .trim(); const { url } = patchlogs.posts[0]; - const readmeLocation = path.join(__dirname, '../README.md'); + const readmeLocation = new URL('../README.md', import.meta.url); const readmeOld = await fs.readFile(readmeLocation, 'utf-8'); const readmeNew = readmeOld.replace( /\[!\[warframe update.*/, diff --git a/build/dedupe.js b/build/dedupe.mjs similarity index 86% rename from build/dedupe.js rename to build/dedupe.mjs index e2cfcdd4a..d56c2b496 100644 --- a/build/dedupe.js +++ b/build/dedupe.mjs @@ -1,13 +1,11 @@ -'use strict'; - -const objectsort = require('./objectsort'); +import objectsort from './objectsort.mjs'; /** * Simple deduplication leveraging reduce (and equality based on stringification) * @param {Iterable<*>} iter Should be an iterable object, but function will check first. * @returns {Iterable<*>} type will be whatever was originally passed in */ -module.exports = (iter) => { +export default (iter) => { return Array.isArray(iter) ? iter .reduce( diff --git a/build/hashManager.js b/build/hashManager.mjs similarity index 77% rename from build/hashManager.js rename to build/hashManager.mjs index 736ce5446..90d58e446 100644 --- a/build/hashManager.js +++ b/build/hashManager.mjs @@ -1,10 +1,10 @@ -'use strict'; +import fs from 'node:fs/promises'; -const fs = require('fs/promises'); -const path = require('path'); -const scraper = require('./scraper'); -const exportCache = require('../data/cache/.export.json'); -const locales = require('../config/locales.json'); +import scraper from './scraper.mjs'; +import readJson from './readJson.mjs'; + +const exportCache = await readJson(new URL('../data/cache/.export.json', import.meta.url)); +const locales = await readJson(new URL('../config/locales.json', import.meta.url)); const exportKeyWhitelist = ['Manifest', 'DropChances', 'Patchlogs']; @@ -31,7 +31,7 @@ class HashManager { async saveExportCache() { await fs.writeFile( - path.join(__dirname, '../data/cache/.export.json'), + new URL('../data/cache/.export.json', import.meta.url), JSON.stringify(this.exportCache, undefined, 1) ); } @@ -55,4 +55,4 @@ class HashManager { } } -module.exports = new HashManager(); +export default new HashManager(); diff --git a/build/objectsort.js b/build/objectsort.mjs similarity index 90% rename from build/objectsort.js rename to build/objectsort.mjs index 46c13d963..8110e730c 100644 --- a/build/objectsort.js +++ b/build/objectsort.mjs @@ -1,12 +1,10 @@ -'use strict'; - /** * Sorting objects by keys * https://www.w3docs.com/snippets/javascript/how-to-sort-javascript-object-by-key.html * @param {Record} obj object to be sorted * @returns {Record} same as {@param obj} but sorted keys */ -module.exports = (obj) => { +export default (obj) => { return Object.keys(obj) .sort() .reduce(function (result, key) { diff --git a/build/parser.js b/build/parser.mjs old mode 100755 new mode 100644 similarity index 97% rename from build/parser.js rename to build/parser.mjs index 754eed8a0..b73c98176 --- a/build/parser.js +++ b/build/parser.mjs @@ -1,13 +1,18 @@ -'use strict'; - -const _ = require('lodash'); -const Progress = require('./progress'); -const previousBuild = require('../data/json/All.json'); -const watson = require('../config/dt_map.json'); -const bpConflicts = require('../config/bpConflicts.json'); -const { prefixes, suffixes } = require('../config/variants.json'); -const dedupe = require('./dedupe'); -const tradable = require('./tradable'); +import _ from 'lodash'; + +import Progress from './progress.mjs'; +import dedupe from './dedupe.mjs'; +import tradable from './tradable.mjs'; +import readJson from './readJson.mjs'; + +const previousBuild = await readJson(new URL('../data/json/All.json', import.meta.url)); +const watson = await readJson(new URL('../config/dt_map.json', import.meta.url)); +const bpConflicts = await readJson(new URL('../config/bpConflicts.json', import.meta.url)); +const { prefixes, suffixes } = await readJson(new URL('../config/variants.json', import.meta.url)); +const grades = await readJson(new URL('../config/relicGrades.json', import.meta.url)); +const polarities = await readJson(new URL('../config/polarities.json', import.meta.url)); +const types = await readJson(new URL('../config/itemTypes.json', import.meta.url)); +const overrides = await readJson(new URL('../config/overrides.json', import.meta.url)); /** * Titlecase a string @@ -372,7 +377,6 @@ class Parser { // Relics don't have their grade in the name for some reason if (item.type === 'Relic') { - const grades = require('../config/relicGrades.json'); // eslint-disable-next-line no-restricted-syntax for (const grade of grades) { if (item.uniqueName.includes(grade.id)) { @@ -396,7 +400,6 @@ class Parser { // Use proper polarity names if (item.polarity) { - const polarities = require('../config/polarities.json'); const polarity = polarities.find((p) => p.id === item.polarity); if (polarity) { item.polarity = polarity.name; @@ -424,7 +427,6 @@ class Parser { */ addType(item) { if (item.parent) return; - const types = require('../config/itemTypes.json'); // eslint-disable-next-line no-restricted-syntax for (const type of types) { const contains = type.regex ? new RegExp(type.id, 'ig').test(item.uniqueName) : item.uniqueName.includes(type.id); @@ -980,7 +982,7 @@ class Parser { applyOverrides(item) { // universal polarity casing override if (item.polarity) item.polarity = item.polarity.toLowerCase(); - const override = require('../config/overrides.json')[item.uniqueName]; + const override = overrides[item.uniqueName]; if (override) { Object.keys(override).forEach((key) => { item[key] = override[key]; @@ -1080,4 +1082,4 @@ class Parser { } } -module.exports = new Parser(); +export default new Parser(); diff --git a/build/progress.js b/build/progress.mjs old mode 100755 new mode 100644 similarity index 83% rename from build/progress.js rename to build/progress.mjs index e7ec7379f..316bbc8d3 --- a/build/progress.js +++ b/build/progress.mjs @@ -1,8 +1,7 @@ -'use strict'; +import ProgressBar from 'progress'; +import colors from 'colors/safe.js'; const prod = process.env.NODE_ENV === 'production'; -const ProgressBar = require('progress'); -const colors = require('colors/safe'); /** * Simple progress bar @@ -26,7 +25,7 @@ class Progress extends ProgressBar { * Use dummy object in prod because pm2 won't render * the progress bar properly. */ -module.exports = prod +export default prod ? class Empty { interrupt() {} tick() {} diff --git a/build/readJson.mjs b/build/readJson.mjs new file mode 100644 index 000000000..8c2663aaf --- /dev/null +++ b/build/readJson.mjs @@ -0,0 +1,16 @@ +import fs from 'node:fs/promises'; + +const jsonCache = new Map(); + +/** + * @param {URL} jsonURL URL to json file + * @returns {Promise | Array<*>>} + */ +export default async (jsonURL) => { + const { pathname } = jsonURL; + if (jsonCache.has(pathname)) { + return jsonCache.get(pathname); + } + + return JSON.parse(await fs.readFile(jsonURL, { encoding: 'utf-8' })); +}; diff --git a/build/scraper.js b/build/scraper.mjs old mode 100755 new mode 100644 similarity index 88% rename from build/scraper.js rename to build/scraper.mjs index 065c6c40e..7bc3d5265 --- a/build/scraper.js +++ b/build/scraper.mjs @@ -1,23 +1,24 @@ -'use strict'; +import Agent from 'socks5-http-client/lib/Agent.js'; +import fetch from 'node-fetch'; +import crypto from 'crypto'; +import lzma from 'lzma'; +import fs from 'node:fs/promises'; +import cheerio from 'cheerio'; -const prod = process.env.NODE_ENV === 'production'; -const Agent = require('socks5-http-client/lib/Agent'); -const fetch = require('node-fetch'); -const crypto = require('crypto'); -const lzma = require('lzma'); -const fs = require('node:fs/promises'); -const path = require('path'); -const cheerio = require('cheerio'); +import { Generator as RelicGenerator } from '@wfcd/relics'; +import patchlogs from 'warframe-patchlogs'; + +import Progress from './progress.mjs'; +import ModScraper from './wikia/scrapers/ModScraper.mjs'; +import WeaponScraper from './wikia/scrapers/WeaponScraper.mjs'; +import WarframeScraper from './wikia/scrapers/WarframeScraper.mjs'; +import VersionScraper from './wikia/scrapers/VersionScraper.mjs'; +import readJson from './readJson.mjs'; -const { Generator: RelicGenerator } = require('@wfcd/relics'); +const exportCache = await readJson(new URL('../data/cache/.export.json', import.meta.url)); +const locales = await readJson(new URL('../config/locales.json', import.meta.url)); -const Progress = require('./progress'); -const exportCache = require('../data/cache/.export.json'); -const locales = require('../config/locales.json'); -const ModScraper = require('./wikia/scrapers/ModScraper'); -const WeaponScraper = require('./wikia/scrapers/WeaponScraper'); -const WarframeScraper = require('./wikia/scrapers/WarframeScraper'); -const VersionScraper = require('./wikia/scrapers/VersionScraper'); +const prod = process.env.NODE_ENV === 'production'; // eslint-disable-next-line no-control-regex const sanitize = (str) => str.replace(/\\r|\r?\n|\x09/g, '').replace(/\\\\"/g, "'"); const agent = process.env.SOCK5_HOST @@ -149,7 +150,10 @@ class Scraper { // Update checksum if (changed) { exportCache.DropChances.hash = ratesHash; - await fs.writeFile(path.join(__dirname, '../data/cache/.export.json'), JSON.stringify(exportCache, undefined, 1)); + await fs.writeFile( + new URL('../data/cache/.export.json', import.meta.url), + JSON.stringify(exportCache, undefined, 1) + ); } bar.tick(); @@ -170,13 +174,15 @@ class Scraper { */ async fetchPatchLogs() { const bar = new Progress('Fetching Patchlogs', 1); - const patchlogs = require('warframe-patchlogs'); const patchlogsHash = crypto.createHash('md5').update(JSON.stringify(patchlogs.posts)).digest('hex'); const changed = exportCache.Patchlogs.hash !== patchlogsHash; if (changed) { exportCache.Patchlogs.hash = patchlogsHash; - await fs.writeFile(path.join(__dirname, '../data/cache/.export.json'), JSON.stringify(exportCache, undefined, 1)); + await fs.writeFile( + new URL('../data/cache/.export.json', import.meta.url), + JSON.stringify(exportCache, undefined, 1) + ); } bar.tick(); @@ -287,4 +293,4 @@ class Scraper { } } -module.exports = new Scraper(); +export default new Scraper(); diff --git a/build/stringify.js b/build/stringify.mjs old mode 100755 new mode 100644 similarity index 91% rename from build/stringify.js rename to build/stringify.mjs index bc8e86518..310848302 --- a/build/stringify.js +++ b/build/stringify.mjs @@ -1,6 +1,4 @@ -'use strict'; - -const dedupe = require('./dedupe'); +import dedupe from './dedupe.mjs'; /** * Pretty print JSON as it should be. @@ -15,4 +13,4 @@ const replacer = (key, value) => (isArrayOfPrimitive(value) ? format(value) : va const expand = (str) => str.replace(/"\^\^\^(\[ .* ])"/g, (match, a) => a.replace(/\\"/g, '"')).replace(/\\\\"/g, "'"); const stringify = (obj) => expand(JSON.stringify(Array.isArray(obj) ? dedupe(obj) : obj, replacer, 2)); -module.exports = stringify; +export default stringify; diff --git a/build/tradable.js b/build/tradable.mjs similarity index 97% rename from build/tradable.js rename to build/tradable.mjs index 617973c93..a100c4af9 100644 --- a/build/tradable.js +++ b/build/tradable.mjs @@ -1,5 +1,3 @@ -'use strict'; - const builtUntradable = ['Warframe', 'Throwing', 'Shotgun', 'Rifle', 'Pistol', 'Melee', 'Sword And Shield']; const tradableConditions = (item) => !(builtUntradable.includes(item.type) && item.name.match(/Prime/gi)); @@ -51,7 +49,7 @@ const untradableRegex = * @param {module:warframe-items.Item} item Item to determine tradability * @returns {boolean} */ -module.exports = (item) => { +export default (item) => { const notFiltered = !untradableTypes.includes(item.type) && !item.name.match(untradableRegex) && diff --git a/build/wikia/WikiaDataScraper.js b/build/wikia/WikiaDataScraper.mjs old mode 100755 new mode 100644 similarity index 94% rename from build/wikia/WikiaDataScraper.js rename to build/wikia/WikiaDataScraper.mjs index ab7bb879d..5249a9cd3 --- a/build/wikia/WikiaDataScraper.js +++ b/build/wikia/WikiaDataScraper.mjs @@ -1,12 +1,10 @@ -'use strict'; - -const cheerio = require('cheerio'); -const fs = require('fs/promises'); -const os = require('os'); -const path = require('path'); -const { promisify } = require('util'); -const cmd = require('node-cmd'); -const fetch = require('node-fetch'); +import cheerio from 'cheerio'; +import fs from 'fs/promises'; +import os from 'os'; +import path from 'path'; +import { promisify } from 'util'; +import cmd from 'node-cmd'; +import fetch from 'node-fetch'; const run = promisify(cmd.get); @@ -121,7 +119,7 @@ let blueprints; /** * Scrape Wikia data from data modules */ -module.exports = class WikiaDataScraper { +export default class WikiaDataScraper { constructor(url, luaObjectName, transformFunction) { if (Array.isArray(url)) { this.urls = url; @@ -189,4 +187,4 @@ module.exports = class WikiaDataScraper { if (!things.length) console.error(`scraped no ${this.luaObjectName}`); return things; } -}; +} diff --git a/build/wikia/scrapers/ModScraper.js b/build/wikia/scrapers/ModScraper.js deleted file mode 100644 index cb9cdc7fa..000000000 --- a/build/wikia/scrapers/ModScraper.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = class ModScraper extends require('../WikiaDataScraper') { - constructor() { - super( - 'https://warframe.fandom.com/wiki/Module:Mods/data?action=edit', - 'Mod', - require('../transformers/transformMod') - ); - } -}; diff --git a/build/wikia/scrapers/ModScraper.mjs b/build/wikia/scrapers/ModScraper.mjs new file mode 100644 index 000000000..c09ee814e --- /dev/null +++ b/build/wikia/scrapers/ModScraper.mjs @@ -0,0 +1,8 @@ +import WikiaDataScraper from '../WikiaDataScraper.mjs'; +import transformMod from '../transformers/transformMod.mjs'; + +export default class ModScraper extends WikiaDataScraper { + constructor() { + super('https://warframe.fandom.com/wiki/Module:Mods/data?action=edit', 'Mod', transformMod); + } +} diff --git a/build/wikia/scrapers/VersionScraper.js b/build/wikia/scrapers/VersionScraper.js deleted file mode 100644 index ad03b4c26..000000000 --- a/build/wikia/scrapers/VersionScraper.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = class VersionScraper extends require('../WikiaDataScraper') { - constructor() { - super( - 'https://warframe.fandom.com/wiki/Module:Version/data?action=edit', - 'Version', - require('../transformers/transformVersion') - ); - } -}; diff --git a/build/wikia/scrapers/VersionScraper.mjs b/build/wikia/scrapers/VersionScraper.mjs new file mode 100644 index 000000000..3beef74ba --- /dev/null +++ b/build/wikia/scrapers/VersionScraper.mjs @@ -0,0 +1,8 @@ +import WikiaDataScraper from '../WikiaDataScraper.mjs'; +import transformVersion from '../transformers/transformVersion.mjs'; + +export default class VersionScraper extends WikiaDataScraper { + constructor() { + super('https://warframe.fandom.com/wiki/Module:Version/data?action=edit', 'Version', transformVersion); + } +} diff --git a/build/wikia/scrapers/WarframeScraper.js b/build/wikia/scrapers/WarframeScraper.js deleted file mode 100755 index 1bc5704f9..000000000 --- a/build/wikia/scrapers/WarframeScraper.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -module.exports = class WarframeScraper extends require('../WikiaDataScraper') { - constructor() { - super( - 'https://warframe.fandom.com/wiki/Module:Warframes/data?action=edit', - 'Warframe', - require('../transformers/transformWarframe') - ); - } -}; diff --git a/build/wikia/scrapers/WarframeScraper.mjs b/build/wikia/scrapers/WarframeScraper.mjs new file mode 100644 index 000000000..ae4000540 --- /dev/null +++ b/build/wikia/scrapers/WarframeScraper.mjs @@ -0,0 +1,8 @@ +import WikiaDataScraper from '../WikiaDataScraper.mjs'; +import transformWarframe from '../transformers/transformWarframe.mjs'; + +export default class WarframeScraper extends WikiaDataScraper { + constructor() { + super('https://warframe.fandom.com/wiki/Module:Warframes/data?action=edit', 'Warframe', transformWarframe); + } +} diff --git a/build/wikia/scrapers/WeaponScraper.js b/build/wikia/scrapers/WeaponScraper.mjs old mode 100755 new mode 100644 similarity index 61% rename from build/wikia/scrapers/WeaponScraper.js rename to build/wikia/scrapers/WeaponScraper.mjs index 82db0d609..64beafc4a --- a/build/wikia/scrapers/WeaponScraper.js +++ b/build/wikia/scrapers/WeaponScraper.mjs @@ -1,15 +1,16 @@ -'use strict'; +import WikiaDataScraper from '../WikiaDataScraper.mjs'; +import transformWeapon from '../transformers/transformWeapon.mjs'; const base = 'https://warframe.fandom.com/wiki/Module:Weapons/data'; const suffix = '?action=edit'; const subModules = ['archwing', 'companion', 'melee', 'misc', 'modular', 'primary', 'secondary', 'railjack']; -module.exports = class WeaponScraper extends require('../WikiaDataScraper') { +export default class WeaponScraper extends WikiaDataScraper { constructor() { super( subModules.map((subModule) => `${base}/${subModule}${suffix}`), 'Weapon', - require('../transformers/transformWeapon') + transformWeapon ); } -}; +} diff --git a/build/wikia/transformers/elements.js b/build/wikia/transformers/elements.mjs similarity index 86% rename from build/wikia/transformers/elements.js rename to build/wikia/transformers/elements.mjs index 668886003..76c6264c3 100644 --- a/build/wikia/transformers/elements.js +++ b/build/wikia/transformers/elements.mjs @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = { +export default { Electricity: 'electricity', Corrosive: 'corrosive', Toxin: 'toxin', diff --git a/build/wikia/transformers/polarities.js b/build/wikia/transformers/polarities.mjs similarity index 77% rename from build/wikia/transformers/polarities.js rename to build/wikia/transformers/polarities.mjs index f6c5e2595..93eada7d0 100644 --- a/build/wikia/transformers/polarities.js +++ b/build/wikia/transformers/polarities.mjs @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = { +export default { Bar: 'naramon', V: 'madurai', D: 'vazarin', diff --git a/build/wikia/transformers/transformMod.js b/build/wikia/transformers/transformMod.mjs similarity index 88% rename from build/wikia/transformers/transformMod.js rename to build/wikia/transformers/transformMod.mjs index bdc0cd52f..9451973a6 100644 --- a/build/wikia/transformers/transformMod.js +++ b/build/wikia/transformers/transformMod.mjs @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = async (oldMod, imageUrls) => { +export default async (oldMod, imageUrls) => { let newMod; if (!oldMod || !oldMod.Name) { return undefined; diff --git a/build/wikia/transformers/transformPolarity.js b/build/wikia/transformers/transformPolarity.mjs similarity index 88% rename from build/wikia/transformers/transformPolarity.js rename to build/wikia/transformers/transformPolarity.mjs index b60f22c06..41b6662a6 100644 --- a/build/wikia/transformers/transformPolarity.js +++ b/build/wikia/transformers/transformPolarity.mjs @@ -1,6 +1,4 @@ -'use strict'; - -const POLARITIES = require('./polarities'); +import POLARITIES from './polarities.mjs'; const transform = (field) => { let output; @@ -21,7 +19,7 @@ const transform = (field) => { * @param {Array} [Polarities] list of strings designating polarities on a weapon or warframe * @returns {*} */ -module.exports = ({ AuraPolarity, StancePolarity, Polarity, Polarities }, target) => { +export default ({ AuraPolarity, StancePolarity, Polarity, Polarities }, target) => { const output = { ...target }; output.auraPolarity = transform(AuraPolarity); output.stancePolarity = transform(StancePolarity); diff --git a/build/wikia/transformers/transformVersion.js b/build/wikia/transformers/transformVersion.mjs similarity index 89% rename from build/wikia/transformers/transformVersion.js rename to build/wikia/transformers/transformVersion.mjs index 13027c1c2..c788a8e0f 100644 --- a/build/wikia/transformers/transformVersion.js +++ b/build/wikia/transformers/transformVersion.mjs @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = async (oldVersion) => { +export default async (oldVersion) => { let newVersion; if (!oldVersion || !oldVersion.Name) { diff --git a/build/wikia/transformers/transformWarframe.js b/build/wikia/transformers/transformWarframe.mjs old mode 100755 new mode 100644 similarity index 88% rename from build/wikia/transformers/transformWarframe.js rename to build/wikia/transformers/transformWarframe.mjs index c9cbf126f..4d5e89bed --- a/build/wikia/transformers/transformWarframe.js +++ b/build/wikia/transformers/transformWarframe.mjs @@ -1,8 +1,7 @@ -'use strict'; +import getColors from 'get-image-colors'; +import imageDownloader from 'image-downloader'; -const getColors = require('get-image-colors'); -const imageDownloader = require('image-downloader'); -const transformPolarity = require('./transformPolarity'); +import transformPolarity from './transformPolarity.mjs'; const mapColors = async (oldFrame, imageUrl) => { if (!imageUrl) return 0; @@ -28,7 +27,7 @@ const mapColors = async (oldFrame, imageUrl) => { * @param {Record} blueprints blueprint objects * @returns {Promise} */ -module.exports = async (oldFrame, imageUrls, blueprints) => { +export default async (oldFrame, imageUrls, blueprints) => { let newFrame; if (!oldFrame || !oldFrame.Name) { return undefined; diff --git a/build/wikia/transformers/transformWeapon.js b/build/wikia/transformers/transformWeapon.mjs old mode 100755 new mode 100644 similarity index 96% rename from build/wikia/transformers/transformWeapon.js rename to build/wikia/transformers/transformWeapon.mjs index bb68752cb..80f33a70f --- a/build/wikia/transformers/transformWeapon.js +++ b/build/wikia/transformers/transformWeapon.mjs @@ -1,7 +1,5 @@ -'use strict'; - -const ELEMENTS = require('./elements'); -const transformPolarity = require('./transformPolarity'); +import ELEMENTS from './elements.mjs'; +import transformPolarity from './transformPolarity.mjs'; const damageTypes = [ 'Impact', @@ -74,7 +72,7 @@ const parseSlam = ({ SlamAttack, SlamRadialDmg, SlamRadialElement, SlamRadialPro }; }; -module.exports = (oldWeapon, imageUrls, blueprints) => { +export default (oldWeapon, imageUrls, blueprints) => { let newWeapon; if (!oldWeapon || !oldWeapon.Name) { return undefined; diff --git a/package-lock.json b/package-lock.json index 1fbb93f73..204a11ae1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "@types/imagemin-jpegtran": "^5.0.1", "@types/node-fetch": "^2.5.12", "@types/sharp": "^0.31.0", - "@wfcd/eslint-config": "^1.1.5", + "@wfcd/eslint-config": "^1.3.0", "@wfcd/relics": "^2.0.0", "ajv-cli": "^5.0.0", "cheerio": "^1.0.0-rc.3", @@ -973,13 +973,13 @@ } }, "node_modules/@babel/plugin-syntax-import-assertions": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.18.6.tgz", - "integrity": "sha512-/DU3RXad9+bZwrgWJQKbr39gYbJpLJHezqEzRzi/BHRlJ9zsQb4CK2CA/5apllXNomwA1qHwzvHl+AdEmC5krQ==", + "version": "7.20.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.20.0.tgz", + "integrity": "sha512-IUh1vakzNoWalR8ch/areW7qFopR2AEw03JlG7BbrDqmQ4X3q9uuipQwSGrUn7oGiemKjtSLDhNtQHzMHr1JdQ==", "dev": true, "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.18.6" + "@babel/helper-plugin-utils": "^7.19.0" }, "engines": { "node": ">=6.9.0" @@ -2616,9 +2616,9 @@ } }, "node_modules/@wfcd/eslint-config": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@wfcd/eslint-config/-/eslint-config-1.2.0.tgz", - "integrity": "sha512-pl50im5WrRfP3d16PeMIkSb/Ehzx8YUK3rc4clEux7SRRncmg6d44wsQuVRUlmVMMLEu3+Tqdwc1FHMu4ZwIrA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@wfcd/eslint-config/-/eslint-config-1.3.0.tgz", + "integrity": "sha512-osQgFrOyTcGZdR9BmZzkcYNwtVeFoh+va91HBuDsn9yGJJmfIQlhH1m6L89p+dfBKuj1Sq21KEZLdmDui7sNWA==", "dev": true, "engines": { "npm": ">=7" @@ -2628,6 +2628,7 @@ "@babel/eslint-parser": "^7.19.1", "@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/plugin-proposal-private-methods": "^7.18.6", + "@babel/plugin-syntax-import-assertions": "^7.20.0", "@babel/preset-env": "^7.19.1", "@typescript-eslint/eslint-plugin": "^5.38.0", "@typescript-eslint/parser": "^5.38.0", @@ -12211,13 +12212,13 @@ } }, "@babel/plugin-syntax-import-assertions": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.18.6.tgz", - "integrity": "sha512-/DU3RXad9+bZwrgWJQKbr39gYbJpLJHezqEzRzi/BHRlJ9zsQb4CK2CA/5apllXNomwA1qHwzvHl+AdEmC5krQ==", + "version": "7.20.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.20.0.tgz", + "integrity": "sha512-IUh1vakzNoWalR8ch/areW7qFopR2AEw03JlG7BbrDqmQ4X3q9uuipQwSGrUn7oGiemKjtSLDhNtQHzMHr1JdQ==", "dev": true, "peer": true, "requires": { - "@babel/helper-plugin-utils": "^7.18.6" + "@babel/helper-plugin-utils": "^7.19.0" } }, "@babel/plugin-syntax-json-strings": { @@ -13399,9 +13400,9 @@ } }, "@wfcd/eslint-config": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@wfcd/eslint-config/-/eslint-config-1.2.0.tgz", - "integrity": "sha512-pl50im5WrRfP3d16PeMIkSb/Ehzx8YUK3rc4clEux7SRRncmg6d44wsQuVRUlmVMMLEu3+Tqdwc1FHMu4ZwIrA==", + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@wfcd/eslint-config/-/eslint-config-1.3.0.tgz", + "integrity": "sha512-osQgFrOyTcGZdR9BmZzkcYNwtVeFoh+va91HBuDsn9yGJJmfIQlhH1m6L89p+dfBKuj1Sq21KEZLdmDui7sNWA==", "dev": true, "requires": {} }, diff --git a/package.json b/package.json index c4e260f23..bc96d0293 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "require": "./index.js" }, "scripts": { - "build": "node ./build/build.js", + "build": "node ./build/build.mjs", "test": "nyc mocha --exclude test/*.regression.spec.mjs", "regression": "mocha --include test/index.regression.spec.mjs", "lint": "eslint --ignore-path .gitignore .", @@ -38,7 +38,7 @@ "@types/imagemin-jpegtran": "^5.0.1", "@types/node-fetch": "^2.5.12", "@types/sharp": "^0.31.0", - "@wfcd/eslint-config": "^1.1.5", + "@wfcd/eslint-config": "^1.3.0", "@wfcd/relics": "^2.0.0", "ajv-cli": "^5.0.0", "cheerio": "^1.0.0-rc.3", diff --git a/test/index.regression.spec.mjs b/test/index.regression.spec.mjs index 9225f4bb8..bf79c05e7 100644 --- a/test/index.regression.spec.mjs +++ b/test/index.regression.spec.mjs @@ -1,6 +1,6 @@ import fetch from 'node-fetch'; import assert from 'node:assert'; -import dedupe from '../build/dedupe.js'; +import dedupe from '../build/dedupe.mjs'; const grab = async (path) => { return fetch(`https://api.warframestat.us/${path}/?language=en`).then((d) => d.json()); diff --git a/test/index.spec.mjs b/test/index.spec.mjs index 722ebb0cb..7c7890e4f 100755 --- a/test/index.spec.mjs +++ b/test/index.spec.mjs @@ -1,6 +1,6 @@ import assert from 'node:assert'; import { resolve } from 'node:path'; -import dedupe from '../build/dedupe.js'; +import dedupe from '../build/dedupe.mjs'; import { createRequire } from 'module' const require = createRequire(import.meta.url)