Skip to content
Permalink
Browse files
feat: support .gitignore files in generated app (#53)
It is impossible to deploy `.gitignore` files via npm packages.
Instead, Cordova templates should include `gitignore` files that we
rename to `.gitignore`. This PR implements that renaming.

For more details see apache/cordova-discuss#69.

This also bumps the dependency on `cordova-app-hello-world`
to a version that includes apache/cordova-app-hello-world#50.

Closes #8, apache/cordova-app-hello-world#30 and
apache/cordova-discuss#69.
  • Loading branch information
raphinesse committed Nov 15, 2019
1 parent b64df2e commit 1d0d67e0c6a2a49935591a152597db54b1a5bd01
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 8 deletions.
@@ -23,6 +23,7 @@ var path = require('path');

var tmp = require('tmp');
const npa = require('npm-package-arg');
const globby = require('globby');
var isObject = require('isobject');
var pathIsInside = require('path-is-inside');
var requireFresh = require('import-fresh');
@@ -127,6 +128,15 @@ function cordovaCreate (dest, opts = {}) {
throw e;
}

// It is impossible to deploy .gitignore files via npm packages.
// Instead, Cordova templates should include gitignore files that we
// rename to .gitignore here. For more details see
// https://github.com/apache/cordova-discuss/issues/69
globby.sync(['**/gitignore'], { cwd: dir, absolute: true })
.forEach(f =>
fs.moveSync(f, path.join(path.dirname(f), '.gitignore'))
);

// Write out id, name and version to config.xml
const configPath = path.join(dir, 'config.xml');
const conf = new ConfigParser(configPath);

Some generated files are not rendered by default. Learn more.

@@ -24,10 +24,11 @@
"node": ">=10"
},
"dependencies": {
"cordova-app-hello-world": "^4.0.0",
"cordova-app-hello-world": "github:apache/cordova-app-hello-world#4046a690e49f",
"cordova-common": "^3.1.0",
"cordova-fetch": "^2.0.0",
"fs-extra": "^8.1.0",
"globby": "^10.0.1",
"import-fresh": "^3.1.0",
"isobject": "^4.0.0",
"npm-package-arg": "^6.1.1",
@@ -181,6 +181,33 @@ describe('create end-to-end', function () {
return create(project, opts)
.then(checkProjectCreatedWithDefaultTemplate);
});

it('should rename all gitignore files in template to .gitignore', () => {
const baseTemplatePkg = path.join(__dirname, 'templates/withsubdirectory');
const templatePkg = path.join(tmpDir, 'gitignore-template');
fs.copySync(baseTemplatePkg, templatePkg);

// Setup a few gitignore files that should be renamed (or not)
const templateDir = path.join(templatePkg, 'template');
fs.ensureFileSync(path.join(templateDir, 'gitignore'));
fs.ensureFileSync(path.join(templateDir, 'www/gitignore'));
fs.ensureDirSync(path.join(templateDir, 'foo/gitignore'));

opts.template = templatePkg;
return create(project, opts).then(() => {
// Renames gitignore at template root
expect(path.join(project, 'gitignore')).not.toExist();
expect(path.join(project, '.gitignore')).toExist();

// Renames gitignores in sub-directories
expect(path.join(project, 'www/gitignore')).not.toExist();
expect(path.join(project, 'www/.gitignore')).toExist();

// Does not rename directories with name gitignore
expect(path.join(project, 'foo/gitignore')).toExist();
expect(path.join(project, 'foo/.gitignore')).not.toExist();
});
});
});

describe('when shit happens', function () {

0 comments on commit 1d0d67e

Please sign in to comment.