Skip to content

workaround for https://github.com/foxglove/rosmsg/issues/39 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 24 additions & 1 deletion src/lib/rosTypescriptGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,41 @@ import { IConfig } from '../types/config';
import { generateFromRosMsg } from './generateFromRosMsg';
import { getMsgFilesData } from './readMsgFiles';

const disambiguatePkgOfPropertyTypes = (joinedMessages: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test and fixing of lint issues on this would be much appreciated

// this is a workaround for https://github.com/foxglove/rosmsg/issues/39
let lines = joinedMessages.split("\n");
let re_new_msg = /^MSG: (.*)\/.*$/;
let re_field = /^([a-zA-Z0-9\[\]]+) ([a-zA-Z0-9]+).*/
let pkg = undefined;
for (let i = 0; i < lines.length; i++) {
let line = lines[i];
let match = re_new_msg.exec(line);
if (match) {
pkg = match[1];
} else {
let match = re_field.exec(line);
if (match && match[1] !== "Header" && match[1][0] === match[1][0].toUpperCase()) {
lines[i] = `${pkg}/${lines[i]}`;
}
}
}
return lines.join("\n");
}

export const rosTypescriptGenerator = async (config: IConfig) => {
const files = flatten(
await Promise.all(
config.input.map((dir) => getMsgFilesData(dir.path, dir.namespace))
)
);
const joinedMessages = files
let joinedMessages = files
.map((file) =>
[`MSG: ${file.namespace}/${file.name}`, file.data].join('\n')
)
.join('\n===\n');

joinedMessages = disambiguatePkgOfPropertyTypes(joinedMessages);

const typescriptInterfaces = generateFromRosMsg(
joinedMessages,
config.typePrefix,
Expand Down