From 0bcf4b0700c7bf4cb1de6b4124f0ee87427351b5 Mon Sep 17 00:00:00 2001 From: SteveSandersonMS Date: Thu, 8 Sep 2016 15:58:47 +0100 Subject: [PATCH] Further work on fix for #235 (solving additional problem that 'npm publish' is hardcoded to exclude node_modules dirs) --- .gitignore | 9 +-------- ...lder.txt => template_nodemodules_placeholder.txt} | 0 ...lder.txt => template_nodemodules_placeholder.txt} | 0 ...lder.txt => template_nodemodules_placeholder.txt} | 0 ...lder.txt => template_nodemodules_placeholder.txt} | 0 ...lder.txt => template_nodemodules_placeholder.txt} | 0 templates/package-builder/src/build/build.ts | 6 +++++- templates/package-builder/src/yeoman/app/index.ts | 12 ++++++++++++ templates/package-builder/src/yeoman/package.json | 2 +- 9 files changed, 19 insertions(+), 10 deletions(-) rename templates/Angular2Spa/{node_modules/_placeholder.txt => template_nodemodules_placeholder.txt} (100%) rename templates/KnockoutSpa/{node_modules/_placeholder.txt => template_nodemodules_placeholder.txt} (100%) rename templates/ReactReduxSpa/{node_modules/_placeholder.txt => template_nodemodules_placeholder.txt} (100%) rename templates/ReactSpa/{node_modules/_placeholder.txt => template_nodemodules_placeholder.txt} (100%) rename templates/WebApplicationBasic/{node_modules/_placeholder.txt => template_nodemodules_placeholder.txt} (100%) diff --git a/.gitignore b/.gitignore index 6df4b42..06cc11a 100644 --- a/.gitignore +++ b/.gitignore @@ -34,13 +34,6 @@ npm-debug.log # 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. - -# Note that we need to exclude node_modules/** (i.e., subdirs, not the whole of node_modules) because we do need to -# include the _placeholder.txt files, and can't do that using gitignore exclusion because developers aren't promoted to -# commit files included that way. This is all a workaround for Workaround for https://github.com/aspnet/JavaScriptServices/issues/235 -/templates/*/node_modules/** +/templates/*/node_modules/ /templates/*/wwwroot/dist/ .vscode/ - -# Workaround for https://github.com/aspnet/JavaScriptServices/issues/235 -!/templates/*/node_modules/_placeholder.txt diff --git a/templates/Angular2Spa/node_modules/_placeholder.txt b/templates/Angular2Spa/template_nodemodules_placeholder.txt similarity index 100% rename from templates/Angular2Spa/node_modules/_placeholder.txt rename to templates/Angular2Spa/template_nodemodules_placeholder.txt diff --git a/templates/KnockoutSpa/node_modules/_placeholder.txt b/templates/KnockoutSpa/template_nodemodules_placeholder.txt similarity index 100% rename from templates/KnockoutSpa/node_modules/_placeholder.txt rename to templates/KnockoutSpa/template_nodemodules_placeholder.txt diff --git a/templates/ReactReduxSpa/node_modules/_placeholder.txt b/templates/ReactReduxSpa/template_nodemodules_placeholder.txt similarity index 100% rename from templates/ReactReduxSpa/node_modules/_placeholder.txt rename to templates/ReactReduxSpa/template_nodemodules_placeholder.txt diff --git a/templates/ReactSpa/node_modules/_placeholder.txt b/templates/ReactSpa/template_nodemodules_placeholder.txt similarity index 100% rename from templates/ReactSpa/node_modules/_placeholder.txt rename to templates/ReactSpa/template_nodemodules_placeholder.txt diff --git a/templates/WebApplicationBasic/node_modules/_placeholder.txt b/templates/WebApplicationBasic/template_nodemodules_placeholder.txt similarity index 100% rename from templates/WebApplicationBasic/node_modules/_placeholder.txt rename to templates/WebApplicationBasic/template_nodemodules_placeholder.txt diff --git a/templates/package-builder/src/build/build.ts b/templates/package-builder/src/build/build.ts index 546ff89..a0433bd 100644 --- a/templates/package-builder/src/build/build.ts +++ b/templates/package-builder/src/build/build.ts @@ -110,7 +110,11 @@ function buildDotNetNewNuGetPackage() { const projectGuid = '00000000-0000-0000-0000-000000000000'; const filenameReplacements = [ { from: /.*\.xproj$/, to: `${sourceProjectName}.xproj` }, - { from: /\btemplate_gitignore$/, to: '.gitignore' } + { from: /\btemplate_gitignore$/, to: '.gitignore' }, + + // Workaround for https://github.com/aspnet/JavaScriptServices/issues/235 + // For details, see the comment in ../yeoman/app/index.ts + { from: /\btemplate_nodemodules_placeholder.txt$/, to: 'node_modules/_placeholder.txt' } ]; const contentReplacements = [ { from: /[0-9a-f\-]{36}<\/ProjectGuid>/g, to: `${projectGuid}` }, diff --git a/templates/package-builder/src/yeoman/app/index.ts b/templates/package-builder/src/yeoman/app/index.ts index ecb5366..04687a0 100644 --- a/templates/package-builder/src/yeoman/app/index.ts +++ b/templates/package-builder/src/yeoman/app/index.ts @@ -52,6 +52,18 @@ class MyGenerator extends yeoman.Base { outputFn = path.join(path.dirname(fn), '.gitignore'); } + // Likewise, output template_nodemodules_placeholder.txt as node_modules/_placeholder.txt + // This is a workaround for https://github.com/aspnet/JavaScriptServices/issues/235. We need the new project + // to have a nonempty node_modules dir as far as *source control* is concerned. So, there's a gitignore + // rule that explicitly causes node_modules/_placeholder.txt to be tracked in source control. But how + // does that file get there in the first place? It's not enough for such a file to exist when the + // generator-aspnetcore-spa NPM package is published, because NPM doesn't allow any directories called + // node_modules to exist in the package. So we have a file with at a different location, and move it + // to node_modules as part of executing the template. + if (path.basename(fn) === 'template_nodemodules_placeholder.txt') { + outputFn = path.join(path.dirname(fn), 'node_modules', '_placeholder.txt'); + } + this.fs.copyTpl( path.join(templateRoot, fn), this.destinationPath(outputFn), diff --git a/templates/package-builder/src/yeoman/package.json b/templates/package-builder/src/yeoman/package.json index f68b9ae..49302f9 100644 --- a/templates/package-builder/src/yeoman/package.json +++ b/templates/package-builder/src/yeoman/package.json @@ -1,6 +1,6 @@ { "name": "generator-aspnetcore-spa", - "version": "0.2.5", + "version": "0.2.6", "description": "Single-Page App templates for ASP.NET Core", "author": "Microsoft", "license": "Apache-2.0",