Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 96 lines (86 sloc) 4.493 kb
c0f62d8 @gampleman Added a build system.
authored
1 {exec} = require 'child_process'
2 fs = require 'fs'
3
4 # Function to not brake the string
5 strip_special = (contents) -> contents.replace(///\\ ///g, '\\\\').replace(/\n/g, '\\n').replace(/"/g, '\\"')
6
7 task 'build', 'Compile the CoffeeScript source.', (options) ->
22b6442 @gampleman Updated build system
authored
8 exec 'coffee --join -b --compile src/toolbar.coffee src/diff.coffee src/autocorrect.coffee src/code_sane.coffee src/search.coffee src/togglecase.coffee', (err) ->
9 if err then throw err else console.log "Code build succesful."
c0f62d8 @gampleman Added a build system.
authored
10
11 task 'build:safari', 'Compile and reload the Safari Extension', (options) ->
12 invoke 'build'
13 exec """osascript -e '
14 tell application "System Events"
15 tell process "Safari"
16 click button "Reload" of UI element "ReloadUninstallSE Editor Toolkit" of UI element 1 of scroll area 1 of window "Extension Builder"
17 end tell
18 end tell '
19 """
20
21 task 'build:userscript', 'Compile and transform into UserScript version', (options) ->
22 invoke 'build'
23 # Userscript prelude
24 js = """
25 // ==UserScript==
26 // @name SE Editor Toolkit
27 // @author Jakub Hampl (adapted by Nathan Osman)
28 // @namespace http://quickmediasolutions.com
29 // @description Provides enhanced editing tools to the post editor
30 // @include http://stackoverflow.com/posts/*/edit*
31 // @include http://meta.stackoverflow.com/posts/*/edit*
32 // @include http://superuser.com/posts/*/edit*
33 // @include http://serverfault.com/posts/*/edit*
34 // @include http://askubuntu.com/posts/*/edit*
35 // @include http://stackapps.com/posts/*/edit*
36 // @include http://*.stackexchange.com/posts/*/edit*
37 // ==/UserScript==
38
39 var exec_script = document.createElement('script');
40 exec_script.type = 'text/javascript';
41 exec_script.textContent = "var load_functions = new Array();\\nfunction RegisterLoadFunction(item, ignored) { load_functions.push(item); }\\n
42 """
43 # Add in the files we need
44 for file in ["concatenation.js", "resig_diff.js"]
45 # Strip off some stuff and replace the events
46 js += strip_special fs.readFileSync('concatenation.js', 'utf8').replace("window.addEventListener('load',", 'RegisterLoadFunction(')
47
48 # Call the load functions and append to the dom
49 js += "\\nfor(var i=0;i<load_functions.length;++i)\\n load_functions[i]();\";
50 document.getElementsByTagName('head')[0].appendChild(exec_script);"
51
52 fs.writeFile 'output.user.js', js
53
0d4b604 @gampleman Updated build system
authored
54 option '-o', '--build_name [NAME]', 'What to name the code'
55 option '-v', '--version [VERSION]', 'Publish as version'
c0f62d8 @gampleman Added a build system.
authored
56 task 'deploy:safari', 'Save the Safari Extension bundle', (options) ->
0d4b604 @gampleman Updated build system
authored
57 throw "ArgumentError" unless options.version
c0f62d8 @gampleman Added a build system.
authored
58 invoke 'build'
22b6442 @gampleman Updated build system
authored
59 file_name = "#{options.build_name || "latest"}.safariextz"
c0f62d8 @gampleman Added a build system.
authored
60 exec """osascript -e '
61 tell application "System Events"
62 tell process "Safari"
0d4b604 @gampleman Updated build system
authored
63 set value of text field 1 of group 22 of UI element 1 of scroll area 1 of window "Extension Builder" to "#{options.version}"
64 set num to (value of text field 1 of group 24 of UI element 1 of scroll area 1 of window "Extension Builder") + 1
65 set value of text field 1 of group 24 of UI element 1 of scroll area 1 of window "Extension Builder" to num as string
66 click button "Reload" of UI element "ReloadUninstallSE Editor Toolkit" of UI element 1 of scroll area 1 of window "Extension Builder"
c0f62d8 @gampleman Added a build system.
authored
67 click button "Build Package…" of group 4 of UI element 1 of scroll area 1 of window "Extension Builder"
68 delay 1
22b6442 @gampleman Updated build system
authored
69 set value of text field 1 of sheet 1 of window "Extension Builder" to "#{file_name}"
c0f62d8 @gampleman Added a build system.
authored
70 click button "Save" of sheet 1 of window "Extension Builder"
22b6442 @gampleman Updated build system
authored
71 click button "Replace" of sheet 1 of sheet 1 of window "Extension Builder"
72 num
c0f62d8 @gampleman Added a build system.
authored
73 end tell
74 end tell'
22b6442 @gampleman Updated build system
authored
75 """, (err, version) -> if err
0d4b604 @gampleman Updated build system
authored
76 throw err
77 else
22b6442 @gampleman Updated build system
authored
78 exec 'git checkout gh-pages', (err) -> throw err if err
79 fs.renameSync "../#{file_name}", "./#{file_name}"
80 fs.writeFileSync 'updates.plist', fs.readFileSync('updates.plist', 'utf8').replace(///
81 <key>CFBundleVersion</key>\n
82 \s*<string>\d+</string>\n
83 \s*<key>CFBundleShortVersionString</key>\n
84 \s*<string>[\d\.]+</string>
85 ///,
86 """
87 <key>CFBundleVersion</key>
88 <string>#{version}</string>
89 <key>CFBundleShortVersionString</key>
90 <string>#{options.version}</string>
91 """), 'utf8'
92
93 exec "git add #{file_name}"
94 exec "git commit #{file_name} updates.plist -m 'Released version #{options.version}'"
95 exec "git checkout master"
Something went wrong with that request. Please try again.