feat(scripts): Add write-userconfig (#511)
This commit is contained in:
committed by
László Monda
parent
2d416e7668
commit
40b72e8903
31
packages/usb/write-userconfig.ts
Executable file
31
packages/usb/write-userconfig.ts
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env ts-node
|
||||
///<reference path="./node_modules/@types/node/index.d.ts"/>
|
||||
|
||||
import { UhkBlhost, UhkHidDevice, UhkOperations } from 'uhk-usb';
|
||||
import { LogService } from 'uhk-common';
|
||||
import * as fs from 'fs';
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.log(`use: write-userconfig <path to config file.bin>`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const fileContent = fs.readFileSync(process.argv[2]);
|
||||
const json = JSON.stringify(fileContent);
|
||||
const logger = new LogService();
|
||||
const uhkDevice = new UhkHidDevice(logger);
|
||||
const uhkBlHost = new UhkBlhost(logger, '.');
|
||||
const uhkOperations = new UhkOperations(logger, uhkBlHost, uhkDevice, '.');
|
||||
|
||||
const init = async (): Promise<void> => {
|
||||
await uhkOperations.saveUserConfiguration(json);
|
||||
};
|
||||
|
||||
init()
|
||||
.then(() => {
|
||||
console.log('Success');
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error);
|
||||
process.exit(-1);
|
||||
});
|
||||
Reference in New Issue
Block a user