-
Notifications
You must be signed in to change notification settings - Fork 10
/
actions.coffee
191 lines (147 loc) · 4.97 KB
/
actions.coffee
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
File = require "./models/file"
Issue = require("./models/issue")
Packager = require("./packager")
{readSourceConfig} = require("./source/util")
emoji = require "./util/emojis"
SearchResultsTemplate = require "./templates/search-results"
actions =
save: (editor) ->
editor.notify "Saving..."
message = "#{emoji()}#{emoji()} Updated at https://danielx.net/editor/"
editor.save(message)
.then ->
# TODO: This could get slightly out of sync if there were changes
# during the async call
# The correct solution will be to use git shas to determine changed status
# but that's a little heavy duty for right now.
editor.filetree().markSaved()
editor.publish(message)
.then ->
editor.notify "Saved and published!"
.catch editor.errorCatcher
run: (editor) ->
editor.notify "Running..."
editor.run()
.catch editor.errorCatcher
test: (editor) ->
editor.notify "Running tests..."
editor.test()
.catch (e) ->
editor.errors [].concat(e)
docs: (editor) ->
editor.notify "Running Docs..."
if file = prompt("Docs file", "index")
editor.runDocs({file})
.catch (e) ->
editor.errors [e]
new_file: (editor) ->
if name = prompt("File Name", "newfile.coffee")
file = File
path: name
content: ""
editor.filetree().files.push file
editor.filetree().selectedFile file
load_repo: (editor) ->
editor.confirmUnsaved()
.then ->
currentRepositoryName = editor.repository().full_name()
fullName = prompt("Github repo", currentRepositoryName)
if fullName
editor.notify "Loading repo data..."
github.repository(fullName)
else
throw "No repo given"
.then (repository) ->
editor.notifications.push "Done!\nLoading files..."
editor.repository repository
editor.load repository
.then ->
editor.notifications.push "Done!"
editor.closeOpenEditors()
.catch editor.errorCatcher
new_feature: (editor) ->
if title = prompt("Description")
editor.notify "Creating feature branch..."
editor.repository().createPullRequest
title: title
.then (data) ->
issue = Issue(data)
issues = editor.issues
issues.issues.push issue
# TODO: Standardize this like backbone or something
# or think about using deferreds in some crazy way
issues.silent = true
issues.currentIssue issue
issues.silent = false
editor.notifications.push "Created!"
.catch editor.errorCatcher
pull_master: (editor) ->
editor.confirmUnsaved()
.then ->
editor.notify "Merging in default branch..."
editor.repository().pullFromBranch()
.then ->
editor.notifications.push "Merged!"
branchName = editor.repository().branch()
editor.notifications.push "\nReloading branch #{branchName}..."
editor.load editor.repository()
.then ->
editor.notifications.push "Loaded!"
.catch ->
editor.classicError "Error loading #{editor.repository().url()}"
.catch editor.errorCatcher
pull_upstream: (editor) ->
editor.confirmUnsaved()
.then ->
editor.notify "Pulling from upstream master"
upstreamRepo = editor.repository().parent().full_name
github.repository(upstreamRepo)
.then (repository) ->
repository.latestContent()
.then (results) ->
files = processDirectory results
editor.loadFiles files
.then ->
editor.notifications.push "\nYour code is up to date with the upstream master"
editor.closeOpenEditors()
.catch editor.errorCatcher
tag_version: (editor) ->
editor.notify "Building..."
editor.build()
.then (pkg) ->
version = "v#{readSourceConfig(pkg).version}"
editor.notify "Tagging version #{version} ..."
editor.repository().createRef("refs/tags/#{version}")
.then ->
editor.notifications.push "Tagged #{version}"
editor.notifications.push "\nPublishing..."
# Force branch for jsonp wrapper
pkg.repository.branch = version
editor.repository().publish Packager.standAlone(pkg), version
.then ->
editor.notifications.push "Published!"
.catch editor.errorCatcher
find: (editor) ->
query = window.prompt "Search", editor.findRegex()
if query
editor.findRegex query
results = editor.findInFiles(query)
document.body.appendChild SearchResultsTemplate
editor: editor
results: results
module.exports = (I={}, self) ->
self.actions = Observable []
self.extend
addAction: (name, fn, index) ->
index ?= self.actions().length
self.actions.splice index, 0,
name: name
handler: ->
fn(self)
removeActionByName: (name) ->
[action] = self.actions().filter (action) ->
action.name is name
self.actions.remove action
Object.keys(actions).forEach (key) ->
self.addAction key, actions[key]
return self