1
+ {BufferedProcess } = require ' atom'
1
2
{$$ , SelectListView } = require ' atom-space-pen-views'
2
3
GeneratorNameView = require ' ./generator-name-view'
3
4
@@ -6,7 +7,14 @@ module.exports = class GeneratorListView extends SelectListView
6
7
initialize : (@view )->
7
8
super
8
9
@ addClass ' overlay from-top'
9
- @ setItems [' component' , ' controller' , ' helper' , ' mixin' , ' route' , ' template' , ' view' ]
10
+
11
+ # Generate list of blueprints from Ember executable
12
+ @ getBlueprints ()
13
+ .catch (err)->
14
+ throw err
15
+ .then (prints)=>
16
+ # ::show uses this variable to populate the list of items
17
+ @blueprints = prints .sort ()
10
18
11
19
12
20
viewForItem : (item ) ->
@@ -19,20 +27,52 @@ module.exports = class GeneratorListView extends SelectListView
19
27
@ cancel ()
20
28
21
29
22
- getEmptyMessage : ->
23
- " Select a type to generate"
30
+ getEmptyMessage : -> " Select a type to generate"
24
31
25
32
26
33
show : ->
27
34
@ storeFocusedElement ()
28
35
@panel ?= atom .workspace .addModalPanel (item : this )
36
+ @ setItems @blueprints
29
37
@panel .show ()
30
38
@ focusFilterEditor ()
31
39
32
40
33
- hide : ->
34
- @panel ? .hide ()
41
+ # Needed for hiding the list of generators
42
+ hide : -> @panel ? .hide ()
43
+
44
+ cancelled : -> @ hide ()
45
+
46
+ destroy : ->
47
+ @ cancel ()
48
+ @panel ? .destroy ()
49
+
50
+
51
+ # Dynamically generate the list of blueprints
52
+ getBlueprints : ->
53
+ new Promise (resolve , reject )->
54
+
55
+ # Array of blueprints
56
+ blueprints = []
35
57
58
+ # Set up the command options
59
+ command = atom .config .get (' ember-cli-helper.pathToEmberExecutable' )
60
+ args = [' generate' , ' --help' ]
61
+ options =
62
+ cwd : atom .project .getPaths ()[0 ] + atom .config .get (' ember-cli-helper.emberProjectPath' )
63
+ stdout = (out )->
64
+ outArray = out .split (' \n ' )
65
+ outArray .forEach (line)->
66
+ if line .match (/ . * (?=\s <name>)/ ) && line .match (/ ^ \s {6} / )
67
+ command = line .trim ().split (" " )[0 ]
68
+ blueprints .push command
69
+ exit = (code )->
70
+ if (code != 0 )
71
+ reject new Error (" There was a problem reading the generator options" )
72
+ else
73
+ resolve blueprints
36
74
37
- cancelled : ->
38
- @ hide ()
75
+ try
76
+ new BufferedProcess ({command, args, options, stdout, exit})
77
+ catch e
78
+ reject (e)
0 commit comments