-
-
Save jeffgca/1021239 to your computer and use it in GitHub Desktop.
Jetpack project creation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sanitize_name = function(s) { | |
return s.replace(/[\s\.]*/g, '').toLowerCase(); | |
} | |
var os = Components.classes['@activestate.com/koOs;1']. | |
getService(Components.interfaces.koIOs); | |
var project_root = ko.filepicker.getFolder(os.getcwd(), "Choose a directory to create your new project in."); | |
// var project_root = '/Users/jeff/code/moz/jetpack/tmp/two'; | |
var name = ko.dialogs.prompt('Addon name', 'What do you want to call your new extension?'); | |
var safe_name = sanitize_name(name); | |
var dir = os.path.join(project_root, safe_name); | |
function jetpack_init(base_dir, safe_name) { | |
try { | |
var dir = os.path.join(project_root, safe_name); | |
os.mkdir(dir); | |
// should be in extension prefs | |
var cmd = '/Users/jeff/code/moz/jetpack/addon-sdk/bin/cfx ' | |
+ '-b /Applications/Coms/Firefox4.app ' | |
+ 'init'; | |
cmd += " {'cwd': u'"+ dir +"'}"; // necessary? | |
ko.run.runEncodedCommand(window, cmd, function() { | |
create_project(dir, safe_name); | |
}); | |
} | |
catch(e) { | |
ko.eggs.writeLine(e); | |
} | |
} | |
function create_project(dir, name) { | |
var projectName = name + '.komodoproject'; | |
var path_list = [dir, projectName]; | |
var url = ko.uriparse.localPathToURI(os.path.joinlist(path_list.length, path_list)); | |
var project = Components.classes["@activestate.com/koProject;1"] | |
.createInstance(Components.interfaces.koIProject); | |
project.create(); | |
project.url = url; | |
project.save(); | |
ko.projects.open(url); | |
} | |
jetpack_init(project_root, safe_name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CHALLENGE: post back a Python version of this ;)
Agreed that runEncodedCommand() is awkward to implement; that bit is lifted from how the Firefox & Komodo project templates work. At the time we decided it might be better to run koext out-of-process. None of the people involved in that conversation work on Komodo anymore though ;). Doing things in-process either requires blocking the main thread or delving into Python threading, yes?
I'm more comfortable with JS async programming I guess; what I really like about the pattern is the callback. Trent added that into that method specifically so I could do things like shell out to something and then run JS macro code afterwards. I just wish there was a more convenient method signature, something like:
ko.run.runCommandSanely( cmd, cwd, callback )
...the string munging for the command is less than obvious.