Skip to content

Commit

Permalink
Add stagingDir, fix zip/deleteDevChannel/captureScreenshot function c…
Browse files Browse the repository at this point in the history
…alls, delete Deploy function
  • Loading branch information
MilapNaik committed Mar 4, 2024
1 parent 2858dd6 commit 3186e88
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 101 deletions.
9 changes: 4 additions & 5 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as path from 'path';
import * as JSZip from 'jszip';
import * as child_process from 'child_process';
import * as glob from 'glob';
import type { BeforeZipCallbackInfo } from './RokuDeploy';
import { RokuDeploy } from './RokuDeploy';
import * as errors from './Errors';
import { util, standardizePath as s, standardizePathPosix as sp } from './util';
Expand Down Expand Up @@ -2023,8 +2022,8 @@ describe('index', () => {
expect(result).not.to.be.undefined;
});

it('continues with deploy if deleteInstalledChannel fails', async () => {
sinon.stub(rokuDeploy, 'deleteInstalledChannel').returns(
it('continues with deploy if deleteDevChannel fails', async () => {
sinon.stub(rokuDeploy, 'deleteDevChannel').returns(
Promise.reject(
new Error('failed')
)
Expand All @@ -2043,7 +2042,7 @@ describe('index', () => {
it('should delete installed channel if requested', async () => {
fsExtra.outputFileSync(s`${rootDir}/manifest`, '');

const spy = sinon.spy(rokuDeploy, 'deleteInstalledChannel');
const spy = sinon.spy(rokuDeploy, 'deleteDevChannel');
options.deleteInstalledChannel = true;
mockDoPostRequest();

Expand All @@ -2060,7 +2059,7 @@ describe('index', () => {
it('should not delete installed channel if not requested', async () => {
fsExtra.outputFileSync(s`${rootDir}/manifest`, '');

const spy = sinon.spy(rokuDeploy, 'deleteInstalledChannel');
const spy = sinon.spy(rokuDeploy, 'deleteDevChannel');
mockDoPostRequest();

await rokuDeploy.deploy({
Expand Down
21 changes: 8 additions & 13 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ export class RokuDeploy {
await fsExtra.ensureDir(options.stagingDir);
// await this.copyToStaging(options.files, options.stagingDir, options.rootDir);

if (!stagingPath) {
if (!options.stagingDir) {
throw new Error('stagingPath is required');
}
if (!await fsExtra.pathExists(rootDir)) {
throw new Error(`rootDir does not exist at "${rootDir}"`);
if (!await fsExtra.pathExists(options.rootDir)) {
throw new Error(`rootDir does not exist at "${options.rootDir}"`);
}

let fileObjects = await util.getFilePaths(options.files, rootDir);
let fileObjects = await util.getFilePaths(options.files, options.rootDir);
//copy all of the files
await Promise.all(fileObjects.map(async (fileObject) => {
let destFilePath = util.standardizePath(`${stagingPath}/${fileObject.dest}`);
let destFilePath = util.standardizePath(`${options.stagingDir}/${fileObject.dest}`);

//make sure the containing folder exists
await fsExtra.ensureDir(path.dirname(destFilePath));
Expand Down Expand Up @@ -644,6 +644,7 @@ export class RokuDeploy {
let defaultOptions = <RokuDeployOptions>{
outDir: './out',
outFile: 'roku-deploy',
stagingDir: `./out/.roku-deploy-staging`,
retainDeploymentArchive: true,
incrementBuildNumber: false,
failOnCompileError: true,
Expand All @@ -668,16 +669,14 @@ export class RokuDeploy {
let stagingDir = finalOptions.stagingDir || finalOptions.stagingFolderPath;

//stagingDir
if (stagingDir) {
finalOptions.stagingDir = path.resolve(process.cwd(), stagingDir);
if (options.stagingDir) {
finalOptions.stagingDir = path.resolve(options.cwd, options.stagingDir);
} else {
finalOptions.stagingDir = path.resolve(
process.cwd(),
util.standardizePath(`${finalOptions.outDir}/.roku-deploy-staging`)
);
}
//sync the new option with the old one (for back-compat)
finalOptions.stagingFolderPath = finalOptions.stagingDir;

return finalOptions;
}
Expand Down Expand Up @@ -867,10 +866,6 @@ export interface BeforeZipCallbackInfo {
* Contains an associative array of the parsed values in the manifest
*/
manifestData: ManifestData;
/**
* @deprecated since 3.9.0. use `stagingDir` instead
*/
stagingFolderPath: string;
/**
* The directory where the files were staged
*/
Expand Down
6 changes: 0 additions & 6 deletions src/RokuDeployOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ export interface RokuDeployOptions {
*/
retainDeploymentArchive?: boolean;

/**
* The path where roku-deploy should stage all of the files right before being zipped. defaults to ${outDir}/.roku-deploy-staging
* @deprecated since 3.9.0. use `stagingDir` instead
*/
stagingFolderPath?: string;

/**
* The path where roku-deploy should stage all of the files right before being zipped. defaults to ${outDir}/.roku-deploy-staging
*/
Expand Down
33 changes: 4 additions & 29 deletions src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { PublishCommand } from './commands/PublishCommand';
import { ConvertToSquashfsCommand } from './commands/ConvertToSquashfsCommand';
import { RekeyDeviceCommand } from './commands/RekeyDeviceCommand';
import { CreateSignedPackageCommand } from './commands/CreateSignedPackageCommand';
import { DeployCommand } from './commands/DeployCommand';
import { DeleteInstalledChannelCommand } from './commands/DeleteInstalledChannelCommand';
import { DeleteDevChannelCommand } from './commands/DeleteDevChannelCommand';
import { TakeScreenshotCommand } from './commands/TakeScreenshotCommand';
import { GetDeviceInfoCommand } from './commands/GetDeviceInfoCommand';
import { GetDevIdCommand } from './commands/GetDevIdCommand';
Expand Down Expand Up @@ -162,36 +161,12 @@ describe('cli', () => {
});
});

it('Deploys a package', async () => {
const stub = sinon.stub(rokuDeploy, 'deploy').callsFake(async () => {
return Promise.resolve({
message: 'Convert successful',
results: {}
});
});

const command = new DeployCommand();
await command.run({
host: '1.2.3.4',
password: '5536',
rootDir: rootDir
});

expect(
stub.getCall(0).args[0]
).to.eql({
host: '1.2.3.4',
password: '5536',
rootDir: rootDir
});
});

it('Deletes an installed channel', async () => {
const stub = sinon.stub(rokuDeploy, 'deleteInstalledChannel').callsFake(async () => {
const stub = sinon.stub(rokuDeploy, 'deleteDevChannel').callsFake(async () => {
return Promise.resolve({ response: {}, body: {} });
});

const command = new DeleteInstalledChannelCommand();
const command = new DeleteDevChannelCommand();
await command.run({
host: '1.2.3.4',
password: '5536'
Expand All @@ -206,7 +181,7 @@ describe('cli', () => {
});

it('Takes a screenshot', async () => {
const stub = sinon.stub(rokuDeploy, 'takeScreenshot').callsFake(async () => {
const stub = sinon.stub(rokuDeploy, 'captureScreenshot').callsFake(async () => {
return Promise.resolve('');
});

Expand Down
5 changes: 2 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import { PublishCommand } from './commands/PublishCommand';
import { ConvertToSquashfsCommand } from './commands/ConvertToSquashfsCommand';
import { RekeyDeviceCommand } from './commands/RekeyDeviceCommand';
import { CreateSignedPackageCommand } from './commands/CreateSignedPackageCommand';
import { DeployCommand } from './commands/DeployCommand';
import { DeleteInstalledChannelCommand } from './commands/DeleteInstalledChannelCommand';
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 { ZipFolderCommand } from './commands/ZipFolderCommand';
import { ZipCommand } from './commands/ZipCommand';

void yargs

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rokuDeploy } from '../index';

export class DeleteInstalledChannelCommand {
export class DeleteDevChannelCommand {
async run(args) {
await rokuDeploy.deleteDevChannel({
host: args.host,
Expand Down
11 changes: 0 additions & 11 deletions src/commands/DeployCommand.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/commands/ZipCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { rokuDeploy } from '../index';

export class ZipCommand {
async run(args) {
await rokuDeploy.zip({
stagingDir: args.stagingDir,
outDir: args.outDir
});
}
}
10 changes: 0 additions & 10 deletions src/commands/ZipFolderCommand.ts

This file was deleted.

10 changes: 6 additions & 4 deletions src/commands/ZipPackageCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { rokuDeploy } from '../index';
import { util } from '../util';

export class ZipPackageCommand {
async run(args) {
await rokuDeploy.zip({
stagingDir: args.stagingDir,
outDir: args.outDir
});
const options = {
...util.getOptionsFromJson(),
...args
};
await rokuDeploy.zip(options);
}
}
21 changes: 2 additions & 19 deletions src/device.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as assert from 'assert';
import * as fsExtra from 'fs-extra';
import type { RokuDeployOptions } from './index';
import { rokuDeploy } from './index';
import { cwd, expectThrowsAsync, outDir, rootDir, tempDir, writeFiles } from './testUtils.spec';
import { cwd, outDir, rootDir, tempDir, writeFiles } from './testUtils.spec';
import * as dedent from 'dedent';

//these tests are run against an actual roku device. These cannot be enabled when run on the CI server
Expand Down Expand Up @@ -62,21 +61,5 @@ describe('device', function device() {
});

this.timeout(20000);

describe('deploy', () => {
it('works', async () => {
options.retainDeploymentArchive = true;
let response = await rokuDeploy.deploy(options as any);
assert.equal(response.message, 'Successful deploy');
});

it('Presents nice message for 401 unauthorized status code', async () => {
this.timeout(20000);
options.password = 'NOT_THE_PASSWORD';
await expectThrowsAsync(
rokuDeploy.deploy(options as any),
'Unauthorized. Please verify username and password for target Roku.'
);
});
});
console.log(options); // So there are no errors about unused variable
});

0 comments on commit 3186e88

Please sign in to comment.