diff --git a/.gitignore b/.gitignore index d081f78f..3cd91e1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ dist/ out/ node_modules -.vscode/.env +.env **/roku_modules/** playlet-lib/src/www playlet/src/lib/playlet-lib.zip diff --git a/.vscode/launch.json b/.vscode/launch.json index 7c098bd5..4746ee15 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,7 +4,7 @@ { "type": "brightscript", "request": "launch", - "envFile": "${workspaceFolder}/.vscode/.env", + "envFile": "${workspaceFolder}/.env", "host": "${env:ROKU_DEV_TARGET}", "password": "${env:ROKU_DEVPASSWORD}", "stopOnEntry": false, @@ -35,7 +35,7 @@ { "type": "brightscript", "request": "launch", - "envFile": "${workspaceFolder}/.vscode/.env", + "envFile": "${workspaceFolder}/.env", "host": "${env:ROKU_DEV_TARGET}", "password": "${env:ROKU_DEVPASSWORD}", "stopOnEntry": false, diff --git a/config/bsconfig.base.json b/config/bsconfig.base.json index cb4df27e..c651f0c2 100644 --- a/config/bsconfig.base.json +++ b/config/bsconfig.base.json @@ -23,8 +23,8 @@ "plugins": [ "roku-log-bsc-plugin", "@rokucommunity/bslint", - "../tools/asynctask-plugin.ts", - "../tools/manifest-bsconst-debug-plugin.ts" + "../tools/bs-plugins/asynctask-plugin.ts", + "../tools/bs-plugins/manifest-bsconst-debug-plugin.ts" ], "retainStagingDir": true, "require": [ diff --git a/docs/README.md b/docs/README.md index 996d791c..7d80e649 100644 --- a/docs/README.md +++ b/docs/README.md @@ -60,7 +60,7 @@ Visual Studio Code is pretty much necessary for development. Once you have it installed, you probably want to install the recommened plugins for this project, such as [BrightScript Language extension for VSCode](https://marketplace.visualstudio.com/items?itemName=RokuCommunity.brightscript) and [Svelte for VS Code](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) -Next, create a file in `.vscode/.env` containing the following: +Next, create a file `.env` containing the following: ```makefile ROKU_DEV_TARGET=INSERT_IP_HERE diff --git a/package-lock.json b/package-lock.json index 3e98d548..4f5d8412 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "brighterscript": "^0.65.1", "brighterscript-formatter": "^1.6.29", "convert-svg-to-png": "^0.6.4", + "cross-fetch": "^4.0.0", "dotenv": "^16.3.1", "express": "^4.18.2", "ip": "^1.1.8", @@ -29,9 +30,6 @@ "shelljs": "^0.8.5", "ts-node": "^10.9.1", "typescript": "^5.1.3" - }, - "engines": { - "node": "<19.0.0" } }, "node_modules/@cspotcode/source-map-support": { @@ -1341,12 +1339,12 @@ "dev": true }, "node_modules/cross-fetch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", - "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz", + "integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==", "dev": true, "dependencies": { - "node-fetch": "2.6.7" + "node-fetch": "^2.6.12" } }, "node_modules/cross-platform-clear-console": { @@ -2826,9 +2824,9 @@ } }, "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz", + "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==", "dev": true, "dependencies": { "whatwg-url": "^5.0.0" @@ -3308,6 +3306,15 @@ "node": ">=10.18.1" } }, + "node_modules/puppeteer/node_modules/cross-fetch": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", + "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", + "dev": true, + "dependencies": { + "node-fetch": "2.6.7" + } + }, "node_modules/puppeteer/node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -3331,6 +3338,26 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "node_modules/puppeteer/node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dev": true, + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/qs": { "version": "6.11.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", diff --git a/package.json b/package.json index bb75fbb2..6f77e74d 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "brighterscript": "^0.65.1", "brighterscript-formatter": "^1.6.29", "convert-svg-to-png": "^0.6.4", + "cross-fetch": "^4.0.0", "dotenv": "^16.3.1", "express": "^4.18.2", "ip": "^1.1.8", diff --git a/playlet-web/vite.config.ts b/playlet-web/vite.config.ts index c0e30074..1db504ef 100644 --- a/playlet-web/vite.config.ts +++ b/playlet-web/vite.config.ts @@ -1,8 +1,9 @@ import { defineConfig, UserConfig } from 'vite' import { svelte } from '@sveltejs/vite-plugin-svelte' -import { readFileSync, existsSync } from 'fs' -import { parse as dotEnvParse } from 'dotenv' import ip from 'ip'; +import { existsSync, readFileSync } from 'fs' +import { join as joinPath } from 'path' +import { parse as dotEnvParse } from 'dotenv' const PORT = 5173 @@ -14,8 +15,22 @@ const config: UserConfig = { } } -if (existsSync('../.vscode/.env')) { - const envVars = dotEnvParse(readFileSync('../.vscode/.env')) +// TODO: refactor this with the same code in tools/get-env-vars.js +function getEnvVars() { + const envFile = joinPath(__dirname, '../.env'); + + let envVars = process.env; + if (existsSync(envFile)) { + const envConfig = dotEnvParse(readFileSync(envFile)); + envVars = { ...envVars, ...envConfig }; + } + + return envVars; +} + +const envVars = getEnvVars(); + +if (envVars.ROKU_DEV_TARGET) { config.server = { host: true, port: PORT, diff --git a/tools/asynctask-plugin.ts b/tools/bs-plugins/asynctask-plugin.ts similarity index 100% rename from tools/asynctask-plugin.ts rename to tools/bs-plugins/asynctask-plugin.ts diff --git a/tools/manifest-bsconst-debug-plugin.ts b/tools/bs-plugins/manifest-bsconst-debug-plugin.ts similarity index 100% rename from tools/manifest-bsconst-debug-plugin.ts rename to tools/bs-plugins/manifest-bsconst-debug-plugin.ts diff --git a/tools/generate-images.js b/tools/generate-images.js index b937f34d..068a2e11 100644 --- a/tools/generate-images.js +++ b/tools/generate-images.js @@ -1,3 +1,6 @@ +// Description: Generates images for the project. +// Converts SVGs to PNGs and resizes them to the correct dimensions. + const fs = require('fs'); const path = require('path'); const { convertFile } = require('convert-svg-to-png'); diff --git a/tools/generate-sponsorblock-config.js b/tools/generate-sponsorblock-config.js index eb707d34..d3711e37 100644 --- a/tools/generate-sponsorblock-config.js +++ b/tools/generate-sponsorblock-config.js @@ -1,14 +1,25 @@ +// Description: Generates the SponsorBlock config for Playlet + const fs = require('fs'); const path = require('path'); +const { ArgumentParser } = require('argparse') -if (process.argv.length !== 3) { - console.error("Invalid usage! usage: npm run generate-sponsorblock-config -- sponsorblock_root"); - exit(-1); +function getArgumentParser() { + const parser = new ArgumentParser({ + description: 'Generate SponsorBlock config' + }); + + parser.add_argument('--sponsorblock-root', { help: 'Local path to the SponsorBlock repository', required: true }); + + return parser; } +const parser = getArgumentParser(); +const args = parser.parse_args() + const PLAYLEY_CONFIG_PATH = "./playlet-lib/src/config/sponsorblock_config.json" -const sponsorblockRoot = process.argv[2]; +const sponsorblockRoot = args.sponsorblock_root; const configExamplePath = path.join(sponsorblockRoot, "config.json.example") const englishLocalePath = path.join(sponsorblockRoot, "public/_locales/en/messages.json") diff --git a/tools/get-env-vars.js b/tools/get-env-vars.js index ea9e1858..506e5b81 100644 --- a/tools/get-env-vars.js +++ b/tools/get-env-vars.js @@ -1,14 +1,23 @@ const dotenv = require('dotenv'); const fs = require('fs'); +const path = require('path'); + +const envFile = path.join(__dirname, '../.env'); function getEnvVars() { let envVars = process.env; - if (fs.existsSync('.vscode/.env')) { - const envConfig = dotenv.parse(fs.readFileSync('.vscode/.env')); + if (fs.existsSync(envFile)) { + const envConfig = dotenv.parse(fs.readFileSync(envFile)); envVars = { ...envVars, ...envConfig }; } - + return envVars; } -module.exports = getEnvVars; +if (typeof module !== 'undefined' && module.exports) { + module.exports = getEnvVars; +} + +if (typeof exports !== 'undefined') { + exports.getEnvVars = getEnvVars; +} diff --git a/tools/profile-sync.js b/tools/profile-sync.js index ad37b44b..406c5e4a 100644 --- a/tools/profile-sync.js +++ b/tools/profile-sync.js @@ -1,5 +1,5 @@ -// This script reads recommendations, subscriptions, watch later, liked, and history from Youtube -// and imports them into invidious. +// Description: Read recommendations, subscriptions, watch later, liked, and history from Youtube +// and import them into invidious. Requires yt-dlp to be installed. const { ArgumentParser } = require('argparse') const fs = require('fs'); @@ -7,6 +7,20 @@ const getEnvVars = require('./get-env-vars'); const spawn = require('child_process').spawn; const express = require('express') const ip = require('ip'); +const fetch = require('cross-fetch'); + +function getArgumentParser() { + const parser = new ArgumentParser({ + description: 'Sync Youtube profile with Invidious' + }); + + parser.add_argument('--browser', { help: 'Use cookies from browser' }); + parser.add_argument('--invidious', { help: 'Invidious instance to sync to' }); + parser.add_argument('--output-file', { help: 'Write profile to Invidious JSON compatible file' }); + parser.add_argument('--playlist-limit', { help: 'Maximum playlist video count', default: 500 }); + + return parser; +} const config = getEnvVars(); const PLAYLEY_SERVER = `http://${config.ROKU_DEV_TARGET}:8888`; @@ -167,8 +181,8 @@ async function getInvidiousInstance() { throw new Error("Playlet not logged in") } - console.log(`Invidious instance: ${state.invidious.logged_in_instance}`) - return state.invidious.logged_in_instance; + console.log(`Invidious instance: ${state.invidious.current_instance}`) + return state.invidious.current_instance; } async function getAccessToken(invidiousInstance) { @@ -216,16 +230,9 @@ async function deleteAccessToken(invidiousInstance, token) { let invidiousInstance = undefined let token = undefined; try { - const parser = new ArgumentParser({ - description: 'Sync Youtube profile with Invidious' - }); + const parser = getArgumentParser() + const args = parser.parse_args() - parser.add_argument('--browser', { help: 'Use cookies from browser' }); - parser.add_argument('--invidious', { help: 'Invidious instance to sync to' }); - parser.add_argument('--output-file', { help: 'Write profile to Invidious JSON compatible file' }); - parser.add_argument('--playlist-limit', { help: 'Maximum playlist video count', default: 500 }); - - let args = parser.parse_args() invidiousInstance = args.invidious browser = args.browser outputFile = args.output_file diff --git a/tools/screenshot.js b/tools/screenshot.js index c6e9a579..6db6837b 100644 --- a/tools/screenshot.js +++ b/tools/screenshot.js @@ -1,14 +1,24 @@ +// Description: Take a screenshot of the Roku device + +const { ArgumentParser } = require('argparse') const rokuDeploy = require('roku-deploy'); const fs = require('fs'); -const { exit } = require('process'); const getEnvVars = require('./get-env-vars'); -if(process.argv.length !== 3) { - console.error("Invalid usage! usage: npm run screenshot -- filename"); - exit(-1); +function getArgumentParser() { + const parser = new ArgumentParser({ + description: 'Take a screenshot of the Roku device' + }); + + parser.add_argument('filename', { help: 'Path where the screenshot will be saved (without extension)' }); + + return parser; } -const filename = process.argv[2]; +const parser = getArgumentParser(); +const args = parser.parse_args() +const filename = args.filename; + const config = getEnvVars(); const options = { @@ -25,5 +35,6 @@ const options = { } catch (error) { console.error(error); + throw error; } })(); diff --git a/tools/sign-package.js b/tools/sign-package.js index 00e1bb8a..f34992b2 100644 --- a/tools/sign-package.js +++ b/tools/sign-package.js @@ -1,3 +1,6 @@ +// Description: Publish, sign the package and retrieve it from the Roku device +// It expects release/playelt.zip to exist + const getEnvVars = require('./get-env-vars'); const rokuDeploy = require('roku-deploy'); @@ -16,12 +19,16 @@ const options = { (async () => { try { + // Sideload playlet.zip await rokuDeploy.publish(options); + // Sign the package const remotePkgPath = await rokuDeploy.signExistingPackage(options); + // Retrieve the signed package const localPkgFilePath = await rokuDeploy.retrieveSignedPackage(remotePkgPath, options); console.log(`Created signed package: ${localPkgFilePath}`) } catch (error) { console.error(error); + throw error; } })(); diff --git a/tools/update-manifest-git-hash.js b/tools/update-manifest-git-hash.js index 3d1e55ed..133997d9 100644 --- a/tools/update-manifest-git-hash.js +++ b/tools/update-manifest-git-hash.js @@ -1,3 +1,7 @@ +// Description: Updates the git commit hash in the manifest files. +// It will update both Playlet and Playlet-lib manifest files. +// It will abort if there are any changes in the working directory. + const fs = require('fs'); const shell = require('shelljs'); diff --git a/tools/update-manifest-version.js b/tools/update-manifest-version.js index 6bde4d20..277c15a7 100644 --- a/tools/update-manifest-version.js +++ b/tools/update-manifest-version.js @@ -1,3 +1,7 @@ +// Description: Updates the version in the manifest files. +// Reads the version from the root package.json and updates the manifest files, +// as well as the package.json files in the playlet-web folder. + const fs = require('fs'); const { execSync } = require("child_process");