Create Component Library (#43)

* Move src under playlet-lib

* Update configuration

* Update script

* Update script

* Working version

* Vs code config WIP

* Package lock sync

* Lint fix

* Fix images

* Reuse config files

* Kind of a working setup

* Lock node version

* Rename scripts to tools

* Fix build scripts, lib url system

* Lint fix

* rale

* Fix args and web server

* Load fallbacks and build script cleanups

* Remove unused method

* no message

* no message

* Remove generic message field

* Lint fix

* no message

* Use loading indicator on main app

* Add playlet lib version to settings

---------

Co-authored-by: github-action linter <githubaction@githubaction.com>
This commit is contained in:
Brahim Hadricheandgithub-action linter authored and GitHub committed 2023-01-29 16:50:28 -05:00
1 parent 90df81df4b
commit 9d8a3d1cea
156 files changed
+3341 -213

No files matched your search

+2 -1
View File
@@ -3,6 +3,7 @@ out/
node_modules node_modules
.vscode/.env .vscode/.env
**/roku_modules/** **/roku_modules/**
playlet-lib/src/www
playlet/src/lib/playlet-lib.zip
release/playlet.zip release/playlet.zip
release/playlet.pkg release/playlet.pkg
src/www
+1
View File
@@ -0,0 +1 @@
engine-strict=true
+15 -16
View File
@@ -10,23 +10,22 @@
"stopOnEntry": false, "stopOnEntry": false,
"enableDebuggerAutoRecovery": false, "enableDebuggerAutoRecovery": false,
"stopDebuggerOnAppExit": false, "stopDebuggerOnAppExit": false,
"rootDir": "${workspaceFolder}/dist/build", "rootDir": "${workspaceFolder}/dist/build/playlet",
"preLaunchTask": "build-dev", "sourceDirs": [
"${workspaceFolder}/playlet/src",
"${workspaceFolder}/playlet-lib/src"
],
"files": [
"**/*",
],
"preLaunchTask": "build",
"name": "Playlet (dev)", "name": "Playlet (dev)",
"injectRdbOnDeviceComponent": true "injectRdbOnDeviceComponent": true,
}, "injectRaleTrackerTask": true,
{ // TODO: change to ${workspaceFolder}/tools/RALE/TrackerTask.xml
"type": "brightscript", // Once https://github.com/rokucommunity/vscode-brightscript-language/pull/462
"request": "launch", // is released (after v2.38.7)
"envFile": "${workspaceFolder}/.vscode/.env", "raleTrackerTaskFileLocation": "/Users/brahim/Roku/playlet/tools/RALE/TrackerTask.xml"
"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)"
}, },
{ {
"command": "npm run dev:web", "command": "npm run dev:web",
+3
View File
@@ -0,0 +1,3 @@
{
"brightscript.output.clearConsoleOnChannelStart": false
}
+22 -15
View File
@@ -2,23 +2,30 @@
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{ {
"label": "build-dev", "label": "build",
"presentation": { "dependsOn": [
"close": true, "build-app"
"reveal": "silent", ]
"revealProblems": "onProblem"
},
"script": "build:dev",
"type": "npm"
}, },
{ {
"label": "build-prod", "label": "build-app",
"presentation": { "script": "build:app:dev",
"close": true, "type": "npm",
"reveal": "silent", "dependsOn": [
"revealProblems": "onProblem" "build-lib"
}, ]
"script": "build:prod", },
{
"label": "build-lib",
"script": "build:lib:dev",
"type": "npm",
"dependsOn": [
"build-web"
]
},
{
"label": "build-web",
"script": "build:web",
"type": "npm" "type": "npm"
} }
] ]
-5
View File
@@ -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": ""
}
+6 -5
View File
@@ -12,16 +12,19 @@
"source/**/*", "source/**/*",
"components/**/*", "components/**/*",
"images/**/*", "images/**/*",
"!images/vector/**/*",
"fonts/**/*", "fonts/**/*",
"config/**/*", "config/**/*",
"lib/**/*",
"www/**/*.*", "www/**/*.*",
"manifest" "manifest"
], ],
"lintConfig": "config/bslint.jsonc", "lintConfig": "./config/bslint.jsonc",
"plugins": [ "plugins": [
"roku-log-bsc-plugin", "roku-log-bsc-plugin",
"@rokucommunity/bslint", "@rokucommunity/bslint",
"../scripts/asynctask-plugin.ts" "../tools/asynctask-plugin.ts",
"../tools/manifest-bsconst-debug-plugin.ts"
], ],
"retainStagingDir": true, "retainStagingDir": true,
"require": [ "require": [
@@ -32,7 +35,5 @@
"removeComments": false, "removeComments": false,
"strip": false "strip": false
}, },
"rootDir": "../src/", "sourceMap": true
"sourceMap": true,
"stagingDir": "dist/build"
} }
+3
View File
@@ -28,6 +28,9 @@
"semver": "^7.3.8", "semver": "^7.3.8",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^4.9.4" "typescript": "^4.9.4"
},
"engines": {
"node": "<19.0.0"
} }
}, },
"node_modules/@cspotcode/source-map-support": { "node_modules/@cspotcode/source-map-support": {
+21 -16
View File
@@ -16,15 +16,17 @@
"convert-svg-to-png": "^0.6.4", "convert-svg-to-png": "^0.6.4",
"dotenv": "^16.0.3", "dotenv": "^16.0.3",
"express": "^4.18.2", "express": "^4.18.2",
"ip": "^1.1.8",
"roku-log-bsc-plugin": "^0.7.0", "roku-log-bsc-plugin": "^0.7.0",
"ropm": "^0.10.11", "ropm": "^0.10.11",
"semver": "^7.3.8", "semver": "^7.3.8",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^4.9.4" "typescript": "^4.9.4"
}, },
"engines": {
"node": "<19.0.0"
},
"ropm": { "ropm": {
"rootDir": "src", "rootDir": "playlet-lib/src",
"noprefix": [ "noprefix": [
"roku-requests" "roku-requests"
] ]
@@ -32,23 +34,26 @@
"scripts": { "scripts": {
"dev:web": "cd playlet-web && npm run dev", "dev:web": "cd playlet-web && npm run dev",
"prebuild": "rm -rf dist", "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:web": "cd playlet-web && npm run build",
"build": "npm run build:web && bsc", "lint": "bslint --project playlet-lib/bsconfig.lint.json --lintConfig config/bslint.jsonc && bslint --project playlet/bsconfig.lint.json --lintConfig config/bslint.jsonc",
"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:fix": "npm run lint -- --fix", "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": "npm run format:base -- --check",
"format:fix": "npm run format:base -- --write", "format:fix": "npm run format:base -- --write",
"generate-images": "node scripts/generate-images.js", "generate-images": "node tools/generate-images.js",
"manifest-version": "node scripts/update-manifest-version.js", "manifest-version": "node tools/update-manifest-version.js",
"zip-package": "node scripts/zip-package.js", "sign-package": "node tools/sign-package.js",
"sign-package": "node scripts/sign-package.js", "screenshot": "node tools/screenshot.js",
"screenshot": "node scripts/screenshot.js", "profile-sync": "node tools/profile-sync.js",
"manifest-symbols": "node scripts/update-manifest-symbols.js",
"profile-sync": "node scripts/profile-sync.js",
"postinstall": "npx ropm copy && cd playlet-web && npm install" "postinstall": "npx ropm copy && cd playlet-web && npm install"
} }
} }
+6
View File
@@ -0,0 +1,6 @@
{
"extends": "../config/bsconfig.base.json",
"rootDir": "src/",
"stagingDir": "../dist/build/playlet-lib",
"outFile": "../playlet/src/lib/playlet-lib.zip"
}
@@ -1,7 +1,7 @@
{ {
"createPackage": false, "createPackage": false,
"deploy": false, "deploy": false,
"extends": "bsconfig.base.json", "extends": "bsconfig.json",
"retainStagingDir": false, "retainStagingDir": false,
"sourceMap": false "sourceMap": false
} }
File renamed without changes.
@@ -8,8 +8,6 @@ function Init()
m.top.ObserveField("focus", "OnFocusChange") m.top.ObserveField("focus", "OnFocusChange")
m.top.ObserveField("refresh", "OnRefresh") m.top.ObserveField("refresh", "OnRefresh")
m.top.focus = true
InitContent() InitContent()
end function end function
@@ -32,7 +30,7 @@ function InitContent()
}, true) }, true)
m.top.content = contentNode 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 if m.defaultLayout.Count() > 0
m.currentLoadingIndex = 0 m.currentLoadingIndex = 0
@@ -4,20 +4,15 @@ import "pkg:/components/VideoPlayer/Video.bs"
function Init() function Init()
log.initializeLogManager(["log_PrintTransport"], 2) 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.videoContainer = m.top.findNode("VideoContainer")
m.global.addFields({ m.global.addFields({
loadingIndicator: m.loadingIndicator,
videoContainer: m.videoContainer videoContainer: m.videoContainer
}) })
m.loadingIndicator.visible = true
m.homeGridScreen = m.top.findNode("HomeGridScreen") m.homeGridScreen = m.top.findNode("HomeGridScreen")
m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape") m.homeGridScreen.ObserveField("escape", "OnHomeGridScreenEscape")
m.homeGridScreen.SetFocus(true) m.homeGridScreen.SetFocus(true)
m.currentFocued = m.homeGridScreen
m.settingsScreen = m.top.findNode("SettingsScreen") m.settingsScreen = m.top.findNode("SettingsScreen")
@@ -28,9 +23,12 @@ function Init()
m.navBar.ObserveField("escapeIndex", "OnNavBarEscape") m.navBar.ObserveField("escapeIndex", "OnNavBarEscape")
m.navBar.ObserveField("focusIndex", "OnNavIndexChange") m.navBar.ObserveField("focusIndex", "OnNavIndexChange")
m.currentFocued = m.homeGridScreen
InitWebServer() InitWebServer()
LaunchArgumentsReceived()
scene = m.top.getScene()
scene.ObserveField("inputArgs", "InputArgumentsReceived")
end function end function
function InitWebServer() function InitWebServer()
@@ -97,25 +95,18 @@ function OnWebServerCommand()
end if end if
end function 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 function LaunchArgumentsReceived() as void
? "LaunchArgumentsReceived" m.top.launchArgs scene = m.top.getScene()
PlayVideoFromArgs(m.top.launchArgs) launchArgs = scene.launchArgs
? "LaunchArgumentsReceived " launchArgs
PlayVideoFromArgs(launchArgs)
end function end function
function InputArgumentsReceived() as void function InputArgumentsReceived() as void
? "InputArgumentsReceived" m.top.inputArgs scene = m.top.getScene()
PlayVideoFromArgs(m.top.inputArgs) inputArgs = scene.inputArgs
? "InputArgumentsReceived " inputArgs
PlayVideoFromArgs(inputArgs)
end function end function
function PlayVideoFromArgs(args as object) as void function PlayVideoFromArgs(args as object) as void
@@ -128,8 +119,10 @@ function PlayVideoFromArgs(args as object) as void
' bs:disable-next-line ' bs:disable-next-line
mediaType = args.mediaType mediaType = args.mediaType
if contentId <> invalid if contentId = invalid
sender = m.videoContainer.sender ?? m.currentFocued return
PlayVideo(contentId, { sender: sender })
end if end if
sender = m.videoContainer.sender ?? m.currentFocued
PlayVideo(contentId, { sender: sender })
end function end function
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<component name="MainScene" extends="Group">
<children>
<SearchScreen id="SearchScreen" visible="false" />
<HomeGridScreen id="HomeGridScreen" />
<SettingsScreen id="SettingsScreen" visible="false" />
<NavBar id="NavBar" />
<VideoContainer id="VideoContainer" />
</children>
</component>
@@ -51,7 +51,7 @@ function OnExitDialog(event as object)
buttonIndex = event.GetData() buttonIndex = event.GetData()
if buttonIndex = 0 ' Exit if buttonIndex = 0 ' Exit
? "EXITING APP" ? "EXITING APP"
m.top.GetScene().exitChannel = true m.top.getScene().exitChannel = true
end if end if
end function end function
@@ -1,13 +1,15 @@
import "pkg:/source/utils/General.bs" import "pkg:/source/utils/General.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/asyncTask/asyncTask.bs" import "pkg:/source/asyncTask/asyncTask.bs"
import "pkg:/components/SettingsScreen/AppVersionTask.bs" import "pkg:/components/SettingsScreen/AppVersionTask.bs"
function Init() function Init()
m.versionLabel = m.top.findNode("VersionLabel") m.versionLabel = m.top.findNode("VersionLabel")
m.top.url = `http://${GetLocalIpAddress()}:8888` m.top.url = `http://${GetLocalIpAddress()}:8888`
appInfo = GetAppInfo()
m.currentVersion = appInfo.version m.appInfo = GetAppInfo()
SetVersionLabel(m.currentVersion, "N/A")
SetVersionLabel(m.appInfo.version, m.appInfo.lib_version, "N/A")
GetLatestVersion() GetLatestVersion()
end function end function
@@ -24,11 +26,11 @@ end function
function GetLatestVersion() function GetLatestVersion()
StartAsyncTask(AppVersionTask, {}, function(output as object) as void StartAsyncTask(AppVersionTask, {}, function(output as object) as void
if output.result.latest <> invalid 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 if
end function) end function)
end function end function
function SetVersionLabel(current as string, latest as string) function SetVersionLabel(appVersion as string, libVersion as string, latest as string)
m.versionLabel.text = `Version: ${current} | Latest: ${latest}` m.versionLabel.text = `Playlet: ${appVersion} | Playlet-Lib: ${libVersion} | Latest: ${latest}`
end function end function
@@ -88,6 +88,12 @@ namespace Http
m.source = Http.HttpResponseSource.GENERATED m.source = Http.HttpResponseSource.GENERATED
end function 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) function SetBodyDataString(data as string)
m.body_buffer.fromasciistring(data) m.body_buffer.fromasciistring(data)
m.body_buffer_length = m.body_buffer.count() m.body_buffer_length = m.body_buffer.count()
@@ -7,8 +7,9 @@ namespace Http
private route private route
private showDirectories private showDirectories
private showHidden 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() super()
m.log = new log.Logger("HttpStaticFilesRouter") m.log = new log.Logger("HttpStaticFilesRouter")
@@ -16,6 +17,7 @@ namespace Http
m.route = route m.route = route
m.showDirectories = showDirectories m.showDirectories = showDirectories
m.showHidden = showHidden m.showHidden = showHidden
m.fsCheck = fsCheck
m.Get("*", function(context as object) as boolean m.Get("*", function(context as object) as boolean
router = context.router router = context.router
@@ -31,6 +33,19 @@ namespace Http
decoded_path = path_in_route.DecodeUri() decoded_path = path_in_route.DecodeUri()
full_path = PathJoin(router.root, decoded_path) 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) path = CreateObject("roPath", full_path)
fs = CreateObject("roFilesystem") fs = CreateObject("roFilesystem")
@@ -21,7 +21,7 @@ function WebServerLoop()
m.settings = new Http.HttpSettings(m.webServerPort) m.settings = new Http.HttpSettings(m.webServerPort)
' Root at www to get http://IP_ADDRESS:PORT/index.html ' 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 ' Short interval to keep polling on web socket messages
m.settings.Timeout = 500 m.settings.Timeout = 500
m.server = new Http.HttpServer(m.settings, m) m.server = new Http.HttpServer(m.settings, m)
@@ -43,11 +43,11 @@ function WebServerLoop()
return true return true
end function) end function)
#if DEBUG if IsDebugMode()
allowedOrigin = "*" allowedOrigin = "*"
#else else
allowedOrigin = `http://${GetLocalIpAddress()}:8888` allowedOrigin = `http://${GetLocalIpAddress()}:8888`
#end if end if
m.server.UseRouter(new Http.CorsMiddleware(allowedOrigin)) m.server.UseRouter(new Http.CorsMiddleware(allowedOrigin))
#if WEB_SOCKETS #if WEB_SOCKETS
m.server.UseRouter(new Http.WebSocketMiddleware()) m.server.UseRouter(new Http.WebSocketMiddleware())
@@ -57,13 +57,14 @@ function WebServerLoop()
m.server.UseRouter(new Http.CommandsApiRouter()) m.server.UseRouter(new Http.CommandsApiRouter())
m.server.UseRouter(new Http.StateApiRouter()) m.server.UseRouter(new Http.StateApiRouter())
m.server.UseRouter(new Http.InvidiousRouter()) m.server.UseRouter(new Http.InvidiousRouter())
m.server.UseRouter(new Http.HttpStaticFilesRouter("/", m.settings.WwwRoot)) m.server.UseRouter(new Http.HttpStaticFilesRouter("/", m.settings.WwwRoot, false, false, false))
#if DEBUG 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/pkg", "pkg:/", true, true))
m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/tmp", "tmp:/", 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/cachefs", "cachefs:/", true, true))
m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/common", "common:/", true, true)) m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug/common", "common:/", true, true))
#end if end if
#if WEB_SERVER_BASIC_AUTH #if WEB_SERVER_BASIC_AUTH
m.server.UseRouter(new Http.BasicAuthMiddleware()) m.server.UseRouter(new Http.BasicAuthMiddleware())
#end if #end if
@@ -5,4 +5,5 @@
<field id="login" type="boolean" alwaysNotify="true" /> <field id="login" type="boolean" alwaysNotify="true" />
<field id="command" type="string" alwaysNotify="true" /> <field id="command" type="string" alwaysNotify="true" />
</interface> </interface>
<script type="text/brightscript" uri="pkg:/source/utils/Debug.bs" />
</component> </component>
File renamed without changes.

Before

Width:  |  Height:  |  Size: 292 B

After

Width:  |  Height:  |  Size: 292 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 483 B

After

Width:  |  Height:  |  Size: 483 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 925 B

After

Width:  |  Height:  |  Size: 925 B

File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Loaded 100 of 156 files, more files were not shown because too many files have changed in this diff. Show more