Skip to content

Commit

Permalink
CB-11412 improve template implementation
Browse files Browse the repository at this point in the history
 This closes #456
  • Loading branch information
carynbear authored and stevengill committed Jun 20, 2016
1 parent 5fb8dff commit 1f29cba
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 231 deletions.
166 changes: 102 additions & 64 deletions cordova-lib/spec-cordova/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

var helpers = require('./helpers'),
path = require('path'),
fs = require('fs'),
shell = require('shelljs'),
Q = require('q'),
events = require('cordova-common').events,
Expand All @@ -31,22 +30,25 @@ var appName = 'TestBase';
var appId = 'org.testing';
var project = path.join(tmpDir, appName);

var configNormal = {
lib: {
var configSubDirPkgJson = {
lib: {
www: {
url: path.join(__dirname, 'fixtures', 'base', 'www'),
version: 'testCordovaCreate'
template: true,
url: path.join(__dirname, 'fixtures', 'templates', 'withsubdirectory_package_json'),
version: ''
}
}
};
var configSymlink = {
lib: {
}
};

var configConfigInWww = {
lib: {
www: {
url: path.join(__dirname, 'fixtures', 'base'), // "create" should copy or link the www child of this dir and not the dir itself.
link: true
template: true,
url: path.join(__dirname, 'fixtures', 'templates', 'config_in_www'),
version: ''
}
}
};
}
};

var configGit = {
lib: {
Expand Down Expand Up @@ -110,58 +112,79 @@ describe('create end-to-end', function() {

expect(path.join(project, 'hooks', 'README.md')).toExist();

// Check if config files exist.
// Check if www files exist.
expect(path.join(project, 'www', 'index.html')).toExist();

// Check that www/config.xml was updated.
// Check that config.xml was updated.
var configXml = new ConfigParser(path.join(project, 'config.xml'));
expect(configXml.packageName()).toEqual(appId);

// TODO (kamrik): check somehow that we got the right config.xml from the fixture and not some place else.
// expect(configXml.name()).toEqual('TestBase');
}

var results;
events.on('results', function(res) { results = res; });
function checkConfigXml() {
// Check if top level dirs exist.
var dirs = ['hooks', 'platforms', 'plugins', 'www'];
dirs.forEach(function(d) {
expect(path.join(project, d)).toExist();
});
expect(path.join(project, 'hooks', 'README.md')).toExist();

//index.js and template subdir folder should not exist (inner files should be copied to the project folder)
expect(path.join(project, 'index.js')).not.toExist();
expect(path.join(project, 'template')).not.toExist();

it('should successfully run with regular config', function(done) {
// Call cordova create with no args, should return help.
Q()
.then(function() {
// Create a real project
return cordova.raw.create(project, appId, appName, configNormal);
})
.then(checkProject)
.fail(function(err) {
console.log(err && err.stack);
expect(err).toBeUndefined();
})
.fin(done);
});
// Check if www files exist.
expect(path.join(project, 'www', 'index.html')).toExist();
var configXml = new ConfigParser(path.join(project, 'www', 'config.xml'));
expect(configXml.packageName()).toEqual(appId);
expect(configXml.version()).toEqual('1.0.0');

it('should successfully run with symlinked www', function(done) {
// Call cordova create with no args, should return help.
cordova.raw.create(project, appId, appName, configSymlink)
.then(checkProject)
.then(function() {
// Check that www is really a symlink
expect(fs.lstatSync(path.join(project, 'www')).isSymbolicLink()).toBe(true);
})
.fail(function(err) {
if(process.platform.slice(0, 3) == 'win') {
// Allow symlink error if not in admin mode
expect(err.message).toBe('Symlinks on Windows require Administrator privileges');
} else {
if (err) {
console.log(err.stack);
}
expect(err).toBeUndefined();
}
})
.fin(done);
});
// Check that config.xml does not exist outside of www
expect(path.join(project, 'config.xml')).not.toExist();

// Check that we got no package.json
expect(path.join(project, 'package.json')).not.toExist();

// Check that we got the right config.xml from the template and not stock
expect(configXml.description()).toEqual('this is the correct config.xml');
}

it('should successfully run with Git URL', function(done) {
function checkSubDir() {
// Check if top level dirs exist.
var dirs = ['hooks', 'platforms', 'plugins', 'www'];
dirs.forEach(function(d) {
expect(path.join(project, d)).toExist();
});
expect(path.join(project, 'hooks', 'README.md')).toExist();

//index.js and template subdir folder should not exist (inner files should be copied to the project folder)
expect(path.join(project, 'index.js')).not.toExist();
expect(path.join(project, 'template')).not.toExist();

// Check if config files exist.
expect(path.join(project, 'www', 'index.html')).toExist();

// Check that config.xml was updated.
var configXml = new ConfigParser(path.join(project, 'config.xml'));
expect(configXml.packageName()).toEqual(appId);
expect(configXml.version()).toEqual('1.0.0');


// Check that we got package.json (the correct one)
var pkjson = require(path.join(project, 'package.json'));
expect(pkjson.name).toEqual(appName.toLowerCase());
expect(pkjson.valid).toEqual('true');

// Check that we got the right config.xml
expect(configXml.description()).toEqual('this is the correct config.xml');
}

var results;
events.on('results', function(res) { results = res; });

it('should successfully run with Git URL', function(done) {
// Call cordova create with no args, should return help.
Q()
.then(function() {
Expand Down Expand Up @@ -208,6 +231,11 @@ describe('create end-to-end', function() {
return cordova.raw.create(project, appId, appName, config);
})
.then(checkProject)
.then(function(){
// Check that we got the right config.xml
var configXml = new ConfigParser(path.join(project, 'config.xml'));
expect(configXml.description()).toEqual('this is the very correct config.xml');
})
.fail(function(err) {
console.log(err && err.stack);
expect(err).toBeUndefined();
Expand Down Expand Up @@ -262,31 +290,41 @@ describe('create end-to-end', function() {
})
.fin(done);
});



it('should successfully run with template having package.json, and subdirectory, and package.json in subdirectory', function(done) {
// Call cordova create with no args, should return help.
var config = {
lib: {
www: {
template: true,
url: path.join(__dirname, 'fixtures', 'templates', 'withsubdirectory_package_json'),
version: ''
}
}
};
var config = configSubDirPkgJson;
Q()
.then(function() {
// Create a real project
project = project + '1';
return cordova.raw.create(project, appId, appName, config);
})
.then(checkProject)
.then(checkSubDir)
.fail(function(err) {
console.log(err && err.stack);
expect(err).toBeUndefined();
})
.fin(done);
});

it('should successfully run config.xml in the www folder', function(done) {
// Call cordova create with no args, should return help.
var config = configConfigInWww;
Q()
.then(function() {
// Create a real project
project = project + '2';
return cordova.raw.create(project, appId, appName, config);
})
.then(checkConfigXml)
.fail(function(err) {
console.log(err && err.stack);
expect(err).toBeUndefined();
})
.fin(done);
});


});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version='1.0' encoding='utf-8'?>
<!--
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.
-->
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HelloCordova</name>
<description>this is the correct config.xml</description>
<author email="[email protected]" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<!-- Whitelist configuration. Refer to https://cordova.apache.org/docs/en/edge/guide_appdev_whitelist_index.md.html -->
<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<!--
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.
-->
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
-->
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HelloCordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<description>this is the very correct config.xml</description>
<author email="[email protected]" href="http://cordova.io">
Apache Cordova Team
</author>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"type": "git",
"url": "https://github.com/apache/cordova-app-hello-world.git"
},
"license": "Apache-2.0"
"license": "Apache-2.0",
"test": "false"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
-->
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HelloCordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<description>this is the correct config.xml</description>
<author email="[email protected]" href="http://cordova.io">
Apache Cordova Team
</author>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"type": "git",
"url": "https://github.com/apache/cordova-app-hello-world.git"
},
"license": "Apache-2.0"
"license": "Apache-1.0",
"valid": "true"
}
Loading

0 comments on commit 1f29cba

Please sign in to comment.