From 9a57776866b15189d5a20937452a9c45365eb236 Mon Sep 17 00:00:00 2001 From: Dimitri Nikitopoulos Date: Mon, 14 Oct 2024 11:10:12 -0400 Subject: [PATCH 1/2] fix: push constants --- rostsd_gen/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rostsd_gen/index.js b/rostsd_gen/index.js index d438cdb1..6533f7cc 100644 --- a/rostsd_gen/index.js +++ b/rostsd_gen/index.js @@ -303,11 +303,21 @@ function saveMsgConstructorAsTSD(rosMsgInterface, fd) { const type = rosMsgInterface.type(); const msgName = type.interfaceName; + fs.writeSync(fd, ` export interface ${msgName}Constants {\n`); + for (const constant of rosMsgInterface.ROSMessageDef.constants) { + if(primitiveType2JSName(constant.type) === "string"){ + fs.writeSync(fd, ` ${constant.name} = "${constant.value}";\n`); + } else { + fs.writeSync(fd, ` ${constant.name} = ${constant.value};\n`); + } + } + fs.writeSync(fd, ' }\n'); + + fs.writeSync(fd, ` export interface ${msgName}Constructor {\n`); for (const constant of rosMsgInterface.ROSMessageDef.constants) { - const constantType = primitiveType2JSName(constant.type); - fs.writeSync(fd, ` readonly ${constant.name}: ${constantType};\n`); + s.writeSync(fd, ` readonly ${constant.name}: ${msgName}Constants.${constant.name};\n`); } fs.writeSync(fd, ` new(other?: ${msgName}): ${msgName};\n`); From d75b4d50f15ff2766b4545b456843e01054cd79c Mon Sep 17 00:00:00 2001 From: Dimitri Nikitopoulos Date: Mon, 14 Oct 2024 11:11:44 -0400 Subject: [PATCH 2/2] fix: typo --- rostsd_gen/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rostsd_gen/index.js b/rostsd_gen/index.js index 6533f7cc..1fc64cbf 100644 --- a/rostsd_gen/index.js +++ b/rostsd_gen/index.js @@ -306,9 +306,9 @@ function saveMsgConstructorAsTSD(rosMsgInterface, fd) { fs.writeSync(fd, ` export interface ${msgName}Constants {\n`); for (const constant of rosMsgInterface.ROSMessageDef.constants) { if(primitiveType2JSName(constant.type) === "string"){ - fs.writeSync(fd, ` ${constant.name} = "${constant.value}";\n`); + fs.writeSync(fd, ` ${constant.name} = "${constant.value}",\n`); } else { - fs.writeSync(fd, ` ${constant.name} = ${constant.value};\n`); + fs.writeSync(fd, ` ${constant.name} = ${constant.value},\n`); } } fs.writeSync(fd, ' }\n');