2012-05-08 01:56:37 +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.
|
|
|
|
*/
|
|
|
|
|
2011-08-21 04:42:46 +08:00
|
|
|
/*
|
2012-02-02 09:45:49 +08:00
|
|
|
* create a cordova/android project
|
2011-08-21 04:42:46 +08:00
|
|
|
*
|
|
|
|
* USAGE
|
|
|
|
* ./create [path package activity]
|
|
|
|
*/
|
|
|
|
|
|
|
|
function read(filename) {
|
2012-05-17 10:38:11 +08:00
|
|
|
WScript.Echo('Reading in ' + filename);
|
2011-08-21 04:42:46 +08:00
|
|
|
var fso=WScript.CreateObject("Scripting.FileSystemObject");
|
2012-05-17 10:38:11 +08:00
|
|
|
var f=fso.OpenTextFile(filename, 1);
|
2011-08-21 04:42:46 +08:00
|
|
|
var s=f.ReadAll();
|
|
|
|
f.Close();
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
function write(filename, contents) {
|
|
|
|
var fso=WScript.CreateObject("Scripting.FileSystemObject");
|
|
|
|
var f=fso.OpenTextFile(filename, 2, true);
|
|
|
|
f.Write(contents);
|
|
|
|
f.Close();
|
|
|
|
}
|
|
|
|
function replaceInFile(filename, regexp, replacement) {
|
|
|
|
write(filename, read(filename).replace(regexp, replacement));
|
|
|
|
}
|
2012-05-17 10:38:11 +08:00
|
|
|
function exec(s, output) {
|
|
|
|
WScript.Echo('Executing ' + s);
|
2011-08-21 04:42:46 +08:00
|
|
|
var o=shell.Exec(s);
|
2012-05-17 10:38:11 +08:00
|
|
|
while (o.Status == 0) {
|
|
|
|
WScript.Sleep(100);
|
|
|
|
}
|
|
|
|
WScript.Echo("Command exited with code " + o.Status);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fork(s) {
|
|
|
|
WScript.Echo('Executing ' + s);
|
|
|
|
var o=shell.Exec(s);
|
|
|
|
while (o.Status != 1) {
|
|
|
|
WScript.Sleep(100);
|
|
|
|
}
|
|
|
|
WScript.Echo(o.StdOut.ReadAll());
|
|
|
|
WScript.Echo(o.StdErr.ReadAll());
|
|
|
|
WScript.Echo("Command exited with code " + o.Status);
|
2011-08-21 04:42:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var args = WScript.Arguments, PROJECT_PATH="example",
|
2012-02-02 09:45:49 +08:00
|
|
|
PACKAGE="org.apache.cordova.example", ACTIVITY="cordovaExample",
|
2011-08-21 04:42:46 +08:00
|
|
|
shell=WScript.CreateObject("WScript.Shell");
|
|
|
|
|
|
|
|
if (args.Count() == 3) {
|
|
|
|
WScript.Echo('Found expected arguments');
|
|
|
|
PROJECT_PATH=args(0);
|
|
|
|
PACKAGE=args(1);
|
|
|
|
ACTIVITY=args(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
var PACKAGE_AS_PATH=PACKAGE.replace(/\./g, '\\');
|
|
|
|
var ACTIVITY_PATH=PROJECT_PATH+'\\src\\'+PACKAGE_AS_PATH+'\\'+ACTIVITY+'.java';
|
|
|
|
var MANIFEST_PATH=PROJECT_PATH+'\\AndroidManifest.xml';
|
|
|
|
var TARGET=shell.Exec('android.bat list targets').StdOut.ReadAll().match(/id:\s([0-9]).*/)[1];
|
|
|
|
var VERSION=read('VERSION').replace(/\r\n/,'').replace(/\n/,'');
|
|
|
|
|
2012-05-17 10:38:11 +08:00
|
|
|
WScript.Echo("Project path: " + PROJECT_PATH);
|
|
|
|
WScript.Echo("Package: " + PACKAGE);
|
|
|
|
WScript.Echo("Activity: " + ACTIVITY);
|
|
|
|
WScript.Echo("Package as path: " + PACKAGE_AS_PATH);
|
|
|
|
WScript.Echo("Activity path: " + ACTIVITY_PATH);
|
|
|
|
WScript.Echo("Manifest path: " + MANIFEST_PATH);
|
|
|
|
WScript.Echo("Cordova version: " + VERSION);
|
|
|
|
|
2011-08-21 04:42:46 +08:00
|
|
|
// clobber any existing example
|
|
|
|
|
|
|
|
/*
|
|
|
|
if [ $# -eq 0 ]
|
|
|
|
then
|
|
|
|
rm -rf $PROJECT_PATH
|
|
|
|
fi
|
|
|
|
*/
|
|
|
|
|
|
|
|
// create the project
|
|
|
|
exec('android.bat create project --target '+TARGET+' --path '+PROJECT_PATH+' --package '+PACKAGE+' --activity '+ACTIVITY);
|
|
|
|
|
2012-02-02 09:45:49 +08:00
|
|
|
// update the cordova framework project to a target that exists on this machine
|
2011-08-21 04:42:46 +08:00
|
|
|
exec('android.bat update project --target '+TARGET+' --path framework');
|
|
|
|
|
2012-02-02 09:45:49 +08:00
|
|
|
// compile cordova.js and cordova.jar
|
2011-08-21 04:42:46 +08:00
|
|
|
// if you see an error about "Unable to resolve target" then you may need to
|
|
|
|
// update your android tools or install an additional Android platform version
|
2011-08-21 15:29:07 +08:00
|
|
|
exec('ant.bat -f framework\\build.xml jar');
|
2011-08-21 04:42:46 +08:00
|
|
|
|
|
|
|
// copy in the project template
|
|
|
|
exec('cmd /c xcopy bin\\templates\\project '+PROJECT_PATH+' /S /Y');
|
|
|
|
|
2012-05-17 10:38:11 +08:00
|
|
|
// copy example www assets
|
|
|
|
exec('cmd /c xcopy ' + PROJECT_PATH + '\\cordova\\assets ' + PROJECT_PATH + ' /S /Y');
|
|
|
|
|
2012-02-02 09:45:49 +08:00
|
|
|
// copy in cordova.js
|
2012-05-17 10:38:11 +08:00
|
|
|
exec('cmd /c copy framework\\assets\\js\\cordova.android.js '+PROJECT_PATH+'\\.cordova\\android\\cordova-'+VERSION+'.js /Y');
|
2011-08-21 04:42:46 +08:00
|
|
|
|
2012-02-02 09:45:49 +08:00
|
|
|
// copy in cordova.jar
|
2012-05-17 10:38:11 +08:00
|
|
|
exec('cmd /c copy framework\\cordova-'+VERSION+'.jar '+PROJECT_PATH+'\\.cordova\\android\\cordova-'+VERSION+'.jar /Y');
|
|
|
|
|
|
|
|
// copy in xml
|
|
|
|
exec('cmd /c copy framework\\res\\xml\\cordova.xml ' + PROJECT_PATH + '\\.cordova\\android\\cordova.xml /Y');
|
|
|
|
exec('cmd /c copy framework\\res\\xml\\plugins.xml ' + PROJECT_PATH + '\\.cordova\\android\\plugins.xml /Y');
|
|
|
|
|
|
|
|
// write out config file
|
|
|
|
write(PROJECT_PATH + '\\.cordova\\config',
|
|
|
|
'VERSION=' + VERSION + '\r\n' +
|
|
|
|
'PROJECT_PATH=' + PROJECT_PATH + '\r\n' +
|
|
|
|
'PACKAGE=' + PACKAGE + '\r\n' +
|
|
|
|
'ACTIVITY=' + ACTIVITY + '\r\n' +
|
|
|
|
'TARGET=' + TARGET);
|
|
|
|
|
|
|
|
// run project-specific create process
|
|
|
|
fork('cscript.exe ' + PROJECT_PATH + '\\cordova\\create.js');
|