Skip to content

Commit

Permalink
Merge pull request #10 from HyperPlay-Gaming/fix/zip_name
Browse files Browse the repository at this point in the history
[Fix] Zip naming
  • Loading branch information
BrettCleary authored Mar 15, 2024
2 parents b63d4bd + a30339a commit 6b144fb
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hyperplay/cli",
"version": "2.10.0",
"version": "2.10.1",
"description": "Hyperplay CLI",
"author": "HyperPlay Labs, Inc.",
"bin": {
Expand Down
2 changes: 0 additions & 2 deletions src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ export default class Publish extends Command {
this.error(`release ${config.release} exists`);
}

CliUx.ux.action.start('uploading files');
const release = await uploadRelease(valist, config, yamlConfig);
CliUx.ux.action.stop();
CliUx.ux.log(`successfully uploaded files to IPFS: ${release.external_url}`);

CliUx.ux.action.start('publishing release');
Expand Down
7 changes: 6 additions & 1 deletion src/releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fs from 'fs';
import path from 'path';
import { zipDirectory } from './zip';
import { YamlConfig } from './types';
import { getZipName } from './utils/getZipName';

export async function uploadRelease(valist: Client, config: ReleaseConfig, yamlConfig?: YamlConfig) {
/* eslint-disable-next-line */
Expand All @@ -14,8 +15,10 @@ export async function uploadRelease(valist: Client, config: ReleaseConfig, yamlC
if (yamlConfig && yamlConfig.platforms[platform] && !yamlConfig.platforms[platform].zip) {
return [platform, filePath]
}
const zipPath = `./${path.basename(filePath)}.zip`;
const zipPath = getZipName(filePath);
CliUx.ux.action.start(`zipping ${filePath}`);
await zipDirectory(filePath, zipPath);
CliUx.ux.action.stop();
return [platform, zipPath] as [string, string];
}));

Expand All @@ -36,13 +39,15 @@ export async function uploadRelease(valist: Client, config: ReleaseConfig, yamlC
};
});

CliUx.ux.action.start('uploading files');
meta.external_url = await valist.writeFolder(
platformIC,
true,
(bytes: string | number) => {
CliUx.ux.log(`Uploading ${bytes}`);
},
);
CliUx.ux.action.stop();

for (const [platformName, zipPath] of updatedPlatformEntries) {
const stats = await fs.promises.stat(zipPath);
Expand Down
6 changes: 6 additions & 0 deletions src/utils/getZipName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import path from 'path';

export function getZipName(filePath: string){
const zipName = path.basename(path.resolve(filePath), path.extname(filePath))
return `./${zipName}.zip`;
}
19 changes: 19 additions & 0 deletions test/utils/getZipName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from 'chai';
import { getZipName } from '../../src/utils/getZipName'

describe('Zip Name Tests', ()=>{
it('should get the folder name when zipping the same folder as hyperplay.yml', ()=>{
const name = getZipName('.').toLowerCase()
expect(name).to.eq('./cli.zip')
})

it('should get the folder name for subdirectory path', ()=>{
const name = getZipName('../mock_data/windows_amd64')
expect(name).to.eq('./windows_amd64.zip')
})

it('should get the file name for file path', ()=>{
const name = getZipName('../mock_data/dmg.txt')
expect(name).to.eq('./dmg.zip')
})
})

0 comments on commit 6b144fb

Please sign in to comment.