Skip to content

Commit c71955a

Browse files
committed
Fixed for defferent OS
1 parent 7465eb5 commit c71955a

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

forward_engineering/api.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,21 @@ const removeCommentLines = (scriptString) => {
152152
}
153153

154154
const replaceRelativePathByAbsolute=(script, modelDirectory)=>{
155-
if(!modelDirectory || typeof modelDirectory !== 'string'){
156-
return script;
157-
}
158-
const stringifiedScript=JSON.stringify(script);
159-
const fixedScript= stringifiedScript.replace(/("\$ref":\s*)"(.*?(?<!\\))"/g, (match, refGroup, relativePath)=>{
160-
const isAbsolutePath=relativePath.startsWith('file:');
161-
const isInternetLink=relativePath.startsWith('http:') || relativePath.startsWith('https:');
162-
const isModelRef=relativePath.startsWith('#');
163-
164-
if(isAbsolutePath || isInternetLink || isModelRef){
165-
return match
166-
}
167-
const absolutePath=path.resolve(modelDirectory, '..',relativePath)
168-
169-
return `${refGroup}"file://${absolutePath}"`
170-
});
171-
172-
return JSON.parse(fixedScript);
155+
if(!modelDirectory || typeof modelDirectory !== 'string'){
156+
return script;
157+
}
158+
const stringifiedScript=JSON.stringify(script);
159+
const fixedScript= stringifiedScript.replace(/("\$ref":\s*)"(.*?(?<!\\))"/g, (match, refGroup, relativePath)=>{
160+
const isAbsolutePath=relativePath.startsWith('file:');
161+
const isInternetLink=relativePath.startsWith('http:') || relativePath.startsWith('https:');
162+
const isModelRef=relativePath.startsWith('#');
163+
if(isAbsolutePath || isInternetLink || isModelRef){
164+
return match
165+
}
166+
const absolutePath=path.join(path.dirname(modelDirectory), relativePath).replace(/\\/g, '/');
167+
return `${refGroup}"file://${absolutePath}"`
168+
});
169+
return JSON.parse(fixedScript);
173170
}
174171

175172
const handleRefInContainers = (containers, externalDefinitions) => {

0 commit comments

Comments
 (0)