From 4c92b4ecb1d2b0e40b8e0290b35aed62ed192bb4 Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Fri, 22 Sep 2023 05:17:22 +0300 Subject: [PATCH] Install @freearhey/core --- package-lock.json | 61 ++++++- package.json | 6 +- scripts/commands/api/generate.ts | 3 +- scripts/commands/playlist/format.ts | 3 +- scripts/commands/playlist/generate.ts | 7 +- scripts/commands/playlist/update.ts | 3 +- scripts/commands/playlist/validate.ts | 3 +- scripts/commands/readme/update.ts | 3 +- scripts/commands/report/create.ts | 3 +- scripts/core/collection.ts | 175 ------------------- scripts/core/dictionary.ts | 31 ---- scripts/core/file.ts | 31 ---- scripts/core/index.ts | 6 - scripts/core/issueLoader.ts | 16 +- scripts/core/issueParser.ts | 2 +- scripts/core/logger.ts | 9 - scripts/core/playlistParser.ts | 4 +- scripts/core/storage.ts | 84 --------- scripts/core/url.ts | 20 --- scripts/generators/categoriesGenerator.ts | 2 +- scripts/generators/countriesGenerator.ts | 2 +- scripts/generators/indexCategoryGenerator.ts | 2 +- scripts/generators/indexCountryGenerator.ts | 2 +- scripts/generators/indexGenerator.ts | 2 +- scripts/generators/indexLanguageGenerator.ts | 2 +- scripts/generators/indexNsfwGenerator.ts | 2 +- scripts/generators/indexRegionGenerator.ts | 2 +- scripts/generators/languagesGenerator.ts | 2 +- scripts/generators/regionsGenerator.ts | 2 +- scripts/models/channel.ts | 2 +- scripts/models/issue.ts | 2 +- scripts/models/playlist.ts | 2 +- scripts/models/region.ts | 2 +- scripts/models/stream.ts | 8 +- scripts/tables/categoryTable.ts | 7 +- scripts/tables/countryTable.ts | 7 +- scripts/tables/languageTable.ts | 7 +- scripts/tables/regionTable.ts | 7 +- yarn.lock | 27 ++- 39 files changed, 141 insertions(+), 420 deletions(-) delete mode 100644 scripts/core/collection.ts delete mode 100644 scripts/core/dictionary.ts delete mode 100644 scripts/core/file.ts delete mode 100644 scripts/core/logger.ts delete mode 100644 scripts/core/storage.ts delete mode 100644 scripts/core/url.ts diff --git a/package-lock.json b/package-lock.json index e16a1924b..ef1492447 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,7 @@ "name": "iptv", "license": "MIT", "dependencies": { + "@freearhey/core": "^0.1.2", "@octokit/core": "^4.2.1", "@octokit/plugin-paginate-rest": "^7.1.2", "@octokit/plugin-rest-endpoint-methods": "^7.1.3", @@ -675,6 +676,32 @@ "node": ">=12" } }, + "node_modules/@freearhey/core": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@freearhey/core/-/core-0.1.2.tgz", + "integrity": "sha512-o6FaLHiKED0JkUXxqHcUUM2P+Jd4kvE96p0MZlLjhCFAPii/lVr5mTwrHehKMzve/r7AbDUX7kyNLNG8Qec6uw==", + "dependencies": { + "@types/fs-extra": "^11.0.2", + "@types/lodash": "^4.14.198", + "fs-extra": "^11.1.1", + "glob": "^10.3.4", + "lodash": "^4.17.21", + "natural-orderby": "^3.0.2", + "normalize-url": "^6.1.0", + "signale": "^1.4.0" + } + }, + "node_modules/@freearhey/core/node_modules/normalize-url": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", + "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -1430,9 +1457,9 @@ } }, "node_modules/@types/fs-extra": { - "version": "11.0.1", - "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.1.tgz", - "integrity": "sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==", + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.2.tgz", + "integrity": "sha512-c0hrgAOVYr21EX8J0jBMXGLMgJqVf/v6yxi0dLaJboW9aQPh16Id+z6w2Tx1hm+piJOLv8xPfVKZCLfjPw/IMQ==", "dependencies": { "@types/jsonfile": "*", "@types/node": "*" @@ -5563,6 +5590,28 @@ "@jridgewell/trace-mapping": "0.3.9" } }, + "@freearhey/core": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@freearhey/core/-/core-0.1.2.tgz", + "integrity": "sha512-o6FaLHiKED0JkUXxqHcUUM2P+Jd4kvE96p0MZlLjhCFAPii/lVr5mTwrHehKMzve/r7AbDUX7kyNLNG8Qec6uw==", + "requires": { + "@types/fs-extra": "^11.0.2", + "@types/lodash": "^4.14.198", + "fs-extra": "^11.1.1", + "glob": "^10.3.4", + "lodash": "^4.17.21", + "natural-orderby": "^3.0.2", + "normalize-url": "^6.1.0", + "signale": "^1.4.0" + }, + "dependencies": { + "normalize-url": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", + "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==" + } + } + }, "@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -6201,9 +6250,9 @@ } }, "@types/fs-extra": { - "version": "11.0.1", - "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.1.tgz", - "integrity": "sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA==", + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.2.tgz", + "integrity": "sha512-c0hrgAOVYr21EX8J0jBMXGLMgJqVf/v6yxi0dLaJboW9aQPh16Id+z6w2Tx1hm+piJOLv8xPfVKZCLfjPw/IMQ==", "requires": { "@types/jsonfile": "*", "@types/node": "*" diff --git a/package.json b/package.json index 55ec7891f..ddeae6942 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,9 @@ }, "jest": { "transform": { - "^.*test.(ts|js)$": "ts-jest" + "^.+\\.ts$": "ts-jest" }, - "testRegex": "tests/(.*?/)?.*test.(ts|js)$", + "testRegex": "tests/(.*?/)?.*test.ts$", "setupFilesAfterEnv": [ "jest-expect-message" ] @@ -40,8 +40,8 @@ "author": "Arhey", "private": true, "license": "MIT", - "type": "module", "dependencies": { + "@freearhey/core": "^0.1.2", "@octokit/core": "^4.2.1", "@octokit/plugin-paginate-rest": "^7.1.2", "@octokit/plugin-rest-endpoint-methods": "^7.1.3", diff --git a/scripts/commands/api/generate.ts b/scripts/commands/api/generate.ts index 0c0b033d7..f1acd6a8c 100644 --- a/scripts/commands/api/generate.ts +++ b/scripts/commands/api/generate.ts @@ -1,5 +1,6 @@ +import { Logger, Storage } from '@freearhey/core' import { API_DIR, STREAMS_DIR } from '../../constants' -import { Logger, PlaylistParser, Storage } from '../../core' +import { PlaylistParser } from '../../core' import { Stream } from '../../models' async function main() { diff --git a/scripts/commands/playlist/format.ts b/scripts/commands/playlist/format.ts index 862b90e36..d532db607 100644 --- a/scripts/commands/playlist/format.ts +++ b/scripts/commands/playlist/format.ts @@ -1,5 +1,6 @@ +import { Logger, Storage, Collection } from '@freearhey/core' import { STREAMS_DIR, DATA_DIR } from '../../constants' -import { Storage, Logger, PlaylistParser, Collection } from '../../core' +import { PlaylistParser } from '../../core' import { Stream, Playlist, Channel } from '../../models' import { program } from 'commander' diff --git a/scripts/commands/playlist/generate.ts b/scripts/commands/playlist/generate.ts index 44a75be23..7ca6d4a80 100644 --- a/scripts/commands/playlist/generate.ts +++ b/scripts/commands/playlist/generate.ts @@ -1,7 +1,6 @@ -import { File, PlaylistParser, Storage } from '../../core' +import { Logger, Storage, Collection, File } from '@freearhey/core' +import { PlaylistParser } from '../../core' import { Stream, Category, Channel, Language, Country, Region, Subdivision } from '../../models' -import { Collection } from '../../core/collection' -import { Logger } from '../../core/logger' import _ from 'lodash' import { CategoriesGenerator, @@ -124,7 +123,7 @@ async function loadStreams({ if (channel.logo) stream.logo = channel.logo } else { const file = new File(stream.filepath) - const [_, countryCode] = file.getFilename().match(/^([a-z]{2})(_|$)/) || [null, null] + const [_, countryCode] = file.name().match(/^([a-z]{2})(_|$)/) || [null, null] const defaultBroadcastArea = countryCode ? [`c/${countryCode.toUpperCase()}`] : [] stream.broadcastArea = new Collection(defaultBroadcastArea) diff --git a/scripts/commands/playlist/update.ts b/scripts/commands/playlist/update.ts index 2eab9107d..b9814f463 100644 --- a/scripts/commands/playlist/update.ts +++ b/scripts/commands/playlist/update.ts @@ -1,5 +1,6 @@ +import { Logger, Storage, Collection, Dictionary } from '@freearhey/core' import { DATA_DIR, STREAMS_DIR } from '../../constants' -import { Storage, Logger, Collection, Dictionary, IssueLoader, PlaylistParser } from '../../core' +import { IssueLoader, PlaylistParser } from '../../core' import { Stream, Playlist, Channel, Issue } from '../../models' let processedIssues = new Collection() diff --git a/scripts/commands/playlist/validate.ts b/scripts/commands/playlist/validate.ts index 03295a47c..b128058cf 100644 --- a/scripts/commands/playlist/validate.ts +++ b/scripts/commands/playlist/validate.ts @@ -1,4 +1,5 @@ -import { Logger, Storage, PlaylistParser, Collection, File, Dictionary } from '../../core' +import { Logger, Storage, Collection, Dictionary, File } from '@freearhey/core' +import { PlaylistParser } from '../../core' import { Channel, Stream, Blocked } from '../../models' import { program } from 'commander' import chalk from 'chalk' diff --git a/scripts/commands/readme/update.ts b/scripts/commands/readme/update.ts index 5dc06ae98..7af55feff 100644 --- a/scripts/commands/readme/update.ts +++ b/scripts/commands/readme/update.ts @@ -1,5 +1,6 @@ +import { Logger } from '@freearhey/core' import { CategoryTable, CountryTable, LanguageTable, RegionTable } from '../../tables' -import { Logger, Markdown } from '../../core' +import { Markdown } from '../../core' import { README_DIR } from '../../constants' import path from 'path' diff --git a/scripts/commands/report/create.ts b/scripts/commands/report/create.ts index 4327a4a59..030a10d60 100644 --- a/scripts/commands/report/create.ts +++ b/scripts/commands/report/create.ts @@ -1,5 +1,6 @@ +import { Logger, Storage, Collection, Dictionary } from '@freearhey/core' import { DATA_DIR, STREAMS_DIR } from '../../constants' -import { Collection, Dictionary, IssueLoader, Storage, Logger, PlaylistParser } from '../../core' +import { IssueLoader, PlaylistParser } from '../../core' import { Blocked, Channel, Issue, Stream } from '../../models' async function main() { diff --git a/scripts/core/collection.ts b/scripts/core/collection.ts deleted file mode 100644 index 92836dcb5..000000000 --- a/scripts/core/collection.ts +++ /dev/null @@ -1,175 +0,0 @@ -import _ from 'lodash' -import { orderBy, Order } from 'natural-orderby' -import { Dictionary } from './' - -type Iteratee = (value: any, value2?: any) => void - -export class Collection { - _items: any[] - - constructor(items?: any[]) { - this._items = Array.isArray(items) ? items : [] - } - - first(predicate?: Iteratee) { - if (predicate) { - return this._items.find(predicate) - } - - return this._items[0] - } - - last(predicate?: Iteratee) { - if (predicate) { - return _.findLast(this._items, predicate) - } - - return this._items[this._items.length - 1] - } - - find(iteratee: Iteratee): Collection { - const found = this._items.filter(iteratee) - - return new Collection(found) - } - - add(data: any) { - this._items.push(data) - - return this - } - - intersects(collection: Collection): boolean { - return _.intersection(this._items, collection.all()).length > 0 - } - - count() { - return this._items.length - } - - join(separator: string) { - return this._items.join(separator) - } - - indexOf(value: string) { - return this._items.indexOf(value) - } - - push(data: any) { - this.add(data) - } - - uniq() { - const items = _.uniq(this._items) - - return new Collection(items) - } - - reduce(iteratee: Iteratee, accumulator: any) { - const items = _.reduce(this._items, iteratee, accumulator) - - return new Collection(items) - } - - filter(iteratee: Iteratee) { - const items = _.filter(this._items, iteratee) - - return new Collection(items) - } - - forEach(iteratee: Iteratee) { - for (let item of this._items) { - iteratee(item) - } - - return this - } - - remove(iteratee: Iteratee): Collection { - const removed = _.remove(this._items, iteratee) - - return new Collection(removed) - } - - concat(collection: Collection) { - const items = this._items.concat(collection._items) - - return new Collection(items) - } - - isEmpty(): boolean { - return this._items.length === 0 - } - - notEmpty(): boolean { - return this._items.length > 0 - } - - sort() { - const items = this._items.sort() - - return new Collection(items) - } - - orderBy(iteratees: Iteratee | Iteratee[], orders?: Order | Order[]) { - const items = orderBy(this._items, iteratees, orders) - - return new Collection(items) - } - - keyBy(iteratee: Iteratee) { - const items = _.keyBy(this._items, iteratee) - - return new Dictionary(items) - } - - empty() { - return this._items.length === 0 - } - - includes(value: any) { - if (typeof value === 'function') { - const found = this._items.find(value) - - return !!found - } - - return this._items.includes(value) - } - - missing(value: any) { - if (typeof value === 'function') { - const found = this._items.find(value) - - return !found - } - - return !this._items.includes(value) - } - - uniqBy(iteratee: Iteratee) { - const items = _.uniqBy(this._items, iteratee) - - return new Collection(items) - } - - groupBy(iteratee: Iteratee) { - const object = _.groupBy(this._items, iteratee) - - return new Dictionary(object) - } - - map(iteratee: Iteratee) { - const items = this._items.map(iteratee) - - return new Collection(items) - } - - all() { - return this._items - } - - toJSON() { - return JSON.stringify(this._items) - } -} diff --git a/scripts/core/dictionary.ts b/scripts/core/dictionary.ts deleted file mode 100644 index 0058f58e4..000000000 --- a/scripts/core/dictionary.ts +++ /dev/null @@ -1,31 +0,0 @@ -export class Dictionary { - dict: any - - constructor(dict?: any) { - this.dict = dict || {} - } - - set(key: string, value: any) { - this.dict[key] = value - } - - has(key: string): boolean { - return !!this.dict[key] - } - - missing(key: string): boolean { - return !this.dict[key] - } - - get(key: string): any { - return this.dict[key] ? this.dict[key] : undefined - } - - keys(): string[] { - return Object.keys(this.dict) - } - - data() { - return this.dict - } -} diff --git a/scripts/core/file.ts b/scripts/core/file.ts deleted file mode 100644 index 54c88fe64..000000000 --- a/scripts/core/file.ts +++ /dev/null @@ -1,31 +0,0 @@ -import * as path from 'path' - -export class File { - filepath: string - content: string - - constructor(filepath: string, content?: string) { - this.filepath = path.normalize(filepath) - this.content = content || '' - } - - getFilename() { - return path.parse(this.filepath).name - } - - dirname() { - return path.dirname(this.filepath) - } - - basename() { - return path.basename(this.filepath) - } - - append(data: string) { - this.content = this.content + data - } - - extension() { - return this.filepath.split('.').pop() - } -} diff --git a/scripts/core/index.ts b/scripts/core/index.ts index 75090eca2..a1419eb00 100644 --- a/scripts/core/index.ts +++ b/scripts/core/index.ts @@ -1,13 +1,7 @@ -export * from './logger' export * from './playlistParser' export * from './numberParser' export * from './logParser' export * from './markdown' -export * from './file' -export * from './collection' -export * from './dictionary' -export * from './storage' -export * from './url' export * from './issueLoader' export * from './issueParser' export * from './htmlTable' diff --git a/scripts/core/issueLoader.ts b/scripts/core/issueLoader.ts index 9e0ecfaec..84f1177a2 100644 --- a/scripts/core/issueLoader.ts +++ b/scripts/core/issueLoader.ts @@ -1,7 +1,8 @@ +import { Collection } from '@freearhey/core' import { restEndpointMethods } from '@octokit/plugin-rest-endpoint-methods' import { paginateRest } from '@octokit/plugin-paginate-rest' import { Octokit } from '@octokit/core' -import { Collection, IssueParser } from './' +import { IssueParser } from './' import { TESTING, OWNER, REPO } from '../constants' const CustomOctokit = Octokit.plugin(paginateRest, restEndpointMethods) @@ -14,23 +15,22 @@ export class IssueLoader { if (TESTING) { switch (labels) { case 'streams:add': - issues = (await import('../../tests/__data__/input/issues/streams_add')).default + issues = require('../../tests/__data__/input/issues/streams_add.js') break case 'streams:edit': - issues = (await import('../../tests/__data__/input/issues/streams_edit')).default + issues = require('../../tests/__data__/input/issues/streams_edit.js') break case 'broken stream': - issues = (await import('../../tests/__data__/input/issues/broken_stream')).default + issues = require('../../tests/__data__/input/issues/broken_stream.js') break case 'streams:add,approved': - issues = (await import('../../tests/__data__/input/issues/streams_add_approved')).default + issues = require('../../tests/__data__/input/issues/streams_add_approved.js') break case 'streams:edit,approved': - issues = (await import('../../tests/__data__/input/issues/streams_edit_approved')).default + issues = require('../../tests/__data__/input/issues/streams_edit_approved.js') break case 'streams:remove,approved': - issues = (await import('../../tests/__data__/input/issues/streams_remove_approved')) - .default + issues = require('../../tests/__data__/input/issues/streams_remove_approved.js') break } } else { diff --git a/scripts/core/issueParser.ts b/scripts/core/issueParser.ts index 0114e703f..fc545ad6c 100644 --- a/scripts/core/issueParser.ts +++ b/scripts/core/issueParser.ts @@ -1,4 +1,4 @@ -import { Dictionary } from './' +import { Dictionary } from '@freearhey/core' import { Issue } from '../models' import _ from 'lodash' diff --git a/scripts/core/logger.ts b/scripts/core/logger.ts deleted file mode 100644 index 0305ddd00..000000000 --- a/scripts/core/logger.ts +++ /dev/null @@ -1,9 +0,0 @@ -import signale from 'signale' - -const { Signale } = signale - -export class Logger extends Signale { - constructor(options?: any) { - super(options) - } -} diff --git a/scripts/core/playlistParser.ts b/scripts/core/playlistParser.ts index 7a96dacc7..776eb0cfd 100644 --- a/scripts/core/playlistParser.ts +++ b/scripts/core/playlistParser.ts @@ -1,6 +1,6 @@ +import { Collection, Storage } from '@freearhey/core' import parser from 'iptv-playlist-parser' import { Stream } from '../models' -import { Collection, Storage } from './' import path from 'path' import { STREAMS_DIR } from '../constants' @@ -26,7 +26,7 @@ export class PlaylistParser { async parseFile(filepath: string): Promise { const streams = new Collection() - const content = await this.storage.read(filepath) + const content = await this.storage.load(filepath) const parsed: parser.Playlist = parser.parse(content) parsed.items.forEach((item: parser.PlaylistItem) => { diff --git a/scripts/core/storage.ts b/scripts/core/storage.ts deleted file mode 100644 index 81f2ede4f..000000000 --- a/scripts/core/storage.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { File, Collection } from './' -import * as path from 'path' -import fs from 'fs-extra' -import { glob } from 'glob' - -export class Storage { - rootDir: string - - constructor(rootDir?: string) { - this.rootDir = path.normalize(rootDir || './') - } - - async list(pattern: string): Promise { - const files = await glob(pattern, { - cwd: this.rootDir - }) - - return files.sort() - } - - async createDir(dir: string): Promise { - if (await fs.exists(dir)) return - - await fs.mkdir(dir, { recursive: true }).catch(console.error) - } - - async load(filepath: string): Promise { - return this.read(filepath) - } - - async read(filepath: string): Promise { - const absFilepath = path.join(this.rootDir, filepath) - - return await fs.readFile(absFilepath, { encoding: 'utf8' }) - } - - async json(filepath: string): Promise { - const absFilepath = path.join(this.rootDir, filepath) - const content = await fs.readFile(absFilepath, { encoding: 'utf8' }) - - return JSON.parse(content) - } - - async exists(filepath: string): Promise { - const absFilepath = path.join(this.rootDir, filepath) - - return await fs.exists(absFilepath) - } - - async write(filepath: string, data: string = ''): Promise { - const absFilepath = path.join(this.rootDir, filepath) - const dir = path.dirname(absFilepath) - - await this.createDir(dir) - await fs.writeFile(absFilepath, data, { encoding: 'utf8', flag: 'w' }) - } - - async append(filepath: string, data: string = ''): Promise { - const absFilepath = path.join(this.rootDir, filepath) - - await fs.appendFile(absFilepath, data, { encoding: 'utf8', flag: 'w' }) - } - - async clear(filepath: string): Promise { - await this.write(filepath) - } - - async createStream(filepath: string): Promise { - const absFilepath = path.join(this.rootDir, filepath) - const dir = path.dirname(absFilepath) - - await this.createDir(dir) - - return fs.createWriteStream(absFilepath) as unknown as NodeJS.WriteStream - } - - async save(filepath: string, content: string): Promise { - await this.write(filepath, content) - } - - async saveFile(file: File): Promise { - await this.write(file.filepath, file.content) - } -} diff --git a/scripts/core/url.ts b/scripts/core/url.ts deleted file mode 100644 index df6ff4dd8..000000000 --- a/scripts/core/url.ts +++ /dev/null @@ -1,20 +0,0 @@ -import normalizeUrl from 'normalize-url' - -export class URL { - url: string - - constructor(url: string) { - this.url = url - } - - normalize(): URL { - const normalized = normalizeUrl(this.url, { stripWWW: false }) - this.url = decodeURIComponent(normalized).replace(/\s/g, '+') - - return this - } - - toString(): string { - return this.url - } -} diff --git a/scripts/generators/categoriesGenerator.ts b/scripts/generators/categoriesGenerator.ts index 48a99107e..cf768b982 100644 --- a/scripts/generators/categoriesGenerator.ts +++ b/scripts/generators/categoriesGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from './generator' -import { Collection, Storage, Logger } from '../core' +import { Collection, Storage, Logger } from '@freearhey/core' import { Stream, Category, Playlist } from '../models' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/countriesGenerator.ts b/scripts/generators/countriesGenerator.ts index bd683760a..158bf031c 100644 --- a/scripts/generators/countriesGenerator.ts +++ b/scripts/generators/countriesGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from './generator' -import { Collection, Storage, Logger } from '../core' +import { Collection, Storage, Logger } from '@freearhey/core' import { Country, Region, Subdivision, Stream, Playlist } from '../models' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/indexCategoryGenerator.ts b/scripts/generators/indexCategoryGenerator.ts index 733eb9186..fb4647e3a 100644 --- a/scripts/generators/indexCategoryGenerator.ts +++ b/scripts/generators/indexCategoryGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from './generator' -import { Collection, Storage, Logger } from '../core' +import { Collection, Storage, Logger } from '@freearhey/core' import { Stream, Playlist, Category } from '../models' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/indexCountryGenerator.ts b/scripts/generators/indexCountryGenerator.ts index f48945047..72974e6d8 100644 --- a/scripts/generators/indexCountryGenerator.ts +++ b/scripts/generators/indexCountryGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from './generator' -import { Collection, Storage, Logger } from '../core' +import { Collection, Storage, Logger } from '@freearhey/core' import { Stream, Playlist, Country, Subdivision, Region } from '../models' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/indexGenerator.ts b/scripts/generators/indexGenerator.ts index 9a8754db9..96784cc6e 100644 --- a/scripts/generators/indexGenerator.ts +++ b/scripts/generators/indexGenerator.ts @@ -1,4 +1,4 @@ -import { Collection, Logger, Storage } from '../core' +import { Collection, Logger, Storage } from '@freearhey/core' import { Stream, Playlist } from '../models' import { Generator } from './generator' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/indexLanguageGenerator.ts b/scripts/generators/indexLanguageGenerator.ts index 692e896dd..07f3d74aa 100644 --- a/scripts/generators/indexLanguageGenerator.ts +++ b/scripts/generators/indexLanguageGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from './generator' -import { Collection, Storage, Logger } from '../core' +import { Collection, Storage, Logger } from '@freearhey/core' import { Stream, Playlist, Language } from '../models' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/indexNsfwGenerator.ts b/scripts/generators/indexNsfwGenerator.ts index 500d51c9a..c0b80b9a0 100644 --- a/scripts/generators/indexNsfwGenerator.ts +++ b/scripts/generators/indexNsfwGenerator.ts @@ -1,4 +1,4 @@ -import { Collection, Logger, Storage } from '../core' +import { Collection, Logger, Storage } from '@freearhey/core' import { Stream, Playlist } from '../models' import { Generator } from './generator' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/indexRegionGenerator.ts b/scripts/generators/indexRegionGenerator.ts index ebebb85e6..9f2096866 100644 --- a/scripts/generators/indexRegionGenerator.ts +++ b/scripts/generators/indexRegionGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from './generator' -import { Collection, Storage, Logger } from '../core' +import { Collection, Storage, Logger } from '@freearhey/core' import { Stream, Playlist, Region } from '../models' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/languagesGenerator.ts b/scripts/generators/languagesGenerator.ts index 728807e9a..5a158a761 100644 --- a/scripts/generators/languagesGenerator.ts +++ b/scripts/generators/languagesGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from './generator' -import { Collection, Storage, Logger } from '../core' +import { Collection, Storage, Logger } from '@freearhey/core' import { Playlist, Language, Stream } from '../models' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/generators/regionsGenerator.ts b/scripts/generators/regionsGenerator.ts index d2325c3a6..f6918951c 100644 --- a/scripts/generators/regionsGenerator.ts +++ b/scripts/generators/regionsGenerator.ts @@ -1,5 +1,5 @@ import { Generator } from './generator' -import { Collection, Storage, Logger } from '../core' +import { Collection, Storage, Logger } from '@freearhey/core' import { Playlist, Subdivision, Region } from '../models' import { PUBLIC_DIR } from '../constants' diff --git a/scripts/models/channel.ts b/scripts/models/channel.ts index 668b72914..dd7a7a1d9 100644 --- a/scripts/models/channel.ts +++ b/scripts/models/channel.ts @@ -1,4 +1,4 @@ -import { Collection } from '../core' +import { Collection } from '@freearhey/core' type ChannelProps = { id: string diff --git a/scripts/models/issue.ts b/scripts/models/issue.ts index 622981d82..fecb1fde1 100644 --- a/scripts/models/issue.ts +++ b/scripts/models/issue.ts @@ -1,4 +1,4 @@ -import { Dictionary } from '../core' +import { Dictionary } from '@freearhey/core' type IssueProps = { number: number diff --git a/scripts/models/playlist.ts b/scripts/models/playlist.ts index b9b5c60ac..6266282cc 100644 --- a/scripts/models/playlist.ts +++ b/scripts/models/playlist.ts @@ -1,4 +1,4 @@ -import { Collection } from '../core' +import { Collection } from '@freearhey/core' import { Stream } from '../models' type PlaylistOptions = { diff --git a/scripts/models/region.ts b/scripts/models/region.ts index 6db1c3a43..72b30c192 100644 --- a/scripts/models/region.ts +++ b/scripts/models/region.ts @@ -1,4 +1,4 @@ -import { Collection } from '../core' +import { Collection } from '@freearhey/core' type RegionProps = { code: string diff --git a/scripts/models/stream.ts b/scripts/models/stream.ts index b6d3e20c3..37559f931 100644 --- a/scripts/models/stream.ts +++ b/scripts/models/stream.ts @@ -1,4 +1,4 @@ -import { URL, Collection } from '../core' +import { URL, Collection } from '@freearhey/core' import { Category, Language } from './index' type StreamProps = { @@ -86,7 +86,7 @@ export class Stream { } noCategories(): boolean { - return this.categories.empty() + return this.categories.isEmpty() } hasCategory(category: Category): boolean { @@ -94,7 +94,7 @@ export class Stream { } noLanguages(): boolean { - return this.languages.empty() + return this.languages.isEmpty() } hasLanguage(language: Language): boolean { @@ -102,7 +102,7 @@ export class Stream { } noBroadcastArea(): boolean { - return this.broadcastArea.empty() + return this.broadcastArea.isEmpty() } isInternational(): boolean { diff --git a/scripts/tables/categoryTable.ts b/scripts/tables/categoryTable.ts index 57f11c15b..a3fb49f14 100644 --- a/scripts/tables/categoryTable.ts +++ b/scripts/tables/categoryTable.ts @@ -1,4 +1,5 @@ -import { Storage, HTMLTable, Collection, LogParser, LogItem, File } from '../core' +import { Storage, Collection, File } from '@freearhey/core' +import { HTMLTable, LogParser, LogItem } from '../core' import { Category } from '../models' import { DATA_DIR, LOGS_DIR, README_DIR } from '../constants' import { Table } from './table' @@ -13,7 +14,7 @@ export class CategoryTable implements Table { const parser = new LogParser() const logsStorage = new Storage(LOGS_DIR) - const generatorsLog = await logsStorage.read('generators.log') + const generatorsLog = await logsStorage.load('generators.log') let data = new Collection() parser @@ -21,7 +22,7 @@ export class CategoryTable implements Table { .filter((logItem: LogItem) => logItem.filepath.includes('categories/')) .forEach((logItem: LogItem) => { const file = new File(logItem.filepath) - const categoryId = file.getFilename() + const categoryId = file.name() const category: Category = categories.first( (category: Category) => category.id === categoryId ) diff --git a/scripts/tables/countryTable.ts b/scripts/tables/countryTable.ts index c78a23eaa..c85a59a37 100644 --- a/scripts/tables/countryTable.ts +++ b/scripts/tables/countryTable.ts @@ -1,4 +1,5 @@ -import { Storage, HTMLTable, Collection, LogParser, LogItem, File } from '../core' +import { Storage, Collection, File } from '@freearhey/core' +import { HTMLTable, LogParser, LogItem } from '../core' import { Country, Subdivision } from '../models' import { DATA_DIR, LOGS_DIR, README_DIR } from '../constants' import { Table } from './table' @@ -17,7 +18,7 @@ export class CountryTable implements Table { const parser = new LogParser() const logsStorage = new Storage(LOGS_DIR) - const generatorsLog = await logsStorage.read('generators.log') + const generatorsLog = await logsStorage.load('generators.log') let data = new Collection() parser @@ -28,7 +29,7 @@ export class CountryTable implements Table { ) .forEach((logItem: LogItem) => { const file = new File(logItem.filepath) - const code = file.getFilename().toUpperCase() + const code = file.name().toUpperCase() const [countryCode, subdivisionCode] = code.split('-') || ['', ''] if (subdivisionCode) { diff --git a/scripts/tables/languageTable.ts b/scripts/tables/languageTable.ts index 2b298b180..f0b54d242 100644 --- a/scripts/tables/languageTable.ts +++ b/scripts/tables/languageTable.ts @@ -1,4 +1,5 @@ -import { Storage, HTMLTable, Collection, LogParser, LogItem, File } from '../core' +import { Storage, Collection, File } from '@freearhey/core' +import { HTMLTable, LogParser, LogItem } from '../core' import { Language } from '../models' import { DATA_DIR, LOGS_DIR, README_DIR } from '../constants' import { Table } from './table' @@ -13,7 +14,7 @@ export class LanguageTable implements Table { const parser = new LogParser() const logsStorage = new Storage(LOGS_DIR) - const generatorsLog = await logsStorage.read('generators.log') + const generatorsLog = await logsStorage.load('generators.log') let data = new Collection() parser @@ -21,7 +22,7 @@ export class LanguageTable implements Table { .filter((logItem: LogItem) => logItem.filepath.includes('languages/')) .forEach((logItem: LogItem) => { const file = new File(logItem.filepath) - const languageCode = file.getFilename() + const languageCode = file.name() const language: Language = languages.first( (language: Language) => language.code === languageCode ) diff --git a/scripts/tables/regionTable.ts b/scripts/tables/regionTable.ts index ee29f4088..60a6e5ff7 100644 --- a/scripts/tables/regionTable.ts +++ b/scripts/tables/regionTable.ts @@ -1,4 +1,5 @@ -import { Storage, HTMLTable, Collection, LogParser, LogItem, File } from '../core' +import { Storage, Collection, File } from '@freearhey/core' +import { HTMLTable, LogParser, LogItem } from '../core' import { Region } from '../models' import { DATA_DIR, LOGS_DIR, README_DIR } from '../constants' import { Table } from './table' @@ -13,7 +14,7 @@ export class RegionTable implements Table { const parser = new LogParser() const logsStorage = new Storage(LOGS_DIR) - const generatorsLog = await logsStorage.read('generators.log') + const generatorsLog = await logsStorage.load('generators.log') let data = new Collection() parser @@ -21,7 +22,7 @@ export class RegionTable implements Table { .filter((logItem: LogItem) => logItem.filepath.includes('regions/')) .forEach((logItem: LogItem) => { const file = new File(logItem.filepath) - const regionCode = file.getFilename().toUpperCase() + const regionCode = file.name().toUpperCase() const region: Region = regions.first((region: Region) => region.code === regionCode) if (region) { diff --git a/yarn.lock b/yarn.lock index 79504afd3..e85067f6a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -301,6 +301,20 @@ dependencies: "@jridgewell/trace-mapping" "0.3.9" +"@freearhey/core@^0.1.2": + version "0.1.2" + resolved "https://registry.npmjs.org/@freearhey/core/-/core-0.1.2.tgz" + integrity sha512-o6FaLHiKED0JkUXxqHcUUM2P+Jd4kvE96p0MZlLjhCFAPii/lVr5mTwrHehKMzve/r7AbDUX7kyNLNG8Qec6uw== + dependencies: + "@types/fs-extra" "^11.0.2" + "@types/lodash" "^4.14.198" + fs-extra "^11.1.1" + glob "^10.3.4" + lodash "^4.17.21" + natural-orderby "^3.0.2" + normalize-url "^6.1.0" + signale "^1.4.0" + "@isaacs/cliui@^8.0.2": version "8.0.2" resolved "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz" @@ -742,10 +756,10 @@ dependencies: "@babel/types" "^7.20.7" -"@types/fs-extra@^11.0.1": - version "11.0.1" - resolved "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.1.tgz" - integrity sha512-MxObHvNl4A69ofaTRU8DFqvgzzv8s9yRtaPPm5gud9HDNvpB3GPQFvNuTWAI59B9huVGV5jXYJwbCsmBsOGYWA== +"@types/fs-extra@^11.0.1", "@types/fs-extra@^11.0.2": + version "11.0.2" + resolved "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.2.tgz" + integrity sha512-c0hrgAOVYr21EX8J0jBMXGLMgJqVf/v6yxi0dLaJboW9aQPh16Id+z6w2Tx1hm+piJOLv8xPfVKZCLfjPw/IMQ== dependencies: "@types/jsonfile" "*" "@types/node" "*" @@ -2340,6 +2354,11 @@ normalize-path@^3.0.0: resolved "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz" integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA== +normalize-url@^6.1.0: + version "6.1.0" + resolved "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz" + integrity sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A== + normalize-url@^7.2.0: version "7.2.0" resolved "https://registry.npmjs.org/normalize-url/-/normalize-url-7.2.0.tgz"