Skip to content

Commit ba53616

Browse files
committed
Initial commit (converted typescript extension to v3 starUML)
0 parents  commit ba53616

File tree

10 files changed

+1745
-0
lines changed

10 files changed

+1745
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+

CodeGenUtils.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2014 MKLab. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
class CodeWriter {
24+
/**
25+
* CodeWriter
26+
* @constructor
27+
*/
28+
constructor(indentString) {
29+
30+
/** @member {Array.<string>} lines */
31+
this.lines = [];
32+
33+
/** @member {string} indentString */
34+
this.indentString = (indentString ? indentString : " "); // default 4 spaces
35+
36+
/** @member {Array.<string>} indentations */
37+
this.indentations = [];
38+
}
39+
40+
/**
41+
* Indent
42+
*/
43+
indent() {
44+
this.indentations.push(this.indentString);
45+
};
46+
47+
/**
48+
* Outdent
49+
*/
50+
outdent() {
51+
this.indentations.splice(this.indentations.length - 1, 1);
52+
};
53+
54+
/**
55+
* Write a line
56+
* @param {string} line
57+
*/
58+
writeLine(line) {
59+
if (line) {
60+
this.lines.push(this.indentations.join("") + line);
61+
} else {
62+
this.lines.push("");
63+
}
64+
};
65+
66+
/**
67+
* Return as all string data
68+
* @return {string}
69+
*/
70+
getData() {
71+
return this.lines.join("\n");
72+
};
73+
}
74+
75+
module.exports = CodeWriter;

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# staruml-typescript
2+
TypeScript Code Generator for StarUML 3
3+
4+
# Installation
5+
You can install from URL with below UML
6+
```
7+
https://github.com/qwin/staruml-typescript
8+
```
9+
10+
# License
11+
This extension is released under the terms of GPLv3 License. See the LICENSE file for more details.
12+
13+
Copyright © 2019 Thomas Min.
14+
Copyright © 2019 Robert Al-Malak.

main.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const typeScriptCodeGenerator = require("./typeScriptCodeGenerator")
2+
3+
function _handleGen(base, path, options) {
4+
console.log('this is a test');
5+
6+
7+
// window.alert('Hello World!');
8+
// If options is not passed, get from preference
9+
options = options || getGenOptions()
10+
// If base is not assigned, popup ElementPicker
11+
if (!base) {
12+
app.elementPickerDialog.showDialog('Select a base model to generate codes', null, type.UMLPackage).then(function ({ buttonId, returnValue }) {
13+
if (buttonId === 'ok') {
14+
base = returnValue
15+
console.log(base);
16+
// If path is not assigned, popup Open Dialog to select a folder
17+
if (!path) {
18+
var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory'] })
19+
if (files && files.length > 0) {
20+
path = files[0]
21+
console.log(path);
22+
typeScriptCodeGenerator.generate(base, path, options);
23+
}
24+
} else {
25+
typeScriptCodeGenerator.generate(base, path, options)
26+
}
27+
}
28+
})
29+
} else {
30+
// If path is not assigned, popup Open Dialog to select a folder
31+
if (!path) {
32+
var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory'] })
33+
if (files && files.length > 0) {
34+
path = files[0]
35+
console.log(path);
36+
typeScriptCodeGenerator.generate(base, path, options);
37+
}
38+
} else {
39+
console.log(path);
40+
typeScriptCodeGenerator.generate(base, path, options);
41+
}
42+
}
43+
}
44+
45+
function getGenOptions() {
46+
return {
47+
tsDoc: app.preferences.get("typescript.gen.tsDoc"),
48+
indentSpaces: app.preferences.get("typescript.gen.indentSpaces"),
49+
copyright: app.preferences.get("typescript.gen.copyright"),
50+
comments: app.preferences.get("typescript.gen.comments")
51+
};
52+
}
53+
54+
function init() {
55+
app.commands.register('typescript:generate', _handleGen)
56+
}
57+
58+
exports.init = init

menus/menu.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"menu": [
3+
{
4+
"id": "tools",
5+
"submenu": [
6+
{
7+
"label": "Typescript",
8+
"id": "tools.typescript",
9+
"submenu": [
10+
{ "label": "Generate Code...", "id": "tools.typescript.generate", "command": "typescript:generate" }
11+
]
12+
}
13+
]
14+
}
15+
]
16+
}

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "robertalmalak.staruml-typescript",
3+
"title": "TypeScript",
4+
"description": "TypeScript code generation",
5+
"homepage": "https://github.com/qwin/staruml-typescript",
6+
"issues": "https://github.com/qwin/staruml-typescript/issues",
7+
"version": "0.2.0",
8+
"keywords": ["TypeScript", "ts", "UML", "staruml"],
9+
"author": {
10+
"name": "Robert Al Malak",
11+
"email": "robertalmalak7@gmail.com",
12+
"url": "https://github.com/qwin"
13+
},
14+
"license": "GPLv3",
15+
"engines": {
16+
"staruml": ">=3.0.0"
17+
},
18+
"devDependencies": {
19+
"lodash": "^4.17.11"
20+
}
21+
}

preferences/preference.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"id": "typescript",
3+
"name": "TS",
4+
"schema": {
5+
"typescript.gen": {
6+
"text": "TypeScript Code Generation",
7+
"type": "section"
8+
},
9+
"typescript.gen.tsDoc": {
10+
"text": "TypeScript Doc",
11+
"description": "Generate TypeScript Doc comments.",
12+
"type": "check",
13+
"default": true
14+
},
15+
"typescript.gen.copyright": {
16+
"text": "Copyright Text",
17+
"description": "Copyright Text to use on all files",
18+
"type": "string",
19+
"default": "\n/*\n*(C) Copyright MyCompany, Inc. \n*All rights reserved\n*/\n"
20+
},
21+
"typescript.gen.indentSpaces": {
22+
"text": "Indent Spaces",
23+
"description": "Number of spaces for indentation.",
24+
"type": "number",
25+
"default": 4
26+
},
27+
"typescript.gen.comments": {
28+
"text": "Generate Comments",
29+
"description": "Generate comments in JSDoc style.",
30+
"type": "check",
31+
"default": false
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)