diff --git a/.gitignore b/.gitignore index 0b46fb6f..d081f78f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ out/ node_modules .vscode/.env **/roku_modules/** +playlet-lib/src/www +playlet/src/lib/playlet-lib.zip release/playlet.zip release/playlet.pkg -src/www \ No newline at end of file diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..4fd02195 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +engine-strict=true \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index bf3ed69f..148739b8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,23 +10,22 @@ "stopOnEntry": false, "enableDebuggerAutoRecovery": false, "stopDebuggerOnAppExit": false, - "rootDir": "${workspaceFolder}/dist/build", - "preLaunchTask": "build-dev", + "rootDir": "${workspaceFolder}/dist/build/playlet", + "sourceDirs": [ + "${workspaceFolder}/playlet/src", + "${workspaceFolder}/playlet-lib/src" + ], + "files": [ + "**/*", + ], + "preLaunchTask": "build", "name": "Playlet (dev)", - "injectRdbOnDeviceComponent": true - }, - { - "type": "brightscript", - "request": "launch", - "envFile": "${workspaceFolder}/.vscode/.env", - "host": "${env:ROKU_DEV_TARGET}", - "password": "${env:ROKU_DEVPASSWORD}", - "stopOnEntry": false, - "enableDebuggerAutoRecovery": false, - "stopDebuggerOnAppExit": false, - "rootDir": "${workspaceFolder}/dist/build", - "preLaunchTask": "build-prod", - "name": "Playlet (prod)" + "injectRdbOnDeviceComponent": true, + "injectRaleTrackerTask": true, + // TODO: change to ${workspaceFolder}/tools/RALE/TrackerTask.xml + // Once https://github.com/rokucommunity/vscode-brightscript-language/pull/462 + // is released (after v2.38.7) + "raleTrackerTaskFileLocation": "/Users/brahim/Roku/playlet/tools/RALE/TrackerTask.xml" }, { "command": "npm run dev:web", diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..6e50c2e6 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "brightscript.output.clearConsoleOnChannelStart": false +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b647da80..e51455a6 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,23 +2,30 @@ "version": "2.0.0", "tasks": [ { - "label": "build-dev", - "presentation": { - "close": true, - "reveal": "silent", - "revealProblems": "onProblem" - }, - "script": "build:dev", - "type": "npm" + "label": "build", + "dependsOn": [ + "build-app" + ] }, { - "label": "build-prod", - "presentation": { - "close": true, - "reveal": "silent", - "revealProblems": "onProblem" - }, - "script": "build:prod", + "label": "build-app", + "script": "build:app:dev", + "type": "npm", + "dependsOn": [ + "build-lib" + ] + }, + { + "label": "build-lib", + "script": "build:lib:dev", + "type": "npm", + "dependsOn": [ + "build-web" + ] + }, + { + "label": "build-web", + "script": "build:web", "type": "npm" } ] diff --git a/bsconfig.json b/bsconfig.json deleted file mode 100644 index b05c19a2..00000000 --- a/bsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "config/bsconfig.base.json", - "host": "If your Roku IP is static, you can set it here and remove the host entry from .vscode/launch.json", - "password": "" -} \ No newline at end of file diff --git a/config/bsconfig.base.json b/config/bsconfig.base.json index 64f04a2c..cb4df27e 100644 --- a/config/bsconfig.base.json +++ b/config/bsconfig.base.json @@ -12,16 +12,19 @@ "source/**/*", "components/**/*", "images/**/*", + "!images/vector/**/*", "fonts/**/*", "config/**/*", + "lib/**/*", "www/**/*.*", "manifest" ], - "lintConfig": "config/bslint.jsonc", + "lintConfig": "./config/bslint.jsonc", "plugins": [ "roku-log-bsc-plugin", "@rokucommunity/bslint", - "../scripts/asynctask-plugin.ts" + "../tools/asynctask-plugin.ts", + "../tools/manifest-bsconst-debug-plugin.ts" ], "retainStagingDir": true, "require": [ @@ -32,7 +35,5 @@ "removeComments": false, "strip": false }, - "rootDir": "../src/", - "sourceMap": true, - "stagingDir": "dist/build" + "sourceMap": true } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 33e3f6b0..6eebb466 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,9 @@ "semver": "^7.3.8", "ts-node": "^10.9.1", "typescript": "^4.9.4" + }, + "engines": { + "node": "<19.0.0" } }, "node_modules/@cspotcode/source-map-support": { diff --git a/package.json b/package.json index aa2d2086..ecb8bdb2 100644 --- a/package.json +++ b/package.json @@ -16,15 +16,17 @@ "convert-svg-to-png": "^0.6.4", "dotenv": "^16.0.3", "express": "^4.18.2", - "ip": "^1.1.8", "roku-log-bsc-plugin": "^0.7.0", "ropm": "^0.10.11", "semver": "^7.3.8", "ts-node": "^10.9.1", "typescript": "^4.9.4" }, + "engines": { + "node": "<19.0.0" + }, "ropm": { - "rootDir": "src", + "rootDir": "playlet-lib/src", "noprefix": [ "roku-requests" ] @@ -32,23 +34,26 @@ "scripts": { "dev:web": "cd playlet-web && npm run dev", "prebuild": "rm -rf dist", + "build:dev": "npm run build:web && npm run build:lib:dev && npm run build:app:dev", + "build:prod": "npm run build:web && npm run build:lib:prod && npm run build:app:prod", + "build:release": "npm run format:fix && npm run lint:fix && npm run manifest-version && npm run generate-images && npm run build:prod && npm run sign-package", + "build:app": "cd playlet && bsc --create-package --lintConfig ../config/bslint.jsonc", + "build:app:dev": "npm run build:app -- --debug=true", + "build:app:prod": "npm run build:app -- --debug=false --sourceMap=false", + "build:lib": "cd playlet-lib && bsc --create-package --lintConfig ../config/bslint.jsonc", + "build:lib:dev": "npm run build:lib -- --debug=true", + "build:lib:prod": "npm run build:lib -- --debug=false --sourceMap=false", "build:web": "cd playlet-web && npm run build", - "build": "npm run build:web && bsc", - "build:dev": "npm run manifest-symbols -- DEBUG=true && npm run build", - "build:prod": "npm run manifest-symbols -- DEBUG=false && npm run build -- --sourceMap=false", - "build:release": "npm run format:fix && npm run lint:fix && npm run manifest-version && npm run generate-images && npm run build:prod && npm run zip-package && npm run sign-package", - "lint": "bslint --project config/bsconfig.lint.json --lintConfig config/bslint.jsonc", + "lint": "bslint --project playlet-lib/bsconfig.lint.json --lintConfig config/bslint.jsonc && bslint --project playlet/bsconfig.lint.json --lintConfig config/bslint.jsonc", "lint:fix": "npm run lint -- --fix", - "format:base": "bsfmt \"src/**/*.brs\" \"src/**/*.bs\" \"!src/components/lib/**/*\" \"!src/source/lib/**/*\" \"!**/bslib.brs\" \"!**/roku_modules/**/*\" --bsfmt-path \"config/bsfmt.jsonc\"", + "format:base": "bsfmt \"playlet/src/**/*.brs\" \"playlet/src/**/*.bs\" \"!playlet/src/components/lib/**/*\" \"!playlet/src/source/lib/**/*\" \"!**/bslib.brs\" \"!**/roku_modules/**/*\" \"playlet-lib/src/**/*.brs\" \"playlet-lib/src/**/*.bs\" \"!playlet-lib/src/components/lib/**/*\" \"!playlet-lib/src/source/lib/**/*\" \"!**/bslib.brs\" \"!**/roku_modules/**/*\" --bsfmt-path \"config/bsfmt.jsonc\"", "format": "npm run format:base -- --check", "format:fix": "npm run format:base -- --write", - "generate-images": "node scripts/generate-images.js", - "manifest-version": "node scripts/update-manifest-version.js", - "zip-package": "node scripts/zip-package.js", - "sign-package": "node scripts/sign-package.js", - "screenshot": "node scripts/screenshot.js", - "manifest-symbols": "node scripts/update-manifest-symbols.js", - "profile-sync": "node scripts/profile-sync.js", + "generate-images": "node tools/generate-images.js", + "manifest-version": "node tools/update-manifest-version.js", + "sign-package": "node tools/sign-package.js", + "screenshot": "node tools/screenshot.js", + "profile-sync": "node tools/profile-sync.js", "postinstall": "npx ropm copy && cd playlet-web && npm install" } -} +} \ No newline at end of file diff --git a/playlet-lib/bsconfig.json b/playlet-lib/bsconfig.json new file mode 100644 index 00000000..4e063602 --- /dev/null +++ b/playlet-lib/bsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../config/bsconfig.base.json", + "rootDir": "src/", + "stagingDir": "../dist/build/playlet-lib", + "outFile": "../playlet/src/lib/playlet-lib.zip" +} \ No newline at end of file diff --git a/config/bsconfig.lint.json b/playlet-lib/bsconfig.lint.json similarity index 74% rename from config/bsconfig.lint.json rename to playlet-lib/bsconfig.lint.json index e5ecdf9a..920ff760 100644 --- a/config/bsconfig.lint.json +++ b/playlet-lib/bsconfig.lint.json @@ -1,7 +1,7 @@ { "createPackage": false, "deploy": false, - "extends": "bsconfig.base.json", + "extends": "bsconfig.json", "retainStagingDir": false, "sourceMap": false } \ No newline at end of file diff --git a/src/components/Dialog/Dialog.bs b/playlet-lib/src/components/Dialog/Dialog.bs similarity index 100% rename from src/components/Dialog/Dialog.bs rename to playlet-lib/src/components/Dialog/Dialog.bs diff --git a/src/components/Dialog/Dialog.xml b/playlet-lib/src/components/Dialog/Dialog.xml similarity index 100% rename from src/components/Dialog/Dialog.xml rename to playlet-lib/src/components/Dialog/Dialog.xml diff --git a/src/components/Dialog/DialogUtils.bs b/playlet-lib/src/components/Dialog/DialogUtils.bs similarity index 100% rename from src/components/Dialog/DialogUtils.bs rename to playlet-lib/src/components/Dialog/DialogUtils.bs diff --git a/src/components/HomeGridScreen/HomeGridScreen.bs b/playlet-lib/src/components/HomeGridScreen/HomeGridScreen.bs similarity index 96% rename from src/components/HomeGridScreen/HomeGridScreen.bs rename to playlet-lib/src/components/HomeGridScreen/HomeGridScreen.bs index 005df181..cc26a8b6 100644 --- a/src/components/HomeGridScreen/HomeGridScreen.bs +++ b/playlet-lib/src/components/HomeGridScreen/HomeGridScreen.bs @@ -8,8 +8,6 @@ function Init() m.top.ObserveField("focus", "OnFocusChange") m.top.ObserveField("refresh", "OnRefresh") - m.top.focus = true - InitContent() end function @@ -32,7 +30,7 @@ function InitContent() }, true) m.top.content = contentNode - m.defaultLayout = ParseJson(ReadAsciiFile("pkg:/config/default_home_layout.json")) + m.defaultLayout = ParseJson(ReadAsciiFile("libpkg:/config/default_home_layout.json")) if m.defaultLayout.Count() > 0 m.currentLoadingIndex = 0 diff --git a/src/components/HomeGridScreen/HomeGridScreen.xml b/playlet-lib/src/components/HomeGridScreen/HomeGridScreen.xml similarity index 100% rename from src/components/HomeGridScreen/HomeGridScreen.xml rename to playlet-lib/src/components/HomeGridScreen/HomeGridScreen.xml diff --git a/src/components/HomeGridScreen/HomeGridScreenTask.bs b/playlet-lib/src/components/HomeGridScreen/HomeGridScreenTask.bs similarity index 100% rename from src/components/HomeGridScreen/HomeGridScreenTask.bs rename to playlet-lib/src/components/HomeGridScreen/HomeGridScreenTask.bs diff --git a/src/components/MainScene.bs b/playlet-lib/src/components/MainScene.bs similarity index 79% rename from src/components/MainScene.bs rename to playlet-lib/src/components/MainScene.bs index f78818bd..7b6c62de 100644 --- a/src/components/MainScene.bs +++ b/playlet-lib/src/components/MainScene.bs @@ -4,20 +4,15 @@ import "pkg:/components/VideoPlayer/Video.bs" function Init() log.initializeLogManager(["log_PrintTransport"], 2) - m.top.backgroundColor = "0x242424FF" - m.top.backgroundURI = "" - - m.loadingIndicator = m.top.findNode("LoadingIndicator") m.videoContainer = m.top.findNode("VideoContainer") m.global.addFields({ - loadingIndicator: m.loadingIndicator, videoContainer: m.videoContainer }) - m.loadingIndicator.visible = true m.homeGridScreen = m.top.findNode("HomeGridScreen") m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape") m.homeGridScreen.SetFocus(true) + m.currentFocued = m.homeGridScreen m.settingsScreen = m.top.findNode("SettingsScreen") @@ -28,9 +23,12 @@ function Init() m.navBar.ObserveField("escapeIndex", "OnNavBarEscape") m.navBar.ObserveField("focusIndex", "OnNavIndexChange") - m.currentFocued = m.homeGridScreen - InitWebServer() + + LaunchArgumentsReceived() + + scene = m.top.getScene() + scene.ObserveField("inputArgs", "InputArgumentsReceived") end function function InitWebServer() @@ -97,25 +95,18 @@ function OnWebServerCommand() end if end function -function GetIndexOfChild(parent as object, childId as string) as integer - count = parent.getChildCount() - for i = 0 to count - 1 - child = parent.getChild(i) - if child.id = childId - return i - end if - end for - return -1 -end function - function LaunchArgumentsReceived() as void - ? "LaunchArgumentsReceived" m.top.launchArgs - PlayVideoFromArgs(m.top.launchArgs) + scene = m.top.getScene() + launchArgs = scene.launchArgs + ? "LaunchArgumentsReceived " launchArgs + PlayVideoFromArgs(launchArgs) end function function InputArgumentsReceived() as void - ? "InputArgumentsReceived" m.top.inputArgs - PlayVideoFromArgs(m.top.inputArgs) + scene = m.top.getScene() + inputArgs = scene.inputArgs + ? "InputArgumentsReceived " inputArgs + PlayVideoFromArgs(inputArgs) end function function PlayVideoFromArgs(args as object) as void @@ -128,8 +119,10 @@ function PlayVideoFromArgs(args as object) as void ' bs:disable-next-line mediaType = args.mediaType - if contentId <> invalid - sender = m.videoContainer.sender ?? m.currentFocued - PlayVideo(contentId, { sender: sender }) + if contentId = invalid + return end if + + sender = m.videoContainer.sender ?? m.currentFocued + PlayVideo(contentId, { sender: sender }) end function diff --git a/playlet-lib/src/components/MainScene.xml b/playlet-lib/src/components/MainScene.xml new file mode 100644 index 00000000..220a9ca0 --- /dev/null +++ b/playlet-lib/src/components/MainScene.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/components/NavBar/IconButton.brs b/playlet-lib/src/components/NavBar/IconButton.brs similarity index 100% rename from src/components/NavBar/IconButton.brs rename to playlet-lib/src/components/NavBar/IconButton.brs diff --git a/src/components/NavBar/IconButton.xml b/playlet-lib/src/components/NavBar/IconButton.xml similarity index 100% rename from src/components/NavBar/IconButton.xml rename to playlet-lib/src/components/NavBar/IconButton.xml diff --git a/src/components/NavBar/NavBar.bs b/playlet-lib/src/components/NavBar/NavBar.bs similarity index 97% rename from src/components/NavBar/NavBar.bs rename to playlet-lib/src/components/NavBar/NavBar.bs index 08bf3562..28cdcd93 100644 --- a/src/components/NavBar/NavBar.bs +++ b/playlet-lib/src/components/NavBar/NavBar.bs @@ -51,7 +51,7 @@ function OnExitDialog(event as object) buttonIndex = event.GetData() if buttonIndex = 0 ' Exit ? "EXITING APP" - m.top.GetScene().exitChannel = true + m.top.getScene().exitChannel = true end if end function diff --git a/src/components/NavBar/NavBar.xml b/playlet-lib/src/components/NavBar/NavBar.xml similarity index 100% rename from src/components/NavBar/NavBar.xml rename to playlet-lib/src/components/NavBar/NavBar.xml diff --git a/src/components/SearchScreen/SearchHistory.bs b/playlet-lib/src/components/SearchScreen/SearchHistory.bs similarity index 100% rename from src/components/SearchScreen/SearchHistory.bs rename to playlet-lib/src/components/SearchScreen/SearchHistory.bs diff --git a/src/components/SearchScreen/SearchScreen.bs b/playlet-lib/src/components/SearchScreen/SearchScreen.bs similarity index 100% rename from src/components/SearchScreen/SearchScreen.bs rename to playlet-lib/src/components/SearchScreen/SearchScreen.bs diff --git a/src/components/SearchScreen/SearchScreen.xml b/playlet-lib/src/components/SearchScreen/SearchScreen.xml similarity index 100% rename from src/components/SearchScreen/SearchScreen.xml rename to playlet-lib/src/components/SearchScreen/SearchScreen.xml diff --git a/src/components/SearchScreen/SearchSuggestionsTask.bs b/playlet-lib/src/components/SearchScreen/SearchSuggestionsTask.bs similarity index 100% rename from src/components/SearchScreen/SearchSuggestionsTask.bs rename to playlet-lib/src/components/SearchScreen/SearchSuggestionsTask.bs diff --git a/src/components/SearchScreen/SearchTask.bs b/playlet-lib/src/components/SearchScreen/SearchTask.bs similarity index 100% rename from src/components/SearchScreen/SearchTask.bs rename to playlet-lib/src/components/SearchScreen/SearchTask.bs diff --git a/src/components/SettingsScreen/AppVersionTask.bs b/playlet-lib/src/components/SettingsScreen/AppVersionTask.bs similarity index 100% rename from src/components/SettingsScreen/AppVersionTask.bs rename to playlet-lib/src/components/SettingsScreen/AppVersionTask.bs diff --git a/src/components/SettingsScreen/SettingsScreen.bs b/playlet-lib/src/components/SettingsScreen/SettingsScreen.bs similarity index 62% rename from src/components/SettingsScreen/SettingsScreen.bs rename to playlet-lib/src/components/SettingsScreen/SettingsScreen.bs index 066a5fd2..0bc6fccf 100644 --- a/src/components/SettingsScreen/SettingsScreen.bs +++ b/playlet-lib/src/components/SettingsScreen/SettingsScreen.bs @@ -1,13 +1,15 @@ import "pkg:/source/utils/General.bs" +import "pkg:/source/utils/StringUtils.bs" import "pkg:/source/asyncTask/asyncTask.bs" import "pkg:/components/SettingsScreen/AppVersionTask.bs" function Init() m.versionLabel = m.top.findNode("VersionLabel") m.top.url = `http://${GetLocalIpAddress()}:8888` - appInfo = GetAppInfo() - m.currentVersion = appInfo.version - SetVersionLabel(m.currentVersion, "N/A") + + m.appInfo = GetAppInfo() + + SetVersionLabel(m.appInfo.version, m.appInfo.lib_version, "N/A") GetLatestVersion() end function @@ -24,11 +26,11 @@ end function function GetLatestVersion() StartAsyncTask(AppVersionTask, {}, function(output as object) as void if output.result.latest <> invalid - SetVersionLabel(m.currentVersion, output.result.latest) + SetVersionLabel(m.appInfo.version, m.appInfo.lib_version, output.result.latest) end if end function) end function -function SetVersionLabel(current as string, latest as string) - m.versionLabel.text = `Version: ${current} | Latest: ${latest}` +function SetVersionLabel(appVersion as string, libVersion as string, latest as string) + m.versionLabel.text = `Playlet: ${appVersion} | Playlet-Lib: ${libVersion} | Latest: ${latest}` end function diff --git a/src/components/SettingsScreen/SettingsScreen.xml b/playlet-lib/src/components/SettingsScreen/SettingsScreen.xml similarity index 100% rename from src/components/SettingsScreen/SettingsScreen.xml rename to playlet-lib/src/components/SettingsScreen/SettingsScreen.xml diff --git a/src/components/VideoPlayer/SponsorBlockTask.bs b/playlet-lib/src/components/VideoPlayer/SponsorBlockTask.bs similarity index 100% rename from src/components/VideoPlayer/SponsorBlockTask.bs rename to playlet-lib/src/components/VideoPlayer/SponsorBlockTask.bs diff --git a/src/components/VideoPlayer/SponsorBlockTrackingTask.bs b/playlet-lib/src/components/VideoPlayer/SponsorBlockTrackingTask.bs similarity index 100% rename from src/components/VideoPlayer/SponsorBlockTrackingTask.bs rename to playlet-lib/src/components/VideoPlayer/SponsorBlockTrackingTask.bs diff --git a/src/components/VideoPlayer/Video.bs b/playlet-lib/src/components/VideoPlayer/Video.bs similarity index 100% rename from src/components/VideoPlayer/Video.bs rename to playlet-lib/src/components/VideoPlayer/Video.bs diff --git a/src/components/VideoPlayer/VideoContainer.xml b/playlet-lib/src/components/VideoPlayer/VideoContainer.xml similarity index 100% rename from src/components/VideoPlayer/VideoContainer.xml rename to playlet-lib/src/components/VideoPlayer/VideoContainer.xml diff --git a/src/components/VideoPlayer/VideoDetailsTask.bs b/playlet-lib/src/components/VideoPlayer/VideoDetailsTask.bs similarity index 100% rename from src/components/VideoPlayer/VideoDetailsTask.bs rename to playlet-lib/src/components/VideoPlayer/VideoDetailsTask.bs diff --git a/src/components/VideoPlayer/VideoPlayer.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayer.bs similarity index 100% rename from src/components/VideoPlayer/VideoPlayer.bs rename to playlet-lib/src/components/VideoPlayer/VideoPlayer.bs diff --git a/src/components/VideoPlayer/VideoPlayer.xml b/playlet-lib/src/components/VideoPlayer/VideoPlayer.xml similarity index 100% rename from src/components/VideoPlayer/VideoPlayer.xml rename to playlet-lib/src/components/VideoPlayer/VideoPlayer.xml diff --git a/src/components/VideoPlayer/VideoPlayerCaptions.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayerCaptions.bs similarity index 100% rename from src/components/VideoPlayer/VideoPlayerCaptions.bs rename to playlet-lib/src/components/VideoPlayer/VideoPlayerCaptions.bs diff --git a/src/components/VideoPlayer/VideoPlayerSponsorBlock.bs b/playlet-lib/src/components/VideoPlayer/VideoPlayerSponsorBlock.bs similarity index 100% rename from src/components/VideoPlayer/VideoPlayerSponsorBlock.bs rename to playlet-lib/src/components/VideoPlayer/VideoPlayerSponsorBlock.bs diff --git a/src/components/VideoRowCell/VideoRowCell.bs b/playlet-lib/src/components/VideoRowCell/VideoRowCell.bs similarity index 100% rename from src/components/VideoRowCell/VideoRowCell.bs rename to playlet-lib/src/components/VideoRowCell/VideoRowCell.bs diff --git a/src/components/VideoRowCell/VideoRowCell.xml b/playlet-lib/src/components/VideoRowCell/VideoRowCell.xml similarity index 100% rename from src/components/VideoRowCell/VideoRowCell.xml rename to playlet-lib/src/components/VideoRowCell/VideoRowCell.xml diff --git a/src/components/WebServer/HttpConnection.bs b/playlet-lib/src/components/WebServer/HttpConnection.bs similarity index 100% rename from src/components/WebServer/HttpConnection.bs rename to playlet-lib/src/components/WebServer/HttpConnection.bs diff --git a/src/components/WebServer/HttpConnectionState.bs b/playlet-lib/src/components/WebServer/HttpConnectionState.bs similarity index 100% rename from src/components/WebServer/HttpConnectionState.bs rename to playlet-lib/src/components/WebServer/HttpConnectionState.bs diff --git a/src/components/WebServer/HttpRequest.bs b/playlet-lib/src/components/WebServer/HttpRequest.bs similarity index 100% rename from src/components/WebServer/HttpRequest.bs rename to playlet-lib/src/components/WebServer/HttpRequest.bs diff --git a/src/components/WebServer/HttpRequestState.bs b/playlet-lib/src/components/WebServer/HttpRequestState.bs similarity index 100% rename from src/components/WebServer/HttpRequestState.bs rename to playlet-lib/src/components/WebServer/HttpRequestState.bs diff --git a/src/components/WebServer/HttpResponse.bs b/playlet-lib/src/components/WebServer/HttpResponse.bs similarity index 97% rename from src/components/WebServer/HttpResponse.bs rename to playlet-lib/src/components/WebServer/HttpResponse.bs index aed42879..4644e468 100644 --- a/src/components/WebServer/HttpResponse.bs +++ b/playlet-lib/src/components/WebServer/HttpResponse.bs @@ -88,6 +88,12 @@ namespace Http m.source = Http.HttpResponseSource.GENERATED end function + function SetBodyDataBuffer(buffer as object) + m.body_buffer = buffer + m.body_buffer_length = m.body_buffer.count() + m.ContentLength(m.body_buffer_length) + end function + function SetBodyDataString(data as string) m.body_buffer.fromasciistring(data) m.body_buffer_length = m.body_buffer.count() diff --git a/src/components/WebServer/HttpResponseSource.bs b/playlet-lib/src/components/WebServer/HttpResponseSource.bs similarity index 100% rename from src/components/WebServer/HttpResponseSource.bs rename to playlet-lib/src/components/WebServer/HttpResponseSource.bs diff --git a/src/components/WebServer/HttpRouter.bs b/playlet-lib/src/components/WebServer/HttpRouter.bs similarity index 100% rename from src/components/WebServer/HttpRouter.bs rename to playlet-lib/src/components/WebServer/HttpRouter.bs diff --git a/src/components/WebServer/HttpServer.bs b/playlet-lib/src/components/WebServer/HttpServer.bs similarity index 100% rename from src/components/WebServer/HttpServer.bs rename to playlet-lib/src/components/WebServer/HttpServer.bs diff --git a/src/components/WebServer/HttpSettings.bs b/playlet-lib/src/components/WebServer/HttpSettings.bs similarity index 100% rename from src/components/WebServer/HttpSettings.bs rename to playlet-lib/src/components/WebServer/HttpSettings.bs diff --git a/src/components/WebServer/Middleware/BasicAuthMiddleware.bs b/playlet-lib/src/components/WebServer/Middleware/BasicAuthMiddleware.bs similarity index 100% rename from src/components/WebServer/Middleware/BasicAuthMiddleware.bs rename to playlet-lib/src/components/WebServer/Middleware/BasicAuthMiddleware.bs diff --git a/src/components/WebServer/Middleware/CommandsApiRouter.bs b/playlet-lib/src/components/WebServer/Middleware/CommandsApiRouter.bs similarity index 100% rename from src/components/WebServer/Middleware/CommandsApiRouter.bs rename to playlet-lib/src/components/WebServer/Middleware/CommandsApiRouter.bs diff --git a/src/components/WebServer/Middleware/CorsMiddleware.bs b/playlet-lib/src/components/WebServer/Middleware/CorsMiddleware.bs similarity index 100% rename from src/components/WebServer/Middleware/CorsMiddleware.bs rename to playlet-lib/src/components/WebServer/Middleware/CorsMiddleware.bs diff --git a/src/components/WebServer/Middleware/DashRouter.bs b/playlet-lib/src/components/WebServer/Middleware/DashRouter.bs similarity index 100% rename from src/components/WebServer/Middleware/DashRouter.bs rename to playlet-lib/src/components/WebServer/Middleware/DashRouter.bs diff --git a/src/components/WebServer/Middleware/HttpDefaultRouter.bs b/playlet-lib/src/components/WebServer/Middleware/HttpDefaultRouter.bs similarity index 100% rename from src/components/WebServer/Middleware/HttpDefaultRouter.bs rename to playlet-lib/src/components/WebServer/Middleware/HttpDefaultRouter.bs diff --git a/src/components/WebServer/Middleware/HttpStaticFilesRouter.bs b/playlet-lib/src/components/WebServer/Middleware/HttpStaticFilesRouter.bs similarity index 91% rename from src/components/WebServer/Middleware/HttpStaticFilesRouter.bs rename to playlet-lib/src/components/WebServer/Middleware/HttpStaticFilesRouter.bs index a462f3c8..4cf3e881 100644 --- a/src/components/WebServer/Middleware/HttpStaticFilesRouter.bs +++ b/playlet-lib/src/components/WebServer/Middleware/HttpStaticFilesRouter.bs @@ -7,8 +7,9 @@ namespace Http private route private showDirectories private showHidden + private fsCheck - function new(route as string, root as string, showDirectories = false as boolean, showHidden = false as boolean) + function new(route as string, root as string, showDirectories = false as boolean, showHidden = false as boolean, fsCheck = true as boolean) super() m.log = new log.Logger("HttpStaticFilesRouter") @@ -16,6 +17,7 @@ namespace Http m.route = route m.showDirectories = showDirectories m.showHidden = showHidden + m.fsCheck = fsCheck m.Get("*", function(context as object) as boolean router = context.router @@ -31,6 +33,19 @@ namespace Http decoded_path = path_in_route.DecodeUri() full_path = PathJoin(router.root, decoded_path) + if not router.fsCheck + ' libpkg:/ does not work with roFilesystem... + buffer = createObject("roByteArray") + if buffer.ReadFile(full_path) and buffer.count() > 0 + mimetype = WebUtils.MimeType(decoded_path) + response.SetBodyDataBuffer(buffer) + response.ContentType(mimetype) + response.http_code = 200 + response.source = Http.HttpResponseSource.GENERATED + return true + end if + end if + path = CreateObject("roPath", full_path) fs = CreateObject("roFilesystem") diff --git a/src/components/WebServer/Middleware/InvidiousRouter.bs b/playlet-lib/src/components/WebServer/Middleware/InvidiousRouter.bs similarity index 100% rename from src/components/WebServer/Middleware/InvidiousRouter.bs rename to playlet-lib/src/components/WebServer/Middleware/InvidiousRouter.bs diff --git a/src/components/WebServer/Middleware/RegistryApiRouter.bs b/playlet-lib/src/components/WebServer/Middleware/RegistryApiRouter.bs similarity index 100% rename from src/components/WebServer/Middleware/RegistryApiRouter.bs rename to playlet-lib/src/components/WebServer/Middleware/RegistryApiRouter.bs diff --git a/src/components/WebServer/Middleware/StateApiRouter.bs b/playlet-lib/src/components/WebServer/Middleware/StateApiRouter.bs similarity index 100% rename from src/components/WebServer/Middleware/StateApiRouter.bs rename to playlet-lib/src/components/WebServer/Middleware/StateApiRouter.bs diff --git a/src/components/WebServer/Task/WebServerTask.bs b/playlet-lib/src/components/WebServer/Task/WebServerTask.bs similarity index 92% rename from src/components/WebServer/Task/WebServerTask.bs rename to playlet-lib/src/components/WebServer/Task/WebServerTask.bs index a1a9df00..306b7b99 100644 --- a/src/components/WebServer/Task/WebServerTask.bs +++ b/playlet-lib/src/components/WebServer/Task/WebServerTask.bs @@ -21,7 +21,7 @@ function WebServerLoop() m.settings = new Http.HttpSettings(m.webServerPort) ' Root at www to get http://IP_ADDRESS:PORT/index.html - m.settings.WwwRoot = "pkg:/www" + m.settings.WwwRoot = "libpkg:/www" ' Short interval to keep polling on web socket messages m.settings.Timeout = 500 m.server = new Http.HttpServer(m.settings, m) @@ -43,11 +43,11 @@ function WebServerLoop() return true end function) - #if DEBUG + if IsDebugMode() allowedOrigin = "*" - #else + else allowedOrigin = `http://${GetLocalIpAddress()}:8888` - #end if + end if m.server.UseRouter(new Http.CorsMiddleware(allowedOrigin)) #if WEB_SOCKETS m.server.UseRouter(new Http.WebSocketMiddleware()) @@ -57,13 +57,14 @@ function WebServerLoop() m.server.UseRouter(new Http.CommandsApiRouter()) m.server.UseRouter(new Http.StateApiRouter()) m.server.UseRouter(new Http.InvidiousRouter()) - m.server.UseRouter(new Http.HttpStaticFilesRouter("/", m.settings.WwwRoot)) - #if DEBUG + m.server.UseRouter(new Http.HttpStaticFilesRouter("/", m.settings.WwwRoot, false, false, false)) + if IsDebugMode() + m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/libpkg", "libpkg:/", true, true, false)) m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/pkg", "pkg:/", true, true)) m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/tmp", "tmp:/", true, true)) m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/cachefs", "cachefs:/", true, true)) m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/common", "common:/", true, true)) - #end if + end if #if WEB_SERVER_BASIC_AUTH m.server.UseRouter(new Http.BasicAuthMiddleware()) #end if diff --git a/src/components/WebServer/Task/WebServerTask.xml b/playlet-lib/src/components/WebServer/Task/WebServerTask.xml similarity index 78% rename from src/components/WebServer/Task/WebServerTask.xml rename to playlet-lib/src/components/WebServer/Task/WebServerTask.xml index af65b7ea..df185c42 100644 --- a/src/components/WebServer/Task/WebServerTask.xml +++ b/playlet-lib/src/components/WebServer/Task/WebServerTask.xml @@ -5,4 +5,5 @@ + + diff --git a/scripts/asynctask-plugin.ts b/tools/asynctask-plugin.ts similarity index 100% rename from scripts/asynctask-plugin.ts rename to tools/asynctask-plugin.ts diff --git a/scripts/generate-images.js b/tools/generate-images.js similarity index 84% rename from scripts/generate-images.js rename to tools/generate-images.js index fdf9c7c1..b937f34d 100644 --- a/scripts/generate-images.js +++ b/tools/generate-images.js @@ -2,8 +2,8 @@ const fs = require('fs'); const path = require('path'); const { convertFile } = require('convert-svg-to-png'); -const logoPoster = './src/images/vector/logo-light.svg'; -const logoSplash = './src/images/vector/logo-dark.svg'; +const logoPoster = './playlet/src/images/vector/logo-light.svg'; +const logoSplash = './playlet/src/images/vector/logo-dark.svg'; const logoOutput = { // Logo @@ -45,13 +45,13 @@ const logoOutput = { }, }; -const iconsInput = './src/images/vector/icons'; -const iconsOutput = './src/images/icons'; +const iconsInput = './playlet/src/images/vector/icons'; +const iconsOutput = './playlet-lib/src/images/icons'; (async () => { for (var logo in logoOutput) { await convertFile(logoOutput[logo].from, { - outputFilePath: './src/images/' + logo, + outputFilePath: './playlet/src/images/' + logo, background: logoOutput[logo].background, height: logoOutput[logo].height, width: logoOutput[logo].width, diff --git a/tools/manifest-bsconst-debug-plugin.ts b/tools/manifest-bsconst-debug-plugin.ts new file mode 100644 index 00000000..a41fbf44 --- /dev/null +++ b/tools/manifest-bsconst-debug-plugin.ts @@ -0,0 +1,28 @@ +import { + CompilerPlugin, + ProgramBuilder, + FileObj +} from 'brighterscript'; +import path from 'path'; +import fs from 'fs'; + +export class ManifestBsConstDebugPlugin implements CompilerPlugin { + public name = 'manifestBsConstDebugPlugin'; + + beforePublish(builder: ProgramBuilder, files: FileObj[]) { + const debugFlag = process.argv.find(arg => /--debug=(true|false)/i.test(arg)) + if (!debugFlag) { + return; + } + const value = /--debug=(true|false)/i.exec(debugFlag)![1].toLowerCase() + builder.logger.log(`Setting bs_const DEBUG to ${value}`) + const manifestPath = path.join(builder.options.stagingDir!, "manifest") + let manifestContent = fs.readFileSync(manifestPath, { encoding: 'utf8', flag: 'r' }) + manifestContent = manifestContent.replace(/DEBUG=(true|false)/i, `DEBUG=${value}`); + fs.writeFileSync(manifestPath, manifestContent) + } +} + +export default () => { + return new ManifestBsConstDebugPlugin(); +}; diff --git a/scripts/profile-sync.js b/tools/profile-sync.js similarity index 100% rename from scripts/profile-sync.js rename to tools/profile-sync.js diff --git a/scripts/screenshot.js b/tools/screenshot.js similarity index 100% rename from scripts/screenshot.js rename to tools/screenshot.js diff --git a/scripts/sign-package.js b/tools/sign-package.js similarity index 95% rename from scripts/sign-package.js rename to tools/sign-package.js index ec4ade64..e82e14c3 100644 --- a/scripts/sign-package.js +++ b/tools/sign-package.js @@ -10,7 +10,7 @@ const options = { outDir: 'release', outFile: 'playlet.zip', failOnCompileError: true, - stagingDir: 'dist/build', + stagingDir: 'dist/build/playlet', retainStagingDir: true, signingPassword: config.ROKU_SIGN_PASSWORD, }; diff --git a/tools/update-manifest-version.js b/tools/update-manifest-version.js new file mode 100644 index 00000000..992f77cf --- /dev/null +++ b/tools/update-manifest-version.js @@ -0,0 +1,27 @@ +const path = require('path'); +const fs = require('fs'); +const { execSync } = require("child_process"); + +const semverParse = require('semver/functions/parse'); + +const packageJsonContent = fs.readFileSync("./package.json", { encoding: 'utf8', flag: 'r' }); +const packageJson = JSON.parse(packageJsonContent); + +const version = packageJson.version; +const parsedVersion = semverParse(version); + +["playlet/src/manifest", "playlet-lib/src/manifest"].forEach(function (manifestPath) { + let appManifestContent = fs.readFileSync(manifestPath, { encoding: 'utf8', flag: 'r' }); + + const majorPattern = /major_version=(\d+)/; + const minorPattern = /minor_version=(\d+)/; + const buildPattern = /build_version=(\d+)/; + + appManifestContent = appManifestContent.replace(majorPattern, `major_version=${parsedVersion.major}`); + appManifestContent = appManifestContent.replace(minorPattern, `minor_version=${parsedVersion.minor}`); + appManifestContent = appManifestContent.replace(buildPattern, `build_version=${String(parsedVersion.patch).padStart(5, '0')}`); + + fs.writeFileSync(manifestPath, appManifestContent); +}) + +execSync(`npm version ${version} --allow-same-version`, { cwd: 'playlet-web' }); \ No newline at end of file