diff --git a/index.js b/index.js index 643213bc..fabaefd9 100644 --- a/index.js +++ b/index.js @@ -255,6 +255,15 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) { // get stock hooks; used if template does not contain hooks paths.hooks = path.join(require('cordova-app-hello-world').dirname, 'hooks'); + // CB-12397 add .gitignore for plugins & platforms to app template + // get stock .npmignore; used if template does not contain .gitignore + // NOTE: This is part of a workaround for the npm .gitignore/.npmignore + // behavior discussed in: + // https://github.com/npm/npm/issues/1862 + // https://github.com/npm/npm/issues/3763 + // https://github.com/npm/npm/issues/7252 + paths.npmignore = path.join(require('cordova-app-hello-world').dirname, '.npmignore'); + // ToDo: get stock package.json if template does not contain package.json; var dirAlreadyExisted = fs.existsSync(dir); if (!dirAlreadyExisted) { @@ -271,13 +280,23 @@ module.exports = function(dir, optionalId, optionalName, cfg, extEvents) { if (!!cfg.lib.www.link) linkFromTemplate(import_from_path, dir); - // If following were not copied/linked from template, copy from stock app hello world + // If following were not copied/linked from template, + // copy from stock cordova-app-hello-world: copyIfNotExists(paths.www, path.join(dir, 'www')); copyIfNotExists(paths.hooks, path.join(dir, 'hooks')); var configXmlExists = projectConfig(dir); //moves config to root if in www if (paths.configXml && !configXmlExists) { shell.cp(paths.configXml, path.join(dir, 'config.xml')); } + + // CB-12397 add .gitignore for plugins & platforms to app template + // get stock .npmignore; used if template does not contain .gitignore + // NOTE: This is part of a workaround for the npm .gitignore/.npmignore + // behavior discussed in: + // https://github.com/npm/npm/issues/1862 + // https://github.com/npm/npm/issues/3763 + // https://github.com/npm/npm/issues/7252 + shell.cp(paths.npmignore, path.join(dir, '.gitignore')); } catch (e) { if (!dirAlreadyExisted) { shell.rm('-rf', dir); diff --git a/spec/create.spec.js b/spec/create.spec.js index b6afe681..8b5176e2 100644 --- a/spec/create.spec.js +++ b/spec/create.spec.js @@ -207,7 +207,7 @@ describe('create end-to-end', function() { // Check that we got package.json expect(path.join(project, 'package.json')).toExist(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).toExist(); }).then(function() { delete require.cache[require.resolve(path.join(project, 'package.json'))]; @@ -229,7 +229,7 @@ describe('create end-to-end', function() { // Check that we got package.json expect(path.join(project, 'package.json')).toExist(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).toExist(); }).fail(function(err) { console.log(err && err.stack); @@ -249,7 +249,7 @@ describe('create end-to-end', function() { // Check that we got package.json expect(path.join(project, 'package.json')).toExist(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).toExist(); }).then(function() { shell.rm('-rf', project); @@ -286,7 +286,7 @@ describe('create end-to-end', function() { // Check that we got no package.json expect(path.join(project, 'package.json')).not.toExist(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).not.toExist(); }).then(function() { // Check that we got the right config.xml @@ -318,7 +318,7 @@ describe('create end-to-end', function() { // Check that we got no package.json expect(path.join(project, 'package.json')).not.toExist(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).not.toExist(); }).fail(function(err) { console.log(err && err.stack); @@ -346,7 +346,7 @@ describe('create end-to-end', function() { // Check that we got no package.json expect(path.join(project, 'package.json')).not.toExist(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).not.toExist(); }).fail(function(err) { console.log(err && err.stack); @@ -362,7 +362,7 @@ describe('create end-to-end', function() { .then(function() { checkArtifactsAndConfigXmlWithPackageFromSubDir(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).not.toExist(); }).fail(function(err) { console.log(err && err.stack); @@ -379,7 +379,7 @@ describe('create end-to-end', function() { .then(function() { checkArtifactsAndConfigXmlWithNoPackageFromWww(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).not.toExist(); }).fail(function(err) { console.log(err && err.stack); @@ -402,7 +402,7 @@ describe('create end-to-end', function() { .then(function() { checkArtifactsAndConfigXmlWithNoPackageFromWww(); // CB-12397 check .gitignore behavior - expect(path.join(project, '.gitignore')).not.toExist(); + expect(path.join(project, '.gitignore')).toExist(); expect(path.join(project, '.npmignore')).not.toExist(); }).fail(function(err) { console.log(err && err.stack);