Skip to content

Commit 519541f

Browse files
Support overriding various package upload form data (#136)
* Support overriding various package upload form data * adds support for squashfs deployments --------- Co-authored-by: George Cook <[email protected]>
1 parent a5e3600 commit 519541f

4 files changed

Lines changed: 83 additions & 14 deletions

File tree

package-lock.json

Lines changed: 20 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RokuDeploy.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,34 @@ describe('index', () => {
919919
} catch (e) { }
920920
});
921921

922+
it('uses overridden route', async () => {
923+
const stub = mockDoPostRequest();
924+
await rokuDeploy.publish({
925+
...options,
926+
packageUploadOverrides: {
927+
route: 'alt_path'
928+
}
929+
});
930+
expect(stub.getCall(0).args[0].url).to.eql('http://0.0.0.0:80/alt_path');
931+
});
932+
933+
it('overrides formData', async () => {
934+
const stub = mockDoPostRequest();
935+
await rokuDeploy.publish({
936+
...options,
937+
remoteDebug: true,
938+
packageUploadOverrides: {
939+
formData: {
940+
remotedebug: null,
941+
newfield: 'here'
942+
}
943+
}
944+
});
945+
expect(stub.getCall(0).args[0].formData).to.include({
946+
newfield: 'here'
947+
}).and.to.not.haveOwnProperty('remotedebug');
948+
});
949+
922950
it('does not delete the archive by default', async () => {
923951
let zipPath = `${options.outDir}/${options.outFile}`;
924952

@@ -2230,6 +2258,9 @@ describe('index', () => {
22302258
it('rejects the promise when an error occurs', async () => {
22312259
//zip path doesn't exist
22322260
await assertThrowsAsync(async () => {
2261+
sinon.stub(fsExtra, 'outputFile').callsFake(() => {
2262+
throw new Error();
2263+
});
22332264
await rokuDeploy.zipFolder('source', '.tmp/some/zip/path/that/does/not/exist');
22342265
});
22352266
});

src/RokuDeploy.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class RokuDeploy {
142142
if (options.incrementBuildNumber) {
143143
let timestamp = dateformat(new Date(), 'yymmddHHMM');
144144
parsedManifest.build_version = timestamp; //eslint-disable-line camelcase
145-
await this.fsExtra.writeFile(manifestPath, this.stringifyManifest(parsedManifest));
145+
await this.fsExtra.outputFile(manifestPath, this.stringifyManifest(parsedManifest));
146146
}
147147

148148
if (beforeZipCallback) {
@@ -433,7 +433,9 @@ export class RokuDeploy {
433433
readStream.on('open', resolve);
434434
});
435435

436-
let requestOptions = this.generateBaseRequestOptions('plugin_install', options, {
436+
const route = options.packageUploadOverrides?.route ?? 'plugin_install';
437+
438+
let requestOptions = this.generateBaseRequestOptions(route, options, {
437439
mysubmit: 'Replace',
438440
archive: readStream
439441
});
@@ -449,6 +451,16 @@ export class RokuDeploy {
449451
requestOptions.formData.remotedebug_connect_early = '1';
450452
}
451453

454+
//apply any supplied formData overrides
455+
for (const key in options.packageUploadOverrides?.formData ?? {}) {
456+
const value = options.packageUploadOverrides.formData[key];
457+
if (value === undefined || value === null) {
458+
delete requestOptions.formData[key];
459+
} else {
460+
requestOptions.formData[key] = value;
461+
}
462+
}
463+
452464
//try to "replace" the channel first since that usually works.
453465
let response: HttpResponse;
454466
try {
@@ -985,7 +997,7 @@ export class RokuDeploy {
985997
options = this.getOptions(options);
986998

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

src/RokuDeployOptions.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ export interface RokuDeployOptions {
158158
* If true, the previously installed dev channel will be deleted before installing the new one
159159
*/
160160
deleteInstalledChannel?: boolean;
161+
162+
/**
163+
* Overrides for values used during the zip upload process. You probably don't need to change these...
164+
*/
165+
packageUploadOverrides?: {
166+
/**
167+
* The route to use for uploading to the Roku device. Defaults to 'plugin_install'
168+
* @default 'plugin_install'
169+
*/
170+
route?: string;
171+
172+
/**
173+
* A dictionary of form fields to be included in the package upload request. Set a value to null to delete from the form
174+
*/
175+
formData?: Record<string, any>;
176+
};
161177
}
162178

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

0 commit comments

Comments
 (0)