Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support .gitignore files in generated app #53

Merged
merged 3 commits into from
Nov 15, 2019
Merged
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
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down
183 changes: 176 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions spec/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down