Skip to content

Commit

Permalink
Allows transpilation of files that do not come from roku deploy's fil… (
Browse files Browse the repository at this point in the history
#212)

* Allows transpilation of files that do not come from roku deploy's file entries, so generated files can be included in the build output

* fix eslint errors.
add bsc protocol to src path for in-memory files

* Add unit tests for in-memory transpile

Co-authored-by: Bronley Plumb <[email protected]>
  • Loading branch information
georgejecook and TwitchBronBron authored Oct 14, 2020
1 parent f4f21e3 commit 0102ef6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
49 changes: 49 additions & 0 deletions src/Program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,55 @@ describe('Program', () => {
});

describe('transpile', () => {
it('transpiles in-memory-only files', async () => {
await program.addOrReplaceFile('source/logger.bs', `
sub logInfo()
print SOURCE_LINE_NUM
end sub
`);
await program.transpile([], program.options.stagingFolderPath);
expect(
fsExtra.readFileSync(s`${stagingFolderPath}/source/logger.brs`).toString().split(/\r?\n/).map(x => x.trim())
).to.eql([
'sub logInfo()',
'print 3',
'end sub'
]);
});

it('copies in-memory-only .brs files to stagingDir', async () => {
await program.addOrReplaceFile('source/logger.brs', `
sub logInfo()
print "logInfo"
end sub
`);
await program.transpile([], program.options.stagingFolderPath);
expect(
fsExtra.readFileSync(s`${stagingFolderPath}/source/logger.brs`).toString()
).to.eql(`
sub logInfo()
print "logInfo"
end sub
`);
});

it('copies in-memory .xml file', async () => {
await program.addOrReplaceFile('components/Component1.xml', `
<?xml version="1.0" encoding="utf-8" ?>
<component name="Component1" extends="Scene">
</component>
`);
await program.transpile([], program.options.stagingFolderPath);
expect(
fsExtra.readFileSync(s`${stagingFolderPath}/components/Component1.xml`).toString()
).to.eql(`
<?xml version="1.0" encoding="utf-8" ?>
<component name="Component1" extends="Scene">
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
</component>
`);
});

it('uses sourceRoot when provided for brs files', async () => {
let sourceRoot = s`${tmpPath}/sourceRootFolder`;
program = new Program({
Expand Down
9 changes: 7 additions & 2 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,14 @@ export class Program {

public async transpile(fileEntries: FileObj[], stagingFolderPath: string) {
const entries = Object.values(this.files).map(file => {
const filePathObj = fileEntries.find(x => s`${x.src}` === s`${file.pathAbsolute}`);
let filePathObj = fileEntries.find(x => s`${x.src}` === s`${file.pathAbsolute}`);
if (!filePathObj) {
throw new Error(`Cannot find fileMap record in fileMaps for '${file.pathAbsolute}'`);
//this file has been added in-memory, from a plugin, for example
filePathObj = {
//add an interpolated src path (since it doesn't actually exist in memory)
src: `bsc:/${file.pkgPath}`,
dest: file.pkgPath
};
}
//replace the file extension
let outputPath = filePathObj.dest.replace(/\.bs$/gi, '.brs');
Expand Down

0 comments on commit 0102ef6

Please sign in to comment.