Some tooling cleanup

This commit is contained in:
Brahim Hadriche committed 2023-07-05 21:00:10 -04:00
1 parent 80bcd4c870
commit 70d66f874d
17 files changed
+145 -46

No files matched your search

@@ -0,0 +1,39 @@
import {
CompilerPlugin,
ProgramBuilder
} from 'brighterscript';
import path from 'path';
import fs from 'fs';
const ip = require('ip');
export class ManifestBsConstDebugPlugin implements CompilerPlugin {
public name = 'manifestBsConstDebugPlugin';
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.rootDir!, "manifest")
this.originalManifestContent = fs.readFileSync(manifestPath, { encoding: 'utf8', flag: 'r' })
let manifestContent = this.originalManifestContent.replace(/DEBUG=(true|false)/i, `DEBUG=${value}`);
manifestContent = manifestContent.replace(/DEBUG_HOST_IP_ADDRESS/i, `${ip.address()}`)
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 () => {
return new ManifestBsConstDebugPlugin();
};