Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
src/
!dist/**
!README.md
!LICENSE
!bundle/**
54 changes: 54 additions & 0 deletions dev-scripts/generate-proto.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { exec } from 'child_process';
import { existsSync, mkdirSync, readdirSync, statSync } from 'fs';
import { join } from 'path';
import path from 'path';
import url from 'url';
import os from 'os';

const __dirname = path.dirname(url.fileURLToPath(import.meta.url));

const protoDir = './protos';
const outDir = './protos/generated';

if (!existsSync(outDir)) {
mkdirSync(outDir, { recursive: true });
}

const protocGenTs = path.join(
__dirname,
'../node_modules',
'.bin',
os.platform() === 'win32' ? 'protoc-gen-ts_proto.cmd' : 'protoc-gen-ts_proto'
);

function listProtoFiles(dir) {
let protoFiles = [];
const items = readdirSync(dir);

for (const item of items) {
const fullPath = join(dir, item);
if (statSync(fullPath).isDirectory()) {
protoFiles = protoFiles.concat(listProtoFiles(fullPath));
} else if (item.endsWith('.proto')) {
protoFiles.push(fullPath);
}
}

return protoFiles;
}

const protoFiles = listProtoFiles(protoDir);

if (!protoFiles.length) {
console.log('No .proto files found.');
process.exit(0);
}

protoFiles.forEach((file) => {
const command = `protoc --proto_path=${protoDir} --plugin=protoc-gen-ts=${protocGenTs} --ts_opt=env=browser --ts_opt=importSuffix=.js --ts_out=${outDir} ${file}`;
exec(command, (error, _stdout, stderr) => {
if (error) {
console.error(`Error compiling ${file}:`, stderr);
}
});
});
4 changes: 2 additions & 2 deletions examples/browser/web/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Innertube, Proto, UniversalCache, Utils } from '../../../../bundle/browser';
import { Innertube, ProtoUtils, UniversalCache, Utils } from '../../../../bundle/browser';
import BG from 'bgutils-js';

// @ts-ignore - Shaka's TS support is not the best.
Expand All @@ -13,7 +13,7 @@ const form = document.querySelector('form') as HTMLFormElement;


async function main() {
const visitorData = Proto.encodeVisitorData(Utils.generateRandomString(11), Math.floor(Date.now() / 1000));
const visitorData = ProtoUtils.encodeVisitorData(Utils.generateRandomString(11), Math.floor(Date.now() / 1000));
const poToken = await getPo(visitorData);

const yt = await Innertube.create({
Expand Down
Loading