cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject git commit: Fixes handling of UTF-8 encoded project files.
Date Thu, 12 Jun 2014 21:07:04 GMT
Repository: cordova-wp8
Updated Branches:
  refs/heads/master 0cfe13f20 -> ac097f280


Fixes handling of UTF-8 encoded project files.


Project: http://git-wip-us.apache.org/repos/asf/cordova-wp8/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp8/commit/ac097f28
Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp8/tree/ac097f28
Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp8/diff/ac097f28

Branch: refs/heads/master
Commit: ac097f2801d4defe5e4d445e10b7102001631a54
Parents: 0cfe13f
Author: Vladimir Kotikov <v-vlkoti@microsoft.com>
Authored: Thu Jun 12 17:18:13 2014 +0400
Committer: Vladimir Kotikov <v-vlkoti@microsoft.com>
Committed: Thu Jun 12 17:28:41 2014 +0400

----------------------------------------------------------------------
 wp8/bin/create.js | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/ac097f28/wp8/bin/create.js
----------------------------------------------------------------------
diff --git a/wp8/bin/create.js b/wp8/bin/create.js
index cb3e3ee..d203b2b 100644
--- a/wp8/bin/create.js
+++ b/wp8/bin/create.js
@@ -71,16 +71,42 @@ function read(filename) {
     return s;
 }
 
+// Reads content of utf-8 encoded file, removing BOM, if exist.
+function readUTF8 (filename) {
+    var inStream = WScript.CreateObject("ADODB.Stream");
+    inStream.Charset = "UTF-8";
+    inStream.Open();
+    inStream.LoadFromFile(filename);
+    var text = inStream.ReadText();
+    inStream.Close();
+    return text;
+}
+
 function write(filename, contents) {
     var f=fso.OpenTextFile(filename, ForWriting, TristateTrue);
     f.Write(contents);
     f.Close();
 }
 
+// Writes content to utf-8 encoded file. Adds BOM if necessary.
+function writeUTF8 (filename, contents) {
+    var outStream = WScript.CreateObject("ADODB.Stream");
+    outStream.Mode = 3;
+    outStream.Open();
+    outStream.Charset = "UTF-8";
+    outStream.WriteText(contents);
+    outStream.SaveToFile(filename, 2);
+    outStream.Close();
+}
+
 function replaceInFile(filename, regexp, replacement) {
     write(filename,read(filename).replace(regexp,replacement));
 }
 
+function replaceInUTF8 (filename, regexp, replacement) {
+    writeUTF8(filename, readUTF8(filename).replace(regexp, replacement));
+}
+
 // deletes file if it exists
 function deleteFileIfExists(path) {
     if(fso.FileExists(path)) {
@@ -151,21 +177,21 @@ function create(path, namespace, name) {
 
     var newProjGuid = genGuid();
     // replace the guid in the AppManifest
-    replaceInFile(path + "\\Properties\\WMAppManifest.xml","$guid1$",newProjGuid);
+    replaceInUTF8(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);
+    replaceInUTF8(path + "\\Properties\\WMAppManifest.xml",/\$safeprojectname\$/g,name);
+    replaceInUTF8(path + "\\Properties\\WMAppManifest.xml",/\$projectname\$/g,name);
 
-    replaceInFile(path + "\\App.xaml",/\$safeprojectname\$/g,namespace);
-    replaceInFile(path + "\\App.xaml.cs",/\$safeprojectname\$/g,namespace);
+    replaceInUTF8(path + "\\App.xaml",/\$safeprojectname\$/g,namespace);
+    replaceInUTF8(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);
+    replaceInUTF8(path + "\\MainPage.xaml",/\$safeprojectname\$/g,namespace);
+    replaceInUTF8(path + "\\MainPage.xaml.cs",/\$safeprojectname\$/g,namespace);
+    replaceInUTF8(path + "\\CordovaWP8AppProj.csproj",/\$safeprojectname\$/g,namespace);
 
     if (name != "CordovaWP8AppProj") {
         var valid_name = name.replace(/(\.\s|\s\.|\s+|\.+)/g, '_');
-        replaceInFile(path + "\\CordovaWP8Solution.sln", /CordovaWP8AppProj/g, valid_name);
+        replaceInUTF8(path + "\\CordovaWP8Solution.sln", /CordovaWP8AppProj/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');


Mime
View raw message