diff --git a/packages/test-serializer/spec/test-convert-user-config-npm-script.spec.ts b/packages/test-serializer/spec/test-convert-user-config-npm-script.spec.ts index 48ea33ac..c66be013 100644 --- a/packages/test-serializer/spec/test-convert-user-config-npm-script.spec.ts +++ b/packages/test-serializer/spec/test-convert-user-config-npm-script.spec.ts @@ -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} ); diff --git a/packages/usb/user-config-json-to-bin.ts b/packages/usb/user-config-json-to-bin.ts index 286f7e99..1b6bfe88 100755 --- a/packages/usb/user-config-json-to-bin.ts +++ b/packages/usb/user-config-json-to-bin.ts @@ -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} `) + .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();