Skip to content

Commit 077c3b7

Browse files
committed
Dynamically generate list of Blueprints
1 parent b2fa24e commit 077c3b7

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.7.0 - Dynamic Blueprint List
2+
* Dynamically generate the list of Blueprints
3+
14
## 0.6.0 - Get APIs up to speed
25
* Include the View packages from the correct repository
36
* Upgrade depreciated keymap selectors

lib/generator-list-view.coffee

+47-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{BufferedProcess} = require 'atom'
12
{$$, SelectListView} = require 'atom-space-pen-views'
23
GeneratorNameView = require './generator-name-view'
34

@@ -6,7 +7,14 @@ module.exports = class GeneratorListView extends SelectListView
67
initialize: (@view)->
78
super
89
@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()
1018

1119

1220
viewForItem: (item) ->
@@ -19,20 +27,52 @@ module.exports = class GeneratorListView extends SelectListView
1927
@cancel()
2028

2129

22-
getEmptyMessage: ->
23-
"Select a type to generate"
30+
getEmptyMessage: -> "Select a type to generate"
2431

2532

2633
show: ->
2734
@storeFocusedElement()
2835
@panel ?= atom.workspace.addModalPanel(item: this)
36+
@setItems @blueprints
2937
@panel.show()
3038
@focusFilterEditor()
3139

3240

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 = []
3557

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
3674

37-
cancelled: ->
38-
@hide()
75+
try
76+
new BufferedProcess({command, args, options, stdout, exit})
77+
catch e
78+
reject(e)

0 commit comments

Comments
 (0)