-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
89 lines (79 loc) · 2.33 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const codeGenerator = require('./lib/code-generator')
const crudGenerator = require('./lib/crud-generator')
const metaGenerator = require('./lib/meta-generator')
function handleGenerate(base, path, options) {
options = options || getGenOptions()
getBase(base).then(base => {
if (base) {
path = getPath(path)
codeGenerator.generate(base, path, options)
}
});
}
function handleGenerateCrud(base, path, options) {
options = options || getGenOptions()
getBase(base).then(base => {
if (base) {
crudGenerator.generate(base, path, options)
}
});
}
function handleGenerateMeta(base, path, options) {
options = options || getGenOptions()
getProject(base).then(base => {
if (base) {
metaGenerator.generate(base, path, options)
}
});
}
function getGenOptions() {
return {
javaDoc: app.preferences.get('nest.gen.javaDoc'),
useTab: app.preferences.get('nest.gen.useTab'),
indentSpaces: app.preferences.get('nest.gen.indentSpaces'),
tablePrefix: app.preferences.get('nest.gen.tablePrefix')
}
}
function getBase(base) {
if (!base) {
return app.elementPickerDialog
.showDialog('Select a base model to generate codes', null, type.UMLPackage)
.then(function ({ buttonId, returnValue }) {
if (buttonId === 'ok') {
return returnValue
}
})
}
return Promise.resolve(base)
}
function getProject(base) {
if (!base) {
return app.elementPickerDialog
.showDialog('Select a project to generate node_modules', null, type.Project)
.then(function ({ buttonId, returnValue }) {
if (buttonId === 'ok') {
return returnValue
}
})
}
return Promise.resolve(base)
}
function getPath(path) {
if (!path) {
var files = app.dialogs.showOpenDialog('Select a folder where generated codes to be located', null, null, { properties: ['openDirectory'] })
if (files && files.length > 0) {
path = files[0]
}
}
return path
}
function _handleConfigure() {
app.commands.execute('application:preferences', 'nest')
}
function init() {
app.commands.register('nest:generate:code', handleGenerate)
app.commands.register('nest:generate:crud', handleGenerateCrud)
app.commands.register('nest:generate:meta', handleGenerateMeta)
app.commands.register('nest:configure', _handleConfigure)
}
exports.init = init