Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/update framework folder to match structure on device #306

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 36 additions & 6 deletions bsc-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bsc-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"compile": "npm run clean && tsc -p .",
"prepublishOnly": "npm run build",
"lint": "eslint \"src/**\"",
"build": "npm run compile && cp -r ../framework/src/source ./dist/lib/framework",
"build": "npm run compile && cp -r ../framework/src ./dist/lib/framework",
"test": "nyc mocha",
"test:nocover": "mocha",
"publish-coverage": "nyc report --reporter=text-lcov | coveralls",
Expand Down Expand Up @@ -57,6 +57,7 @@
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.16.0",
"eslint-plugin-no-only-tests": "^2.4.0",
"fast-glob": "^3.2.12",
"fs-extra": "^10.1.0",
"minimatch": "^3.0.4",
"mocha": "^9.1.3",
Expand Down
93 changes: 43 additions & 50 deletions bsc-plugin/src/lib/rooibos/FileFactory.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,64 @@
import type { BrsFile, Program, XmlFile } from 'brighterscript';
import type { BrsFile, BscFile, Program, XmlFile } from 'brighterscript';
import { standardizePath as s } from 'brighterscript';
import * as path from 'path';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import * as fastGlob from 'fast-glob';
import type { TestSuite } from './TestSuite';

export class FileFactory {
private coverageComponentXmlTemplate;
private coverageComponentBrsTemplate;

constructor(
private options?: {
frameworkSourcePath?: string;
}
) {
this.options = this.options ?? {};
if (!this.options.frameworkSourcePath) {
if (__filename.endsWith('.ts')) {
//load the files directly from their source location. (i.e. the plugin is running as a typescript file from within ts-node)
this.options.frameworkSourcePath = s`${__dirname}/../../../../framework/src/source`;
} else {
//load the framework files from the dist folder (i.e. the plugin is running as a node_module)
this.options.frameworkSourcePath = s`${__dirname}/../framework`;
}
private frameworkSourcePath: string;

constructor() {
if (__filename.endsWith('.ts')) {
//load the files directly from their source location. (i.e. the plugin is running as a typescript file from within ts-node)
this.frameworkSourcePath = s`${__dirname}/../../../../framework/src`;
} else {
//load the framework files from the dist folder (i.e. the plugin is running as a node_module)
this.frameworkSourcePath = s`${__dirname}/../framework`;
}

this.coverageComponentXmlTemplate = fs.readFileSync(path.join(this.options.frameworkSourcePath, 'CodeCoverage.xml'), 'utf8');
this.coverageComponentBrsTemplate = fs.readFileSync(path.join(this.options.frameworkSourcePath, 'CodeCoverage.brs'), 'utf8');
this.coverageComponentXmlTemplate = fs.readFileSync(path.join(this.frameworkSourcePath, '/components/rooibos/CodeCoverage.xml'), 'utf8');
this.coverageComponentBrsTemplate = fs.readFileSync(path.join(this.frameworkSourcePath, '/source/rooibos/CodeCoverage.brs'), 'utf8');
}

private frameworkFileNames = [
'BaseTestSuite',
'CommonUtils',
'Coverage',
'Matchers',
'Rooibos',
'RuntimeConfig',
'Stats',
'Test',
'TestGroup',
'BaseTestReporter',
'ConsoleTestReporter',
'JUnitTestReporter',
'TestResult',
'TestRunner',
'Utils'
];

private targetPath = 'source/rooibos/';
private targetCompsPath = 'components/rooibos/';
public addedFrameworkFiles = [];
public addedSourceFrameworkFilePaths: string[] = [];
public addedFrameworkFiles: BscFile[] = [];

public addFrameworkFiles(program: Program) {
this.addedFrameworkFiles = [];
for (let fileName of this.frameworkFileNames) {
let sourcePath = path.resolve(path.join(this.options.frameworkSourcePath, `${fileName}.bs`));
let fileContents = fs.readFileSync(sourcePath, 'utf8');
let destPath = path.join(this.targetPath, `${fileName}.bs`);
let entry = { src: sourcePath, dest: destPath };
let globedFiles = fastGlob.sync([
'**/*.{bs,brs,xml}',
'!**/bslib.brs',
'!**/manifest',
'!**/CodeCoverage.{brs,xml}',
'!**/RooibosScene.xml'
], {
cwd: this.frameworkSourcePath,
absolute: false,
followSymbolicLinks: true,
onlyFiles: true
});

for (let filePath of globedFiles) {
if (/^source[/\\]rooibos[/\\]/g.test(filePath)) {
// Save a list of all source files added to the program
// to be imported by node test components
this.addedSourceFrameworkFilePaths.push(filePath);
}
let sourcePath = path.resolve(this.frameworkSourcePath, filePath);
let fileContents = fs.readFileSync(sourcePath, 'utf8').toString();
let entry = { src: sourcePath, dest: filePath };
this.addedFrameworkFiles.push(
program.setFile(entry, fileContents)
);
}

let entry = {
src: s`${this.options.frameworkSourcePath}/RooibosScene.xml`,
dest: s`${this.targetCompsPath}/RooibosScene.xml`
src: s`${this.frameworkSourcePath}/components/RooibosScene.xml`,
dest: s`components/rooibos/RooibosScene.xml`
};
this.addedFrameworkFiles.push(
program.setFile(entry, this.createTestXML('RooibosScene', 'Scene'))
Expand All @@ -74,8 +67,8 @@ export class FileFactory {

public createTestXML(name: string, baseName: string, suite?: TestSuite): string {
let scriptImports = [];
for (let fileName of this.frameworkFileNames) {
scriptImports.push(`<script type="text/brighterscript" uri="pkg:/${this.targetPath}${fileName}.bs" />`);
for (let filePath of this.addedSourceFrameworkFilePaths) {
scriptImports.push(`<script type="text/brighterscript" uri="pkg:/${filePath}" />`);
}

// Add the test spec file rather then relying on auto imports
Expand Down Expand Up @@ -117,8 +110,8 @@ export class FileFactory {

public isIgnoredFile(file: BrsFile | XmlFile): boolean {
let name = file.pkgPath.toLowerCase();
let result = this.frameworkFileNames.find((f) => {
return name === path.join(this.targetPath, `${f}.bs`).toLowerCase();
let result = this.addedFrameworkFiles.find((f) => {
return name === f.pkgPath.toLowerCase();
}
);
return result !== undefined;
Expand Down
6 changes: 0 additions & 6 deletions bsc-plugin/src/lib/rooibos/RooibosConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,4 @@ export interface RooibosConfig {
reporters?: string[];
keepAppOpen?: boolean;
testSceneName?: string;

/**
* The path to the folder where the rooibos framework roku files reside.
* @default `dist/lib/framework`
*/
frameworkSourcePath?: string;
}
1 change: 0 additions & 1 deletion bsc-plugin/src/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('RooibosPlugin', () => {
program.plugins.add(plugin);
program.createSourceScope(); //ensure source scope is created
plugin.beforeProgramCreate(builder);
plugin.fileFactory['options'].frameworkSourcePath = path.resolve(path.join('../framework/src/source'));
plugin.afterProgramCreate(program);
}

Expand Down
2 changes: 1 addition & 1 deletion bsc-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class RooibosPlugin implements CompilerPlugin {

this.config = this.getConfig((builder.options as any).rooibos || {});

this.fileFactory = new FileFactory(this.config);
this.fileFactory = new FileFactory();
if (!this.session) {
this.session = new RooibosSession(builder, this.fileFactory);
this.codeCoverageProcessor = new CodeCoverageProcessor(builder, this.fileFactory);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading