Skip to content

Commit

Permalink
Feature/types definition file (#33)
Browse files Browse the repository at this point in the history
* Add types declaration file (resolve #30)

* Amend types file (add Class, Relationship, others inside namespace)

* Example Note typescript class

* typescript setup
  * build types.js in gulp pipeline
  * .gitignore
  * package.json
* use types.js in PEG

* make typescript and gulp-typescript dev dependencies

* ts-pegjs

* refactr to use more ts

* relative imports

* npm i --save-dev @types/node

* gitignore

* format fix

* don't cover src

* use dist folder

* remove generated typescript files

* ignore generated typescript files

* more types and ~ accessor

* Member variable type

* finixh Members

* improved watch rules

* add interface type

* not text is not optional

* remove original interface class

* add Class type

* add Component type

* Add UseCase type

* Add Relationship type

* porting more to ts

* eslint --fix

* coverage report for typescript

* prep for publishing

* prepublish -> prepublishOnly

* re-export types

* remove newline

* readme++

* social media button

* Update README.md

* Update README.md

* Update README.md

* spelling

* update example

* prep for 0.0.10

Co-authored-by: George Pickering <29524044+geopic@users.noreply.github.com>
  • Loading branch information
Enteee and geopic committed Feb 23, 2020
1 parent d6cdc85 commit 3c30bf5
Show file tree
Hide file tree
Showing 50 changed files with 3,531 additions and 16,905 deletions.
5 changes: 3 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
src/plantuml.js
src/plantuml-trace.js
src/plantuml.ts
src/plantuml-trace.ts
dist/
58 changes: 43 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
module.exports = {
'env': {
'browser': true,
'commonjs': true,
'es6': true
"env": { "browser": true, "es6": true, "node": true },
"extends": ["eslint:recommended"],
"globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly" },
"parserOptions": {
"ecmaFeatures": { "jsx": true },
"ecmaVersion": 2018,
"sourceType": "module"
},
'extends': 'standard',
'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
"plugins": [],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"comma-dangle": ["error", "always-multiline"],
"semi": ["error", "always"]
},
'parserOptions': {
'ecmaVersion': 2018
},
'rules': {
'semi': ['error', 'always'],
'quotes': ['error', 'single']
}
"settings": {},
"overrides": [
{
"files": ["**/*.ts", "**/*.tsx"],
"env": { "browser": true, "es6": true, "node": true },
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly" },
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": { "jsx": true },
"ecmaVersion": 2018,
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": ["error", 2, { "SwitchCase": 1 }],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"comma-dangle": ["error", "always-multiline"],
"@typescript-eslint/no-explicit-any": 0
},
"settings": {},
}
]
}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ typings/
# next.js build output
.next

# Ignore distribution folder
dist/

# Generated plantuml typescript filtes
src/plantuml-trace.ts
src/plantuml.ts

# vim
*.swp
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# plantuml-parser [![npm version](https://badge.fury.io/js/plantuml-parser.svg)](https://badge.fury.io/js/plantuml-parser) [![Build Status](https://travis-ci.com/Enteee/plantuml-parser.svg?branch=master)](https://travis-ci.com/Enteee/plantuml-parser) [![Coverage Status](https://coveralls.io/repos/github/Enteee/plantuml-parser/badge.svg?branch=master)](https://coveralls.io/github/Enteee/plantuml-parser?branch=master)
_Parse PlantUML Syntax in JavaScript_
# plantuml-parser [![npm version](https://badge.fury.io/js/plantuml-parser.svg)](https://badge.fury.io/js/plantuml-parser) [![Build Status](https://travis-ci.com/Enteee/plantuml-parser.svg?branch=master)](https://travis-ci.com/Enteee/plantuml-parser) [![Coverage Status](https://coveralls.io/repos/github/Enteee/plantuml-parser/badge.svg?branch=master)](https://coveralls.io/github/Enteee/plantuml-parser?branch=master) [![Twitter URL](https://img.shields.io/twitter/url?label=%23PlantUMLParser&url=https%3A%2F%2Fgithub.com%2FEnteee%2Fplantuml-parser)](https://twitter.com/intent/tweet?text=Parse%20PlantUML%20with%20JavaScript%20or%20TypeScript%20%F0%9F%9A%80&hashtags=PlantUMLParser,JavaScript,TypeScript&url=https%3A%2F%2Fgithub.com%2FEnteee%2Fplantuml-parser)
_Parse PlantUML with JavaScript or TypeScript_

The aim of this project is to provide a feature-complete, well tested, and
The aim of this project is to provide a feature-complete, well tested and
maintainable [Parsing Expression Grammar (PEG)](src/plantuml.pegjs)
for the [PlantUML](http://plantuml.com/) syntax. The parser is designed
to be used as [JavaScript library](#usage) or from the [Command Line](#command-line-interface).

**Important**: The parser is not yet feature-complete. But we focus on writing a
robust implementation which can parse parts of diagrams without implementing the full
robust implementation which can parse parts of diagrams without knowing the full
syntax. This means that the parser probably still parses just about enough to get
you started. If not, please [contribute :heart:](#contribute-heart).

[#PlantUMLParser](https://twitter.com/hashtag/PlantUMLParser)

## Installation

```
Expand All @@ -21,8 +19,13 @@ $ npm install --save plantuml-parser

## Examples / Fixtures

We keep a set of PlantUML scripts (`in.plantuml`) and the corresponding
formatted output (`parse[File]-out.<formatter>`) in [test/fixtures/](test/fixtures).
PlantUML is not a formally defined language - something we would like to change.
This means we have to build this parser by reverse engineering from examples.
For this reason we keep a large set of PlantUML diagrams (`in.plantuml`) and the corresponding
formatted output (`parse[File]-out.<formatter>`) in [test/fixtures/](test/fixtures).
We even have diagrams which exposed bugs in the parser or diagrams which contain known
broken PlantUML syntax. Please help us expand that collection by [contributing](#contribute-heart)
your own diagrams. Every diagram counts :rocket:.

## Usage

Expand Down Expand Up @@ -77,7 +80,8 @@ console.log(
"rightArrowBody": "-",
"leftCardinality": "",
"rightCardinality": "",
"label": ""
"label": "",
"hidden": false
}
]
}
Expand All @@ -93,7 +97,7 @@ Parse PlantUML in `data`. Returns the parse result.

* `data`: data to parse
* `options`: supports all [PEG.js parser options]. Enable tracing with
`options.verbose = true`. If tracing is enabled, `options` is also forwardet to the
`options.verbose = true`. If tracing is enabled, `options` is also forwarded to the
tracer object. See [pegjs-backtrace options] for a full list of supported tracer options.

### `parseFile(pattern, options, cb)`
Expand All @@ -102,7 +106,7 @@ Parse all PlantUML diagrams in the files matching `pattern`. If given, the callb

* `pattern`: files to parse, supports globbing, e.g.: `**/*.plantuml`.
* `options`: supports all [PEG.js parser options]. Enable tracing with
`options.verbose = true`. If tracing is enabled, `options` is also forwardet to the
`options.verbose = true`. If tracing is enabled, `options` is also forwarded to the
tracer object. See [pegjs-backtrace options] for a full list of supported tracer options.
* `cb`: (optional) asynchronous callback. Called with: `cb(err, result)`

Expand Down Expand Up @@ -156,6 +160,10 @@ Options:
- [x] Code linting
- [x] Error case testing
- [ ] Dependency audit
- Misc
- [x] Typescript support
- [x] Fully typed parser result
- [ ] [Internally typed parser](https://github.com/Enteee/plantuml-parser/issues/34)

## Test

Expand Down Expand Up @@ -185,6 +193,8 @@ $ git commit

## Related

* [PEG.js](https://pegjs.org): Parser Generator for JavaScript
* [ts-pegjs](https://github.com/metadevpro/ts-pegjs): Plugin for pegjs to generate TypeScript parsers
* [PlantUML code generator](https://github.com/bafolts/plantuml-code-generator): Provides a command line utility to generate code in various languages given a PlantUML class diagram.

## License
Expand Down
27 changes: 20 additions & 7 deletions conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@
*/

const { join } = require('path');
const tspegjs = require('ts-pegjs');
const serializeError = require('serialize-error');

module.exports = {
encoding: 'utf-8',
src: {
dir: join(__dirname, 'src/')
dir: join(__dirname, 'src/'),
},
dist: {
dir: join(__dirname, 'dist/'),
},
test: {
dir: join(__dirname, 'test/')
dir: join(__dirname, 'test/'),
},
formatters: {
dir: join(__dirname, 'src/formatters/')
build: {
options: {
format: 'commonjs',
plugins: [tspegjs],
tspegjs: {
customHeader: '// import types\nimport * as types from \'./types\';',
},
returnTypes: {
'PlantUMLFile': 'types.UML[]',
},
},
},
fixtures: {
dir: join(__dirname, 'test/fixtures'),
Expand All @@ -30,11 +43,11 @@ module.exports = {
return JSON.stringify(
err,
null,
2
2,
);
},
deserializeParseError: function (err) {
return JSON.parse(err);
}
}
},
},
};
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ in stdenv.mkDerivation {
export NPM_CONFIG_PREFIX="$(${mktemp.outPath}/bin/mktemp -d -t npm_XXXXXXX)"
export PATH="''${PATH}:''${NPM_CONFIG_PREFIX}/bin"
npm set prefix "''${NPM_CONFIG_PREFIX}/.npm-global"
npm install -g npm-check-updates
'';

exitHook = ''
Expand Down
65 changes: 52 additions & 13 deletions gulp/build.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,79 @@
const conf = require('../conf');

const { task, parallel, src, dest } = require('gulp');
const { task, series, parallel, src, dest } = require('gulp');
const { join } = require('path');


const rename = require('gulp-rename');
const pegjs = require('gulp-pegjs');
const ts = require('gulp-typescript');
const sourcemaps = require('gulp-sourcemaps');
const tsProject = ts.createProject('tsconfig.json');

task('build-copy-js',
() => src(join(conf.src.dir, '**', '*.js'))
.pipe(
dest(conf.dist.dir),
),
);

task('build-optimized',
(cb) => src(join(conf.src.dir, '*.pegjs'))
.pipe(
pegjs({
format: 'commonjs'
}).on('error', cb)
...conf.build.options,
}).on('error', cb),
)
.pipe(
dest(conf.src.dir)
rename('plantuml.ts'),
)
.pipe(
dest(conf.src.dir),
),
);

task('build-debug',
(cb) => src(join(conf.src.dir, '*.pegjs'))
.pipe(
pegjs({
format: 'commonjs',
trace: true
}).on('error', cb)
trace: true,
...conf.build.options,
}).on('error', cb),
)
.pipe(
rename('plantuml-trace.js')
rename('plantuml-trace.ts'),
)
.pipe(
dest(conf.src.dir)
dest(conf.src.dir),
),
);

task('build-typescript',
() => tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(
sourcemaps.write(
'.',
{
includeContent: false,
sourceRoot: '../src',
},
),
)
.pipe(
dest(conf.dist.dir),
),
);

task('build', parallel(
'build-optimized',
'build-debug'
));
task(
'build',
series(
'build-copy-js',
parallel(
'build-optimized',
'build-debug',
),
'build-typescript',
),
);

0 comments on commit 3c30bf5

Please sign in to comment.