Add add-platform, remove-platform, and list-platforms commands

Also, remove platforms from meteor add, remove, and list
This commit is contained in:
Sashko Stubailo
2014-08-18 16:40:30 -07:00
parent ff1a6c05b6
commit c268a2ada7
3 changed files with 111 additions and 42 deletions

View File

@@ -536,7 +536,6 @@ cordova.filterPackages = function (packages) {
// We hard-code the 'cordova' and 'platform' namespaces
var ret = {
rest: [],
platforms: [],
plugins: []
};
@@ -545,11 +544,88 @@ cordova.filterPackages = function (packages) {
var name = p.split(':').slice(1).join(':');
if (namespace === 'cordova') {
ret.plugins.push(name);
} else if (namespace === 'platform') {
ret.platforms.push(name);
} else
} else {
ret.rest.push(p); // leave it the same
}
});
return ret;
};
// add one or more Cordova platforms
main.registerCommand({
name: "add-platform",
minArgs: 1,
maxArgs: Infinity,
requiresApp: true
}, function (options) {
var platforms = options.args;
try {
_.each(platforms, function (platform) {
cordova.checkIsValidPlatform(platform);
});
} catch (err) {
process.stderr.write(err.message + "\n");
return 1;
}
project.addCordovaPlatforms(platforms);
if (platforms.length) {
var localPath = path.join(options.appDir, '.meteor', 'local');
files.mkdir_p(localPath);
var appName = path.basename(options.appDir);
cordova.ensureCordovaProject(localPath, appName);
// We checked the platforms above
if (platforms.length) {
cordova.ensureCordovaPlatforms(localPath);
}
}
_.each(platforms, function (platform) {
process.stdout.write("added platform " + platform + "\n");
});
});
// remove one or more Cordova platforms
main.registerCommand({
name: "remove-platform",
minArgs: 1,
maxArgs: Infinity,
requiresApp: true
}, function (options) {
var platforms = options.args;
project.removeCordovaPlatforms(platforms);
if (platforms.length) {
var localPath = path.join(options.appDir, '.meteor', 'local');
files.mkdir_p(localPath);
var appName = path.basename(options.appDir);
cordova.ensureCordovaProject(localPath, appName);
if (platforms.length) {
cordova.ensureCordovaPlatforms(localPath);
}
}
_.each(platforms, function (platform) {
process.stdout.write("removed platform " + platform + "\n");
});
});
main.registerCommand({
name: "list-platforms",
requiresApp: true
}, function () {
var platforms = project.getCordovaPlatforms();
process.stdout.write(platforms.join("\n"));
// print nothing at all if no platforms
if (platforms.length) {
process.stdout.write("\n");
}
});

View File

@@ -1151,16 +1151,12 @@ main.registerCommand({
return 1;
}
// Append extra information about special packages, such as Cordova plugins
// and platforms to the list.
// Append extra information about special packages such as Cordova plugins
// to the list.
var plugins = project.getCordovaPlugins();
_.each(plugins, function (version, name) {
items.push({ name: 'cordova:' + name, description: version });
});
var platforms = project.getCordovaPlatforms();
_.each(platforms, function (name) {
items.push({ name: 'platform:' + name, description: 'Mobile build target platform.' });
});
process.stdout.write(formatList(items));
@@ -1562,16 +1558,11 @@ main.registerCommand({
force: { type: Boolean, required: false }
}
}, function (options) {
// Special case on reserved package namespaces, such as 'cordova' or 'platform'
// Special case on reserved package namespaces, such as 'cordova'
try {
var filteredPackages = cordova.filterPackages(options.args);
var cordovaPlatforms = filteredPackages.platforms;
var cordovaPlugins = filteredPackages.plugins;
_.each(cordovaPlatforms, function (platform) {
cordova.checkIsValidPlatform(platform);
});
_.each(cordovaPlugins, function (plugin) {
cordova.checkIsValidPlugin(plugin);
});
@@ -1582,9 +1573,6 @@ main.registerCommand({
var oldPlugins = project.getCordovaPlugins();
// Update the platforms & plugins lists
project.addCordovaPlatforms(cordovaPlatforms);
var pluginsDict = {};
_.each(cordovaPlugins, function (s) {
var splt = s.split('@');
@@ -1594,18 +1582,13 @@ main.registerCommand({
});
project.addCordovaPlugins(pluginsDict);
if (cordovaPlugins.length || cordovaPlatforms.length) {
if (cordovaPlugins.length) {
var localPath = path.join(options.appDir, '.meteor', 'local');
files.mkdir_p(localPath);
var appName = path.basename(options.appDir);
cordova.ensureCordovaProject(localPath, appName);
// We checked the platforms above
if (cordovaPlatforms.length) {
cordova.ensureCordovaPlatforms(localPath);
}
// The plugins installation still can fail
try {
if (cordovaPlugins.length) {
@@ -1621,10 +1604,6 @@ main.registerCommand({
}
}
_.each(cordovaPlatforms, function (platform) {
process.stdout.write("added platform " + platform + "\n");
});
_.each(cordovaPlugins, function (plugin) {
process.stdout.write("added cordova plugin " + plugin + "\n");
});
@@ -1808,34 +1787,25 @@ main.registerCommand({
maxArgs: Infinity,
requiresApp: true
}, function (options) {
// Special case on reserved package namespaces, such as 'cordova' or 'platform'
// Special case on reserved package namespaces, such as 'cordova'
var filteredPackages = cordova.filterPackages(options.args);
var cordovaPlatforms = filteredPackages.platforms;
var cordovaPlugins = filteredPackages.plugins;
// Update the platforms & plugins lists
project.removeCordovaPlatforms(cordovaPlatforms);
// Update the plugins lists
project.removeCordovaPlugins(cordovaPlugins);
if (cordovaPlugins.length || cordovaPlatforms.length) {
if (cordovaPlugins.length) {
var localPath = path.join(options.appDir, '.meteor', 'local');
files.mkdir_p(localPath);
var appName = path.basename(options.appDir);
cordova.ensureCordovaProject(localPath, appName);
if (cordovaPlatforms.length) {
cordova.ensureCordovaPlatforms(localPath);
}
if (cordovaPlugins.length) {
cordova.ensureCordovaPlugins(localPath);
}
}
_.each(cordovaPlatforms, function (platform) {
process.stdout.write("removed platform " + platform + "\n");
});
_.each(cordovaPlugins, function (plugin) {
process.stdout.write("removed cordova plugin " + plugin + "\n");
});

View File

@@ -18,7 +18,7 @@ See 'meteor help <command>' for details on a command.
>>> run
[default] Run this project in local development mode.
Usage: meteor run [options]
Usage: meteor run [platform] [options]
Searches upward from the current directory for the root directory of a
Meteor project, then runs that project in local development
@@ -31,6 +31,9 @@ are automatically detected and applied to the running application.
The application's database persists between runs. It's stored under
the .meteor directory in the root of the project.
If you have added any platforms such as ios or android
using 'meteor add-platform', you can specify which platform to run your app on.
Options:
--port, -p Port to listen on (instead of the default 3000). Also
uses port N+1 and a port specified by --app-port.
@@ -139,6 +142,26 @@ This will not list transitive dependencies.
Also lists the Cordova plugins and platforms used by your mobile
build directly.
>>> add-platform
Add a platform to this project.
Usage: meteor add-platform <platform> [platform..]
Add one or more platforms such as ios or android to your Meteor project,
enabling you to run your app with the new platform as a target.
See 'meteor help run'.
>>> remove-platform
Remove a platform from this project.
Usage: meteor remove-platform <platform> [platform..]
Remove one or more platforms previously added to your Meteor project.
>>> list-platforms
List the platforms added to your project.
Usage: meteor list-packages
Lists all of the platforms that have been added using 'meteor add-platform'.
>>> bundle
Deprecated command. Use 'build' instead.
Usage: meteor bundle <output_file.tar.gz>