Skip to content

Commit

Permalink
Merge pull request #3 from theiconic/feature/support-more-extensions
Browse files Browse the repository at this point in the history
Add support for `.pml`, `.puml` and `.plantuml` extensions
  • Loading branch information
wyrfel authored Aug 7, 2020
2 parents ecee2da + a934a01 commit 29ac134
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 12 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ UML is very useful, but there are some difficulties to maintain.
[PlantUML](https://plantuml.com/) enables you to write UML with text code, that is engineer-friendly so you would like it.


This actions generate UML diagrams from plantuml code with [PlantUML Server](https://plantuml.com/en/server) when you commit `.pu` file or `.md` file that plantuml code is written on.
This actions generate UML diagrams from plantuml code
with [PlantUML Server](https://plantuml.com/en/server) when you commit plantUML files
or Markdown files that plantuml code is written in.

PlantUML files must end in either of
- `.pu`
- `.pml`
- `.puml`
- `.plantuml`

Markdown files must end in
- `.md`

## Usage

Expand Down
4 changes: 4 additions & 0 deletions __tests__/assets/test5.pml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@startuml
A -> B: test5
B -> C: test5
@enduml
4 changes: 4 additions & 0 deletions __tests__/assets/test6.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@startuml
A -> B: test6
B -> C: test6
@enduml
4 changes: 4 additions & 0 deletions __tests__/assets/test7.plantuml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@startuml
A -> B: test7
B -> C: test7
@enduml
30 changes: 30 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ test('retrieveCodes', async() => {
const codes = await retrieveCodes([
'__tests__/assets/test1.md',
'__tests__/assets/test3.pu',
'__tests__/assets/test5.pml',
'__tests__/assets/test6.puml',
'__tests__/assets/test7.plantuml',
]);
await expect(codes).toEqual([
{
Expand Down Expand Up @@ -40,6 +43,33 @@ A -> B: test2
A -> B: test3
B -> C: test3
@enduml
`,
dir: '__tests__/assets'
},
{
name: 'test5',
code: `@startuml
A -> B: test5
B -> C: test5
@enduml
`,
dir: '__tests__/assets'
},
{
name: 'test6',
code: `@startuml
A -> B: test6
B -> C: test6
@enduml
`,
dir: '__tests__/assets'
},
{
name: 'test7',
code: `@startuml
A -> B: test7
B -> C: test7
@enduml
`,
dir: '__tests__/assets'
}
Expand Down
39 changes: 31 additions & 8 deletions dist/index.js

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,35 @@ import fs from 'fs';
import { uniq } from 'lodash';
import path from 'path';
const markdownit = require('markdown-it');
const umlFileExtensions = [
'.pu',
'.pml',
'.puml',
'.plantuml',
];
const markdownExtensions = [
'.md',
'.markdown',
'.mdown',
'.mkdn',,
'.mdwn',
'.mkd',
'.mdn',
'.md.txt',
];

export function retrieveCodes(files) {
return files.reduce((accum, f) => {
const p = path.parse(f);
if (p.ext === '.pu') {
if (umlFileExtensions.indexOf(p.ext) !== -1) {
return accum.concat({
name: p.name,
// TODO: files may have been deleted.
code: fs.readFileSync(f).toString(),
dir: p.dir
});
}
if (p.ext === '.md') {
if (markdownExtensions.indexOf(p.ext) !== -1) {
// TODO: files may have been deleted.
const content = fs.readFileSync(f).toString();
const dir = path.dirname(f);
Expand All @@ -25,7 +41,7 @@ export function retrieveCodes(files) {
})
return accum.concat(codes);
}
return p.ext === '.md' ? accum.concat(f) : accum
return accum;
}, []);
}

Expand Down

0 comments on commit 29ac134

Please sign in to comment.