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

Support overriding various package upload form data #136

Merged
merged 3 commits into from
Mar 1, 2024
Merged
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
30 changes: 20 additions & 10 deletions package-lock.json

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

31 changes: 31 additions & 0 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,34 @@ describe('index', () => {
} catch (e) { }
});

it('uses overridden route', async () => {
const stub = mockDoPostRequest();
await rokuDeploy.publish({
...options,
packageUploadOverrides: {
route: 'alt_path'
}
});
expect(stub.getCall(0).args[0].url).to.eql('http://0.0.0.0:80/alt_path');
});

it('overrides formData', async () => {
const stub = mockDoPostRequest();
await rokuDeploy.publish({
...options,
remoteDebug: true,
packageUploadOverrides: {
formData: {
remotedebug: null,
newfield: 'here'
}
}
});
expect(stub.getCall(0).args[0].formData).to.include({
newfield: 'here'
}).and.to.not.haveOwnProperty('remotedebug');
});

it('does not delete the archive by default', async () => {
let zipPath = `${options.outDir}/${options.outFile}`;

Expand Down Expand Up @@ -2230,6 +2258,9 @@ describe('index', () => {
it('rejects the promise when an error occurs', async () => {
//zip path doesn't exist
await assertThrowsAsync(async () => {
sinon.stub(fsExtra, 'outputFile').callsFake(() => {
throw new Error();
});
await rokuDeploy.zipFolder('source', '.tmp/some/zip/path/that/does/not/exist');
});
});
Expand Down
20 changes: 16 additions & 4 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class RokuDeploy {
if (options.incrementBuildNumber) {
let timestamp = dateformat(new Date(), 'yymmddHHMM');
parsedManifest.build_version = timestamp; //eslint-disable-line camelcase
await this.fsExtra.writeFile(manifestPath, this.stringifyManifest(parsedManifest));
await this.fsExtra.outputFile(manifestPath, this.stringifyManifest(parsedManifest));
}

if (beforeZipCallback) {
Expand Down Expand Up @@ -433,7 +433,9 @@ export class RokuDeploy {
readStream.on('open', resolve);
});

let requestOptions = this.generateBaseRequestOptions('plugin_install', options, {
const route = options.packageUploadOverrides?.route ?? 'plugin_install';

let requestOptions = this.generateBaseRequestOptions(route, options, {
mysubmit: 'Replace',
archive: readStream
});
Expand All @@ -449,6 +451,16 @@ export class RokuDeploy {
requestOptions.formData.remotedebug_connect_early = '1';
}

//apply any supplied formData overrides
for (const key in options.packageUploadOverrides?.formData ?? {}) {
const value = options.packageUploadOverrides.formData[key];
if (value === undefined || value === null) {
delete requestOptions.formData[key];
} else {
requestOptions.formData[key] = value;
}
}

//try to "replace" the channel first since that usually works.
let response: HttpResponse;
try {
Expand Down Expand Up @@ -985,7 +997,7 @@ export class RokuDeploy {
options = this.getOptions(options);

let zipFileName = options.outFile;
if (!zipFileName.toLowerCase().endsWith('.zip')) {
if (!zipFileName.toLowerCase().endsWith('.zip') && !zipFileName.toLowerCase().endsWith('.squashfs')) {
zipFileName += '.zip';
}
let outFolderPath = path.resolve(options.outDir);
Expand Down Expand Up @@ -1170,7 +1182,7 @@ export class RokuDeploy {
await Promise.all(promises);
// level 2 compression seems to be the best balance between speed and file size. Speed matters more since most will be calling squashfs afterwards.
const content = await zip.generateAsync({ type: 'nodebuffer', compressionOptions: { level: 2 } });
return this.fsExtra.writeFile(zipFilePath, content);
return this.fsExtra.outputFile(zipFilePath, content);
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/RokuDeployOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ export interface RokuDeployOptions {
* If true, the previously installed dev channel will be deleted before installing the new one
*/
deleteInstalledChannel?: boolean;

/**
* Overrides for values used during the zip upload process. You probably don't need to change these...
*/
packageUploadOverrides?: {
/**
* The route to use for uploading to the Roku device. Defaults to 'plugin_install'
* @default 'plugin_install'
*/
route?: string;

/**
* A dictionary of form fields to be included in the package upload request. Set a value to null to delete from the form
*/
formData?: Record<string, any>;
};
}

export type FileEntry = (string | { src: string | string[]; dest?: string });