diff --git a/src/commands/ConvertToSquashfsCommand.ts b/src/commands/ConvertToSquashfsCommand.ts index b1e1e7b..79ebf6e 100644 --- a/src/commands/ConvertToSquashfsCommand.ts +++ b/src/commands/ConvertToSquashfsCommand.ts @@ -1,10 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class ConvertToSquashfsCommand { async run(args) { - await rokuDeploy.convertToSquashfs({ - host: args.host, - password: args.password - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.convertToSquashfs(options); } } diff --git a/src/commands/CreateSignedPackageCommand.ts b/src/commands/CreateSignedPackageCommand.ts index 8488650..904a9fe 100644 --- a/src/commands/CreateSignedPackageCommand.ts +++ b/src/commands/CreateSignedPackageCommand.ts @@ -1,12 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class CreateSignedPackageCommand { async run(args) { - await rokuDeploy.createSignedPackage({ - host: args.host, - password: args.password, - signingPassword: args.signingPassword, - stagingDir: args.stagingDir - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.createSignedPackage(options); } } diff --git a/src/commands/DeleteDevChannelCommand.ts b/src/commands/DeleteDevChannelCommand.ts index 52dd95f..5bfa269 100644 --- a/src/commands/DeleteDevChannelCommand.ts +++ b/src/commands/DeleteDevChannelCommand.ts @@ -1,10 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class DeleteDevChannelCommand { async run(args) { - await rokuDeploy.deleteDevChannel({ - host: args.host, - password: args.password - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.deleteDevChannel(options); } } diff --git a/src/commands/ExecCommand.ts b/src/commands/ExecCommand.ts index 9bdf9ad..5a56b44 100644 --- a/src/commands/ExecCommand.ts +++ b/src/commands/ExecCommand.ts @@ -21,11 +21,6 @@ export class ExecCommand { ...this.options }; - // Possibilities: - // 'stage|zip' - // 'stage|zip|delete|close|sideload' - // 'close|rekey|stage|zip|delete|close|sideload|squash|sign' - if (this.actions.includes('stage')) { await rokuDeploy.stage(this.options); } diff --git a/src/commands/GetDevIdCommand.ts b/src/commands/GetDevIdCommand.ts index 72ccde8..c54c8e6 100644 --- a/src/commands/GetDevIdCommand.ts +++ b/src/commands/GetDevIdCommand.ts @@ -1,9 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class GetDevIdCommand { async run(args) { - await rokuDeploy.getDevId({ - host: args.host - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.getDevId(options); } } diff --git a/src/commands/GetDeviceInfoCommand.ts b/src/commands/GetDeviceInfoCommand.ts index 1bf10b3..3255fe3 100644 --- a/src/commands/GetDeviceInfoCommand.ts +++ b/src/commands/GetDeviceInfoCommand.ts @@ -3,9 +3,11 @@ import { util } from '../util'; export class GetDeviceInfoCommand { async run(args) { - const outputPath = await rokuDeploy.getDeviceInfo({ - host: args.host - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + const outputPath = await rokuDeploy.getDeviceInfo(options); console.log(util.objectToTableString(outputPath)); } } diff --git a/src/commands/GetOutputPkgFilePathCommand.ts b/src/commands/GetOutputPkgFilePathCommand.ts index 0861d1e..3bfc2d0 100644 --- a/src/commands/GetOutputPkgFilePathCommand.ts +++ b/src/commands/GetOutputPkgFilePathCommand.ts @@ -1,12 +1,13 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class GetOutputPkgFilePathCommand { run(args) { + let options = { + ...util.getOptionsFromJson(args), + ...args + }; // eslint-disable-next-line @typescript-eslint/dot-notation - const outputPath = rokuDeploy['getOutputPkgPath']({ - outFile: args.outFile, - outDir: args.outDir - }); + const outputPath = rokuDeploy['getOutputPkgPath'](options); //TODO fix this? console.log(outputPath); } } diff --git a/src/commands/GetOutputZipFilePathCommand.ts b/src/commands/GetOutputZipFilePathCommand.ts index bd9d7de..c5761c0 100644 --- a/src/commands/GetOutputZipFilePathCommand.ts +++ b/src/commands/GetOutputZipFilePathCommand.ts @@ -1,12 +1,13 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class GetOutputZipFilePathCommand { run(args) { + let options = { + ...util.getOptionsFromJson(args), + ...args + }; // eslint-disable-next-line @typescript-eslint/dot-notation - const outputPath = rokuDeploy['getOutputZipFilePath']({ - outFile: args.outFile, - outDir: args.outDir - }); + const outputPath = rokuDeploy['getOutputZipFilePath'](options); console.log(outputPath); } } diff --git a/src/commands/KeyDownCommand.ts b/src/commands/KeyDownCommand.ts index 3936e8a..ae05b91 100644 --- a/src/commands/KeyDownCommand.ts +++ b/src/commands/KeyDownCommand.ts @@ -1,7 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class KeyDownCommand { async run(args) { - await rokuDeploy.keyDown(args.text); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.keyDown(options); } } diff --git a/src/commands/KeyPressCommand.ts b/src/commands/KeyPressCommand.ts index 7cf1e0b..4554df7 100644 --- a/src/commands/KeyPressCommand.ts +++ b/src/commands/KeyPressCommand.ts @@ -1,7 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class KeyPressCommand { async run(args) { - await rokuDeploy.keyPress(args.text); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.keyPress(options); } } diff --git a/src/commands/KeyUpCommand.ts b/src/commands/KeyUpCommand.ts index 5e7e66d..36b71ea 100644 --- a/src/commands/KeyUpCommand.ts +++ b/src/commands/KeyUpCommand.ts @@ -1,7 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class KeyUpCommand { async run(args) { - await rokuDeploy.keyUp(args.text); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.keyUp(options); } } diff --git a/src/commands/PrepublishCommand.ts b/src/commands/PrepublishCommand.ts index 48152ed..e44613b 100644 --- a/src/commands/PrepublishCommand.ts +++ b/src/commands/PrepublishCommand.ts @@ -1,10 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class PrepublishCommand { async run(args) { - await rokuDeploy.stage({ - stagingDir: args.stagingDir, - rootDir: args.rootDir - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.stage(options); } } diff --git a/src/commands/PublishCommand.ts b/src/commands/PublishCommand.ts index 7338471..e365b12 100644 --- a/src/commands/PublishCommand.ts +++ b/src/commands/PublishCommand.ts @@ -1,12 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class PublishCommand { async run(args) { - await rokuDeploy.sideload({ - host: args.host, - password: args.password, - outDir: args.outDir, - outFile: args.outFile - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.sideload(options); } } diff --git a/src/commands/RekeyDeviceCommand.ts b/src/commands/RekeyDeviceCommand.ts index 7098772..ca00fd8 100644 --- a/src/commands/RekeyDeviceCommand.ts +++ b/src/commands/RekeyDeviceCommand.ts @@ -1,14 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class RekeyDeviceCommand { async run(args) { - await rokuDeploy.rekeyDevice({ - host: args.host, - password: args.password, - rekeySignedPackage: args.rekeySignedPackage, - signingPassword: args.signingPassword, - rootDir: args.rootDir, - devId: args.devId - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.rekeyDevice(options); } } diff --git a/src/commands/SendTextCommand.ts b/src/commands/SendTextCommand.ts index a71db16..3e11810 100644 --- a/src/commands/SendTextCommand.ts +++ b/src/commands/SendTextCommand.ts @@ -1,8 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class SendTextCommand { - // this.options = getDefaultArgsFromJson(this.configPath ?? `${cwd}/rokudeploy.json`);TODO async run(args) { - await rokuDeploy.sendText(args.text); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.sendText(options); } } diff --git a/src/commands/TakeScreenshotCommand.ts b/src/commands/TakeScreenshotCommand.ts index 2d9f358..c77ef61 100644 --- a/src/commands/TakeScreenshotCommand.ts +++ b/src/commands/TakeScreenshotCommand.ts @@ -1,10 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class TakeScreenshotCommand { async run(args) { - await rokuDeploy.captureScreenshot({ - host: args.host, - password: args.password - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.captureScreenshot(options); } } diff --git a/src/commands/ZipCommand.ts b/src/commands/ZipCommand.ts index 44b0e12..b03e80d 100644 --- a/src/commands/ZipCommand.ts +++ b/src/commands/ZipCommand.ts @@ -1,10 +1,11 @@ -import { rokuDeploy } from '../index'; +import { rokuDeploy, util } from '../index'; export class ZipCommand { async run(args) { - await rokuDeploy.zip({ - stagingDir: args.stagingDir, - outDir: args.outDir - }); + let options = { + ...util.getOptionsFromJson(args), + ...args + }; + await rokuDeploy.zip(options); } } diff --git a/src/util.spec.ts b/src/util.spec.ts index ea34990..b30032e 100644 --- a/src/util.spec.ts +++ b/src/util.spec.ts @@ -1,12 +1,10 @@ -import { util, standardizePath as s, standardizePathPosix as sp } from './util'; +import { util, standardizePath as s } from './util'; import { expect } from 'chai'; import * as fsExtra from 'fs-extra'; -import { cwd, tempDir, rootDir, outDir, expectThrowsAsync, writeFiles } from './testUtils.spec'; +import { cwd, tempDir, rootDir } from './testUtils.spec'; import * as path from 'path'; import * as dns from 'dns'; import { createSandbox } from 'sinon'; -import { RokuDeploy } from './RokuDeploy'; -import type { FileEntry, RokuDeployOptions } from './RokuDeployOptions'; const sinon = createSandbox(); describe('util', () => { @@ -453,608 +451,30 @@ describe('util', () => { }); }); - describe('getFilePaths', () => { - const otherProjectName = 'otherProject'; - const otherProjectDir = sp`${rootDir}/../${otherProjectName}`; - let rokuDeploy: RokuDeploy; - let options: RokuDeployOptions; - //create baseline project structure + describe.only('getOptionsFromJson', () => { beforeEach(() => { - rokuDeploy = new RokuDeploy(); - options = rokuDeploy.getOptions({}); - fsExtra.ensureDirSync(`${rootDir}/components/emptyFolder`); - writeFiles(rootDir, [ - `manifest`, - `source/main.brs`, - `source/lib.brs`, - `components/component1.xml`, - `components/component1.brs`, - `components/screen1/screen1.xml`, - `components/screen1/screen1.brs` - ]); - }); - - async function getFilePaths(files: FileEntry[], rootDirOverride = rootDir) { - return (await util.getFilePaths(files, rootDirOverride)) - .sort((a, b) => a.src.localeCompare(b.src)); - } - - describe('top-level-patterns', () => { - it('excludes a file that is negated', async () => { - expect(await getFilePaths([ - 'source/**/*', - '!source/main.brs' - ])).to.eql([{ - src: s`${rootDir}/source/lib.brs`, - dest: s`source/lib.brs` - }]); - }); - - it('excludes file from non-rootdir top-level pattern', async () => { - writeFiles(rootDir, ['../externalDir/source/main.brs']); - expect(await getFilePaths([ - '../externalDir/**/*', - '!../externalDir/**/*' - ])).to.eql([]); - }); - - it('throws when using top-level string referencing file outside the root dir', async () => { - writeFiles(rootDir, [`../source/main.brs`]); - await expectThrowsAsync(async () => { - await getFilePaths([ - '../source/**/*' - ]); - }, 'Cannot reference a file outside of rootDir when using a top-level string. Please use a src;des; object instead'); - }); - - it('works for brighterscript files', async () => { - writeFiles(rootDir, ['src/source/main.bs']); - expect(await getFilePaths([ - 'manifest', - 'source/**/*.bs' - ], s`${rootDir}/src`)).to.eql([{ - src: s`${rootDir}/src/source/main.bs`, - dest: s`source/main.bs` - }]); - }); - - it('works for root-level double star in top-level pattern', async () => { - expect(await getFilePaths([ - '**/*' - ])).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/component1.xml`, - dest: s`components/component1.xml` - }, - { - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`components/screen1/screen1.brs` - }, - { - src: s`${rootDir}/components/screen1/screen1.xml`, - dest: s`components/screen1/screen1.xml` - }, - { - src: s`${rootDir}/manifest`, - dest: s`manifest` - }, - { - src: s`${rootDir}/source/lib.brs`, - dest: s`source/lib.brs` - }, - { - src: s`${rootDir}/source/main.brs`, - dest: s`source/main.brs` - }]); - }); - - it('works for multile entries', async () => { - expect(await getFilePaths([ - 'source/**/*', - 'components/**/*', - 'manifest' - ])).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/component1.xml`, - dest: s`components/component1.xml` - }, { - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`components/screen1/screen1.brs` - }, { - src: s`${rootDir}/components/screen1/screen1.xml`, - dest: s`components/screen1/screen1.xml` - }, { - src: s`${rootDir}/manifest`, - dest: s`manifest` - }, { - src: s`${rootDir}/source/lib.brs`, - dest: s`source/lib.brs` - }, { - src: s`${rootDir}/source/main.brs`, - dest: s`source/main.brs` - }]); - }); - - it('copies top-level-string single-star globs', async () => { - writeFiles(rootDir, [ - 'source/lib.brs', - 'source/main.brs' - ]); - expect(await getFilePaths([ - 'source/*.brs' - ])).to.eql([{ - src: s`${rootDir}/source/lib.brs`, - dest: s`source/lib.brs` - }, { - src: s`${rootDir}/source/main.brs`, - dest: s`source/main.brs` - }]); - }); - - it('works for double-star globs', async () => { - expect(await getFilePaths([ - '**/*.brs' - ])).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`components/screen1/screen1.brs` - }, { - src: s`${rootDir}/source/lib.brs`, - dest: s`source/lib.brs` - }, { - src: s`${rootDir}/source/main.brs`, - dest: s`source/main.brs` - }]); - }); - - it('copies subdir-level relative double-star globs', async () => { - expect(await getFilePaths([ - 'components/**/*.brs' - ])).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`components/screen1/screen1.brs` - }]); - }); - - it('Finds folder using square brackets glob pattern', async () => { - fsExtra.outputFileSync(`${rootDir}/e/file.brs`, ''); - expect(await getFilePaths([ - '[test]/*' - ], - rootDir - )).to.eql([{ - src: s`${rootDir}/e/file.brs`, - dest: s`e/file.brs` - }]); - }); - - it('Finds folder with escaped square brackets glob pattern as name', async () => { - fsExtra.outputFileSync(`${rootDir}/[test]/file.brs`, ''); - fsExtra.outputFileSync(`${rootDir}/e/file.brs`, ''); - expect(await getFilePaths([ - '\\[test\\]/*' - ], - rootDir - )).to.eql([{ - src: s`${rootDir}/[test]/file.brs`, - dest: s`[test]/file.brs` - }]); - }); - - it('throws exception when top-level strings reference files not under rootDir', async () => { - writeFiles(otherProjectDir, [ - 'manifest' - ]); - await expectThrowsAsync( - getFilePaths([ - `../${otherProjectName}/**/*` - ]) - ); - }); - - it('applies negated patterns', async () => { - expect(await getFilePaths([ - //include all components - 'components/**/*.brs', - //exclude all xml files - '!components/**/*.xml', - //re-include a specific xml file - 'components/screen1/screen1.xml' - ])).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`components/screen1/screen1.brs` - }, { - src: s`${rootDir}/components/screen1/screen1.xml`, - dest: s`components/screen1/screen1.xml` - }]); - }); - - it('handles negated multi-globs', async () => { - expect((await getFilePaths([ - 'components/**/*', - '!components/screen1/**/*' - ])).map(x => x.dest)).to.eql([ - s`components/component1.brs`, - s`components/component1.xml` - ]); - }); - - it('allows negating paths outside rootDir without requiring src;dest; syntax', async () => { - fsExtra.outputFileSync(`${rootDir}/../externalLib/source/lib.brs`, ''); - const filePaths = await getFilePaths([ - 'source/**/*', - { src: '../externalLib/**/*', dest: 'source' }, - '!../externalLib/source/**/*' - ], rootDir); - expect( - filePaths.map(x => s`${x.src}`).sort() - ).to.eql([ - s`${rootDir}/source/lib.brs`, - s`${rootDir}/source/main.brs` - ]); - }); - - it('applies multi-glob paths relative to rootDir', async () => { - expect(await getFilePaths([ - 'manifest', - 'source/**/*', - 'components/**/*', - '!components/scenes/**/*' - ])).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/component1.xml`, - dest: s`components/component1.xml` - }, { - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`components/screen1/screen1.brs` - }, { - src: s`${rootDir}/components/screen1/screen1.xml`, - dest: s`components/screen1/screen1.xml` - }, { - src: s`${rootDir}/manifest`, - dest: s`manifest` - }, { - src: s`${rootDir}/source/lib.brs`, - dest: s`source/lib.brs` - }, { - src: s`${rootDir}/source/main.brs`, - dest: s`source/main.brs` - }]); - }); - - it('ignores non-glob folder paths', async () => { - expect(await getFilePaths([ - //this is the folder called "components" - 'components' - ])).to.eql([]); //there should be no matches because rokudeploy ignores folders - }); - - }); - - describe('{src;dest} objects', () => { - it('excludes a file that is negated in src;dest;', async () => { - expect(await getFilePaths([ - 'source/**/*', - { - src: '!source/main.brs' - } - ])).to.eql([{ - src: s`${rootDir}/source/lib.brs`, - dest: s`source/lib.brs` - }]); - }); - - it('works for root-level double star in {src;dest} object', async () => { - expect(await getFilePaths([{ - src: '**/*', - dest: '' - } - ])).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/component1.xml`, - dest: s`components/component1.xml` - }, - { - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`components/screen1/screen1.brs` - }, - { - src: s`${rootDir}/components/screen1/screen1.xml`, - dest: s`components/screen1/screen1.xml` - }, - { - src: s`${rootDir}/manifest`, - dest: s`manifest` - }, - { - src: s`${rootDir}/source/lib.brs`, - dest: s`source/lib.brs` - }, - { - src: s`${rootDir}/source/main.brs`, - dest: s`source/main.brs` - }]); - }); - - it('uses the root of staging folder for dest when not specified with star star', async () => { - writeFiles(otherProjectDir, [ - 'components/component1/subComponent/screen.brs', - 'manifest', - 'source/thirdPartyLib.brs' - ]); - expect(await getFilePaths([{ - src: `${otherProjectDir}/**/*` - }])).to.eql([{ - src: s`${otherProjectDir}/components/component1/subComponent/screen.brs`, - dest: s`components/component1/subComponent/screen.brs` - }, { - src: s`${otherProjectDir}/manifest`, - dest: s`manifest` - }, { - src: s`${otherProjectDir}/source/thirdPartyLib.brs`, - dest: s`source/thirdPartyLib.brs` - }]); - }); - - it('copies absolute path files to specified dest', async () => { - writeFiles(otherProjectDir, [ - 'source/thirdPartyLib.brs' - ]); - expect(await getFilePaths([{ - src: `${otherProjectDir}/source/thirdPartyLib.brs`, - dest: 'lib/thirdPartyLib.brs' - }])).to.eql([{ - src: s`${otherProjectDir}/source/thirdPartyLib.brs`, - dest: s`lib/thirdPartyLib.brs` - }]); - }); - - it('copies relative path files to specified dest', async () => { - const rootDirName = path.basename(rootDir); - writeFiles(rootDir, [ - 'source/main.brs' - ]); - expect(await getFilePaths([{ - src: `../${rootDirName}/source/main.brs`, - dest: 'source/main.brs' - }])).to.eql([{ - src: s`${rootDir}/source/main.brs`, - dest: s`source/main.brs` - }]); - }); - - it('maintains relative path after **', async () => { - writeFiles(otherProjectDir, [ - 'components/component1/subComponent/screen.brs', - 'manifest', - 'source/thirdPartyLib.brs' - ]); - expect(await getFilePaths([{ - src: `../otherProject/**/*`, - dest: 'outFolder/' - }])).to.eql([{ - src: s`${otherProjectDir}/components/component1/subComponent/screen.brs`, - dest: s`outFolder/components/component1/subComponent/screen.brs` - }, { - src: s`${otherProjectDir}/manifest`, - dest: s`outFolder/manifest` - }, { - src: s`${otherProjectDir}/source/thirdPartyLib.brs`, - dest: s`outFolder/source/thirdPartyLib.brs` - }]); - }); - - it('works for other globs', async () => { - expect(await getFilePaths([{ - src: `components/screen1/*creen1.brs`, - dest: s`/source` - }])).to.eql([{ - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`source/screen1.brs` - }]); - }); - - it('applies negated patterns', async () => { - writeFiles(rootDir, [ - 'components/component1.brs', - 'components/component1.xml', - 'components/screen1/screen1.brs', - 'components/screen1/screen1.xml' - ]); - expect(await getFilePaths([ - //include all component brs files - 'components/**/*.brs', - //exclude all xml files - '!components/**/*.xml', - //re-include a specific xml file - 'components/screen1/screen1.xml' - ])).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/screen1/screen1.brs`, - dest: s`components/screen1/screen1.brs` - }, { - src: s`${rootDir}/components/screen1/screen1.xml`, - dest: s`components/screen1/screen1.xml` - }]); - }); - }); - - it('converts relative rootDir path to absolute', async () => { - let stub = sinon.stub(rokuDeploy, 'getOptions').callThrough(); - await getFilePaths([ - 'source/main.brs' - ], './rootDir'); - expect(stub.callCount).to.be.greaterThan(0); - expect(stub.getCall(0).args[0].rootDir).to.eql('./rootDir'); - expect(stub.getCall(0).returnValue.rootDir).to.eql(s`${cwd}/rootDir`); - }); - - it('works when using a different current working directory than rootDir', async () => { - writeFiles(rootDir, [ - 'manifest', - 'images/splash_hd.jpg' - ]); - //sanity check, make sure it works without fiddling with cwd intact - let paths = await getFilePaths([ - 'manifest', - 'images/splash_hd.jpg' - ]); - - expect(paths).to.eql([{ - src: s`${rootDir}/images/splash_hd.jpg`, - dest: s`images/splash_hd.jpg` - }, { - src: s`${rootDir}/manifest`, - dest: s`manifest` - }]); - - //change the working directory and verify everything still works - - let wrongCwd = path.dirname(path.resolve(options.rootDir)); - process.chdir(wrongCwd); - - paths = await getFilePaths([ - 'manifest', - 'images/splash_hd.jpg' - ]); - - expect(paths).to.eql([{ - src: s`${rootDir}/images/splash_hd.jpg`, - dest: s`images/splash_hd.jpg` - }, { - src: s`${rootDir}/manifest`, - dest: s`manifest` - }]); + fsExtra.ensureDirSync(rootDir); + process.chdir(rootDir); }); - - it('supports absolute paths from outside of the rootDir', async () => { - //dest not specified - expect(await getFilePaths([{ - src: sp`${cwd}/README.md` - }], options.rootDir)).to.eql([{ - src: s`${cwd}/README.md`, - dest: s`README.md` - }]); - - //dest specified - expect(await getFilePaths([{ - src: sp`${cwd}/README.md`, - dest: 'docs/README.md' - }], options.rootDir)).to.eql([{ - src: s`${cwd}/README.md`, - dest: s`docs/README.md` - }]); - - let paths: any[]; - - paths = await getFilePaths([{ - src: sp`${cwd}/README.md`, - dest: s`docs/README.md` - }], outDir); - - expect(paths).to.eql([{ - src: s`${cwd}/README.md`, - dest: s`docs/README.md` - }]); - - //top-level string paths pointing to files outside the root should thrown an exception - await expectThrowsAsync(async () => { - paths = await getFilePaths([ - sp`${cwd}/README.md` - ], outDir); + it('should fill in options from rokudeploy.json', () => { + fsExtra.writeJsonSync(s`${rootDir}/rokudeploy.json`, { password: 'password' }); + expect( + util.getOptionsFromJson({ cwd: rootDir }) + ).to.eql({ + password: 'password' }); }); - it('supports relative paths that grab files from outside of the rootDir', async () => { - writeFiles(`${rootDir}/../`, [ - 'README.md' - ]); - expect( - await getFilePaths([{ - src: sp`../README.md` - }], rootDir) - ).to.eql([{ - src: s`${rootDir}/../README.md`, - dest: s`README.md` - }]); - + it(`can't find file`, () => { + fsExtra.writeJsonSync(s`${rootDir}/rokudeployed.json`, { host: '1.2.3.4' }); expect( - await getFilePaths([{ - src: sp`../README.md`, - dest: 'docs/README.md' - }], rootDir) - ).to.eql([{ - src: s`${rootDir}/../README.md`, - dest: s`docs/README.md` - }]); - }); - - it('should throw exception because we cannot have top-level string paths pointed to files outside the root', async () => { - writeFiles(rootDir, [ - '../README.md' - ]); - await expectThrowsAsync( - getFilePaths([ - path.posix.join('..', 'README.md') - ], outDir) - ); - }); + util.getOptionsFromJson({ cwd: rootDir }) + ).to.eql(undefined); - it('supports overriding paths', async () => { - let paths = await getFilePaths([{ - src: sp`${rootDir}/components/component1.brs`, - dest: 'comp1.brs' - }, { - src: sp`${rootDir}/components/screen1/screen1.brs`, - dest: 'comp1.brs' - }], rootDir); - expect(paths).to.be.lengthOf(1); - expect(s`${paths[0].src}`).to.equal(s`${rootDir}/components/screen1/screen1.brs`); }); - it('supports overriding paths from outside the root dir', async () => { - let thisRootDir = s`${tempDir}/tempTestOverrides/src`; + it(`loads cwd from process`, () => { try { - - fsExtra.ensureDirSync(s`${thisRootDir}/source`); - fsExtra.ensureDirSync(s`${thisRootDir}/components`); - fsExtra.ensureDirSync(s`${thisRootDir}/../.tmp`); - - fsExtra.writeFileSync(s`${thisRootDir}/source/main.brs`, ''); - fsExtra.writeFileSync(s`${thisRootDir}/components/MainScene.brs`, ''); - fsExtra.writeFileSync(s`${thisRootDir}/components/MainScene.xml`, ''); - fsExtra.writeFileSync(s`${thisRootDir}/../.tmp/MainScene.brs`, ''); - - let files = [ - '**/*.xml', - '**/*.brs', - { - src: '../.tmp/MainScene.brs', - dest: 'components/MainScene.brs' - } - ]; - let paths = await getFilePaths(files, thisRootDir); - - //the MainScene.brs file from source should NOT be included - let mainSceneEntries = paths.filter(x => s`${x.dest}` === s`components/MainScene.brs`); expect( mainSceneEntries, `Should only be one files entry for 'components/MainScene.brs'` @@ -1064,84 +484,6 @@ describe('util', () => { //clean up await fsExtra.remove(s`${thisRootDir}/../`); } - }); - - it('maintains original file path', async () => { - fsExtra.outputFileSync(`${rootDir}/components/CustomButton.brs`, ''); - expect( - await getFilePaths([ - 'components/CustomButton.brs' - ], rootDir) - ).to.eql([{ - src: s`${rootDir}/components/CustomButton.brs`, - dest: s`components/CustomButton.brs` - }]); - }); - - it('correctly assumes file path if not given', async () => { - fsExtra.outputFileSync(`${rootDir}/components/CustomButton.brs`, ''); - expect( - (await getFilePaths([ - { src: 'components/*' } - ], rootDir)).sort((a, b) => a.src.localeCompare(b.src)) - ).to.eql([{ - src: s`${rootDir}/components/component1.brs`, - dest: s`components/component1.brs` - }, { - src: s`${rootDir}/components/component1.xml`, - dest: s`components/component1.xml` - }, { - src: s`${rootDir}/components/CustomButton.brs`, - dest: s`components/CustomButton.brs` - }]); - }); - }); - - describe('getOptionsFromJson', () => { - beforeEach(() => { - fsExtra.ensureDirSync(rootDir); - process.chdir(rootDir); - }); - it('should fill in missing options from rokudeploy.json', () => { - fsExtra.writeJsonSync(s`${rootDir}/rokudeploy.json`, { password: 'password' }); - let options = util.getOptionsFromJson({ - rootDir: `${rootDir}`, - host: '1.2.3.4' - }); - let expectedOutput = { - rootDir: `${rootDir}`, - host: '1.2.3.4', - password: 'password' - }; - expect(options).to.eql(expectedOutput); - }); - - it('should fill in missing default options from bsconfig.json', () => { - fsExtra.writeJsonSync(s`${rootDir}/bsconfig.json`, { password: 'password' }); - let options = util.getOptionsFromJson({ - rootDir: `${rootDir}`, - host: '1.2.3.4' - }); - let expectedOutput = { - rootDir: `${rootDir}`, - host: '1.2.3.4', - password: 'password' - }; - expect(options).to.eql(expectedOutput); - - }); - - it('should not replace default options', () => { - fsExtra.writeJsonSync(s`${rootDir}/rokudeploy.json`, { host: '4.3.2.1' }); - let options = util.getOptionsFromJson({ - rootDir: `${rootDir}`, - host: '1.2.3.4' - }); - let expectedOutput = { - rootDir: `${rootDir}`, - host: '1.2.3.4', - }; - expect(options).to.eql(expectedOutput); }); });