diff --git a/src/RokuDeploy.spec.ts b/src/RokuDeploy.spec.ts index a8f4032..ea25416 100644 --- a/src/RokuDeploy.spec.ts +++ b/src/RokuDeploy.spec.ts @@ -1535,7 +1535,6 @@ describe('index', () => { 'manifest', 'components/!(scenes)/**/*' ], - retainStagingDir: true, rootDir: rootDir, stagingDir: stagingDir }); @@ -1557,7 +1556,6 @@ describe('index', () => { 'components/**/*', '!components/scenes/**/*' ], - retainStagingDir: true, rootDir: rootDir, stagingDir: stagingDir }); @@ -1572,7 +1570,6 @@ describe('index', () => { 'manifest', {} ], - retainStagingDir: true, rootDir: rootDir, stagingDir: stagingDir }); @@ -2235,50 +2232,6 @@ describe('index', () => { }); }); - it('allows modification of file contents with callback', async () => { - writeFiles(rootDir, [ - 'components/components/Loader/Loader.brs', - 'images/splash_hd.jpg', - 'source/main.brs', - 'manifest' - ]); - const stageFolder = path.join(tempDir, 'testProject'); - fsExtra.ensureDirSync(stageFolder); - const files = [ - 'components/components/Loader/Loader.brs', - 'images/splash_hd.jpg', - 'source/main.brs', - 'manifest' - ]; - for (const file of files) { - fsExtra.copySync(path.join(options.rootDir, file), path.join(stageFolder, file)); - } - - const outputZipPath = path.join(tempDir, 'output.zip'); - const addedManifestLine = 'bs_libs_required=roku_ads_lib'; - await rokuDeploy['makeZip'](stageFolder, outputZipPath, (file, data) => { - if (file.dest === 'manifest') { - let manifestContents = data.toString(); - manifestContents += addedManifestLine; - data = Buffer.from(manifestContents, 'utf8'); - } - return data; - }); - - const data = fsExtra.readFileSync(outputZipPath); - const zip = await JSZip.loadAsync(data); - for (const file of files) { - const zipFileContents = await zip.file(file.toString()).async('string'); - const sourcePath = path.join(options.rootDir, file); - const incomingContents = fsExtra.readFileSync(sourcePath, 'utf8'); - if (file === 'manifest') { - expect(zipFileContents).to.contain(addedManifestLine); - } else { - expect(zipFileContents).to.equal(incomingContents); - } - } - }); - it('filters the folders before making the zip', async () => { const files = [ 'components/MainScene.brs', @@ -2291,7 +2244,7 @@ describe('index', () => { writeFiles(stagingDir, files); const outputZipPath = path.join(tempDir, 'output.zip'); - await rokuDeploy['makeZip'](stagingDir, outputZipPath, null, ['**/*', '!**/*.map']); + await rokuDeploy['makeZip'](stagingDir, outputZipPath, ['**/*', '!**/*.map']); const data = fsExtra.readFileSync(outputZipPath); const zip = await JSZip.loadAsync(data); @@ -2307,6 +2260,64 @@ describe('index', () => { ].sort().filter(x => !x.endsWith('.map')) ); }); + + it('should create zip in proper directory', async () => { + const outputZipPath = path.join(outDir, 'output.zip'); + await rokuDeploy['makeZip'](rootDir, outputZipPath, ['**/*', '!**/*.map']); + expectPathExists(rokuDeploy['getOutputZipFilePath']({ outDir: outDir, outFile: 'output.zip' })); + }); + + it('should only include the specified files', async () => { + await rokuDeploy.stage({ + files: [ + 'manifest' + ], + stagingDir: stagingDir, + rootDir: rootDir + }); + + await rokuDeploy.zip({ + stagingDir: stagingDir, + outDir: outDir + }); + const data = fsExtra.readFileSync(rokuDeploy['getOutputZipFilePath']({ outDir: outDir })); + const zip = await JSZip.loadAsync(data); + + const files = ['manifest']; + for (const file of files) { + const zipFileContents = await zip.file(file.toString()).async('string'); + const sourcePath = path.join(options.rootDir, file); + const incomingContents = fsExtra.readFileSync(sourcePath, 'utf8'); + expect(zipFileContents).to.equal(incomingContents); + } + }); + + it('generates full package with defaults', async () => { + const filePaths = writeFiles(rootDir, [ + 'components/components/Loader/Loader.brs', + 'images/splash_hd.jpg', + 'source/main.brs', + 'manifest' + ]); + options = { + files: filePaths, + stagingDir: stagingDir, + outDir: outDir, + rootDir: rootDir + }; + await rokuDeploy.stage(options); + await rokuDeploy.zip(options); + + const data = fsExtra.readFileSync(rokuDeploy['getOutputZipFilePath']({ outDir: outDir })); + const zip = await JSZip.loadAsync(data); + + for (const file of filePaths) { + const zipFileContents = await zip.file(file.toString())?.async('string'); + const sourcePath = path.join(options.rootDir, file); + const incomingContents = fsExtra.readFileSync(sourcePath, 'utf8'); + expect(zipFileContents).to.equal(incomingContents); + } + }); }); describe('getFilePaths', () => { diff --git a/src/RokuDeploy.ts b/src/RokuDeploy.ts index 74cd4da..8b22f3e 100644 --- a/src/RokuDeploy.ts +++ b/src/RokuDeploy.ts @@ -89,10 +89,9 @@ export class RokuDeploy { * Given a path to a folder, zip up that folder and all of its contents * @param srcFolder the folder that should be zipped * @param zipFilePath the path to the zip that will be created - * @param preZipCallback a function to call right before every file gets added to the zip * @param files a files array used to filter the files from `srcFolder` */ - private async makeZip(srcFolder: string, zipFilePath: string, preFileZipCallback?: (file: StandardizedFileEntry, data: Buffer) => Buffer, files: FileEntry[] = ['**/*']) { + private async makeZip(srcFolder: string, zipFilePath: string, files: FileEntry[] = ['**/*']) { const filePaths = await this.getFilePaths(files, srcFolder); const zip = new JSZip(); @@ -100,10 +99,6 @@ export class RokuDeploy { const promises = []; for (const file of filePaths) { const promise = fsExtra.readFile(file.src).then((data) => { - if (preFileZipCallback) { - data = preFileZipCallback(file, data); - } - const ext = path.extname(file.dest).toLowerCase(); let compression = 'DEFLATE'; @@ -691,7 +686,6 @@ export class RokuDeploy { outDir: './out', outFile: 'roku-deploy', retainDeploymentArchive: true, - incrementBuildNumber: false, failOnCompileError: true, deleteDevChannel: true, packagePort: 80, @@ -870,17 +864,6 @@ export interface ManifestData { lineCount?: number; } -export interface BeforeZipCallbackInfo { - /** - * Contains an associative array of the parsed values in the manifest - */ - manifestData: ManifestData; - /** - * The directory where the files were staged - */ - stagingDir: string; -} - export interface StandardizedFileEntry { /** * The full path to the source file @@ -1000,7 +983,6 @@ export interface StageOptions { rootDir?: string; files?: FileEntry[]; stagingDir?: string; - retainStagingDir?: boolean; } export interface ZipOptions { diff --git a/src/RokuDeployOptions.ts b/src/RokuDeployOptions.ts index fc1bebf..9fcc638 100644 --- a/src/RokuDeployOptions.ts +++ b/src/RokuDeployOptions.ts @@ -42,12 +42,6 @@ export interface RokuDeployOptions { */ files?: FileEntry[]; - /** - * Set this to true to prevent the staging folder from being deleted after creating the package - * @default false - */ - retainStagingDir?: boolean; - /** * Should the zipped package be retained after deploying to a roku. If false, this will delete the zip after a deployment. * @default true @@ -125,11 +119,6 @@ export interface RokuDeployOptions { */ devId?: string; - /** - * If true we increment the build number to be a timestamp in the format yymmddHHMM - */ - incrementBuildNumber?: boolean; - /** * If true we convert to squashfs before creating the pkg file */ diff --git a/src/cli.spec.ts b/src/cli.spec.ts index 03ee835..f836b7a 100644 --- a/src/cli.spec.ts +++ b/src/cli.spec.ts @@ -305,7 +305,7 @@ describe('cli', () => { expectPathExists(`${outDir}/roku-deploy.zip`); }); - it.only('should delete installed channel if requested', async () => { + it('should delete installed channel if requested', async () => { const spy = sinon.spy(rokuDeploy, 'deleteDevChannel'); mockDoPostRequest(); const args = { @@ -321,7 +321,7 @@ describe('cli', () => { expect(spy.called).to.equal(true); }); - it.only('should not delete installed channel if not requested', async () => { + it('should not delete installed channel if not requested', async () => { const spy = sinon.spy(rokuDeploy, 'deleteDevChannel'); mockDoPostRequest(); diff --git a/src/cli.ts b/src/cli.ts index 9e9a7d0..7383e78 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -87,7 +87,6 @@ void yargs .option('outFile', { type: 'string', description: 'The output file', demandOption: false }) .option('stagingDir', { type: 'string', description: 'The selected staging folder', demandOption: false }) .option('retainedStagingDir', { type: 'boolean', description: 'Should the staging folder be retained after the command is complete', demandOption: false }) - .option('incrementBuildNumber', { type: 'boolean', description: 'Should the build number be incremented', demandOption: false }) .option('failOnCompileError', { type: 'boolean', description: 'Should the command fail if there is a compile error', demandOption: false }) .option('deleteDevChannel', { type: 'boolean', description: 'Should the dev channel be deleted', demandOption: false }) .option('packagePort', { type: 'number', description: 'The port to use for packaging', demandOption: false })