diff --git a/bsc-plugin/package-lock.json b/bsc-plugin/package-lock.json index c141899c..396a9fae 100644 --- a/bsc-plugin/package-lock.json +++ b/bsc-plugin/package-lock.json @@ -36,6 +36,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", @@ -3919,9 +3920,9 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "node_modules/fast-glob": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", - "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "version": "3.2.12", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", + "integrity": "sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==", "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -7686,6 +7687,22 @@ "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", "dev": true }, + "node_modules/release-it/node_modules/fast-glob": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", + "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.8" + }, + "engines": { + "node": ">=8.6.0" + } + }, "node_modules/release-it/node_modules/globby": { "version": "14.0.2", "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.2.tgz", @@ -12641,9 +12658,9 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "fast-glob": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", - "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "version": "3.2.12", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz", + "integrity": "sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==", "requires": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -15416,6 +15433,19 @@ "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", "dev": true }, + "fast-glob": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", + "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", + "dev": true, + "requires": { + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.8" + } + }, "globby": { "version": "14.0.2", "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.2.tgz", diff --git a/bsc-plugin/package.json b/bsc-plugin/package.json index a4d62aad..64d0e2a0 100644 --- a/bsc-plugin/package.json +++ b/bsc-plugin/package.json @@ -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", @@ -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", diff --git a/bsc-plugin/src/lib/rooibos/FileFactory.ts b/bsc-plugin/src/lib/rooibos/FileFactory.ts index 24b16c59..71ddeaec 100644 --- a/bsc-plugin/src/lib/rooibos/FileFactory.ts +++ b/bsc-plugin/src/lib/rooibos/FileFactory.ts @@ -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')) @@ -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(`