Workaround for Yeoman generators not producing .gitignore files due to Yeoman issue #1862

This commit is contained in:
SteveSandersonMS
2016-06-22 10:57:00 +01:00
parent 7e51fc4480
commit d3ded5bbdf
9 changed files with 32 additions and 17 deletions

7
.gitignore vendored
View File

@@ -29,3 +29,10 @@ project.lock.json
.vs/
npm-debug.log
/.build/
# The templates can't contain their own .gitignore files, because Yeoman has strange default handling for
# files with that name (https://github.com/npm/npm/issues/1862). So, each template instead has a template_gitignore
# file which gets renamed after the files are copied. And so any files that need to be excluded in the source
# repo have to be excluded here.
/templates/*/node_modules/
/templates/*/wwwroot/dist/

View File

@@ -6,7 +6,7 @@ import * as _ from 'lodash';
import * as mkdirp from 'mkdirp';
import * as rimraf from 'rimraf';
const textFileExtensions = ['.gitignore', '.config', '.cs', '.cshtml', 'Dockerfile', '.html', '.js', '.json', '.jsx', '.md', '.ts', '.tsx', '.xproj'];
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', 'Dockerfile', '.html', '.js', '.json', '.jsx', '.md', '.ts', '.tsx', '.xproj'];
const templates = {
'angular-2': '../../templates/Angular2Spa/',
@@ -38,7 +38,10 @@ function writeFileEnsuringDirExists(root: string, filename: string, contents: st
}
function listFilesExcludingGitignored(root: string): string[] {
let gitIgnorePath = path.join(root, '.gitignore');
// Note that the gitignore files, prior to be written by the generator, are called 'template_gitignore'
// instead of '.gitignore'. This is a workaround for Yeoman doing strange stuff with .gitignore files
// (it renames them to .npmignore, which is not helpful).
let gitIgnorePath = path.join(root, 'template_gitignore');
let gitignoreEvaluator = fs.existsSync(gitIgnorePath)
? gitignore.compile(fs.readFileSync(gitIgnorePath, 'utf8'))
: { accepts: () => true };

View File

@@ -47,6 +47,11 @@ class MyGenerator extends yeoman.Base {
// Token replacement in filenames
let outputFn = fn.replace(/tokenreplace\-([^\.\/]*)/g, (substr, token) => this._answers[token]);
// Rename template_gitignore to .gitignore in output
if (path.basename(fn) === 'template_gitignore') {
outputFn = path.join(path.dirname(fn), '.gitignore');
}
this.fs.copyTpl(
path.join(templateRoot, fn),
this.destinationPath(outputFn),

View File

@@ -1,6 +1,6 @@
{
"name": "generator-aspnetcore-spa",
"version": "0.1.5",
"version": "0.1.6",
"description": "Single-Page App templates for ASP.NET Core",
"author": "Microsoft",
"license": "Apache-2.0",