From 43446661cf3ac18fd6bb1b96f552a1395fbf2f9e Mon Sep 17 00:00:00 2001 From: Milap Naik Date: Tue, 5 Mar 2024 23:36:44 -0500 Subject: [PATCH] delete unnecessary commands, fix some tests --- src/RokuDeploy.spec.ts | 40 ++++++++++----------- src/RokuDeploy.ts | 8 ++--- src/RokuDeployOptions.ts | 5 +++ src/cli.ts | 27 +++----------- src/commands/GetOutputPkgFilePathCommand.ts | 13 ------- src/commands/GetOutputZipFilePathCommand.ts | 13 ------- 6 files changed, 33 insertions(+), 73 deletions(-) delete mode 100644 src/commands/GetOutputPkgFilePathCommand.ts delete mode 100644 src/commands/GetOutputZipFilePathCommand.ts diff --git a/src/RokuDeploy.spec.ts b/src/RokuDeploy.spec.ts index 9f51329..59eec4f 100644 --- a/src/RokuDeploy.spec.ts +++ b/src/RokuDeploy.spec.ts @@ -1877,35 +1877,35 @@ describe('index', () => { describe('normalizeFilesArray', () => { it('catches invalid dest entries', () => { expect(() => { - rokuDeploy['normalizeFilesArray']([{ + util['normalizeFilesArray']([{ src: 'some/path', dest: true }]); }).to.throw(); expect(() => { - rokuDeploy['normalizeFilesArray']([{ + util['normalizeFilesArray']([{ src: 'some/path', dest: false }]); }).to.throw(); expect(() => { - rokuDeploy['normalizeFilesArray']([{ + util['normalizeFilesArray']([{ src: 'some/path', dest: /asdf/gi }]); }).to.throw(); expect(() => { - rokuDeploy['normalizeFilesArray']([{ + util['normalizeFilesArray']([{ src: 'some/path', dest: {} }]); }).to.throw(); expect(() => { - rokuDeploy['normalizeFilesArray']([{ + util['normalizeFilesArray']([{ src: 'some/path', dest: [] }]); @@ -1913,7 +1913,7 @@ describe('index', () => { }); it('normalizes directory separators paths', () => { - expect(rokuDeploy['normalizeFilesArray']([{ + expect(util['normalizeFilesArray']([{ src: `long/source/path`, dest: `long/dest/path` }])).to.eql([{ @@ -1923,7 +1923,7 @@ describe('index', () => { }); it('works for simple strings', () => { - expect(rokuDeploy['normalizeFilesArray']([ + expect(util['normalizeFilesArray']([ 'manifest', 'source/main.brs' ])).to.eql([ @@ -1933,7 +1933,7 @@ describe('index', () => { }); it('works for negated strings', () => { - expect(rokuDeploy['normalizeFilesArray']([ + expect(util['normalizeFilesArray']([ '!.git' ])).to.eql([ '!.git' @@ -1941,7 +1941,7 @@ describe('index', () => { }); it('skips falsey and bogus entries', () => { - expect(rokuDeploy['normalizeFilesArray']([ + expect(util['normalizeFilesArray']([ '', 'manifest', false, @@ -1953,7 +1953,7 @@ describe('index', () => { }); it('works for {src:string} objects', () => { - expect(rokuDeploy['normalizeFilesArray']([ + expect(util['normalizeFilesArray']([ { src: 'manifest' } @@ -1964,7 +1964,7 @@ describe('index', () => { }); it('works for {src:string[]} objects', () => { - expect(rokuDeploy['normalizeFilesArray']([ + expect(util['normalizeFilesArray']([ { src: [ 'manifest', @@ -1981,7 +1981,7 @@ describe('index', () => { }); it('retains dest option', () => { - expect(rokuDeploy['normalizeFilesArray']([ + expect(util['normalizeFilesArray']([ { src: 'source/config.dev.brs', dest: 'source/config.brs' @@ -1993,14 +1993,14 @@ describe('index', () => { }); it('throws when encountering invalid entries', () => { - expect(() => rokuDeploy['normalizeFilesArray']([true])).to.throw(); - expect(() => rokuDeploy['normalizeFilesArray']([/asdf/])).to.throw(); - expect(() => rokuDeploy['normalizeFilesArray']([new Date()])).to.throw(); - expect(() => rokuDeploy['normalizeFilesArray']([1])).to.throw(); - expect(() => rokuDeploy['normalizeFilesArray']([{ src: true }])).to.throw(); - expect(() => rokuDeploy['normalizeFilesArray']([{ src: /asdf/ }])).to.throw(); - expect(() => rokuDeploy['normalizeFilesArray']([{ src: new Date() }])).to.throw(); - expect(() => rokuDeploy['normalizeFilesArray']([{ src: 1 }])).to.throw(); + expect(() => util['normalizeFilesArray']([true])).to.throw(); + expect(() => util['normalizeFilesArray']([/asdf/])).to.throw(); + expect(() => util['normalizeFilesArray']([new Date()])).to.throw(); + expect(() => util['normalizeFilesArray']([1])).to.throw(); + expect(() => util['normalizeFilesArray']([{ src: true }])).to.throw(); + expect(() => util['normalizeFilesArray']([{ src: /asdf/ }])).to.throw(); + expect(() => util['normalizeFilesArray']([{ src: new Date() }])).to.throw(); + expect(() => util['normalizeFilesArray']([{ src: 1 }])).to.throw(); }); }); diff --git a/src/RokuDeploy.ts b/src/RokuDeploy.ts index 91d02a9..29055ab 100644 --- a/src/RokuDeploy.ts +++ b/src/RokuDeploy.ts @@ -69,7 +69,7 @@ export class RokuDeploy { * Given an already-populated staging folder, create a zip archive of it and copy it to the output folder * @param options */ - public async zip(options: ZipPackageOptions) { + public async zip(options: ZipOptions) { options = this.getOptions(options) as any; //make sure the output folder exists @@ -708,8 +708,8 @@ export class RokuDeploy { this.logger.logLevel = finalOptions.logLevel; //TODO: Handle logging differently //fully resolve the folder paths - finalOptions.rootDir = path.resolve(options.cwd, finalOptions.rootDir); - finalOptions.outDir = path.resolve(options.cwd, finalOptions.outDir); + finalOptions.rootDir = path.resolve(finalOptions.cwd, finalOptions.rootDir); + finalOptions.outDir = path.resolve(finalOptions.cwd, finalOptions.outDir); //stagingDir if (options.stagingDir) { @@ -1003,7 +1003,7 @@ export interface StageOptions { retainStagingDir?: boolean; } -export interface ZipPackageOptions { +export interface ZipOptions { stagingDir?: string; outDir?: string; } diff --git a/src/RokuDeployOptions.ts b/src/RokuDeployOptions.ts index dc1b4ff..a70b766 100644 --- a/src/RokuDeployOptions.ts +++ b/src/RokuDeployOptions.ts @@ -1,6 +1,11 @@ import type { LogLevel } from './Logger'; export interface RokuDeployOptions { + /** + * The working directory where the command should be executed + */ + cwd?: string; + /** * Path to a bsconfig.json project file */ diff --git a/src/cli.ts b/src/cli.ts index f3c3ead..360ec35 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -10,8 +10,6 @@ import { RekeyDeviceCommand } from './commands/RekeyDeviceCommand'; import { CreateSignedPackageCommand } from './commands/CreateSignedPackageCommand'; import { DeleteDevChannelCommand } from './commands/DeleteDevChannelCommand'; import { TakeScreenshotCommand } from './commands/TakeScreenshotCommand'; -import { GetOutputZipFilePathCommand } from './commands/GetOutputZipFilePathCommand'; -import { GetOutputPkgFilePathCommand } from './commands/GetOutputPkgFilePathCommand'; import { GetDeviceInfoCommand } from './commands/GetDeviceInfoCommand'; import { GetDevIdCommand } from './commands/GetDevIdCommand'; import { ZipCommand } from './commands/ZipCommand'; @@ -172,23 +170,6 @@ void yargs return new TakeScreenshotCommand().run(args); }) - .command('getOutputZipFilePath', 'Centralizes getting output zip file path based on passed in options', (builder) => { - return builder - .option('outFile', { type: 'string', description: 'The output file', demandOption: false }) - .option('outDir', { type: 'string', description: 'The output directory', demandOption: false }); - return builder; - }, (args: any) => { - return new GetOutputZipFilePathCommand().run(args); - }) - - .command('getOutputPkgFilePath', 'Centralizes getting output pkg file path based on passed in options', (builder) => { - return builder - .option('outFile', { type: 'string', description: 'The output file', demandOption: false }) - .option('outDir', { type: 'string', description: 'The output directory', demandOption: false }); - }, (args: any) => { - return new GetOutputPkgFilePathCommand().run(args); - }) - .command(['getDeviceInfo', 'deviceinfo'], 'Get the `device-info` response from a Roku device', (builder) => { return builder .option('host', { type: 'string', description: 'The IP Address of the host Roku', demandOption: false }); @@ -203,13 +184,13 @@ void yargs return new GetDevIdCommand().run(args); }) - .command('zipFolder', 'Given a path to a folder, zip up that folder and all of its contents', (builder) => { + .command('zip', 'Given a path to a folder, zip up that folder and all of its contents', (builder) => { return builder - .option('srcFolder', { type: 'string', description: 'The folder that should be zipped', demandOption: false }) - .option('zipFilePath', { type: 'string', description: 'The path to the zip that will be created. Must be .zip file name', demandOption: false }); + .option('stagingDir', { type: 'string', description: 'The folder that should be zipped', demandOption: false }) + .option('outDir', { type: 'string', description: 'The path to the zip that will be created. Must be .zip file name', demandOption: false }); }, (args: any) => { console.log('args', args); - return new ZipFolderCommand().run(args); + return new ZipCommand().run(args); }) .argv; diff --git a/src/commands/GetOutputPkgFilePathCommand.ts b/src/commands/GetOutputPkgFilePathCommand.ts deleted file mode 100644 index 3bfc2d0..0000000 --- a/src/commands/GetOutputPkgFilePathCommand.ts +++ /dev/null @@ -1,13 +0,0 @@ -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'](options); //TODO fix this? - console.log(outputPath); - } -} diff --git a/src/commands/GetOutputZipFilePathCommand.ts b/src/commands/GetOutputZipFilePathCommand.ts deleted file mode 100644 index c5761c0..0000000 --- a/src/commands/GetOutputZipFilePathCommand.ts +++ /dev/null @@ -1,13 +0,0 @@ -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'](options); - console.log(outputPath); - } -}