Fix bsconst plugin
This commit is contained in:
1 parent
5aac07d36c
commit
1faec073f0
4 files changed
+19
-33
No files matched your search
@@ -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 () => {
|
||||
|
||||
Reference in new issue
Block a user