Skip to content

Commit

Permalink
Remove retainsStagingDir, zipCallBackInfo, incrementBuildNumber, and …
Browse files Browse the repository at this point in the history
…add back tests for createPackage
  • Loading branch information
MilapNaik committed Mar 19, 2024
1 parent a669ee3 commit 906856e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 81 deletions.
107 changes: 59 additions & 48 deletions src/RokuDeploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,6 @@ describe('index', () => {
'manifest',
'components/!(scenes)/**/*'
],
retainStagingDir: true,
rootDir: rootDir,
stagingDir: stagingDir
});
Expand All @@ -1557,7 +1556,6 @@ describe('index', () => {
'components/**/*',
'!components/scenes/**/*'
],
retainStagingDir: true,
rootDir: rootDir,
stagingDir: stagingDir
});
Expand All @@ -1572,7 +1570,6 @@ describe('index', () => {
'manifest',
<any>{}
],
retainStagingDir: true,
rootDir: rootDir,
stagingDir: stagingDir
});
Expand Down Expand Up @@ -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',
Expand All @@ -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);
Expand All @@ -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', () => {
Expand Down
20 changes: 1 addition & 19 deletions src/RokuDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,16 @@ 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();
// Allows us to wait until all are done before we build the zip
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';

Expand Down Expand Up @@ -691,7 +686,6 @@ export class RokuDeploy {
outDir: './out',
outFile: 'roku-deploy',
retainDeploymentArchive: true,
incrementBuildNumber: false,
failOnCompileError: true,
deleteDevChannel: true,
packagePort: 80,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1000,7 +983,6 @@ export interface StageOptions {
rootDir?: string;
files?: FileEntry[];
stagingDir?: string;
retainStagingDir?: boolean;
}

export interface ZipOptions {
Expand Down
11 changes: 0 additions & 11 deletions src/RokuDeployOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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();

Expand Down
1 change: 0 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 906856e

Please sign in to comment.