2013-04-17 01:34:14 +08:00
// 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 ROOT = WScript . ScriptFullName . split ( '\\bin\\check_reqs.js' ) . join ( '' ) ,
shell = WScript . CreateObject ( "WScript.Shell" ) ,
fso = WScript . CreateObject ( 'Scripting.FileSystemObject' ) ;
// executes a command in the shell, returns stdout or stderr if error
function exec _out ( command ) {
var oExec = shell . Exec ( command ) ;
var output = new String ( ) ;
while ( oExec . Status == 0 ) {
if ( ! oExec . StdOut . AtEndOfStream ) {
var line = oExec . StdOut . ReadAll ( ) ;
// XXX: Change to verbose mode
// WScript.StdOut.WriteLine(line);
output += line ;
}
WScript . sleep ( 100 ) ;
}
//Check to make sure our scripts did not encounter an error
if ( ! oExec . StdErr . AtEndOfStream ) {
var line = oExec . StdErr . ReadAll ( ) ;
return { 'error' : true , 'output' : line } ;
} else if ( ! oExec . StdOut . AtEndOfStream ) {
var line = oExec . StdOut . ReadAll ( ) ;
// XXX: Change to verbose mode
// WScript.StdOut.WriteLine(line);
output += line ;
}
return { 'error' : false , 'output' : output } ;
}
// log to stdout or stderr
function Log ( msg , error ) {
if ( error ) {
WScript . StdErr . WriteLine ( msg ) ;
}
else {
WScript . StdOut . WriteLine ( msg ) ;
}
2013-08-02 08:57:58 +08:00
}
2013-04-17 01:34:14 +08:00
// checks that android requirements are met
function check _requirements ( ) {
2013-08-02 08:57:58 +08:00
var target = get _target ( ) ;
if ( target == null ) {
Log ( 'Unable to find android target in project.properties' ) ;
WScript . Quit ( 2 ) ;
}
2013-04-17 01:34:14 +08:00
var result = exec _out ( '%comspec% /c android list target' ) ;
if ( result . error ) {
Log ( 'The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path. Output: ' + result . output , true ) ;
WScript . Quit ( 2 ) ;
}
2013-08-02 08:57:58 +08:00
else if ( result . output . indexOf ( target ) == - 1 ) {
Log ( result . output . indexOf ( target ) ) ;
Log ( 'Please install the latest Android target (' + target + '). Make sure you have the latest Android tools installed as well. Run `android` from your command-line to install/update any missing SDKs or tools.' , true ) ;
Log ( result . output ) ;
2013-04-17 01:34:14 +08:00
WScript . Quit ( 2 ) ;
}
else {
2013-08-02 08:57:58 +08:00
var cmd = '%comspec% /c android update project -p ' + ROOT + '\\framework -t ' + target ;
2013-04-17 01:34:14 +08:00
result = exec _out ( cmd ) ;
if ( result . error ) {
Log ( 'Error updating the Cordova library to work with your Android environment. Command run: "' + cmd + '", output: ' + result . output , true ) ;
WScript . Quit ( 2 ) ;
}
}
}
2013-08-02 08:57:58 +08:00
function get _target ( ) {
var fso = WScript . CreateObject ( "Scripting.FileSystemObject" ) ;
var f = fso . OpenTextFile ( ROOT + '\\framework\\project.properties' , 1 ) ;
var s = f . ReadAll ( ) ;
var lines = s . split ( '\n' ) ;
for ( var line in lines ) {
if ( lines [ line ] . match ( /target=/ ) )
{
return lines [ line ] . split ( '=' ) [ 1 ] . replace ( ' ' , '' ) . replace ( '\r' , '' ) ;
}
}
return null ;
}
2013-07-31 08:14:46 +08:00
check _requirements ( ) ;
2013-08-02 08:57:58 +08:00