Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cordova-lib/spec-cordova/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,28 @@ describe('create end-to-end', function() {
.fin(done);
});

it('should successfully run with www folder as the template', function(done) {
var config = {
lib: {
www: {
template: true,
url: path.join(__dirname, 'fixtures', 'templates', 'config_in_www', 'www'),
version: ''
}
}
};
Q()
.then(function() {
project = project + '3';
return cordova.raw.create(project, appId, appName, config);
})
.then(checkConfigXml)
.fail(function(err) {
console.log(err && err.stack);
expect(err).toBeUndefined();
})
.fin(done);
});


});
37 changes: 22 additions & 15 deletions cordova-lib/src/cordova/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,28 +323,35 @@ function ifNotCopied(src, dst) {

/**
* Copies template files, and directories into a Cordova project directory.
* If the template exists in a subdirectory everything is copied.
* If the template is a www folder, the www folder is simply copied
* Otherwise if the template exists in a subdirectory everything is copied
* Otherwise package.json, RELEASENOTES.md, .git, NOTICE, LICENSE, COPYRIGHT, and .npmignore are not copied over.
* A template directory, and project directory must be passed.
* templateDir - Template directory
* projectDir - Project directory
* isSubDir - boolean is true if template has subdirectory structure (see code around line 229)
*/
function copyTemplateFiles(templateDir, projectDir, isSubDir) {
var templateFiles; // Current file
templateFiles = fs.readdirSync(templateDir);
// Remove directories, and files that are unwanted
if (!isSubDir) {
templateFiles = templateFiles.filter(
function (value) {
return !(value === 'package.json' || value === 'RELEASENOTES.md' || value === '.git' || value === 'NOTICE'||
value === 'LICENSE' || value === 'COPYRIGHT' || value === '.npmignore');
}
);
}
// Copy each template file after filter
for (var i = 0; i < templateFiles.length; i++) {
var copyPath = path.resolve(templateDir, templateFiles[i]);
var copyPath;
// if template is a www dir
if (path.basename(templateDir) === 'www') {
copyPath = path.resolve(templateDir);
shell.cp('-R', copyPath, projectDir);
} else {
var templateFiles; // Current file
templateFiles = fs.readdirSync(templateDir);
// Remove directories, and files that are unwanted
if (!isSubDir) {
var excludes = ['package.json', 'RELEASENOTES.md' , '.git', 'NOTICE', 'LICENSE', 'COPYRIGHT', '.npmignore'];
templateFiles = templateFiles.filter( function (value) {
return excludes.indexOf(value) < 0;
});
}
// Copy each template file after filter
for (var i = 0; i < templateFiles.length; i++) {
copyPath = path.resolve(templateDir, templateFiles[i]);
shell.cp('-R', copyPath, projectDir);
}
}

}