You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/10/02 06:11:29 UTC

[1/6] git commit: added windows8 support, and added tests

Updated Branches:
  refs/heads/cordova-3.1.x 19056770e -> f346be0c4


added windows8 support, and added tests


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

Branch: refs/heads/cordova-3.1.x
Commit: a77a5601ae2d47286e923e5986013269562392b4
Parents: 597ab34
Author: purplecabbage <pu...@gmail.com>
Authored: Wed Sep 25 18:33:31 2013 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Wed Sep 25 18:33:31 2013 -0700

----------------------------------------------------------------------
 platforms.js                          |   9 +-
 spec/metadata/windows8_parser.spec.js | 247 +++++++++++++++++++++++++++
 spec/platform.spec.js                 |  39 +++--
 src/metadata/windows8_parser.js       | 262 +++++++++++++++++++++++++++++
 src/platform.js                       |  11 +-
 5 files changed, 550 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a77a5601/platforms.js
----------------------------------------------------------------------
diff --git a/platforms.js b/platforms.js
index d34c112..e30c308 100644
--- a/platforms.js
+++ b/platforms.js
@@ -22,12 +22,12 @@ module.exports = {
         parser : './src/metadata/ios_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git',
         version: '3.1.0-rc1'
-    }, 
+    },
     'android' : {
         parser : './src/metadata/android_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-android.git',
         version: '3.1.0-rc1'
-    }, 
+    },
     'wp7' : {
         parser : './src/metadata/wp7_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-wp8.git',
@@ -51,6 +51,11 @@ module.exports = {
         parser: './src/metadata/firefoxos_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-firefoxos.git',
         version: '3.1.0-rc1'
+    },
+    'windows8':{
+        parser: './src/metadata/windows8_parser',
+        url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-windows.git',
+        version: '3.1.0-rc1'
     }
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a77a5601/spec/metadata/windows8_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/windows8_parser.spec.js b/spec/metadata/windows8_parser.spec.js
new file mode 100644
index 0000000..f58f35e
--- /dev/null
+++ b/spec/metadata/windows8_parser.spec.js
@@ -0,0 +1,247 @@
+/**
+    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 platforms = require('../../platforms'),
+    util = require('../../src/util'),
+    path = require('path'),
+    shell = require('shelljs'),
+    fs = require('fs'),
+    ET = require('elementtree'),
+    config = require('../../src/config'),
+    config_parser = require('../../src/config_parser'),
+    cordova = require('../../cordova');
+
+describe('windows8 project parser', function() {
+
+    var proj = '/some/path';
+    var exists, exec, custom, readdir, cfg_parser;
+    beforeEach(function() {
+        exists = spyOn(fs, 'existsSync').andReturn(true);
+        exec = spyOn(shell, 'exec').andCallFake(function(cmd, opts, cb) {
+            cb(0, '');
+        });
+        custom = spyOn(config, 'has_custom_path').andReturn(false);
+        readdir = spyOn(fs, 'readdirSync').andReturn(['test.jsproj']);
+        cfg_parser = spyOn(util, 'config_parser');
+    });
+
+    describe('constructions', function() {
+        it('should throw if provided directory does not contain a jsproj file', function() {
+            readdir.andReturn([]);
+            expect(function() {
+                new platforms.windows8.parser(proj);
+            }).toThrow('The provided path "' + proj + '" is not a Windows 8 project. Error: No .jsproj file.');
+        });
+        it('should create an instance with path, manifest properties', function() {
+            expect(function() {
+                var p = new platforms.windows8.parser(proj);
+                expect(p.windows8_proj_dir).toEqual(proj);
+                expect(p.manifest_path).toEqual(path.join(proj, 'Properties', 'WMAppManifest.xml'));
+            }).not.toThrow();
+        });
+    });
+
+    describe('check_requirements', function() {
+        it('should fire a callback if there is an error during shelling out', function(done) {
+            exec.andCallFake(function(cmd, opts, cb) {
+                cb(50, 'there was an errorz!');
+            });
+            platforms.windows8.parser.check_requirements(proj, function(err) {
+                expect(err).toContain('there was an errorz!');
+                done();
+            });
+        });
+        it('should check by calling check_reqs on the stock lib path if no custom path is defined', function(done) {
+            platforms.windows8.parser.check_requirements(proj, function(err) {
+                expect(err).toEqual(false);
+                expect(exec.mostRecentCall.args[0]).toContain(util.libDirectory);
+                expect(exec.mostRecentCall.args[0]).toMatch(/check_reqs"$/);
+                done();
+            });
+        });
+        it('should check by calling check_reqs on a custom path if it is so defined', function(done) {
+            var custom_path = path.join('some','custom','path','to','windows8','lib');
+            custom.andReturn(custom_path);
+            platforms.windows8.parser.check_requirements(proj, function(err) {
+                expect(err).toEqual(false);
+                expect(exec.mostRecentCall.args[0]).toContain(custom_path);
+                expect(exec.mostRecentCall.args[0]).toMatch(/check_reqs"$/);
+                done();
+            });
+        });
+    });
+
+    describe('instance', function() {
+        var p, cp, rm, is_cordova, write, read, mv;
+        var windows8_proj = path.join(proj, 'platforms', 'windows8');
+        beforeEach(function() {
+            p = new platforms.windows8.parser(windows8_proj);
+            cp = spyOn(shell, 'cp');
+            rm = spyOn(shell, 'rm');
+            mv = spyOn(shell, 'mv');
+            is_cordova = spyOn(util, 'isCordova').andReturn(proj);
+            write = spyOn(fs, 'writeFileSync');
+            read = spyOn(fs, 'readFileSync').andReturn('');
+        });
+
+        describe('update_from_config method', function() {
+            var et, xml, find, write_xml, root, cfg, find_obj, root_obj, cfg_access_add, cfg_access_rm, cfg_pref_add, cfg_pref_rm, cfg_content;
+            beforeEach(function() {
+                find_obj = {
+                    text:'hi',
+                    attrib:{Title:'old'}
+                };
+                root_obj = {
+                    attrib:{
+                        package:'android_pkg'
+                    }
+                };
+                find = jasmine.createSpy('ElementTree find').andReturn(find_obj);
+                write_xml = jasmine.createSpy('ElementTree write');
+                root = jasmine.createSpy('ElementTree getroot').andReturn(root_obj);
+                et = spyOn(ET, 'ElementTree').andReturn({
+                    find:find,
+                    write:write_xml,
+                    getroot:root
+                });
+                xml = spyOn(ET, 'XML');
+                cfg = new config_parser();
+                cfg.name = function() { return 'testname' };
+                cfg.content = function() { return 'index.html' };
+                cfg.packageName = function() { return 'testpkg' };
+                cfg.version = function() { return 'one point oh' };
+                cfg.access.get = function() { return [] };
+                cfg.preference.get = function() { return [] };
+                cfg_access_add = jasmine.createSpy('config_parser access add');
+                cfg_access_rm = jasmine.createSpy('config_parser access rm');
+                cfg_pref_rm = jasmine.createSpy('config_parser pref rm');
+                cfg_pref_add = jasmine.createSpy('config_parser pref add');
+                cfg_content = jasmine.createSpy('config_parser content');
+                p.config = {
+                    access:{
+                        remove:cfg_access_rm,
+                        get:function(){},
+                        add:cfg_access_add
+                    },
+                    content:cfg_content,
+                    preference:{
+                        remove:cfg_pref_rm,
+                        get:function(){},
+                        add:cfg_pref_add
+                    }
+                };
+                readdir.andReturn(['test.sln']);
+            });
+
+            it('should write out the app name to wmappmanifest.xml', function() {
+                p.update_from_config(cfg);
+                expect(find_obj.attrib.Title).toEqual('testname');
+            });
+            it('should write out the app id to jsproj file', function() {
+                p.update_from_config(cfg);
+                expect(find_obj.text).toContain('testpkg');
+            });
+            it('should write out the app version to wmappmanifest.xml', function() {
+                p.update_from_config(cfg);
+                expect(find_obj.attrib.Version).toEqual('one point oh');
+            });
+            it('should update the content element (start page)', function() {
+                p.update_from_config(cfg);
+                expect(cfg_content).toHaveBeenCalledWith('index.html');
+            });
+        });
+        describe('www_dir method', function() {
+            it('should return www', function() {
+                expect(p.www_dir()).toEqual(path.join(windows8_proj, 'www'));
+            });
+        });
+        describe('staging_dir method', function() {
+            it('should return .staging/www', function() {
+                expect(p.staging_dir()).toEqual(path.join(windows8_proj, '.staging', 'www'));
+            });
+        });
+        describe('update_www method', function() {
+            var update_jsproj;
+            beforeEach(function() {
+                update_jsproj = spyOn(p, 'update_jsproj');
+            });
+            it('should rm project-level www and cp in platform agnostic www', function() {
+                p.update_www();
+                expect(rm).toHaveBeenCalled();
+                expect(cp).toHaveBeenCalled();
+            });
+            it('should copy in a fresh cordova.js from stock cordova lib if no custom lib is specified', function() {
+                p.update_www();
+                expect(write).toHaveBeenCalled();
+                expect(read.mostRecentCall.args[0]).toContain(util.libDirectory);
+            });
+            it('should copy in a fresh cordova.js from custom cordova lib if custom lib is specified', function() {
+                var custom_path = path.join('custom','path');
+                custom.andReturn(custom_path);
+                p.update_www();
+                expect(write).toHaveBeenCalled();
+                expect(read.mostRecentCall.args[0]).toContain(custom_path);
+            });
+        });
+        describe('update_staging method', function() {
+            it('should do nothing if staging dir does not exist', function() {
+                exists.andReturn(false);
+                p.update_staging();
+                expect(cp).not.toHaveBeenCalled();
+            });
+            it('should copy the staging dir into www if staging dir exists', function() {
+                p.update_staging();
+                expect(cp).toHaveBeenCalled();
+            });
+        });
+        describe('update_project method', function() {
+            var config, www, overrides, staging, svn;
+            beforeEach(function() {
+                config = spyOn(p, 'update_from_config');
+                www = spyOn(p, 'update_www');
+                staging = spyOn(p, 'update_staging');
+                svn = spyOn(util, 'deleteSvnFolders');
+            });
+            it('should call update_from_config', function() {
+                p.update_project();
+                expect(config).toHaveBeenCalled();
+            });
+            it('should throw if update_from_config throws', function(done) {
+                var err = new Error('uh oh!');
+                config.andCallFake(function() { throw err; });
+                p.update_project({}, function(err) {
+                    expect(err).toEqual(err);
+                    done();
+                });
+            });
+            it('should call update_www', function() {
+                p.update_project();
+                expect(www).toHaveBeenCalled();
+            });
+            it('should call update_staging', function() {
+                p.update_project();
+                expect(staging).toHaveBeenCalled();
+            });
+            it('should call deleteSvnFolders', function() {
+                p.update_project();
+                expect(svn).toHaveBeenCalled();
+            });
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a77a5601/spec/platform.spec.js
----------------------------------------------------------------------
diff --git a/spec/platform.spec.js b/spec/platform.spec.js
index b167b20..adcf007 100644
--- a/spec/platform.spec.js
+++ b/spec/platform.spec.js
@@ -118,19 +118,27 @@ describe('platform command', function() {
 
             it('should list out added platforms in a project', function(done) {
                 cordova.on('results', function(res) {
-                    expect(res).toMatch(/^Installed platforms: ios, android, wp7, wp8, blackberry10, firefoxos\s*Available platforms:\s*$/);
+                    expect(res).toMatch(/^Installed platforms: ios, android, wp7, wp8, blackberry10, firefoxos, windows8\s*Available platforms:\s*$/);
                     done();
                 });
                 cordova.platform('list');
             });
         });
         describe('`add`', function() {
-            it('should shell out to specified platform\'s bin/create, using the version that is specified in platforms manifest', function() {
+            it('%%% should shell out to specified platform\'s bin/create, using the version that is specified in platforms manifest', function() {
+                // Android
                 cordova.platform('add', 'android');
-                expect(exec.mostRecentCall.args[0]).toMatch(/lib.android.cordova.\d.\d.\d[\d\w]*.bin.create/gi);
+                expect(exec.mostRecentCall.args[0]).toMatch(/lib.android.cordova.\d.\d.\d[\d\w\-]*.bin.create/gi);
                 expect(exec.mostRecentCall.args[0]).toContain(project_dir);
+
+                // Windows Phone 8
                 cordova.platform('add', 'wp8');
-                expect(exec.mostRecentCall.args[0]).toMatch(/lib.wp.cordova.\d.\d.\d[\d\w]*.wp8.bin.create/gi);
+                expect(exec.mostRecentCall.args[0]).toMatch(/lib.wp.cordova.\d.\d.\d[\d\w\-]*.wp8.bin.create/gi);
+                expect(exec.mostRecentCall.args[0]).toContain(project_dir);
+
+                // Windows 8
+                cordova.platform('add', 'windows8');
+                expect(exec.mostRecentCall.args[0]).toMatch(/lib.windows8.cordova.\d.\d.\d[\d\w\-]*.windows8.bin.create/gi);
                 expect(exec.mostRecentCall.args[0]).toContain(project_dir);
             });
             it('should call into lazy_load.custom if there is a user-specified configruation for consuming custom libraries', function() {
@@ -219,19 +227,22 @@ describe('platform command', function() {
                 });
             });
 
-            describe('success', function() {
-                it('should shell out to the platform update script', function(done) {
-                    var oldVersion = platforms['ios'].version;
-                    platforms['ios'].version = '1.0.0';
-                    cordova.platform('update', ['ios'], function(err) {
-                        expect(err).toBeUndefined();
-                        expect(exec).toHaveBeenCalledWith('HOMEDIR/.cordova/lib/ios/cordova/1.0.0/bin/update "some/path/platforms/ios"', jasmine.any(Object), jasmine.any(Function));
+            // Don't run this test on windows ... iOS will fail always
+            if(!require('os').platform().match(/^win/)) {
+                describe('success', function() {
+                    it('should shell out to the platform update script', function(done) {
+                        var oldVersion = platforms['ios'].version;
+                        platforms['ios'].version = '1.0.0';
+                        cordova.platform('update', ['ios'], function(err) {
+                            expect(err).toBeUndefined();
+                            expect(exec).toHaveBeenCalledWith('HOMEDIR/.cordova/lib/ios/cordova/1.0.0/bin/update "some/path/platforms/ios"', jasmine.any(Object), jasmine.any(Function));
 
-                        platforms['ios'].version = oldVersion;
-                        done();
+                            platforms['ios'].version = oldVersion;
+                            done();
+                        });
                     });
                 });
-            });
+            }
         });
     });
     describe('hooks', function() {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a77a5601/src/metadata/windows8_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/windows8_parser.js b/src/metadata/windows8_parser.js
new file mode 100644
index 0000000..208bec2
--- /dev/null
+++ b/src/metadata/windows8_parser.js
@@ -0,0 +1,262 @@
+/**
+    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 fs            = require('fs'),
+    path          = require('path'),
+    et            = require('elementtree'),
+    util          = require('../util'),
+    events        = require('../events'),
+    shell         = require('shelljs'),
+    events        = require('../events'),
+    config_parser = require('../config_parser'),
+    xml           = require('../xml-helpers'),
+    config        = require('../config');
+
+module.exports = function windows8_parser(project) {
+    try {
+        // TODO : Check that it's not a windows8 project?
+        var jsproj_file   = fs.readdirSync(project).filter(function(e) { return e.match(/\.jsproj$/i); })[0];
+        if (!jsproj_file) throw new Error('No .jsproj file.');
+        this.windows8_proj_dir = project;
+        this.jsproj_path  = path.join(this.windows8_proj_dir, jsproj_file);
+        this.sln_path     = path.join(this.windows8_proj_dir, jsproj_file.replace(/\.jsproj/, '.sln'));
+    } catch(e) {
+        throw new Error('The provided path "' + project + '" is not a Windows 8 project. ' + e);
+    }
+    this.manifest_path  = path.join(this.windows8_proj_dir, 'Properties', 'WMAppManifest.xml');
+    this.config_path = path.join(this.windows8_proj_dir, 'config.xml');
+    this.config = new util.config_parser(this.config_path);
+};
+
+module.exports.check_requirements = function(project_root, callback) {
+    events.emit('log', 'Checking windows8 requirements...');
+    var lib_path = path.join(util.libDirectory, 'windows8', 'cordova', require('../../platforms').windows8.version, 'windows8');
+    var custom_path = config.has_custom_path(project_root, 'windows8');
+    if (custom_path) lib_path = custom_path;
+    var command = '"' + path.join(lib_path, 'bin', 'check_reqs') + '"';
+    events.emit('log', 'Running "' + command + '" (output to follow)');
+    shell.exec(command, {silent:true, async:true}, function(code, output) {
+        events.emit('log', output);
+        if (code != 0) {
+            callback(output);
+        } else {
+            callback(false);
+        }
+    });
+};
+
+module.exports.prototype = {
+    update_from_config:function(config) {
+        //check config parser
+        if (config instanceof config_parser) {
+        } else throw new Error('update_from_config requires a config_parser object');
+
+        //Get manifest file
+        var manifest = xml.parseElementtreeSync(this.manifest_path);
+
+        //Update app version
+        var version = config.version();
+        manifest.find('.//App').attrib.Version = version;
+
+        // Update app name by editing app title in Properties\WMAppManifest.xml
+        var name = config.name();
+        var prev_name = manifest.find('.//App[@Title]')['attrib']['Title'];
+        if(prev_name != name) {
+            //console.log("Updating app name from " + prev_name + " to " + name);
+            manifest.find('.//App').attrib.Title = name;
+            manifest.find('.//App').attrib.Publisher = name + " Publisher";
+            manifest.find('.//App').attrib.Author = name + " Author";
+            manifest.find('.//PrimaryToken').attrib.TokenID = name;
+            //update name of sln and jsproj.
+            name = name.replace(/(\.\s|\s\.|\s+|\.+)/g, '_'); //make it a ligitamate name
+            prev_name = prev_name.replace(/(\.\s|\s\.|\s+|\.+)/g, '_');
+            // TODO: might return .sln.user? (generated file)
+            var sln_name = fs.readdirSync(this.windows8_proj_dir).filter(function(e) { return e.match(/\.sln$/i); })[0];
+            var sln_path = path.join(this.windows8_proj_dir, sln_name);
+            var sln_file = fs.readFileSync(sln_path, 'utf-8');
+            var name_regex = new RegExp(prev_name, "g");
+            fs.writeFileSync(sln_path, sln_file.replace(name_regex, name), 'utf-8');
+            shell.mv('-f', this.jsproj_path, path.join(this.windows8_proj_dir, name + '.jsproj'));
+            this.jsproj_path = path.join(this.windows8_proj_dir, name + '.jsproj');
+            shell.mv('-f', sln_path, path.join(this.windows8_proj_dir, name + '.sln'));
+            this.sln_path    = path.join(this.windows8_proj_dir, name + '.sln');
+        }
+
+        // Update package name by changing:
+        /*  - CordovaAppProj.jsproj
+         *  - MainPage.xaml
+         *  - MainPage.xaml.cs
+         *  - App.xaml
+         *  - App.xaml.cs
+         */
+         var pkg = config.packageName();
+         var jsproj = xml.parseElementtreeSync(this.jsproj_path);
+         prev_name = jsproj.find('.//RootNamespace').text;
+         if(prev_name != pkg) {
+            //console.log("Updating package name from " + prev_name + " to " + pkg);
+            //CordovaAppProj.jsproj
+            jsproj.find('.//RootNamespace').text = pkg;
+            jsproj.find('.//AssemblyName').text = pkg;
+            jsproj.find('.//XapFilename').text = pkg + '.xap';
+            jsproj.find('.//SilverlightAppEntry').text = pkg + '.App';
+            fs.writeFileSync(this.jsproj_path, jsproj.write({indent: 4}), 'utf-8');
+            //MainPage.xaml
+            var mainPageXAML = xml.parseElementtreeSync(path.join(this.windows8_proj_dir, 'MainPage.xaml'));
+            mainPageXAML.getroot().attrib['x:Class'] = pkg + '.MainPage';
+            fs.writeFileSync(path.join(this.windows8_proj_dir, 'MainPage.xaml'), mainPageXAML.write({indent: 4}), 'utf-8');
+            //MainPage.xaml.cs
+            var mainPageCS = fs.readFileSync(path.join(this.windows8_proj_dir, 'MainPage.xaml.cs'), 'utf-8');
+            var namespaceRegEx = new RegExp('namespace ' + prev_name);
+            fs.writeFileSync(path.join(this.windows8_proj_dir, 'MainPage.xaml.cs'), mainPageCS.replace(namespaceRegEx, 'namespace ' + pkg), 'utf-8');
+            //App.xaml
+            var appXAML = xml.parseElementtreeSync(path.join(this.windows8_proj_dir, 'App.xaml'));
+            appXAML.getroot().attrib['x:Class'] = pkg + '.App';
+            fs.writeFileSync(path.join(this.windows8_proj_dir, 'App.xaml'), appXAML.write({indent: 4}), 'utf-8');
+            //App.xaml.cs
+            var appCS = fs.readFileSync(path.join(this.windows8_proj_dir, 'App.xaml.cs'), 'utf-8');
+            fs.writeFileSync(path.join(this.windows8_proj_dir, 'App.xaml.cs'), appCS.replace(namespaceRegEx, 'namespace ' + pkg), 'utf-8');
+         }
+
+         // Update content (start page) element
+         this.config.content(config.content());
+
+         //Write out manifest
+         fs.writeFileSync(this.manifest_path, manifest.write({indent: 4}), 'utf-8');
+    },
+    // Returns the platform-specific www directory.
+    www_dir:function() {
+        return path.join(this.windows8_proj_dir, 'www');
+    },
+    config_xml:function() {
+    },
+    // copy files from merges directory to actual www dir
+    copy_merges:function(merges_sub_path) {
+        var merges_path = path.join(util.appDir(util.isCordova(this.windows8_proj_dir)), 'merges', merges_sub_path);
+        if (fs.existsSync(merges_path)) {
+            var overrides = path.join(merges_path, '*');
+            shell.cp('-rf', overrides, this.www_dir());
+        }
+    },
+    // copies the app www folder into the windows8 project's www folder and updates the jsproj file.
+    update_www:function() {
+        var project_root = util.isCordova(this.windows8_proj_dir);
+        var project_www = util.projectWww(project_root);
+        // remove stock platform assets
+        shell.rm('-rf', this.www_dir());
+        // copy over all app www assets
+        shell.cp('-rf', project_www, this.windows8_proj_dir);
+
+        // copy all files from merges directories (generic first, then specific)
+        this.copy_merges('wp');
+        this.copy_merges('windows8');
+
+        // copy over windows8 lib's cordova.js
+        var lib_path = path.join(util.libDirectory, 'wp', 'cordova', require('../../platforms').windows8.version);
+        var custom_path = config.has_custom_path(project_root, 'windows8');
+        if (custom_path) lib_path = custom_path;
+        var cordovajs_path = path.join(lib_path, 'common', 'www', 'cordova.js');
+        fs.writeFileSync(path.join(this.www_dir(), 'cordova.js'), fs.readFileSync(cordovajs_path, 'utf-8'), 'utf-8');
+        this.update_jsproj();
+    },
+    // updates the jsproj file to explicitly list all www content.
+    update_jsproj:function() {
+        var jsproj_xml = xml.parseElementtreeSync(this.jsproj_path);
+        // remove any previous references to the www files
+        var item_groups = jsproj_xml.findall('ItemGroup');
+        for (var i = 0, l = item_groups.length; i < l; i++) {
+            var group = item_groups[i];
+            var files = group.findall('Content');
+            for (var j = 0, k = files.length; j < k; j++) {
+                var file = files[j];
+                if (file.attrib.Include.substr(0, 3) == 'www') {
+                    // remove file reference
+                    group.remove(0, file);
+                    // remove ItemGroup if empty
+                    var new_group = group.findall('Content');
+                    if(new_group.length < 1) {
+                        jsproj_xml.getroot().remove(0, group);
+                    }
+                }
+            }
+        }
+
+        // now add all www references back in from the root www folder
+        var project_root = util.isCordova(this.windows8_proj_dir);
+        var www_files = this.folder_contents('www', this.www_dir());
+        for(file in www_files) {
+            var item = new et.Element('ItemGroup');
+            var content = new et.Element('Content');
+            content.attrib.Include = www_files[file];
+            item.append(content);
+            jsproj_xml.getroot().append(item);
+        }
+        // save file
+        fs.writeFileSync(this.jsproj_path, jsproj_xml.write({indent:4}), 'utf-8');
+    },
+    // Returns an array of all the files in the given directory with reletive paths
+    // - name     : the name of the top level directory (i.e all files will start with this in their path)
+    // - path     : the directory whos contents will be listed under 'name' directory
+    folder_contents:function(name, dir) {
+        var results = [];
+        var folder_dir = fs.readdirSync(dir);
+        for(item in folder_dir) {
+            var stat = fs.statSync(path.join(dir, folder_dir[item]));
+            // means its a folder?
+            if(stat.size == 0) {
+                var sub_dir = this.folder_contents(path.join(name, folder_dir[item]), path.join(dir, folder_dir[item]));
+                //Add all subfolder item paths
+                for(sub_item in sub_dir) {
+                    results.push(sub_dir[sub_item]);
+                }
+            }
+            else {
+                results.push(path.join(name, folder_dir[item]));
+            }
+        }
+        return results;
+    },
+    staging_dir: function() {
+        return path.join(this.windows8_proj_dir, '.staging', 'www');
+    },
+
+    update_staging: function() {
+        var projectRoot = util.isCordova(this.windows8_proj_dir);
+        if (fs.existsSync(this.staging_dir())) {
+            var staging = path.join(this.staging_dir(), '*');
+            shell.cp('-rf', staging, this.www_dir());
+        }
+    },
+
+    // calls the nessesary functions to update the windows8 project
+    update_project:function(cfg, callback) {
+        //console.log("Updating windows8 project...");
+
+        try {
+            this.update_from_config(cfg);
+        } catch(e) {
+            if (callback) return callback(e);
+            else throw e;
+        }
+        // overrides (merges) are handled in update_www()
+        this.update_www();
+        this.update_staging();
+        util.deleteSvnFolders(this.www_dir());
+
+        if (callback) callback();
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a77a5601/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 3f8d45b..7ab4d4b 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -299,8 +299,15 @@ function call_into_create(target, projectRoot, cfg, id, version, template_dir, c
                 // Create a platform app using the ./bin/create scripts that exist in each repo.
                 // Run platform's create script
                 var bin = path.join(cordova_util.libDirectory, target, id, version, 'bin', 'create');
-                if(target == 'wp7') bin = path.join(cordova_util.libDirectory, 'wp', id, version, 'wp7', 'bin', 'create');
-                if(target == 'wp8') bin = path.join(cordova_util.libDirectory, 'wp', id, version, 'wp8', 'bin', 'create');
+                if(target == 'wp7') {
+                    bin = path.join(cordova_util.libDirectory, 'wp', id, version, 'wp7', 'bin', 'create');
+                }
+                else if(target == 'wp8') {
+                    bin = path.join(cordova_util.libDirectory, 'wp', id, version, 'wp8', 'bin', 'create');
+                }
+                else if(target == 'windows8') {
+                    bin = path.join(cordova_util.libDirectory, 'windows8', id, version, 'windows8', 'bin', 'create');
+                }
                 var args = (target=='ios') ? '--arc' : '';
                 var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
                 var name = cfg.name();


[6/6] git commit: updated to use plugman 0.13.x

Posted by st...@apache.org.
updated to use plugman 0.13.x


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

Branch: refs/heads/cordova-3.1.x
Commit: f346be0c4221a6dfba909d154cddcbf6ba843542
Parents: 6e47692
Author: Steven Gill <st...@gmail.com>
Authored: Tue Oct 1 21:11:17 2013 -0700
Committer: Steven Gill <st...@gmail.com>
Committed: Tue Oct 1 21:11:17 2013 -0700

----------------------------------------------------------------------
 package.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/f346be0c/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index f3f945c..0822880 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,7 @@
   "dependencies": {
     "colors": ">=0.6.0",
     "elementtree": "0.1.5",
-    "plugman": "0.12.x",
+    "plugman": "0.13.x",
     "plist": "0.4.x",
     "xcode": "0.5.1",
     "express": "3.0.0",


[3/6] git commit: config.xml helper function is used, removed error merge of wp folder.

Posted by st...@apache.org.
config.xml helper function is used, removed error merge of wp folder.


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

Branch: refs/heads/cordova-3.1.x
Commit: 7cfbe67d53654580269dad4fb2fcd1bb3c70632e
Parents: 5768f5c
Author: purplecabbage <pu...@gmail.com>
Authored: Fri Sep 27 16:56:52 2013 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Fri Sep 27 16:56:52 2013 -0700

----------------------------------------------------------------------
 src/metadata/windows8_parser.js | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/7cfbe67d/src/metadata/windows8_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/windows8_parser.js b/src/metadata/windows8_parser.js
index 208bec2..a846c50 100644
--- a/src/metadata/windows8_parser.js
+++ b/src/metadata/windows8_parser.js
@@ -39,13 +39,15 @@ module.exports = function windows8_parser(project) {
         throw new Error('The provided path "' + project + '" is not a Windows 8 project. ' + e);
     }
     this.manifest_path  = path.join(this.windows8_proj_dir, 'Properties', 'WMAppManifest.xml');
-    this.config_path = path.join(this.windows8_proj_dir, 'config.xml');
+    this.config_path = this.config_xml();
     this.config = new util.config_parser(this.config_path);
 };
 
 module.exports.check_requirements = function(project_root, callback) {
     events.emit('log', 'Checking windows8 requirements...');
-    var lib_path = path.join(util.libDirectory, 'windows8', 'cordova', require('../../platforms').windows8.version, 'windows8');
+    var lib_path = path.join(util.libDirectory, 'windows8', 'cordova',
+                    require('../../platforms').windows8.version, 'windows8');
+
     var custom_path = config.has_custom_path(project_root, 'windows8');
     if (custom_path) lib_path = custom_path;
     var command = '"' + path.join(lib_path, 'bin', 'check_reqs') + '"';
@@ -61,6 +63,7 @@ module.exports.check_requirements = function(project_root, callback) {
 };
 
 module.exports.prototype = {
+
     update_from_config:function(config) {
         //check config parser
         if (config instanceof config_parser) {
@@ -83,10 +86,12 @@ module.exports.prototype = {
             manifest.find('.//App').attrib.Author = name + " Author";
             manifest.find('.//PrimaryToken').attrib.TokenID = name;
             //update name of sln and jsproj.
-            name = name.replace(/(\.\s|\s\.|\s+|\.+)/g, '_'); //make it a ligitamate name
+            name = name.replace(/(\.\s|\s\.|\s+|\.+)/g, '_'); //make it a valid name
             prev_name = prev_name.replace(/(\.\s|\s\.|\s+|\.+)/g, '_');
             // TODO: might return .sln.user? (generated file)
-            var sln_name = fs.readdirSync(this.windows8_proj_dir).filter(function(e) { return e.match(/\.sln$/i); })[0];
+            var sln_name = fs.readdirSync(this.windows8_proj_dir).filter(function(e) {
+                    return e.match(/\.sln$/i);
+                })[0];
             var sln_path = path.join(this.windows8_proj_dir, sln_name);
             var sln_file = fs.readFileSync(sln_path, 'utf-8');
             var name_regex = new RegExp(prev_name, "g");
@@ -143,6 +148,7 @@ module.exports.prototype = {
         return path.join(this.windows8_proj_dir, 'www');
     },
     config_xml:function() {
+        return path.join(this.windows8_proj_dir,"config.xml");
     },
     // copy files from merges directory to actual www dir
     copy_merges:function(merges_sub_path) {
@@ -162,11 +168,11 @@ module.exports.prototype = {
         shell.cp('-rf', project_www, this.windows8_proj_dir);
 
         // copy all files from merges directories (generic first, then specific)
-        this.copy_merges('wp');
         this.copy_merges('windows8');
 
+
         // copy over windows8 lib's cordova.js
-        var lib_path = path.join(util.libDirectory, 'wp', 'cordova', require('../../platforms').windows8.version);
+        var lib_path = path.join(util.libDirectory, 'windows8', 'cordova', require('../../platforms').windows8.version);
         var custom_path = config.has_custom_path(project_root, 'windows8');
         if (custom_path) lib_path = custom_path;
         var cordovajs_path = path.join(lib_path, 'common', 'www', 'cordova.js');


[4/6] git commit: Merge branch 'cordova-3.1.x' of https://git-wip-us.apache.org/repos/asf/cordova-cli into cordova-3.1.x

Posted by st...@apache.org.
Merge branch 'cordova-3.1.x' of https://git-wip-us.apache.org/repos/asf/cordova-cli into cordova-3.1.x


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

Branch: refs/heads/cordova-3.1.x
Commit: 37f49b5631715b43c5d3e8ecefeff3b6e1de43d1
Parents: 7cfbe67 1905677
Author: Steven Gill <st...@gmail.com>
Authored: Tue Oct 1 17:33:37 2013 -0700
Committer: Steven Gill <st...@gmail.com>
Committed: Tue Oct 1 17:33:37 2013 -0700

----------------------------------------------------------------------
 package.json                                  |  2 +-
 spec/config_parser.spec.js                    | 15 +++++++++++----
 spec/fixtures/templates/no_content_config.xml | 19 +++++++++++++++++++
 src/config_parser.js                          |  2 +-
 4 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------



[5/6] git commit: updated to use 3.1.0

Posted by st...@apache.org.
updated to use 3.1.0


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

Branch: refs/heads/cordova-3.1.x
Commit: 6e476922d4bc9ffff09682778b088daaf1fa98d3
Parents: 37f49b5
Author: Steven Gill <st...@gmail.com>
Authored: Tue Oct 1 20:21:24 2013 -0700
Committer: Steven Gill <st...@gmail.com>
Committed: Tue Oct 1 20:21:24 2013 -0700

----------------------------------------------------------------------
 VERSION      |  2 +-
 package.json |  2 +-
 platforms.js | 16 ++++++++--------
 3 files changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6e476922/VERSION
----------------------------------------------------------------------
diff --git a/VERSION b/VERSION
index 38f8e88..662b81c 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-dev
+3.1.0-0.1.0

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6e476922/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 7a1f78e..f3f945c 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "cordova",
-  "version": "3.0.10",
+  "version": "3.1.0-0.1.0",
   "preferGlobal": "true",
   "description": "Cordova command line interface tool",
   "main": "cordova",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/6e476922/platforms.js
----------------------------------------------------------------------
diff --git a/platforms.js b/platforms.js
index e30c308..c7edaff 100644
--- a/platforms.js
+++ b/platforms.js
@@ -21,41 +21,41 @@ module.exports = {
     'ios' : {
         parser : './src/metadata/ios_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-ios.git',
-        version: '3.1.0-rc1'
+        version: '3.1.0'
     },
     'android' : {
         parser : './src/metadata/android_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-android.git',
-        version: '3.1.0-rc1'
+        version: '3.1.0'
     },
     'wp7' : {
         parser : './src/metadata/wp7_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-wp8.git',
-        version: '3.1.0-rc1'
+        version: '3.1.0'
     },
     'wp8' : {
         parser : './src/metadata/wp8_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-wp8.git',
-        version: '3.1.0-rc1'
+        version: '3.1.0'
     },
     'blackberry10' : {
         parser : './src/metadata/blackberry10_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-blackberry.git',
-        version: '3.1.0-rc1'
+        version: '3.1.0'
     },
     'www':{
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-app-hello-world.git',
-        version: '3.1.0-rc1'
+        version: '3.1.0'
     },
     'firefoxos':{
         parser: './src/metadata/firefoxos_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-firefoxos.git',
-        version: '3.1.0-rc1'
+        version: '3.1.0'
     },
     'windows8':{
         parser: './src/metadata/windows8_parser',
         url    : 'https://git-wip-us.apache.org/repos/asf?p=cordova-windows.git',
-        version: '3.1.0-rc1'
+        version: '3.1.0'
     }
 };
 


[2/6] git commit: available list of platforms includes windows8

Posted by st...@apache.org.
available list of platforms includes windows8


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

Branch: refs/heads/cordova-3.1.x
Commit: 5768f5c4a7c82f0d82146108e99e24116e4b54bd
Parents: a77a560
Author: purplecabbage <pu...@gmail.com>
Authored: Fri Sep 27 16:51:54 2013 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Fri Sep 27 16:51:54 2013 -0700

----------------------------------------------------------------------
 src/platform.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/5768f5c4/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 7ab4d4b..bb988d0 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -42,7 +42,6 @@ module.exports = function platform(command, targets, callback) {
 
     var hooks = new hooker(projectRoot);
 
-
     if (arguments.length === 0) command = 'ls';
     if (targets) {
         if (!(targets instanceof Array)) targets = [targets];
@@ -91,6 +90,7 @@ module.exports = function platform(command, targets, callback) {
                         else throw err;
                     } else {
                         if (config_json.lib && config_json.lib[t]) {
+
                             call_into_create(t, projectRoot, cfg, config_json.lib[t].id, config_json.lib[t].version, config_json.lib[t].template, callback, end(index));
                         } else {
                             call_into_create(t, projectRoot, cfg, 'cordova', platforms[t].version, null, callback, end(index));
@@ -212,6 +212,7 @@ module.exports = function platform(command, targets, callback) {
                     if (os.platform() === 'win32') {
                         available.push('wp7');
                         available.push('wp8');
+                        available.push('windows8');
                     }
 
                     available = available.filter(function(p) {