You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2013/10/15 21:10:13 UTC
git commit: CB-2234 Add 'cordova info' command
Updated Branches:
refs/heads/master d1c802424 -> 3b1724da8
CB-2234 Add 'cordova info' command
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/3b1724da
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/3b1724da
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/3b1724da
Branch: refs/heads/master
Commit: 3b1724da822d18376bd09150c6b3aadc7d9dbc76
Parents: d1c8024
Author: Lucas Holmquist <lh...@redhat.com>
Authored: Tue Aug 6 17:04:58 2013 -0400
Committer: Marcel Kinard <cm...@gmail.com>
Committed: Tue Oct 15 15:08:21 2013 -0400
----------------------------------------------------------------------
cordova.js | 1 +
doc/help.txt | 6 ++-
doc/info.txt | 21 ++++++++
doc/platforms.txt | 7 +++
spec/info.spec.js | 61 +++++++++++++++++++++
src/cli.js | 4 ++
src/info.js | 142 +++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 241 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3b1724da/cordova.js
----------------------------------------------------------------------
diff --git a/cordova.js b/cordova.js
index bca8981..eb0c788 100644
--- a/cordova.js
+++ b/cordova.js
@@ -55,5 +55,6 @@ addModuleProperty(module, 'platform', './src/platform', true);
addModuleProperty(module, 'platforms', './src/platform', true);
addModuleProperty(module, 'compile', './src/compile', true);
addModuleProperty(module, 'run', './src/run', true);
+addModuleProperty(module, 'info', './src/info');
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3b1724da/doc/help.txt
----------------------------------------------------------------------
diff --git a/doc/help.txt b/doc/help.txt
index 5a614b3..599e4ae 100644
--- a/doc/help.txt
+++ b/doc/help.txt
@@ -1,5 +1,5 @@
Synopsis
-
+
cordova command [options]
Global Commands
@@ -8,6 +8,10 @@ Global Commands
optional NAME and ID (reverse-domain-style package name)
help ..................................... shows this syntax summary
+ info ..................................... print out useful information helpful for submitting bug
+ reports and getting help. Creates a info.txt file at the
+ base of your project
+
Project-Level Commands
platform(s) [{add|remove|rm} <PLATFORM>] .. add or remove a specified PLATFORM, OR
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3b1724da/doc/info.txt
----------------------------------------------------------------------
diff --git a/doc/info.txt b/doc/info.txt
new file mode 100644
index 0000000..ad3b665
--- /dev/null
+++ b/doc/info.txt
@@ -0,0 +1,21 @@
+Useful Information For Submitting Bug Reports and Getting Help
+
+Current Node Version
+
+ %Node
+
+Current Cordova CLI Version
+
+ %Cordova
+
+Current Config.xml
+
+ %Config
+
+Currently Installed Platforms
+
+ %Platforms
+
+Currently Installed Plugins
+
+ %Plugins
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3b1724da/doc/platforms.txt
----------------------------------------------------------------------
diff --git a/doc/platforms.txt b/doc/platforms.txt
new file mode 100644
index 0000000..58689f7
--- /dev/null
+++ b/doc/platforms.txt
@@ -0,0 +1,7 @@
+----------------------------------------
+
+ %Platform
+
+ %OtherGoodies
+
+----------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3b1724da/spec/info.spec.js
----------------------------------------------------------------------
diff --git a/spec/info.spec.js b/spec/info.spec.js
new file mode 100644
index 0000000..e281829
--- /dev/null
+++ b/spec/info.spec.js
@@ -0,0 +1,61 @@
+var cordova = require('../cordova'),
+ path = require('path'),
+ shell = require('shelljs'),
+ fs = require('fs'),
+ cordova_util = require('../src/util');
+
+var cwd = process.cwd();
+var project_dir = path.join('spec', 'fixtures', 'templates');
+
+describe('info flag', function(){
+ var is_cordova,
+ writeFileSync,
+ cordova_utilSpy,
+ readFileSync,
+ shellSpy,
+ exec = {},
+ done = false;
+
+ function infoPromise( f ) {
+ f.then( function() { done = true; }, function(err) { done = err; } );
+ }
+
+ beforeEach(function() {
+ is_cordova = spyOn(cordova_util, 'isCordova').andReturn(project_dir);
+ writeFileSync = spyOn( fs, 'writeFileSync' );
+ shellSpy = spyOn( shell, 'exec' ).andReturn( "" );
+ cordova_utilSpy = spyOn( cordova_util, 'projectConfig').andReturn( fs.readFileSync( project_dir + "/no_content_config.xml" ) );
+ done = false;
+ });
+
+ it('should not run outside of a Cordova-based project by calling util.isCordova', function() {
+ is_cordova.andReturn(false);
+ runs(function() {
+ infoPromise( cordova.info() );
+ });
+ waitsFor(function() { return done; }, 'platform promise never resolved', 500);
+ runs(function() {
+ expect( done ).toEqual( new Error( 'Current working directory is not a Cordova-based project.' ) );
+ });
+ });
+
+ it('should run inside a Cordova-based project by calling util.isCordova', function() {
+ readFileSync = spyOn( fs, 'readFileSync' ).andReturn( "" );
+ cordova.raw.info().then(function() {
+ expect(is_cordova).toHaveBeenCalled();
+ done();
+ });
+ });
+
+ it('should emit a results event with info contents', function(done) {
+ readFileSync = spyOn( fs, 'readFileSync' ).andReturn( "info" );
+ this.after(function() {
+ cordova.removeAllListeners('results');
+ });
+ cordova.on('results', function(h) {
+ expect(h).toMatch(/info/gi);
+ done();
+ });
+ cordova.info();
+ });
+});
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3b1724da/src/cli.js
----------------------------------------------------------------------
diff --git a/src/cli.js b/src/cli.js
index 6e82f99..4111172 100755
--- a/src/cli.js
+++ b/src/cli.js
@@ -85,6 +85,10 @@ module.exports = function CLI(inputArgs) {
return cordova.help();
}
+ if (cmd === "info") {
+ return cordova.info();
+ }
+
if (cordova.hasOwnProperty(cmd)) {
if (cmd == 'emulate' || cmd == 'build' || cmd == 'prepare' || cmd == 'compile' || cmd == 'run') {
// Filter all non-platforms into options
http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/3b1724da/src/info.js
----------------------------------------------------------------------
diff --git a/src/info.js b/src/info.js
new file mode 100644
index 0000000..b64c58e
--- /dev/null
+++ b/src/info.js
@@ -0,0 +1,142 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+var cordova_util = require('./util'),
+ shell = require('shelljs'),
+ path = require('path'),
+ fs = require('fs'),
+ Q = require('q'),
+ events = require('./events');
+
+/*
+ A utility funciton to help output the information needed
+ when submitting a help request.
+
+ Outputs to a file
+*/
+module.exports = function info() {
+
+ //Get the template
+ var projectRoot = cordova_util.isCordova(process.cwd());
+
+ if (!projectRoot) {
+ return Q.reject( new Error('Current working directory is not a Cordova-based project.') );
+ }
+
+ var raw = fs.readFileSync(path.join(__dirname, '..', 'doc', 'info.txt'), 'utf-8').split("\n"),
+ output;
+
+ output = raw.map(function(line) {
+ if(line.match(' %') ) {
+ var type = line.substr(5),
+ out = "";
+
+ switch(type) {
+ case "Node":
+ out = shell.exec('node --version',{silent:true}).output;
+ break;
+ case "Cordova":
+ out = require('../package').version;
+ break;
+ case "Config":
+ out = fs.readFileSync( cordova_util.projectConfig(projectRoot) );
+ break;
+ case "Platforms":
+ out = doPlatforms( projectRoot );
+ break;
+ case "Plugins":
+ out = doPlugins( projectRoot );
+ break;
+ default:
+ break;
+ }
+ return line.replace( "%"+type, out );
+ } else {
+ return line;
+ }
+ }).join("\n");
+
+ // /*
+ // Write to File;
+ // */
+ events.emit('results', output);
+ fs.writeFileSync('info.txt', output );
+ return Q();
+};
+
+function doPlatform( currentPlatform ) {
+ var output = "";
+ switch( currentPlatform ){
+ case "ios":
+ output = shell.exec('xcodebuild -version',{silent:true} ).output;
+ break;
+ case "android":
+ output = shell.exec('android list target',{silent:true} ).output;
+ }
+
+ return output;
+}
+
+function doPlatforms( projectRoot ){
+ var platforms = cordova_util.listPlatforms(projectRoot);
+
+ if( platforms.length ) {
+
+ var raw = fs.readFileSync(path.join(__dirname, '..', 'doc', 'platforms.txt')).toString('utf8').split("\n"),
+ output = "",
+ i;
+
+ for(i=0; i<platforms.length; i++){
+ output += raw.map(function(line) {
+ if(line.match(' %') ) {
+ var type = line.substr(5),
+ out = "";
+
+ switch(type) {
+ case "OtherGoodies":
+ out = doPlatform( platforms[ i ] );
+ break;
+ case "Platform":
+ out = platforms[ i ];
+ break;
+ default:
+ break;
+ }
+ return line.replace( "%"+type, out );
+ } else {
+ return line.magenta;
+ }
+ }).join("\n");
+ }
+
+ return output;
+ } else {
+ return "No Platforms Currently Installed";
+ }
+}
+
+function doPlugins( projectRoot ){
+ var pluginPath = path.join(projectRoot, 'plugins'),
+ plugins = cordova_util.findPlugins(pluginPath);
+
+ if( !plugins.length ) {
+ return "No Plugins Currently Installed";
+ } else {
+ return plugins;
+ }
+}