Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
chore: user-config-json-to-bin.ts supports uhk80 config conversion (#168
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ert78gb authored Dec 3, 2024
1 parent 2983496 commit 001757f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,21 @@ describe('convert-user-config-to-bin npm script', () => {
await remove(tmpDirPath);
});

it('should work', async () => {
it('should work with uhk60', async () => {
const response = spawnSync(
'npm',
['run', 'convert-user-config-to-bin', '--', tmpConfigPath],
['run', 'convert-user-config-to-bin', '--', 'uhk60', tmpConfigPath],
{ shell: true, cwd: rootDirPath}
);

expect(response.error).toEqual(undefined);
expect(await pathExists(tmpConfigPath)).toEqual(true);
});

it('should work with uhk80', async () => {
const response = spawnSync(
'npm',
['run', 'convert-user-config-to-bin', '--', 'uhk80', tmpConfigPath],
{ shell: true, cwd: rootDirPath}
);

Expand Down
22 changes: 20 additions & 2 deletions packages/usb/user-config-json-to-bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,26 @@ import { UhkBuffer, UserConfiguration } from 'uhk-common';
import * as fs from 'fs';
import { join } from 'desm';

const outputFile = process.argv[2];
const inputFile = join(import.meta.url, '../uhk-web/src/app/services/user-config.json');
import { yargs } from './src/index.js';

const USER_CONFIG_TYPES = '{uhk60|uhk80}'
;
const argv = yargs
.scriptName('./user-config-json-to-bin.ts')
.usage(`Usage: $0 ${USER_CONFIG_TYPES} <output path>`)
.demandCommand(2, 'User configuration type and output path are required')
.argv as any;

const userConfigType = argv._[0];
const outputFile = argv._[1];

if (userConfigType !== 'uhk60' && userConfigType !== 'uhk80') {
console.log(`Invalid user config type: ${userConfigType}. Available options: ${USER_CONFIG_TYPES}`);
process.exit(1);
}

const inputFileName = userConfigType === 'uhk60' ? 'user-config.json' : 'user-config-80.json';
const inputFile = join(import.meta.url, '..', 'uhk-web', 'src', 'app', 'services', inputFileName);
const config1Js = JSON.parse(fs.readFileSync(inputFile).toString());
const config1Ts: UserConfiguration = new UserConfiguration().fromJsonObject(config1Js);
const config1Buffer = new UhkBuffer();
Expand Down

0 comments on commit 001757f

Please sign in to comment.