You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/06/19 11:00:09 UTC
[2/4] git commit: create scripts working for wp7+8
create scripts working for wp7+8
Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/2274413d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/2274413d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/2274413d
Branch: refs/heads/master
Commit: 2274413ddb09ee6a091d502dd9aae0d535fadaff
Parents: 8310bce
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Wed Jun 19 01:17:02 2013 -0700
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Wed Jun 19 01:17:02 2013 -0700
----------------------------------------------------------------------
wp7/bin/check_reqs | 24 +++
wp7/bin/check_reqs.bat | 9 ++
wp7/bin/check_reqs.js | 111 ++++++++++++++
wp7/bin/create.bat | 9 ++
wp7/bin/create.js | 226 ++++++++++++++++++++++++++++
wp7/bin/update.bat | 9 ++
wp7/bin/update.js | 353 ++++++++++++++++++++++++++++++++++++++++++++
wp8/bin/check_reqs | 24 +++
wp8/bin/check_reqs.bat | 9 ++
wp8/bin/check_reqs.js | 111 ++++++++++++++
wp8/bin/create.bat | 9 ++
wp8/bin/create.js | 226 ++++++++++++++++++++++++++++
wp8/bin/update.bat | 9 ++
wp8/bin/update.js | 353 ++++++++++++++++++++++++++++++++++++++++++++
14 files changed, 1482 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp7/bin/check_reqs
----------------------------------------------------------------------
diff --git a/wp7/bin/check_reqs b/wp7/bin/check_reqs
new file mode 100644
index 0000000..d1b9bc0
--- /dev/null
+++ b/wp7/bin/check_reqs
@@ -0,0 +1,24 @@
+#! /bin/sh
+
+#
+# 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.
+#
+
+echo "ERROR: Cordova tooling for Windows Phone requires a Windows OS with the 'msbuild' command "
+echo " in the PATH environment variable as well as having .NET Framework 4.0 (from WP SDK's)"
+exit 1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp7/bin/check_reqs.bat
----------------------------------------------------------------------
diff --git a/wp7/bin/check_reqs.bat b/wp7/bin/check_reqs.bat
new file mode 100644
index 0000000..26e7393
--- /dev/null
+++ b/wp7/bin/check_reqs.bat
@@ -0,0 +1,9 @@
+@ECHO OFF
+SET full_path=%~dp0
+IF EXIST %full_path%check_reqs.js (
+ cscript "%full_path%check_reqs.js" %* //nologo
+) ELSE (
+ ECHO.
+ ECHO ERROR: Could not find 'check_reqs.js' in 'bin' folder, aborting...>&2
+ EXIT /B 1
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp7/bin/check_reqs.js
----------------------------------------------------------------------
diff --git a/wp7/bin/check_reqs.js b/wp7/bin/check_reqs.js
new file mode 100644
index 0000000..3dc1496
--- /dev/null
+++ b/wp7/bin/check_reqs.js
@@ -0,0 +1,111 @@
+/*
+ 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 args = WScript.Arguments;
+var wscript_shell = WScript.CreateObject("WScript.Shell");
+
+var REQUIRE_GIT = false;
+
+function Usage() {
+ Log("Usage: [ check_reqs | cscript check_reqs.js ]");
+ Log("examples:");
+ Log(" cscript C:\\Users\\anonymous\\cordova-wp7\\bin\\check_reqs.js");
+ Log(" CordovaWindowsPhone\\bin\\check_reqs");
+
+}
+
+// log to stdout or stderr
+function Log(msg, error) {
+ if (error) {
+ WScript.StdErr.WriteLine(msg);
+ }
+ else {
+ WScript.StdOut.WriteLine(msg);
+ }
+}
+
+// gets the output from a command, failing with the given error message
+function check_command(cmd, fail_msg) {
+ var out = wscript_shell.Exec(cmd);
+ while (out.Status == 0) {
+ WScript.Sleep(100);
+ }
+
+ //Check that command executed
+ if (!out.StdErr.AtEndOfStream) {
+ var line = out.StdErr.ReadLine();
+ Log(fail_msg, true);
+ Log('Output : ' + line, true);
+ WScript.Quit(1);
+ }
+
+ if (!out.StdOut.AtEndOfStream) {
+ var line = out.StdOut.ReadAll();
+ return line;
+ }
+ else {
+ Log('Unable to get output from command "' + cmd + '"', true);
+ WScript.Quit(1);
+ }
+}
+
+/* The tooling for cordova windows phone requires these commands
+ * in the environment PATH variable.
+ * - msbuild (C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319)
+ * - git? (for dynamic cli loading of projects?)
+ */
+function SystemRequiermentsMet() {
+ var cmd = 'msbuild -version'
+ var fail_msg = 'The command `msbuild` failed. Make sure you have the latest Windows Phone SDKs installed, and the `msbuild.exe` command (inside C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319) is added to your path.'
+ var output = check_command(cmd, fail_msg);
+ var msversion = output.match(/\.NET\sFramework\,\sversion\s4\.0/);
+ if (!msversion) {
+ Log('Please install the .NET Framwork v4.0.30319 (in the latest windows phone SDK\'s).', true);
+ Log('Make sure the "msbuild" command in your path is pointing to v4.0.30319 of msbuild as well (inside C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319).', true);
+ WScript.Quit(1);
+ }
+
+ if(REQUIRE_GIT) {
+ cmd = 'git --version';
+ fail_msg = 'The command `git` failed. Make sure you have git installed as well ad in your PATH environment so the tool can use it';
+ output = check_command(cmd, fail_msg);
+ var gitVersion = output.match(/git\sversion\s1\./);
+ if (!gitVersion) {
+ Log('Please ensure you have at least git v1 installed and added to you PATH so this tool can use it to get the latest codova.');
+ }
+ }
+}
+
+
+if (args.Count() > 0) {
+ // support help flags
+ if (args(0) == "--help" || args(0) == "/?" ||
+ args(0) == "help" || args(0) == "-help" || args(0) == "/help" || args(0) == "-h") {
+ Usage();
+ WScript.Quit(1);
+ }
+ else {
+ Log('Error : Did not recognize argument ' + args(0), true)
+ Usage();
+ WScript.Quit(1);
+ }
+}
+
+SystemRequiermentsMet();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp7/bin/create.bat
----------------------------------------------------------------------
diff --git a/wp7/bin/create.bat b/wp7/bin/create.bat
new file mode 100644
index 0000000..329048e
--- /dev/null
+++ b/wp7/bin/create.bat
@@ -0,0 +1,9 @@
+@ECHO OFF
+SET full_path=%~dp0
+IF EXIST %full_path%create.js (
+ cscript "%full_path%create.js" %* //nologo
+) ELSE (
+ ECHO.
+ ECHO ERROR: Could not find 'create.js' in 'bin' folder, aborting...>&2
+ EXIT /B 1
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp7/bin/create.js
----------------------------------------------------------------------
diff --git a/wp7/bin/create.js b/wp7/bin/create.js
new file mode 100644
index 0000000..db22352
--- /dev/null
+++ b/wp7/bin/create.js
@@ -0,0 +1,226 @@
+/*
+ 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.
+*/
+
+/*
+ * create a cordova/wp7 project
+ *
+ * USAGE
+ * ./create [path package activity]
+
+ ./bin/create.bat C:\Users\Me\MyTestProj "test.proj" "TestProject"
+ */
+
+
+var fso=WScript.CreateObject("Scripting.FileSystemObject");
+var wscript_shell = WScript.CreateObject("WScript.Shell");
+// working dir
+var platformRoot = WScript.ScriptFullName.split('\\bin\\create.js').join('');
+var repoRoot = fso.GetParentFolderName(platformRoot);
+var args = WScript.Arguments;
+var templatePath = "\\template"
+var destPath;
+
+
+Log("platformRoot = " + platformRoot);
+Log("repoRoot = " + repoRoot);
+
+
+function Usage() {
+ Log("Usage: create PathToNewProject [ PackageName AppName ]");
+ Log(" PathToNewProject : The path to where you wish to create the project");
+ Log(" PackageName : The namespace for the project (default is Cordova.Example)")
+ Log(" AppName : The name of the application (default is CordovaAppProj)");
+ Log("examples:");
+ Log(" create C:\\Users\\anonymous\\Desktop\\MyProject");
+ Log(" create C:\\Users\\anonymous\\Desktop\\MyProject io.Cordova.Example AnApp");
+}
+
+// logs messaged to stdout and stderr
+function Log(msg, error) {
+ if (error) {
+ WScript.StdErr.WriteLine(msg);
+ }
+ else {
+ WScript.StdOut.WriteLine(msg);
+ }
+}
+
+var ForReading = 1, ForWriting = 2, ForAppending = 8;
+var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
+
+function read(filename) {
+ Log("Reading file : " + filename);
+ var f=fso.OpenTextFile(filename, 1,2);
+ var s=f.ReadAll();
+ f.Close();
+ return s;
+}
+
+function write(filename, contents) {
+ var f=fso.OpenTextFile(filename, ForWriting, TristateTrue);
+ f.Write(contents);
+ f.Close();
+}
+
+function replaceInFile(filename, regexp, replacement) {
+ write(filename,read(filename).replace(regexp,replacement));
+}
+
+// deletes file if it exists
+function deleteFileIfExists(path) {
+ if(fso.FileExists(path)) {
+ fso.DeleteFile(path);
+ }
+}
+
+
+// executes a commmand in the shell
+function exec(command) {
+ var oShell=wscript_shell.Exec(command);
+ while (oShell.Status == 0) {
+ WScript.sleep(100);
+ }
+}
+
+// executes a commmand in the shell
+function exec_verbose(command) {
+ //Log("Command: " + command);
+ var oShell=wscript_shell.Exec(command);
+ while (oShell.Status == 0) {
+ //Wait a little bit so we're not super looping
+ WScript.sleep(100);
+ //Print any stdout output from the script
+ if (!oShell.StdOut.AtEndOfStream) {
+ var line = oShell.StdOut.ReadLine();
+ Log(line);
+ }
+ }
+ //Check to make sure our scripts did not encounter an error
+ if (!oShell.StdErr.AtEndOfStream) {
+ var line = oShell.StdErr.ReadAll();
+ Log(line, true);
+ WScript.Quit(1);
+ }
+}
+
+//generate guid for the project
+function genGuid() {
+ var TypeLib = WScript.CreateObject("Scriptlet.TypeLib");
+ strGuid = TypeLib.Guid.split("}")[0]; // there is extra crap after the } that is causing file streams to break, probably an EOF ...
+ strGuid = strGuid.replace(/[\{\}]/g,"");
+ return strGuid;
+}
+
+// creates new project in path, with the given package and app name
+function create(path, namespace, name) {
+ Log("Creating Cordova-WP7 Project:");
+ Log("\tApp Name : " + name);
+ Log("\tNamespace : " + namespace);
+ Log("\tPath : " + path);
+
+ // Copy the template source files to the new destination
+ fso.CopyFolder(platformRoot + templatePath, path);
+ // copy over common files
+ fso.CopyFolder(repoRoot + "\\common", path);
+ // copy the version file
+ fso.CopyFile(repoRoot +'\\VERSION',path + "\\" );
+
+ // remove template cruft
+ deleteFileIfExists(path + "\\__PreviewImage.jpg");
+ deleteFileIfExists(path + "\\__TemplateIcon.png");
+ deleteFileIfExists(path + "\\MyTemplate.vstemplate");
+
+ var newProjGuid = genGuid();
+ // replace the guid in the AppManifest
+ replaceInFile(path + "\\Properties\\WMAppManifest.xml","$guid1$",newProjGuid);
+ // replace safe-project-name in AppManifest
+ replaceInFile(path + "\\Properties\\WMAppManifest.xml",/\$safeprojectname\$/g,name);
+ replaceInFile(path + "\\Properties\\WMAppManifest.xml",/\$projectname\$/g,name);
+
+ replaceInFile(path + "\\App.xaml",/\$safeprojectname\$/g,namespace);
+ replaceInFile(path + "\\App.xaml.cs",/\$safeprojectname\$/g,namespace);
+
+ replaceInFile(path + "\\MainPage.xaml",/\$safeprojectname\$/g,namespace);
+ replaceInFile(path + "\\MainPage.xaml.cs",/\$safeprojectname\$/g,namespace);
+ replaceInFile(path + "\\CordovaWP7AppProj.csproj",/\$safeprojectname\$/g,namespace);
+
+ if (name != "CordovaWP7AppProj") {
+ var valid_name = name.replace(/(\.\s|\s\.|\s+|\.+)/g, '_');
+ replaceInFile(path + "\\CordovaSolution.sln", /CordovaAppProj/g, valid_name);
+ // rename project and solution
+ exec('%comspec% /c ren ' + path + "\\CordovaWP7Solution.sln " + valid_name + '.sln');
+ exec('%comspec% /c ren ' + path + "\\CordovaWP7AppProj.csproj " + valid_name + '.csproj');
+ }
+
+ //clean up any Bin/obj or other generated files
+ exec('cscript ' + path + '\\cordova\\lib\\clean.js //nologo');
+
+ // delete any .user and .sou files if any
+ if (fso.FolderExists(path)) {
+ var proj_folder = fso.GetFolder(path);
+ var proj_files = new Enumerator(proj_folder.Files);
+ for (;!proj_files.atEnd(); proj_files.moveNext()) {
+ if (fso.GetExtensionName(proj_files.item()) == 'user') {
+ fso.DeleteFile(proj_files.item());
+ } else if (fso.GetExtensionName(proj_files.item()) == 'sou') {
+ fso.DeleteFile(proj_files.item());
+ }
+ }
+ }
+
+ Log("CREATE SUCCESS : " + path);
+
+ // TODO:
+ // index.html title set to project name?
+}
+
+// MAIN
+
+if (args.Count() > 0) {
+ // support help flags
+ if (args(0) == "--help" || args(0) == "/?" ||
+ args(0) == "help" || args(0) == "-help" || args(0) == "/help" || args(0) == "-h") {
+ Usage();
+ WScript.Quit(1);
+ }
+
+ destPath = args(0);
+ if (fso.FolderExists(destPath)) {
+ Log("Project directory already exists:", true);
+ Log("\t" + destPath, true);
+ Log("CREATE FAILED.", true);
+ WScript.Quit(1);
+ }
+ var packageName = "Cordova.Example";
+ if (args.Count() > 1) {
+ packageName = args(1);
+ }
+
+ var projName = "CordovaWP7AppProj";
+ if (args.Count() > 2) {
+ projName = args(2);
+ }
+
+ create(destPath, packageName, projName);
+}
+else {
+ Usage();
+ WScript.Quit(1);
+}
+
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp7/bin/update.bat
----------------------------------------------------------------------
diff --git a/wp7/bin/update.bat b/wp7/bin/update.bat
new file mode 100644
index 0000000..9da7e3c
--- /dev/null
+++ b/wp7/bin/update.bat
@@ -0,0 +1,9 @@
+@ECHO OFF
+SET full_path=%~dp0
+IF EXIST %full_path%update.js (
+ cscript "%full_path%update.js" %* //nologo
+) ELSE (
+ ECHO.
+ ECHO ERROR: Could not find 'update.js' in 'bin' folder, aborting...>&2
+ EXIT /B 1
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp7/bin/update.js
----------------------------------------------------------------------
diff --git a/wp7/bin/update.js b/wp7/bin/update.js
new file mode 100644
index 0000000..8ea38a8
--- /dev/null
+++ b/wp7/bin/update.js
@@ -0,0 +1,353 @@
+/*
+ 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 fso = WScript.CreateObject("Scripting.FileSystemObject");
+var wscript_shell = WScript.CreateObject("WScript.Shell");
+var shell = WScript.CreateObject("shell.application");
+var args = WScript.Arguments;
+// working dir
+var ROOT = WScript.ScriptFullName.split('\\bin\\update.js').join('');
+//Get version number
+var VERSION = read(ROOT+'\\VERSION').replace(/\r\n/,'').replace(/\n/,'');
+var plugins_folder = "\\Plugins";
+var template_folder = "\\templates\\standalone";
+// anything thats missing to the project
+var overwrite = false;
+var replace = false;
+
+// usage function
+function Usage() {
+ Log("WARNING : Make sure to back up your project before updating!")
+ Log("Usage: update Path-To-Project ");//[ -f | -r ] ");
+ Log(" Path-To-Old-Project : The path the project you would like to update.");
+ //Log(" -f : Will forcefully overwrite and add all core components of the application.");
+ //Log(" -r : Will create an updated project, only keeping the www assets. *NOTE: no native code will be preserved*");
+ Log("examples:");
+ Log(" update C:\\Users\\anonymous\\Desktop\\MyProject");
+}
+
+// logs messaged to stdout and stderr
+function Log(msg, error) {
+ if (error) {
+ WScript.StdErr.WriteLine(msg);
+ }
+ else {
+ WScript.StdOut.WriteLine(msg);
+ }
+}
+
+// executes a commmand in the shell
+function exec(command) {
+ //Log("Command : " + command);
+ var oShell=wscript_shell.Exec(command);
+ while (oShell.Status === 0) {
+ WScript.sleep(100);
+ }
+}
+
+// executes a commmand in the shell
+function exec_verbose(command) {
+ Log("Command: " + command);
+ var oShell=wscript_shell.Exec(command);
+ while (oShell.Status == 0) {
+ //Wait a little bit so we're not super looping
+ WScript.sleep(100);
+ //Print any stdout output from the script
+ if (!oShell.StdOut.AtEndOfStream) {
+ var line = oShell.StdOut.ReadAll();
+ Log(line);
+ }
+ }
+ //Check to make sure our scripts did not encounter an error
+ if (!oShell.StdErr.AtEndOfStream) {
+ var line = oShell.StdErr.ReadAll();
+ Log(line, true);
+ WScript.Quit(2);
+ }
+}
+
+var ForReading = 1, ForWriting = 2, ForAppending = 8;
+var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
+
+// returns the contents of a file
+function read(filename) {
+ if (fso.FileExists(filename)) {
+ var f=fso.OpenTextFile(filename, 1, 2);
+ var s=f.ReadAll();
+ f.Close();
+ return s;
+ }
+ else {
+ Log('Cannot read non-existant file : ' + filename, true);
+ WScript.Quit(2);
+ }
+ return null;
+}
+
+// writes the contents to the specified file
+function write(filename, contents) {
+ var f=fso.OpenTextFile(filename, ForWriting, TristateTrue);
+ f.Write(contents);
+ f.Close();
+}
+
+// replaces the matches of regexp with replacement
+function replaceInFile(filename, regexp, replacement) {
+ var text = read(filename).replace(regexp,replacement);
+ write(filename,text);
+}
+
+// returns true if the given path is the root of a cordova windows phone project
+// currently returns true if the folder contains a .csproj file.
+function is_windows_phone_project(path) {
+ if (fso.FolderExists(path)) {
+ var proj_folder = fso.GetFolder(path);
+ var proj_files = new Enumerator(proj_folder.Files);
+ for (;!proj_files.atEnd(); proj_files.moveNext()) {
+ if (fso.GetExtensionName(proj_files.item()) == 'csproj') {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+// returns the name of the application
+function get_app_name(path) {
+ var WMAppManifest = read(path + '\\Properties\\WMAppManifest.xml').split('\n');
+ for (line in WMAppManifest) {
+ if (WMAppManifest[line].match(/Title\=\"/)) {
+ return WMAppManifest[line].split('Title="')[1].split('"')[0];
+ }
+ }
+ Log("Error : unable to find applicaiton name in the project.", true);
+ Log(" Path : " + path, true);
+ WScript.Quit(2);
+}
+
+// returns the name of the application package
+function get_package_name(path) {
+ var WMAppManifest = read(path + '\\Properties\\WMAppManifest.xml').split('\n');
+ for (line in WMAppManifest) {
+ if (WMAppManifest[line].match(/Title\=\"/)) {
+ return WMAppManifest[line].split('Title="')[1].split('"')[0];
+ }
+ }
+ Log("Error : unable to find applicaiton name in the project.", true);
+ Log(" Path : " + path, true);
+ WScript.Quit(2);
+}
+
+// returns the GUID ame of the application
+function get_app_GUID(path) {
+ var AppXAML = read(path + '\\App.xaml').split('\n');
+ for (line in AppXAML) {
+ if (AppXAML[line].match(/x\:Class\=\"/)) {
+ return AppXAML[line].split('Class="')[1].split('"')[0];
+ }
+ }
+ Log("Error : unable to find package name in the project.", true);
+ Log(" Path : " + path, true);
+ WScript.Quit(2);
+}
+
+// updates the cordova.js and all references in the given project with this repositories version
+function update_cordova_js(path) {
+ // remove old cordova.js
+ var www_contents = shell.NameSpace(path + '\\www').Items();
+ for(i = 0; i < www_contents.Count; i++)
+ {
+ if(www_contents.Item(i).Name.match(/cordova\-(\d+)[.](\d+)[.](\d+)(rc\d)?[.]js/))
+ {
+ fso.DeleteFile(path + '\\www\\' + www_contents.Item(i).Name);
+ }
+ }
+ // update version file
+ copy_to(ROOT + "\\VERSION", path + "\\VERSION");
+ // copy over new cordova.js
+ copy_to(ROOT + template_folder + "\\www\\cordova.js", path + "\\www\\cordova.js");
+
+ // update corodva references
+ var cordova_regex = /cordova-(\d+)[.](\d+)[.](\d+)(rc\d)?/g; //Matches *first* cordova-x.x.x[rcx] (just ad g at end to make global)
+ // update references in index.html
+ replaceInFile(path + '\\www\\index.html', cordova_regex, "cordova");
+ version_regex = /return\s*\"(\d+)[.](\d+)[.](\d+)(rc\d)?/; //Matches return "x.x.x[rcx]
+ // update references in Device.cs
+ replaceInFile(path + '\\Plugins\\Device.cs', version_regex, "return \"" + VERSION);
+}
+
+// Copies assets that need to be saved from source to desination.
+// TODO : Add all critical assets here
+function save_restore(source, destination) {
+ fso.CreateFolder(destination + '\\www');
+ copy_to(source + '\\www', destination + '\\www');
+ copy_to(source + '\\SplashScreenImage.jpg', destination + '\\SplashScreenImage.jpg');
+ copy_to(source + '\\Background.png', destination + '\\Background.png');
+ copy_to(source + '\\ApplicationIcon.png', destination + '\\ApplicationIcon.png');
+ copy_to(source + '\\config.xml', destination + '\\config.xml');
+}
+
+// deletes the path element if it exists
+function delete_if_exists(path) {
+ if (fso.FolderExists(path)) {
+ fso.DeleteFolder(path);
+ }
+ else if (fso.FileExists(path)) {
+ fso.DeleteFile(path);
+ }
+}
+
+// copies a folder or file from source to destination
+function copy_to(source, destination) {
+ // check that source exists
+ if (!fso.FolderExists(source)) {
+ if (!fso.FileExists(source)) {
+ Log("Error : Could not copy file/folder because it doesn't exist.", true);
+ Log(" File/Folder : " + source, true);
+ WScript.Quit(2);
+ }
+ }
+ // if source is a folder, then copy all folder contents
+ if (fso.FolderExists(source)) {
+ fso.CopyFolder(source, destination, true);
+ }
+ // if it's a file, just copy it.
+ else {
+ exec('%comspec% /c copy /Y /V ' + source + ' ' + destination);
+ }
+}
+
+// updates the cordova.js in project along with the cordova tooling.
+function update_project(path) {
+ // update cordova folder
+ delete_if_exists(path + '\\cordova');
+ fso.CreateFolder(path + '\\cordova');
+ copy_to(ROOT + template_folder + '\\cordova', path + '\\cordova');
+ // clean project (all generated files)
+ exec(path + '\\cordova\\clean.bat');
+
+ // update core cordovalib
+ delete_if_exists(path + '\\cordovalib');
+ fso.CreateFolder(path + '\\cordovalib');
+ copy_to(ROOT + template_folder + '\\cordovalib', path + '\\cordovalib');
+
+ // update core plugins
+ // TODO : Remove for 3.0.0
+ delete_if_exists(path + '\\Plugins');
+ fso.CreateFolder(path + '\\Plugins');
+ copy_to(ROOT + template_folder + '\\Plugins', path + '\\Plugins');
+
+ // update cordova.js
+ update_cordova_js(path);
+}
+
+// Replaces the current project with a newly created project, keeping important assets to preserve the app.
+// TODO: Things that need to be kept other then www
+// - WMAppManifest (capabilities etc...)
+// - GUID (for marketplace apps etc...)
+// - Splashscreen and other images etc...
+// - Find more things that should be kept
+function replace_project(path) {
+ //create new project and move www assets into it.
+ Log("WARNING : Upgrading your app with the \'-r\' flag will delete all native and plugin");
+ Log(" components of your application and replace them with the updated core components given");
+ Log(" by this platforms \'bin\\create\' script. It is *HIGHLY RECOMMENDED* to back up your app");
+ Log(" before continuing. The name and package name along with all of the www assets will be");
+ Log(" preserved. Are you sure you wish to continue? (Y/N)");
+ var response;
+ while (response != 'Y') {
+ response = WScript.StdIn.ReadLine();
+ if (response == 'N') {
+ WScript.Quit(2);
+ } else if (response != "Y") {
+ Log("Error : did not recognize '" + response + "'");
+ Log("Are you sure you wish to continue? (Y/N)");
+ }
+ }
+ // place all assets to be preserved in a temperary folder
+ delete_if_exists(ROOT + '\\temp');
+ fso.CreateFolder(ROOT + '\\temp');
+ save_restore(path, ROOT + '\\temp');
+
+ // get app name from WMAppManifest
+ var app_name = get_app_name(path);
+ // get package name from App.xaml
+ var package_name = get_package_name(path);
+ // get the GUID so that app stays the same
+ var app_GUID = get_app_GUID(path);
+ // delete previous project
+ delete_if_exists(path);
+ // create the new project from the current repository
+ exec(ROOT + '\\bin\\create.bat ' + path + ' ' + app_name + ' ' + package_name);
+ // remove default www assets
+ delete_if_exists(path + '\\www');
+ // move www assets back to project folder
+ save_restore(ROOT + '\\temp', path);
+ // cleanup temp folder
+ delete_if_exists(ROOT + '\\temp');
+}
+
+
+
+if (args.Count() > 0) {
+ if(args.Count() > 2) {
+ Log("Error : too many arguments provided.", true);
+ WScript.Quit(1);
+ }
+
+ if (args(0).indexOf("--help") > -1 ||
+ args(0).indexOf("/?") > -1 ) {
+ Usage();
+ WScript.Quit(1);
+ }
+ else if (fso.FolderExists(args(0)) && is_windows_phone_project(args(0))) {
+ if(args.Count() > 1) {
+ /*if(args(1) == '-f' || args(1) == '--force') {
+ //TODO: do something for this
+ Log("ERROR : NOT IMPLEMENTED", true);
+ WScript.Quit(2);
+ }
+ else if(args(1) == '-r' || args(1) == '--replace') {
+ replace_project(args(0));
+ }
+ else {
+ Log('Error : \'' + args(1) + '\' is not regognized as an update option', true);
+ }*/
+ Usage();
+ Log('Error : too many arguments', true);
+ } else if (args.Count() == 1) {
+ update_project(args(0));
+ }
+ }
+ else if (fso.FolderExists(args(0))) {
+ Log("The path provided is not a path to a cordova windows phone project.", true);
+ Log(" Please provide the path to the root folder of your cordova windows phone project.", true);
+ WScript.Quit(2);
+ }
+ else {
+ Log("The given path to the project does not exist.", true);
+ Log(" Please provide a path to the project you would like to update.", true);
+ Usage();
+ WScript.Quit(2);
+ }
+}
+else {
+ Usage();
+ WScript.Quit(1);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp8/bin/check_reqs
----------------------------------------------------------------------
diff --git a/wp8/bin/check_reqs b/wp8/bin/check_reqs
new file mode 100644
index 0000000..d1b9bc0
--- /dev/null
+++ b/wp8/bin/check_reqs
@@ -0,0 +1,24 @@
+#! /bin/sh
+
+#
+# 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.
+#
+
+echo "ERROR: Cordova tooling for Windows Phone requires a Windows OS with the 'msbuild' command "
+echo " in the PATH environment variable as well as having .NET Framework 4.0 (from WP SDK's)"
+exit 1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp8/bin/check_reqs.bat
----------------------------------------------------------------------
diff --git a/wp8/bin/check_reqs.bat b/wp8/bin/check_reqs.bat
new file mode 100644
index 0000000..26e7393
--- /dev/null
+++ b/wp8/bin/check_reqs.bat
@@ -0,0 +1,9 @@
+@ECHO OFF
+SET full_path=%~dp0
+IF EXIST %full_path%check_reqs.js (
+ cscript "%full_path%check_reqs.js" %* //nologo
+) ELSE (
+ ECHO.
+ ECHO ERROR: Could not find 'check_reqs.js' in 'bin' folder, aborting...>&2
+ EXIT /B 1
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp8/bin/check_reqs.js
----------------------------------------------------------------------
diff --git a/wp8/bin/check_reqs.js b/wp8/bin/check_reqs.js
new file mode 100644
index 0000000..492b13f
--- /dev/null
+++ b/wp8/bin/check_reqs.js
@@ -0,0 +1,111 @@
+/*
+ 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 args = WScript.Arguments;
+var wscript_shell = WScript.CreateObject("WScript.Shell");
+
+var REQUIRE_GIT = false;
+
+function Usage() {
+ Log("Usage: [ check_reqs | cscript check_reqs.js ]");
+ Log("examples:");
+ Log(" cscript C:\\Users\\anonymous\\cordova-wp8\\bin\\check_reqs.js");
+ Log(" CordovaWindowsPhone\\bin\\check_reqs");
+
+}
+
+// log to stdout or stderr
+function Log(msg, error) {
+ if (error) {
+ WScript.StdErr.WriteLine(msg);
+ }
+ else {
+ WScript.StdOut.WriteLine(msg);
+ }
+}
+
+// gets the output from a command, failing with the given error message
+function check_command(cmd, fail_msg) {
+ var out = wscript_shell.Exec(cmd);
+ while (out.Status == 0) {
+ WScript.Sleep(100);
+ }
+
+ //Check that command executed
+ if (!out.StdErr.AtEndOfStream) {
+ var line = out.StdErr.ReadLine();
+ Log(fail_msg, true);
+ Log('Output : ' + line, true);
+ WScript.Quit(1);
+ }
+
+ if (!out.StdOut.AtEndOfStream) {
+ var line = out.StdOut.ReadAll();
+ return line;
+ }
+ else {
+ Log('Unable to get output from command "' + cmd + '"', true);
+ WScript.Quit(1);
+ }
+}
+
+/* The tooling for cordova windows phone requires these commands
+ * in the environment PATH variable.
+ * - msbuild (C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319)
+ * - git? (for dynamic cli loading of projects?)
+ */
+function SystemRequiermentsMet() {
+ var cmd = 'msbuild -version'
+ var fail_msg = 'The command `msbuild` failed. Make sure you have the latest Windows Phone SDKs installed, and the `msbuild.exe` command (inside C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319) is added to your path.'
+ var output = check_command(cmd, fail_msg);
+ var msversion = output.match(/\.NET\sFramework\,\sversion\s4\.0/);
+ if (!msversion) {
+ Log('Please install the .NET Framwork v4.0.30319 (in the latest windows phone SDK\'s).', true);
+ Log('Make sure the "msbuild" command in your path is pointing to v4.0.30319 of msbuild as well (inside C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319).', true);
+ WScript.Quit(1);
+ }
+
+ if(REQUIRE_GIT) {
+ cmd = 'git --version';
+ fail_msg = 'The command `git` failed. Make sure you have git installed as well ad in your PATH environment so the tool can use it';
+ output = check_command(cmd, fail_msg);
+ var gitVersion = output.match(/git\sversion\s1\./);
+ if (!gitVersion) {
+ Log('Please ensure you have at least git v1 installed and added to you PATH so this tool can use it to get the latest codova.');
+ }
+ }
+}
+
+
+if (args.Count() > 0) {
+ // support help flags
+ if (args(0) == "--help" || args(0) == "/?" ||
+ args(0) == "help" || args(0) == "-help" || args(0) == "/help" || args(0) == "-h") {
+ Usage();
+ WScript.Quit(1);
+ }
+ else {
+ Log('Error : Did not recognize argument ' + args(0), true)
+ Usage();
+ WScript.Quit(1);
+ }
+}
+
+SystemRequiermentsMet();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp8/bin/create.bat
----------------------------------------------------------------------
diff --git a/wp8/bin/create.bat b/wp8/bin/create.bat
new file mode 100644
index 0000000..329048e
--- /dev/null
+++ b/wp8/bin/create.bat
@@ -0,0 +1,9 @@
+@ECHO OFF
+SET full_path=%~dp0
+IF EXIST %full_path%create.js (
+ cscript "%full_path%create.js" %* //nologo
+) ELSE (
+ ECHO.
+ ECHO ERROR: Could not find 'create.js' in 'bin' folder, aborting...>&2
+ EXIT /B 1
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp8/bin/create.js
----------------------------------------------------------------------
diff --git a/wp8/bin/create.js b/wp8/bin/create.js
new file mode 100644
index 0000000..c505c68
--- /dev/null
+++ b/wp8/bin/create.js
@@ -0,0 +1,226 @@
+/*
+ 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.
+*/
+
+/*
+ * create a cordova/wp8 project
+ *
+ * USAGE
+ * ./create [path package activity]
+
+ ./bin/create.bat C:\Users\Me\MyTestProj "test.proj" "TestProject"
+ */
+
+
+var fso=WScript.CreateObject("Scripting.FileSystemObject");
+var wscript_shell = WScript.CreateObject("WScript.Shell");
+// working dir
+var platformRoot = WScript.ScriptFullName.split('\\bin\\create.js').join('');
+var repoRoot = fso.GetParentFolderName(platformRoot);
+var args = WScript.Arguments;
+var templatePath = "\\template"
+var destPath;
+
+
+Log("platformRoot = " + platformRoot);
+Log("repoRoot = " + repoRoot);
+
+
+function Usage() {
+ Log("Usage: create PathToNewProject [ PackageName AppName ]");
+ Log(" PathToNewProject : The path to where you wish to create the project");
+ Log(" PackageName : The namespace for the project (default is Cordova.Example)")
+ Log(" AppName : The name of the application (default is CordovaAppProj)");
+ Log("examples:");
+ Log(" create C:\\Users\\anonymous\\Desktop\\MyProject");
+ Log(" create C:\\Users\\anonymous\\Desktop\\MyProject io.Cordova.Example AnApp");
+}
+
+// logs messaged to stdout and stderr
+function Log(msg, error) {
+ if (error) {
+ WScript.StdErr.WriteLine(msg);
+ }
+ else {
+ WScript.StdOut.WriteLine(msg);
+ }
+}
+
+var ForReading = 1, ForWriting = 2, ForAppending = 8;
+var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
+
+function read(filename) {
+ Log("Reading file : " + filename);
+ var f=fso.OpenTextFile(filename, 1,2);
+ var s=f.ReadAll();
+ f.Close();
+ return s;
+}
+
+function write(filename, contents) {
+ var f=fso.OpenTextFile(filename, ForWriting, TristateTrue);
+ f.Write(contents);
+ f.Close();
+}
+
+function replaceInFile(filename, regexp, replacement) {
+ write(filename,read(filename).replace(regexp,replacement));
+}
+
+// deletes file if it exists
+function deleteFileIfExists(path) {
+ if(fso.FileExists(path)) {
+ fso.DeleteFile(path);
+ }
+}
+
+
+// executes a commmand in the shell
+function exec(command) {
+ var oShell=wscript_shell.Exec(command);
+ while (oShell.Status == 0) {
+ WScript.sleep(100);
+ }
+}
+
+// executes a commmand in the shell
+function exec_verbose(command) {
+ //Log("Command: " + command);
+ var oShell=wscript_shell.Exec(command);
+ while (oShell.Status == 0) {
+ //Wait a little bit so we're not super looping
+ WScript.sleep(100);
+ //Print any stdout output from the script
+ if (!oShell.StdOut.AtEndOfStream) {
+ var line = oShell.StdOut.ReadLine();
+ Log(line);
+ }
+ }
+ //Check to make sure our scripts did not encounter an error
+ if (!oShell.StdErr.AtEndOfStream) {
+ var line = oShell.StdErr.ReadAll();
+ Log(line, true);
+ WScript.Quit(1);
+ }
+}
+
+//generate guid for the project
+function genGuid() {
+ var TypeLib = WScript.CreateObject("Scriptlet.TypeLib");
+ strGuid = TypeLib.Guid.split("}")[0]; // there is extra crap after the } that is causing file streams to break, probably an EOF ...
+ strGuid = strGuid.replace(/[\{\}]/g,"");
+ return strGuid;
+}
+
+// creates new project in path, with the given package and app name
+function create(path, namespace, name) {
+ Log("Creating Cordova-WP8 Project:");
+ Log("\tApp Name : " + name);
+ Log("\tNamespace : " + namespace);
+ Log("\tPath : " + path);
+
+ // Copy the template source files to the new destination
+ fso.CopyFolder(platformRoot + templatePath, path);
+ // copy over common files
+ fso.CopyFolder(repoRoot + "\\common", path);
+ // copy the version file
+ fso.CopyFile(repoRoot +'\\VERSION',path + "\\" );
+
+ // remove template cruft
+ deleteFileIfExists(path + "\\__PreviewImage.jpg");
+ deleteFileIfExists(path + "\\__TemplateIcon.png");
+ deleteFileIfExists(path + "\\MyTemplate.vstemplate");
+
+ var newProjGuid = genGuid();
+ // replace the guid in the AppManifest
+ replaceInFile(path + "\\Properties\\WMAppManifest.xml","$guid1$",newProjGuid);
+ // replace safe-project-name in AppManifest
+ replaceInFile(path + "\\Properties\\WMAppManifest.xml",/\$safeprojectname\$/g,name);
+ replaceInFile(path + "\\Properties\\WMAppManifest.xml",/\$projectname\$/g,name);
+
+ replaceInFile(path + "\\App.xaml",/\$safeprojectname\$/g,namespace);
+ replaceInFile(path + "\\App.xaml.cs",/\$safeprojectname\$/g,namespace);
+
+ replaceInFile(path + "\\MainPage.xaml",/\$safeprojectname\$/g,namespace);
+ replaceInFile(path + "\\MainPage.xaml.cs",/\$safeprojectname\$/g,namespace);
+ replaceInFile(path + "\\CordovaWP8AppProj.csproj",/\$safeprojectname\$/g,namespace);
+
+ if (name != "CordovaWP8AppProj") {
+ var valid_name = name.replace(/(\.\s|\s\.|\s+|\.+)/g, '_');
+ replaceInFile(path + "\\CordovaSolution.sln", /CordovaAppProj/g, valid_name);
+ // rename project and solution
+ exec('%comspec% /c ren ' + path + "\\CordovaWP8Solution.sln " + valid_name + '.sln');
+ exec('%comspec% /c ren ' + path + "\\CordovaWP8AppProj.csproj " + valid_name + '.csproj');
+ }
+
+ //clean up any Bin/obj or other generated files
+ exec('cscript ' + path + '\\cordova\\lib\\clean.js //nologo');
+
+ // delete any .user and .sou files if any
+ if (fso.FolderExists(path)) {
+ var proj_folder = fso.GetFolder(path);
+ var proj_files = new Enumerator(proj_folder.Files);
+ for (;!proj_files.atEnd(); proj_files.moveNext()) {
+ if (fso.GetExtensionName(proj_files.item()) == 'user') {
+ fso.DeleteFile(proj_files.item());
+ } else if (fso.GetExtensionName(proj_files.item()) == 'sou') {
+ fso.DeleteFile(proj_files.item());
+ }
+ }
+ }
+
+ Log("CREATE SUCCESS : " + path);
+
+ // TODO:
+ // index.html title set to project name?
+}
+
+// MAIN
+
+if (args.Count() > 0) {
+ // support help flags
+ if (args(0) == "--help" || args(0) == "/?" ||
+ args(0) == "help" || args(0) == "-help" || args(0) == "/help" || args(0) == "-h") {
+ Usage();
+ WScript.Quit(1);
+ }
+
+ destPath = args(0);
+ if (fso.FolderExists(destPath)) {
+ Log("Project directory already exists:", true);
+ Log("\t" + destPath, true);
+ Log("CREATE FAILED.", true);
+ WScript.Quit(1);
+ }
+ var packageName = "Cordova.Example";
+ if (args.Count() > 1) {
+ packageName = args(1);
+ }
+
+ var projName = "CordovaWP8AppProj";
+ if (args.Count() > 2) {
+ projName = args(2);
+ }
+
+ create(destPath, packageName, projName);
+}
+else {
+ Usage();
+ WScript.Quit(1);
+}
+
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp8/bin/update.bat
----------------------------------------------------------------------
diff --git a/wp8/bin/update.bat b/wp8/bin/update.bat
new file mode 100644
index 0000000..9da7e3c
--- /dev/null
+++ b/wp8/bin/update.bat
@@ -0,0 +1,9 @@
+@ECHO OFF
+SET full_path=%~dp0
+IF EXIST %full_path%update.js (
+ cscript "%full_path%update.js" %* //nologo
+) ELSE (
+ ECHO.
+ ECHO ERROR: Could not find 'update.js' in 'bin' folder, aborting...>&2
+ EXIT /B 1
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/2274413d/wp8/bin/update.js
----------------------------------------------------------------------
diff --git a/wp8/bin/update.js b/wp8/bin/update.js
new file mode 100644
index 0000000..f2acd6f
--- /dev/null
+++ b/wp8/bin/update.js
@@ -0,0 +1,353 @@
+/*
+ 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 fso = WScript.CreateObject("Scripting.FileSystemObject");
+var wscript_shell = WScript.CreateObject("WScript.Shell");
+var shell = WScript.CreateObject("shell.application");
+var args = WScript.Arguments;
+// working dir
+var ROOT = WScript.ScriptFullName.split('\\bin\\update.js').join('');
+//Get version number
+var VERSION = read(ROOT+'\\VERSION').replace(/\r\n/,'').replace(/\n/,'');
+var plugins_folder = "\\Plugins";
+var template_folder = "\\templates\\standalone";
+// anything thats missing to the project
+var overwrite = false;
+var replace = false;
+
+// usage function
+function Usage() {
+ Log("WARNING : Make sure to back up your project before updating!")
+ Log("Usage: update Path-To-Project ");//[ -f | -r ] ");
+ Log(" Path-To-Old-Project : The path the project you would like to update.");
+ //Log(" -f : Will forcefully overwrite and add all core components of the application.");
+ //Log(" -r : Will create an updated project, only keeping the www assets. *NOTE: no native code will be preserved*");
+ Log("examples:");
+ Log(" update C:\\Users\\anonymous\\Desktop\\MyProject");
+}
+
+// logs messaged to stdout and stderr
+function Log(msg, error) {
+ if (error) {
+ WScript.StdErr.WriteLine(msg);
+ }
+ else {
+ WScript.StdOut.WriteLine(msg);
+ }
+}
+
+// executes a commmand in the shell
+function exec(command) {
+ Log("Command : " + command);
+ var oShell=wscript_shell.Exec(command);
+ while (oShell.Status === 0) {
+ WScript.sleep(100);
+ }
+}
+
+// executes a commmand in the shell
+function exec_verbose(command) {
+ Log("Command: " + command);
+ var oShell=wscript_shell.Exec(command);
+ while (oShell.Status == 0) {
+ //Wait a little bit so we're not super looping
+ WScript.sleep(100);
+ //Print any stdout output from the script
+ if (!oShell.StdOut.AtEndOfStream) {
+ var line = oShell.StdOut.ReadAll();
+ Log(line);
+ }
+ }
+ //Check to make sure our scripts did not encounter an error
+ if (!oShell.StdErr.AtEndOfStream) {
+ var line = oShell.StdErr.ReadAll();
+ Log(line, true);
+ WScript.Quit(2);
+ }
+}
+
+var ForReading = 1, ForWriting = 2, ForAppending = 8;
+var TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0;
+
+// returns the contents of a file
+function read(filename) {
+ if (fso.FileExists(filename)) {
+ var f=fso.OpenTextFile(filename, 1, 2);
+ var s=f.ReadAll();
+ f.Close();
+ return s;
+ }
+ else {
+ Log('Cannot read non-existant file : ' + filename, true);
+ WScript.Quit(2);
+ }
+ return null;
+}
+
+// writes the contents to the specified file
+function write(filename, contents) {
+ var f=fso.OpenTextFile(filename, ForWriting, TristateTrue);
+ f.Write(contents);
+ f.Close();
+}
+
+// replaces the matches of regexp with replacement
+function replaceInFile(filename, regexp, replacement) {
+ var text = read(filename).replace(regexp,replacement);
+ write(filename,text);
+}
+
+// returns true if the given path is the root of a cordova windows phone project
+// currently returns true if the folder contains a .csproj file.
+function is_windows_phone_project(path) {
+ if (fso.FolderExists(path)) {
+ var proj_folder = fso.GetFolder(path);
+ var proj_files = new Enumerator(proj_folder.Files);
+ for (;!proj_files.atEnd(); proj_files.moveNext()) {
+ if (fso.GetExtensionName(proj_files.item()) == 'csproj') {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+// returns the name of the application
+function get_app_name(path) {
+ var WMAppManifest = read(path + '\\Properties\\WMAppManifest.xml').split('\n');
+ for (line in WMAppManifest) {
+ if (WMAppManifest[line].match(/Title\=\"/)) {
+ return WMAppManifest[line].split('Title="')[1].split('"')[0];
+ }
+ }
+ Log("Error : unable to find applicaiton name in the project.", true);
+ Log(" Path : " + path, true);
+ WScript.Quit(2);
+}
+
+// returns the name of the application package
+function get_package_name(path) {
+ var WMAppManifest = read(path + '\\Properties\\WMAppManifest.xml').split('\n');
+ for (line in WMAppManifest) {
+ if (WMAppManifest[line].match(/Title\=\"/)) {
+ return WMAppManifest[line].split('Title="')[1].split('"')[0];
+ }
+ }
+ Log("Error : unable to find applicaiton name in the project.", true);
+ Log(" Path : " + path, true);
+ WScript.Quit(2);
+}
+
+// returns the GUID ame of the application
+function get_app_GUID(path) {
+ var AppXAML = read(path + '\\App.xaml').split('\n');
+ for (line in AppXAML) {
+ if (AppXAML[line].match(/x\:Class\=\"/)) {
+ return AppXAML[line].split('Class="')[1].split('"')[0];
+ }
+ }
+ Log("Error : unable to find package name in the project.", true);
+ Log(" Path : " + path, true);
+ WScript.Quit(2);
+}
+
+// updates the cordova.js and all references in the given project with this repositories version
+function update_cordova_js(path) {
+ // remove old cordova.js
+ var www_contents = shell.NameSpace(path + '\\www').Items();
+ for(i = 0; i < www_contents.Count; i++)
+ {
+ if(www_contents.Item(i).Name.match(/cordova\-(\d+)[.](\d+)[.](\d+)(rc\d)?[.]js/))
+ {
+ fso.DeleteFile(path + '\\www\\' + www_contents.Item(i).Name);
+ }
+ }
+ // update version file
+ copy_to(ROOT + "\\VERSION", path + "\\VERSION");
+ // copy over new cordova.js
+ copy_to(ROOT + template_folder + "\\www\\cordova.js", path + "\\www\\cordova.js");
+
+ // update corodva references
+ var cordova_regex = /cordova-(\d+)[.](\d+)[.](\d+)(rc\d)?/g; //Matches *first* cordova-x.x.x[rcx] (just ad g at end to make global)
+ // update references in index.html
+ replaceInFile(path + '\\www\\index.html', cordova_regex, "cordova");
+ version_regex = /return\s*\"(\d+)[.](\d+)[.](\d+)(rc\d)?/; //Matches return "x.x.x[rcx]
+ // update references in Device.cs
+ replaceInFile(path + '\\Plugins\\Device.cs', version_regex, "return \"" + VERSION);
+}
+
+// Copies assets that need to be saved from source to desination.
+// TODO : Add all critical assets here
+function save_restore(source, destination) {
+ fso.CreateFolder(destination + '\\www');
+ copy_to(source + '\\www', destination + '\\www');
+ copy_to(source + '\\SplashScreenImage.jpg', destination + '\\SplashScreenImage.jpg');
+ copy_to(source + '\\Background.png', destination + '\\Background.png');
+ copy_to(source + '\\ApplicationIcon.png', destination + '\\ApplicationIcon.png');
+ copy_to(source + '\\config.xml', destination + '\\config.xml');
+}
+
+// deletes the path element if it exists
+function delete_if_exists(path) {
+ if (fso.FolderExists(path)) {
+ fso.DeleteFolder(path);
+ }
+ else if (fso.FileExists(path)) {
+ fso.DeleteFile(path);
+ }
+}
+
+// copies a folder or file from source to destination
+function copy_to(source, destination) {
+ // check that source exists
+ if (!fso.FolderExists(source)) {
+ if (!fso.FileExists(source)) {
+ Log("Error : Could not copy file/folder because it doesn't exist.", true);
+ Log(" File/Folder : " + source, true);
+ WScript.Quit(2);
+ }
+ }
+ // if source is a folder, then copy all folder contents
+ if (fso.FolderExists(source)) {
+ fso.CopyFolder(source, destination, true);
+ }
+ // if it's a file, just copy it.
+ else {
+ exec('%comspec% /c copy /Y /V ' + source + ' ' + destination);
+ }
+}
+
+// updates the cordova.js in project along with the cordova tooling.
+function update_project(path) {
+ // update cordova folder
+ delete_if_exists(path + '\\cordova');
+ fso.CreateFolder(path + '\\cordova');
+ copy_to(ROOT + template_folder + '\\cordova', path + '\\cordova');
+ // clean project (all generated files)
+ exec(path + '\\cordova\\clean.bat');
+
+ // update core cordovalib
+ delete_if_exists(path + '\\cordovalib');
+ fso.CreateFolder(path + '\\cordovalib');
+ copy_to(ROOT + template_folder + '\\cordovalib', path + '\\cordovalib');
+
+ // update core plugins
+ // TODO : Remove for 3.0.0
+ delete_if_exists(path + '\\Plugins');
+ fso.CreateFolder(path + '\\Plugins');
+ copy_to(ROOT + template_folder + '\\Plugins', path + '\\Plugins');
+
+ // update cordova.js
+ update_cordova_js(path);
+}
+
+// Replaces the current project with a newly created project, keeping important assets to preserve the app.
+// TODO: Things that need to be kept other then www
+// - WMAppManifest (capabilities etc...)
+// - GUID (for marketplace apps etc...)
+// - Splashscreen and other images etc...
+// - Find more things that should be kept
+function replace_project(path) {
+ //create new project and move www assets into it.
+ Log("WARNING : Upgrading your app with the \'-r\' flag will delete all native and plugin");
+ Log(" components of your application and replace them with the updated core components given");
+ Log(" by this platforms \'bin\\create\' script. It is *HIGHLY RECOMMENDED* to back up your app");
+ Log(" before continuing. The name and package name along with all of the www assets will be");
+ Log(" preserved. Are you sure you wish to continue? (Y/N)");
+ var response;
+ while (response != 'Y') {
+ response = WScript.StdIn.ReadLine();
+ if (response == 'N') {
+ WScript.Quit(2);
+ } else if (response != "Y") {
+ Log("Error : did not recognize '" + response + "'");
+ Log("Are you sure you wish to continue? (Y/N)");
+ }
+ }
+ // place all assets to be preserved in a temperary folder
+ delete_if_exists(ROOT + '\\temp');
+ fso.CreateFolder(ROOT + '\\temp');
+ save_restore(path, ROOT + '\\temp');
+
+ // get app name from WMAppManifest
+ var app_name = get_app_name(path);
+ // get package name from App.xaml
+ var package_name = get_package_name(path);
+ // get the GUID so that app stays the same
+ var app_GUID = get_app_GUID(path);
+ // delete previous project
+ delete_if_exists(path);
+ // create the new project from the current repository
+ exec(ROOT + '\\bin\\create.bat ' + path + ' ' + app_name + ' ' + package_name);
+ // remove default www assets
+ delete_if_exists(path + '\\www');
+ // move www assets back to project folder
+ save_restore(ROOT + '\\temp', path);
+ // cleanup temp folder
+ delete_if_exists(ROOT + '\\temp');
+}
+
+
+
+if (args.Count() > 0) {
+ if(args.Count() > 2) {
+ Log("Error : too many arguments provided.", true);
+ WScript.Quit(1);
+ }
+
+ if (args(0).indexOf("--help") > -1 ||
+ args(0).indexOf("/?") > -1 ) {
+ Usage();
+ WScript.Quit(1);
+ }
+ else if (fso.FolderExists(args(0)) && is_windows_phone_project(args(0))) {
+ if(args.Count() > 1) {
+ /*if(args(1) == '-f' || args(1) == '--force') {
+ //TODO: do something for this
+ Log("ERROR : NOT IMPLEMENTED", true);
+ WScript.Quit(2);
+ }
+ else if(args(1) == '-r' || args(1) == '--replace') {
+ replace_project(args(0));
+ }
+ else {
+ Log('Error : \'' + args(1) + '\' is not regognized as an update option', true);
+ }*/
+ Usage();
+ Log('Error : too many arguments', true);
+ } else if (args.Count() == 1) {
+ update_project(args(0));
+ }
+ }
+ else if (fso.FolderExists(args(0))) {
+ Log("The path provided is not a path to a cordova windows phone project.", true);
+ Log(" Please provide the path to the root folder of your cordova windows phone project.", true);
+ WScript.Quit(2);
+ }
+ else {
+ Log("The given path to the project does not exist.", true);
+ Log(" Please provide a path to the project you would like to update.", true);
+ Usage();
+ WScript.Quit(2);
+ }
+}
+else {
+ Usage();
+ WScript.Quit(1);
+}
\ No newline at end of file