Skip to content

Commit

Permalink
Merge pull request #2 from theiconic/feature/save-to-source-folder
Browse files Browse the repository at this point in the history
Allow specifying `.` for the target path to save to source folder
  • Loading branch information
wyrfel authored Aug 7, 2020
2 parents 3cf7d6d + 1c716e7 commit ecee2da
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
12 changes: 8 additions & 4 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,34 @@ test('retrieveCodes', async() => {
code: `@startuml
A -> B: test1
@enduml
`
`,
dir: '__tests__/assets'
},
{
name: 'test_2',
code: `@startuml
A -> B: test2
@enduml
`
`,
dir: '__tests__/assets'
},
{
name: 'test.4',
code: `@startgantt
[Prototype design] lasts 15 days
[Test prototype] lasts 10 days
@endgantt
`
`,
dir: '__tests__/assets'
},
{
name: 'test3',
code: `@startuml
A -> B: test3
B -> C: test3
@enduml
`
`,
dir: '__tests__/assets'
}
]);
});
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const octokit = new github.GitHub(process.env.GITHUB_TOKEN);
let tree: any[] = [];
for (const plantumlCode of plantumlCodes) {
const p = path.format({
dir: diagramPath,
dir: (diagramPath === '.') ? plantumlCode.dir : diagramPath,
name: plantumlCode.name,
ext: '.svg'
});
Expand Down
9 changes: 8 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ export function retrieveCodes(files) {
name: p.name,
// TODO: files may have been deleted.
code: fs.readFileSync(f).toString(),
dir: p.dir
});
}
if (p.ext === '.md') {
// TODO: files may have been deleted.
const content = fs.readFileSync(f).toString();
return accum.concat(puFromMd(content));
const dir = path.dirname(f);
const codes = puFromMd(content);
codes.forEach(code => {
code.dir = path.dirname(f)
return code;
})
return accum.concat(codes);
}
return p.ext === '.md' ? accum.concat(f) : accum
}, []);
Expand Down

0 comments on commit ecee2da

Please sign in to comment.