Skip to content

Commit

Permalink
CB-12397 fix .gitignore for plugins & platforms
Browse files Browse the repository at this point in the history
NOTE: This implementation is a workaround for the
npm .gitignore/.npmignore behavior discussed in:
- npm/npm#1862
- npm/npm#3763
- npm/npm#7252
  • Loading branch information
Christopher J. Brody committed May 10, 2017
1 parent 1ade9c4 commit 9293a1d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions spec/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))];
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 9293a1d

Please sign in to comment.