From ea14a639780c451985b520d988f9a95a33763fac Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Thu, 5 Dec 2024 14:25:53 +0300 Subject: [PATCH] Replace require() with import --- scripts/core/issueLoader.ts | 15 ++++++++++----- scripts/db/validate.ts | 3 ++- scripts/schemes/blocklist.js | 8 -------- scripts/schemes/blocklist.ts | 8 ++++++++ scripts/schemes/categories.js | 10 ---------- scripts/schemes/categories.ts | 10 ++++++++++ scripts/schemes/{channels.js => channels.ts} | 11 +++++++---- scripts/schemes/countries.js | 18 ------------------ scripts/schemes/countries.ts | 18 ++++++++++++++++++ scripts/schemes/index.js | 7 ------- scripts/schemes/index.ts | 17 +++++++++++++++++ scripts/schemes/languages.js | 8 -------- scripts/schemes/languages.ts | 8 ++++++++ scripts/schemes/{regions.js => regions.ts} | 4 ++-- scripts/schemes/subdivisions.js | 11 ----------- scripts/schemes/subdivisions.ts | 11 +++++++++++ 16 files changed, 93 insertions(+), 74 deletions(-) delete mode 100644 scripts/schemes/blocklist.js create mode 100644 scripts/schemes/blocklist.ts delete mode 100644 scripts/schemes/categories.js create mode 100644 scripts/schemes/categories.ts rename scripts/schemes/{channels.js => channels.ts} (91%) delete mode 100644 scripts/schemes/countries.js create mode 100644 scripts/schemes/countries.ts delete mode 100644 scripts/schemes/index.js create mode 100644 scripts/schemes/index.ts delete mode 100644 scripts/schemes/languages.js create mode 100644 scripts/schemes/languages.ts rename scripts/schemes/{regions.js => regions.ts} (84%) delete mode 100644 scripts/schemes/subdivisions.js create mode 100644 scripts/schemes/subdivisions.ts diff --git a/scripts/core/issueLoader.ts b/scripts/core/issueLoader.ts index bc0791d3..8d588f12 100644 --- a/scripts/core/issueLoader.ts +++ b/scripts/core/issueLoader.ts @@ -15,19 +15,24 @@ export class IssueLoader { if (TESTING) { switch (labels) { case 'channels:add,approved': - issues = require('../../tests/__data__/input/issues/channels_add_approved.js') + issues = (await import('../../tests/__data__/input/issues/channels_add_approved.js')) + .default break case 'channels:edit,approved': - issues = require('../../tests/__data__/input/issues/channels_edit_approved.js') + issues = (await import('../../tests/__data__/input/issues/channels_edit_approved.js')) + .default break case 'channels:remove,approved': - issues = require('../../tests/__data__/input/issues/channels_remove_approved.js') + issues = (await import('../../tests/__data__/input/issues/channels_remove_approved.js')) + .default break case 'blocklist:add,approved': - issues = require('../../tests/__data__/input/issues/blocklist_add_approved.js') + issues = (await import('../../tests/__data__/input/issues/blocklist_add_approved.js')) + .default break case 'blocklist:remove,approved': - issues = require('../../tests/__data__/input/issues/blocklist_remove_approved.js') + issues = (await import('../../tests/__data__/input/issues/blocklist_remove_approved.js')) + .default break } } else { diff --git a/scripts/db/validate.ts b/scripts/db/validate.ts index 0ca6ae2a..05013b15 100644 --- a/scripts/db/validate.ts +++ b/scripts/db/validate.ts @@ -1,5 +1,6 @@ import { Collection, Storage, File, Dictionary, Logger } from '@freearhey/core' import { DATA_DIR } from '../constants' +import schemesData from '../schemes' import { program } from 'commander' import Joi from 'joi' import { CSVParser, IDCreator } from '../core' @@ -10,7 +11,7 @@ program.argument('[filepath]', 'Path to file to validate').parse(process.argv) const logger = new Logger() const buffer = new Dictionary() const files = new Dictionary() -const schemes: { [key: string]: object } = require('../schemes') +const schemes: { [key: string]: object } = schemesData async function main() { const dataStorage = new Storage(DATA_DIR) diff --git a/scripts/schemes/blocklist.js b/scripts/schemes/blocklist.js deleted file mode 100644 index f629a85c..00000000 --- a/scripts/schemes/blocklist.js +++ /dev/null @@ -1,8 +0,0 @@ -const Joi = require('joi') - -module.exports = { - channel: Joi.string() - .regex(/^[A-Za-z0-9]+\.[a-z]{2}$/) - .required(), - ref: Joi.string().uri().required() -} diff --git a/scripts/schemes/blocklist.ts b/scripts/schemes/blocklist.ts new file mode 100644 index 00000000..530862bc --- /dev/null +++ b/scripts/schemes/blocklist.ts @@ -0,0 +1,8 @@ +import Joi from 'joi' + +export default { + channel: Joi.string() + .regex(/^[A-Za-z0-9]+\.[a-z]{2}$/) + .required(), + ref: Joi.string().uri().required() +} diff --git a/scripts/schemes/categories.js b/scripts/schemes/categories.js deleted file mode 100644 index 7986ecd4..00000000 --- a/scripts/schemes/categories.js +++ /dev/null @@ -1,10 +0,0 @@ -const Joi = require('joi') - -module.exports = { - id: Joi.string() - .regex(/^[a-z]+$/) - .required(), - name: Joi.string() - .regex(/^[A-Z]+$/i) - .required() -} diff --git a/scripts/schemes/categories.ts b/scripts/schemes/categories.ts new file mode 100644 index 00000000..de573f9a --- /dev/null +++ b/scripts/schemes/categories.ts @@ -0,0 +1,10 @@ +import Joi from 'joi' + +export default { + id: Joi.string() + .regex(/^[a-z]+$/) + .required(), + name: Joi.string() + .regex(/^[A-Z]+$/i) + .required() +} diff --git a/scripts/schemes/channels.js b/scripts/schemes/channels.ts similarity index 91% rename from scripts/schemes/channels.js rename to scripts/schemes/channels.ts index 20582cad..a4a5bb52 100644 --- a/scripts/schemes/channels.js +++ b/scripts/schemes/channels.ts @@ -1,8 +1,11 @@ -const Joi = require('joi').extend(require('@joi/date')) -const path = require('path') -const url = require('url') +import BaseJoi from 'joi' +import JoiDate from '@joi/date' +import path from 'path' +import url from 'url' -module.exports = { +const Joi = BaseJoi.extend(JoiDate) + +export default { id: Joi.string() .regex(/^[A-Za-z0-9]+\.[a-z]{2}$/) .required(), diff --git a/scripts/schemes/countries.js b/scripts/schemes/countries.js deleted file mode 100644 index 4db75d24..00000000 --- a/scripts/schemes/countries.js +++ /dev/null @@ -1,18 +0,0 @@ -const Joi = require('joi') - -module.exports = { - name: Joi.string() - .regex(/^[\sA-Z\u00C0-\u00FF().-]+$/i) - .required(), - code: Joi.string() - .regex(/^[A-Z]{2}$/) - .required(), - languages: Joi.array().items( - Joi.string() - .regex(/^[a-z]{3}$/) - .required() - ), - flag: Joi.string() - .regex(/^[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]$/) - .required() -} diff --git a/scripts/schemes/countries.ts b/scripts/schemes/countries.ts new file mode 100644 index 00000000..460763dd --- /dev/null +++ b/scripts/schemes/countries.ts @@ -0,0 +1,18 @@ +import Joi from 'joi' + +export default { + name: Joi.string() + .regex(/^[\sA-Z\u00C0-\u00FF().-]+$/i) + .required(), + code: Joi.string() + .regex(/^[A-Z]{2}$/) + .required(), + languages: Joi.array().items( + Joi.string() + .regex(/^[a-z]{3}$/) + .required() + ), + flag: Joi.string() + .regex(/^[\uD83C][\uDDE6-\uDDFF][\uD83C][\uDDE6-\uDDFF]$/) + .required() +} diff --git a/scripts/schemes/index.js b/scripts/schemes/index.js deleted file mode 100644 index f803aadf..00000000 --- a/scripts/schemes/index.js +++ /dev/null @@ -1,7 +0,0 @@ -exports.channels = require('./channels') -exports.categories = require('./categories') -exports.countries = require('./countries') -exports.languages = require('./languages') -exports.regions = require('./regions') -exports.subdivisions = require('./subdivisions') -exports.blocklist = require('./blocklist') diff --git a/scripts/schemes/index.ts b/scripts/schemes/index.ts new file mode 100644 index 00000000..b01922fb --- /dev/null +++ b/scripts/schemes/index.ts @@ -0,0 +1,17 @@ +import { default as channels } from './channels' +import { default as categories } from './categories' +import { default as countries } from './countries' +import { default as languages } from './languages' +import { default as regions } from './regions' +import { default as subdivisions } from './subdivisions' +import { default as blocklist } from './blocklist' + +export default { + channels, + categories, + countries, + languages, + regions, + subdivisions, + blocklist +} diff --git a/scripts/schemes/languages.js b/scripts/schemes/languages.js deleted file mode 100644 index 4c773ade..00000000 --- a/scripts/schemes/languages.js +++ /dev/null @@ -1,8 +0,0 @@ -const Joi = require('joi') - -module.exports = { - code: Joi.string() - .regex(/^[a-z]{3}$/) - .required(), - name: Joi.string().required() -} diff --git a/scripts/schemes/languages.ts b/scripts/schemes/languages.ts new file mode 100644 index 00000000..ed6e5fe4 --- /dev/null +++ b/scripts/schemes/languages.ts @@ -0,0 +1,8 @@ +import Joi from 'joi' + +export default { + code: Joi.string() + .regex(/^[a-z]{3}$/) + .required(), + name: Joi.string().required() +} diff --git a/scripts/schemes/regions.js b/scripts/schemes/regions.ts similarity index 84% rename from scripts/schemes/regions.js rename to scripts/schemes/regions.ts index 16343bb1..b6d6656e 100644 --- a/scripts/schemes/regions.js +++ b/scripts/schemes/regions.ts @@ -1,6 +1,6 @@ -const Joi = require('joi') +import Joi from 'joi' -module.exports = { +export default { name: Joi.string() .regex(/^[\sA-Z\u00C0-\u00FF().,-]+$/i) .required(), diff --git a/scripts/schemes/subdivisions.js b/scripts/schemes/subdivisions.js deleted file mode 100644 index 763eb28c..00000000 --- a/scripts/schemes/subdivisions.js +++ /dev/null @@ -1,11 +0,0 @@ -const Joi = require('joi') - -module.exports = { - country: Joi.string() - .regex(/^[A-Z]{2}$/) - .required(), - name: Joi.string().required(), - code: Joi.string() - .regex(/^[A-Z]{2}-[A-Z0-9]{1,3}$/) - .required() -} diff --git a/scripts/schemes/subdivisions.ts b/scripts/schemes/subdivisions.ts new file mode 100644 index 00000000..19071ff1 --- /dev/null +++ b/scripts/schemes/subdivisions.ts @@ -0,0 +1,11 @@ +import Joi from 'joi' + +export default { + country: Joi.string() + .regex(/^[A-Z]{2}$/) + .required(), + name: Joi.string().required(), + code: Joi.string() + .regex(/^[A-Z]{2}-[A-Z0-9]{1,3}$/) + .required() +}