Fix bsconst plugin

This commit is contained in:
Brahim Hadriche committed 2023-01-30 08:35:00 -05:00
1 parent 5aac07d36c
commit 1faec073f0
4 files changed
+19 -33

No files matched your search

@@ -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 = []
+2 -2
View File
@@ -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)
-23
View File
@@ -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)
+15 -6
View File
@@ -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 () => {