Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading