From 1faec073f0be6f26d3049c1bc78269b126aebf8c Mon Sep 17 00:00:00 2001 From: Brahim Hadriche Date: Mon, 30 Jan 2023 08:35:00 -0500 Subject: [PATCH] Fix bsconst plugin --- .../BootstrapScene/BootstrapScene.bs | 4 ++-- playlet/src/source/Main.bs | 4 ++-- playlet/src/source/Manifest.bs | 23 ------------------- tools/manifest-bsconst-debug-plugin.ts | 21 ++++++++++++----- 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/playlet/src/components/BootstrapScene/BootstrapScene.bs b/playlet/src/components/BootstrapScene/BootstrapScene.bs index 1f19d887..751897d1 100644 --- a/playlet/src/components/BootstrapScene/BootstrapScene.bs +++ b/playlet/src/components/BootstrapScene/BootstrapScene.bs @@ -19,9 +19,9 @@ function GetPlayletLibUrls() as object embedded = { type: "embedded", link: ReadManifestValue("playlet_lib_embedded_url") } registry = { type: "registry", link: ReadRegistryKey("playlet_lib_url", "Playlet") } - if IsDebugMode() + #if DEBUG return [embedded] - end if + #end if urls = [] diff --git a/playlet/src/source/Main.bs b/playlet/src/source/Main.bs index 585ec0a3..621c67a7 100644 --- a/playlet/src/source/Main.bs +++ b/playlet/src/source/Main.bs @@ -42,14 +42,14 @@ function Main(args as object) as void input = CreateObject("roInput") input.setMessagePort(m.port) - if IsDebugMode() + #if DEBUG ' The following comment is to enable the SceneGraph inspector ' on the VSCode BrightScript plugin. ' vscode_rdb_on_device_component_entry ' The following comment is to enable RALE tracking ' vscode_rale_tracker_entry - end if + #end if while true msg = wait(0, m.port) diff --git a/playlet/src/source/Manifest.bs b/playlet/src/source/Manifest.bs index a7016007..690d6152 100644 --- a/playlet/src/source/Manifest.bs +++ b/playlet/src/source/Manifest.bs @@ -1,26 +1,3 @@ -function IsDebugMode() as boolean - bsConst = GetBsConstValues() - return bsConst["DEBUG"] -end function - -function GetBsConstValues() as object - result = {} - - bsConst = ReadManifestValue("bs_const") - symbols = bsConst.Tokenize(";") - - for each symbol in symbols - keyValuePair = symbol.Tokenize("=") - if keyValuePair.Count() <> 2 - continue for - end if - - result[UCase(keyValuePair[0])] = UCase(keyValuePair[1]) = "TRUE" - end for - - return result -end function - function ReadManifestValue(key as string) as string appInfo = CreateObject("roAppInfo") return appInfo.GetValue(key) diff --git a/tools/manifest-bsconst-debug-plugin.ts b/tools/manifest-bsconst-debug-plugin.ts index a41fbf44..d39a7839 100644 --- a/tools/manifest-bsconst-debug-plugin.ts +++ b/tools/manifest-bsconst-debug-plugin.ts @@ -1,7 +1,6 @@ import { CompilerPlugin, - ProgramBuilder, - FileObj + ProgramBuilder } from 'brighterscript'; import path from 'path'; import fs from 'fs'; @@ -9,18 +8,28 @@ import fs from 'fs'; export class ManifestBsConstDebugPlugin implements CompilerPlugin { public name = 'manifestBsConstDebugPlugin'; - beforePublish(builder: ProgramBuilder, files: FileObj[]) { + private originalManifestContent?: string; + + beforeProgramCreate(builder: ProgramBuilder) { 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}`); + const manifestPath = path.join(builder.options.rootDir!, "manifest") + this.originalManifestContent = fs.readFileSync(manifestPath, { encoding: 'utf8', flag: 'r' }) + let manifestContent = this.originalManifestContent.replace(/DEBUG=(true|false)/i, `DEBUG=${value}`); fs.writeFileSync(manifestPath, manifestContent) } + + afterPublish(builder: ProgramBuilder) { + if (!this.originalManifestContent) { + return + } + const manifestPath = path.join(builder.options.rootDir!, "manifest") + fs.writeFileSync(manifestPath, this.originalManifestContent!) + } } export default () => {