Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
210 changed files
with
34,146 additions
and
0 deletions.
There are no files selected for viewing
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
from cordova.commands.help import HelpCommand | ||
from cordova.commands.version import VersionCommand | ||
from cordova.commands.read_config import ReadConfigCommand | ||
from cordova.commands.validate_config import ValidateConfigCommand | ||
from cordova.commands.version_index import VersionIndexCommand | ||
from cordova.commands.find_plugin import FindPluginCommand | ||
from cordova.commands.install_plugin import InstallPluginCommand | ||
from cordova.commands.create import CreateCommand | ||
from cordova.commands.list_recipes import ListRecipesCommand | ||
|
||
COMMANDS = [ | ||
ListRecipesCommand, | ||
CreateCommand, | ||
FindPluginCommand, | ||
InstallPluginCommand, | ||
ReadConfigCommand, | ||
ValidateConfigCommand, | ||
VersionIndexCommand, | ||
VersionCommand, | ||
HelpCommand, | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
from os.path import abspath, exists, join | ||
|
||
from cordova.version import __version__ | ||
|
||
class Command(object): | ||
|
||
def __init__(self, console): | ||
self.console = console | ||
|
||
@staticmethod | ||
def print_version(): | ||
print 'PhoneGap - Cordova v%d.%d.%d' % __version__ | ||
|
||
def run(self): | ||
raise NotImplementedError() | ||
|
||
def is_cordova_folder(self, path=None): | ||
if not path: | ||
path = abspath(os.curdir) | ||
|
||
return exists(join(path, 'www')) and exists(join(path, 'tmp')) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
import os | ||
from os.path import join, abspath, dirname | ||
from optparse import OptionParser | ||
import shutil | ||
|
||
from cordova.commands.base import Command | ||
|
||
class CreateCommand(Command): | ||
key = 'create' | ||
type = 'main' | ||
|
||
def run(self): | ||
root_path = abspath(join(dirname(__file__), '..', '..')) | ||
recipes_path = join(root_path, 'recipes') | ||
|
||
parser = OptionParser() | ||
|
||
parser.add_option('-w', '--www', action='store', | ||
dest='www', default='vanilla', | ||
help='recipe for www') | ||
|
||
parser.add_option('-t', '--test', action='store', | ||
dest='test', default='qunit', | ||
help='recipe for test directory') | ||
|
||
options, args = parser.parse_args(self.console.arguments) | ||
|
||
if not args: | ||
print 'ERROR: The project name is required!' | ||
print 'Type "phonegap help create" for more information.' | ||
self.print_version() | ||
sys.exit(1) | ||
|
||
prj = args[0] | ||
|
||
www = join(recipes_path, options.www) | ||
test = join(recipes_path, options.test) | ||
|
||
tmpl = join(root_path, 'generate-template') | ||
dest = abspath(join(os.curdir, prj)) | ||
dest_www = join(dest, 'www') | ||
dest_test = join(dest, 'test') | ||
|
||
# copy in the new project yay! | ||
shutil.copytree(tmpl, dest) | ||
|
||
# clobber crummy local www | ||
shutil.rmtree(dest_www) | ||
shutil.rmtree(dest_test) | ||
|
||
# copy in recipes for www and test | ||
shutil.copytree(www, dest_www) | ||
shutil.copytree(test, dest_test) | ||
|
||
print 'Project %s was created successfully!' % prj | ||
print 'Don\'t forget to edit the config.xml file under www.' | ||
print 'Use ./bin/emulate to fire all emulators and ./bin/debug to install and debug your app.' | ||
print 'Explore the ./bin/ for more options.' | ||
print 'Happy hacking!' | ||
|
||
@staticmethod | ||
def print_overview(): | ||
print ' create - starts a new PhoneGap project.' | ||
|
||
@classmethod | ||
def print_detailed_usage(cls): | ||
print 'Usage: phonegap create [project name] [-w WWW_TEMPLATE, --www=WWW_TEMPLATE] [-t TEST_TEMPLATE, --test=TEST_TEMPLATE]' | ||
print ' Starts a new PhoneGap project named after project name.' | ||
print ' The www template is optional and defaults to the vanilla template.' | ||
print ' The test template is also optional and defaults to qunit.' | ||
|
||
cls.print_version() | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
import re | ||
import json | ||
import urllib | ||
|
||
from cordova.commands.base import Command | ||
|
||
class PluginList(list): | ||
def find_by_key(self, key): | ||
for item in self: | ||
if item.key == key: | ||
return item | ||
return None | ||
|
||
class Repository(object): | ||
def __init__(self, type, url): | ||
self.type = type | ||
self.url = url | ||
|
||
class Plugin(object): | ||
def __init__(self, | ||
name, | ||
description, | ||
version, | ||
repository_type, | ||
repository_url, | ||
author, | ||
directories, | ||
engines): | ||
self.name = name | ||
self.description = description | ||
self.version = version | ||
self.repository = Repository(repository_type, repository_url) | ||
self.author = author | ||
self.directories = directories | ||
self.engines = engines | ||
|
||
@classmethod | ||
def from_json(cls, item): | ||
return Plugin(item['name'], item['description'], item['version'], item['repository']['type'], | ||
item['repository']['url'], item['author'], item['directories'], item['engines']) | ||
|
||
def simple_describe(self): | ||
return "%s v%s - %s" % (self.name, self.version, self.description) | ||
|
||
def detailed_describe(self): | ||
name = "%s v%s" % (self.name, self.version) | ||
name_separator = "-" * len(name) | ||
|
||
description = [ | ||
name, | ||
name_separator, | ||
self.description, | ||
'', | ||
'Author: %s' % self.author, | ||
'Repository (%s): %s' % (self.repository.type, self.repository.url) | ||
] | ||
|
||
return "\n".join(description) | ||
|
||
class FindPluginCommand(Command): | ||
key = 'find-plugin' | ||
type = 'main' | ||
url = 'http://phonegap-plugins.appspot.com/_je/plugin' | ||
|
||
@classmethod | ||
def get_all_plugins(cls): | ||
try: | ||
plugins_json = urllib.urlopen(cls.url).read() | ||
plugins = json.loads(plugins_json) | ||
|
||
plugin_list = PluginList() | ||
for index, item in enumerate(plugins): | ||
if not 'name' in item: | ||
continue | ||
plugin_list.append(Plugin.from_json(item)) | ||
|
||
return plugin_list | ||
except (ValueError, ): | ||
return None | ||
|
||
def run(self): | ||
plugin_list = self.get_all_plugins() | ||
if plugin_list is None: | ||
print "Connection to %s failed. Could not retrieve plugin list." % self.url | ||
sys.exit(1) | ||
|
||
plugin_name = None | ||
if self.console.arguments: | ||
plugin_name = self.console.arguments[-1] | ||
|
||
if not plugin_name: | ||
print 'Available PhoneGap Plugins' | ||
|
||
for plugin in plugin_list: | ||
print ' %s' % plugin.simple_describe() | ||
|
||
print "Type 'phonegap find-plugin <plugin name or part of plugin name>' to find more about it." | ||
|
||
self.print_version() | ||
|
||
else: | ||
matching_plugins = [plugin for plugin in plugin_list if re.search(plugin_name.lower(), plugin.name.lower())] | ||
|
||
if not matching_plugins: | ||
print "No plugin found with a name that matches %s." % plugin_name | ||
sys.exit(1) | ||
|
||
for plugin in matching_plugins: | ||
print plugin.detailed_describe() | ||
|
||
self.print_version() | ||
|
||
@staticmethod | ||
def print_overview(): | ||
print ' find-plugin - shows informaton on a given plugin or lists all available plugins.' | ||
|
||
@classmethod | ||
def print_detailed_usage(cls): | ||
print 'Usage: phonegap find-plugin [plugin name]' | ||
print ' Shows information on plugins. Displays information about one plugin if plugin name is specified.' | ||
cls.print_version() | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
|
||
from cordova.commands.base import Command | ||
|
||
class HelpCommand(Command): | ||
key = 'help' | ||
type = 'system' | ||
|
||
def __init__(self, console, all_commands): | ||
super(HelpCommand, self).__init__(console) | ||
self.all_commands = all_commands | ||
|
||
def run(self): | ||
if not self.console.arguments: | ||
self.print_detailed_usage() | ||
return | ||
|
||
command_key = self.console.arguments[0] | ||
command = [command for command in self.all_commands if command.key == command_key] | ||
|
||
if not command or command_key == 'help': | ||
print "Error: command %s not found." % command_key | ||
|
||
print 'Usage: phonegap help command' | ||
|
||
self.print_version() | ||
sys.exit(1) | ||
|
||
command[0].print_detailed_usage() | ||
|
||
def print_detailed_usage(self): | ||
self.print_usage() | ||
|
||
self.print_commands() | ||
|
||
print "See 'phonegap help <command>' for more information on a specific command." | ||
|
||
self.print_version() | ||
|
||
def print_usage(self): | ||
print 'Usage: phonegap command [options]' | ||
|
||
@staticmethod | ||
def print_overview(): | ||
print ' help - show this help message and exit.' | ||
|
||
def print_commands(self): | ||
print 'Available commands:' | ||
for command in filter(lambda c: c.type == 'main', self.all_commands): | ||
command.print_overview() | ||
|
||
print 'Utilities:' | ||
for command in filter(lambda c: c.type == 'util', self.all_commands): | ||
command.print_overview() | ||
|
||
print 'Other commands:' | ||
for command in filter(lambda c: c.type == 'system', self.all_commands): | ||
command.print_overview() | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import sys | ||
|
||
from cordova.commands.base import Command | ||
|
||
class InstallPluginCommand(Command): | ||
key = 'install-plugin' | ||
type = 'main' | ||
|
||
def run(self): | ||
if not self.console.arguments: | ||
print 'ERROR: The plugin name is mandatory!' | ||
self.print_version() | ||
sys.exit(1) | ||
|
||
plugin_list = self.get_all_plugins() | ||
plugin = plugin_list.find_by_key(self.console.arguments) | ||
if not plugin: | ||
print 'ERROR: The plugin with key %s was not found!' | ||
self.print_version() | ||
|
||
@staticmethod | ||
def print_overview(): | ||
print ' install-plugin - install the specified plugin in the current PhoneGap project.' | ||
|
||
@classmethod | ||
def print_detailed_usage(cls): | ||
print 'Usage: phonegap install-plugin [plugin name]' | ||
print ' Install the specified plugin in the current PhoneGap project.' | ||
cls.print_version() | ||
|
||
|
Oops, something went wrong.