feat: expose parser and YTNodes as public APIs

This commit is contained in:
LuanRT
2022-09-04 05:17:24 -03:00
parent 982a086760
commit 3dc357bee0
6 changed files with 24 additions and 16 deletions

View File

@@ -1,6 +1,9 @@
// Deno and browser runtimes // Deno and browser runtimes
import Innertube from './src/Innertube'; import Innertube from './src/Innertube';
export { default as Innertube } from './src/Innertube.js';
export * from './src/utils'; export * from './src/utils';
export default Innertube; export { YTNodes } from './src/parser/map';
export { default as Parser } from './src/parser';
export { default as Innertube } from './src/Innertube';
export default Innertube;

View File

@@ -1,4 +1,4 @@
import Parser from 'youtubei.js/dist/src/parser'; import { Parser } from 'youtubei.js';
import SectionList from 'youtubei.js/dist/src/parser/classes/SectionList'; import SectionList from 'youtubei.js/dist/src/parser/classes/SectionList';
import SingleColumnBrowseResults from 'youtubei.js/dist/src/parser/classes/SingleColumnBrowseResults'; import SingleColumnBrowseResults from 'youtubei.js/dist/src/parser/classes/SingleColumnBrowseResults';
@@ -32,6 +32,6 @@ if (!tab)
if (!tab.content) if (!tab.content)
throw new Error('Target tab appears to be empty'); throw new Error('Target tab appears to be empty');
const sections = tab.content?.as(SectionList).contents.array().as(MusicCarouselShelf, MusicShelf); const sections = tab.content?.as(SectionList).contents.array().as(MusicCarouselShelf, MusicDescriptionShelf, MusicShelf);
console.info('Sections:', sections); console.info('Sections:', sections);

View File

@@ -13,6 +13,9 @@ if (getRuntime() === 'node') {
} }
import Innertube from './src/Innertube'; import Innertube from './src/Innertube';
export { default as Innertube } from './src/Innertube.js';
export * from './src/utils'; export * from './src/utils';
export default Innertube; export { YTNodes } from './src/parser/map';
export { default as Parser } from './src/parser';
export { default as Innertube } from './src/Innertube';
export default Innertube;

View File

@@ -16,20 +16,19 @@
], ],
"directories": { "directories": {
"test": "./test", "test": "./test",
"typings": "./dist",
"examples": "./examples", "examples": "./examples",
"src": "./dist/src" "dist": "./dist"
}, },
"scripts": { "scripts": {
"test": "npx jest --verbose", "test": "npx jest --verbose",
"lint": "npx eslint ./src", "lint": "npx eslint ./src",
"lint:fix": "npx eslint --fix ./src", "lint:fix": "npx eslint --fix ./src",
"build": "npm run build:parser-map && npm run build:proto && npm run bundle:browser && npm run bundle:browser:prod && npm run build:node", "build": "npm run build:parser-map && npm run build:proto && npm run bundle:browser && npm run bundle:browser:prod && npm run build:node",
"build:proto": "npx protoc --ts_out ./src/proto --proto_path ./src/proto ./src/proto/youtube.proto",
"build:node": "npx tsc", "build:node": "npx tsc",
"build:parser-map": "node ./scripts/build-parser-map.js",
"bundle:browser": "npx tsc --module esnext && npx esbuild ./dist/browser.js --banner:js=\"/* eslint-disable */\" --bundle --target=chrome58 --keep-names --format=esm --sourcemap --define:global=globalThis --outfile=./bundle/browser.js --platform=browser", "bundle:browser": "npx tsc --module esnext && npx esbuild ./dist/browser.js --banner:js=\"/* eslint-disable */\" --bundle --target=chrome58 --keep-names --format=esm --sourcemap --define:global=globalThis --outfile=./bundle/browser.js --platform=browser",
"bundle:browser:prod": "npm run bundle:browser -- --outfile=./bundle/browser.min.js --minify", "bundle:browser:prod": "npm run bundle:browser -- --outfile=./bundle/browser.min.js --minify",
"build:parser-map": "node ./scripts/build-parser-map.js",
"build:proto": "npx protoc --ts_out ./src/proto --proto_path ./src/proto ./src/proto/youtube.proto",
"prepare": "npm run build", "prepare": "npm run build",
"watch": "npx tsc --watch" "watch": "npx tsc --watch"
}, },
@@ -45,13 +44,11 @@
"undici": "^5.7.0" "undici": "^5.7.0"
}, },
"devDependencies": { "devDependencies": {
"@protobuf-ts/plugin": "^2.7.0",
"@types/flat": "^5.0.2",
"@types/jest": "^28.1.7",
"@types/node": "^17.0.45",
"@types/user-agents": "^1.0.2",
"@typescript-eslint/eslint-plugin": "^5.30.6", "@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6", "@typescript-eslint/parser": "^5.30.6",
"@protobuf-ts/plugin": "^2.7.0",
"@types/jest": "^28.1.7",
"@types/node": "^17.0.45",
"esbuild": "^0.14.49", "esbuild": "^0.14.49",
"eslint": "^8.19.0", "eslint": "^8.19.0",
"eslint-plugin-tsdoc": "^0.2.16", "eslint-plugin-tsdoc": "^0.2.16",

View File

@@ -3,6 +3,7 @@ const fs = require('fs');
const path = require('path'); const path = require('path');
const import_list = []; const import_list = [];
const json = []; const json = [];
glob.sync('../src/parser/classes/**/*.{js,ts}', { cwd: __dirname }) glob.sync('../src/parser/classes/**/*.{js,ts}', { cwd: __dirname })
@@ -18,7 +19,7 @@ glob.sync('../src/parser/classes/**/*.{js,ts}', { cwd: __dirname })
fs.writeFileSync( fs.writeFileSync(
path.resolve(__dirname, '../src/parser/map.ts'), path.resolve(__dirname, '../src/parser/map.ts'),
`// This file was auto generated, do not edit. `// This file was auto generated, do not edit.
// See ./scripts/build-parser-json.js // See ./scripts/build-parser-map.js
import { YTNodeConstructor } from './helpers'; import { YTNodeConstructor } from './helpers';
${import_list.join('\n')} ${import_list.join('\n')}
@@ -27,6 +28,8 @@ const map: Record<string, YTNodeConstructor> = {
${json.join(',\n ')} ${json.join(',\n ')}
}; };
export const YTNodes = map;
/** /**
* @param name - Name of the node to be parsed * @param name - Name of the node to be parsed
*/ */

View File

@@ -524,6 +524,8 @@ const map: Record<string, YTNodeConstructor> = {
WatchNextTabbedResults WatchNextTabbedResults
}; };
export const YTNodes = map;
/** /**
* @param name - Name of the node to be parsed * @param name - Name of the node to be parsed
*/ */