mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
In Yeoman/dotnetnew generators, remove support for producing project.json projects
This commit is contained in:
@@ -9,7 +9,7 @@ import * as childProcess from 'child_process';
|
||||
import * as targz from 'tar.gz';
|
||||
|
||||
const isWindows = /^win/.test(process.platform);
|
||||
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', 'Dockerfile', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx', '.xproj'];
|
||||
const textFileExtensions = ['.gitignore', 'template_gitignore', '.config', '.cs', '.cshtml', '.csproj', '.html', '.js', '.json', '.jsx', '.md', '.nuspec', '.ts', '.tsx'];
|
||||
const yeomanGeneratorSource = './src/yeoman';
|
||||
|
||||
// To support the "dotnet new" templates, we want to bundle prebuilt dist dev-mode files, because "dotnet new" can't auto-run
|
||||
@@ -92,19 +92,11 @@ function buildYeomanNpmPackage(outputRoot: string) {
|
||||
|
||||
// Copy template files
|
||||
const filenameReplacements = [
|
||||
{ from: /.*\.xproj$/, to: 'tokenreplace-namePascalCase.xproj' },
|
||||
{ from: /.*\.csproj$/, to: 'tokenreplace-namePascalCase.csproj' }
|
||||
];
|
||||
const contentReplacements = [
|
||||
// .xproj items
|
||||
{ from: /\bWebApplicationBasic\b/g, to: '<%= namePascalCase %>' },
|
||||
{ from: /<ProjectGuid>[0-9a-f\-]{36}<\/ProjectGuid>/g, to: '<ProjectGuid><%= projectGuid %></ProjectGuid>' },
|
||||
{ from: /<RootNamespace>.*?<\/RootNamespace>/g, to: '<RootNamespace><%= namePascalCase %></RootNamespace>'},
|
||||
{ from: /\s*<BaseIntermediateOutputPath.*?<\/BaseIntermediateOutputPath>/g, to: '' },
|
||||
{ from: /\s*<OutputPath.*?<\/OutputPath>/g, to: '' },
|
||||
|
||||
// global.json items
|
||||
{ from: /1\.0\.0-preview2-1-003177/, to: '<%= sdkVersion %>' }
|
||||
{ from: /sdkVersionInjectedHere/, to: '<%= sdkVersion %>' }
|
||||
];
|
||||
_.forEach(templates, (templateConfig, templateName) => {
|
||||
const outputDir = path.join(outputTemplatesRoot, templateName);
|
||||
@@ -153,13 +145,13 @@ function buildDotNetNewNuGetPackage() {
|
||||
sources: [{
|
||||
source: './',
|
||||
target: './',
|
||||
exclude: ['.deployment', '.template.config/**', 'project.json', '*.xproj', '**/_placeholder.txt']
|
||||
exclude: ['.template.config/**']
|
||||
}],
|
||||
symbols: {
|
||||
sdkVersion: {
|
||||
type: 'bind',
|
||||
binding: 'dotnet-cli-version',
|
||||
replaces: '1.0.0-preview2-1-003177'
|
||||
replaces: 'sdkVersionInjectedHere'
|
||||
}
|
||||
},
|
||||
tags: { language: 'C#', type: 'project' },
|
||||
|
||||
@@ -40,7 +40,6 @@ interface TemplateConfig {
|
||||
rootDir: string; // Which of the template root directories should be used
|
||||
name: string; // Display name
|
||||
tests: boolean;
|
||||
mapFilenames?: { [pattern: string]: string | boolean };
|
||||
}
|
||||
|
||||
const templates: TemplateConfig[] = [
|
||||
@@ -52,20 +51,6 @@ const templates: TemplateConfig[] = [
|
||||
{ value: 'vue', rootDir: 'vue', name: 'Vue', tests: false }
|
||||
];
|
||||
|
||||
// Once everyone is on .csproj-compatible tooling, we might be able to remove the global.json files and eliminate
|
||||
// this SDK choice altogether. That would be good because then it would work with whatever SDK version you have
|
||||
// installed. For now, we need to specify an SDK version explicitly, because there's no support for wildcards, and
|
||||
// preview3+ tooling doesn't support project.json at all.
|
||||
const sdkChoices = [{
|
||||
value: '1.0.0-preview2-1-003177', // Current released version
|
||||
name: 'project.json' + chalk.gray(' (compatible with .NET Core tooling preview 2 and Visual Studio 2015)'),
|
||||
includeFiles: [/^project.json$/, /\.xproj$/, /_placeholder.txt$/, /\.deployment$/]
|
||||
}, {
|
||||
value: '1.0.0-preview3-004056', // Version that ships with VS2017RC
|
||||
name: '.csproj' + chalk.gray(' (compatible with .NET Core tooling preview 3 and Visual Studio 2017)'),
|
||||
includeFiles: [/\.csproj$/]
|
||||
}];
|
||||
|
||||
class MyGenerator extends yeoman.Base {
|
||||
private _answers: any;
|
||||
private _optionOrPrompt: YeomanPrompt;
|
||||
@@ -89,11 +74,6 @@ class MyGenerator extends yeoman.Base {
|
||||
name: 'framework',
|
||||
message: 'Framework',
|
||||
choices: templates
|
||||
}, {
|
||||
type: 'list',
|
||||
name: 'sdkVersion',
|
||||
message: 'What type of project do you want to create?',
|
||||
choices: sdkChoices
|
||||
}], firstAnswers => {
|
||||
const templateConfig = templates.filter(t => t.value === firstAnswers.framework)[0];
|
||||
const furtherQuestions = [{
|
||||
@@ -117,12 +97,9 @@ class MyGenerator extends yeoman.Base {
|
||||
this._answers = answers;
|
||||
this._answers.framework = firstAnswers.framework;
|
||||
this._answers.templateConfig = templateConfig;
|
||||
this._answers.sdkVersion = firstAnswers.sdkVersion;
|
||||
this._answers.namePascalCase = toPascalCase(answers.name);
|
||||
this._answers.projectGuid = this.options['projectguid'] || uuid.v4();
|
||||
|
||||
const chosenSdk = sdkChoices.filter(sdk => sdk.value === this._answers.sdkVersion)[0];
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
@@ -131,7 +108,6 @@ class MyGenerator extends yeoman.Base {
|
||||
writing() {
|
||||
const templateConfig = this._answers.templateConfig as TemplateConfig;
|
||||
const templateRoot = this.templatePath(templateConfig.rootDir);
|
||||
const chosenSdk = sdkChoices.filter(sdk => sdk.value === this._answers.sdkVersion)[0];
|
||||
glob.sync('**/*', { cwd: templateRoot, dot: true, nodir: true }).forEach(fn => {
|
||||
// Token replacement in filenames
|
||||
let outputFn = fn.replace(/tokenreplace\-([^\.\/]*)/g, (substr, token) => this._answers[token]);
|
||||
@@ -141,22 +117,9 @@ class MyGenerator extends yeoman.Base {
|
||||
outputFn = path.join(path.dirname(fn), '.gitignore');
|
||||
}
|
||||
|
||||
// Perform any filename replacements configured for the template
|
||||
const mappedFilename = applyFirstMatchingReplacement(outputFn, templateConfig.mapFilenames);
|
||||
let fileIsExcludedByTemplateConfig = false;
|
||||
if (typeof mappedFilename === 'string') {
|
||||
outputFn = mappedFilename;
|
||||
} else {
|
||||
fileIsExcludedByTemplateConfig = (mappedFilename === false);
|
||||
}
|
||||
|
||||
// Decide whether to emit this file
|
||||
const isTestSpecificFile = testSpecificPaths.some(regex => regex.test(outputFn));
|
||||
const isSdkSpecificFile = sdkChoices.some(sdk => sdk.includeFiles.some(regex => regex.test(outputFn)));
|
||||
const matchesChosenSdk = chosenSdk.includeFiles.some(regex => regex.test(outputFn));
|
||||
const emitFile = (matchesChosenSdk || !isSdkSpecificFile)
|
||||
&& (this._answers.tests || !isTestSpecificFile)
|
||||
&& !fileIsExcludedByTemplateConfig;
|
||||
const emitFile = (this._answers.tests || !isTestSpecificFile);
|
||||
|
||||
if (emitFile) {
|
||||
let inputFullPath = path.join(templateRoot, fn);
|
||||
@@ -265,28 +228,5 @@ function rewritePackageJson(contents, includeTests) {
|
||||
return contents;
|
||||
}
|
||||
|
||||
function applyFirstMatchingReplacement(inputValue: string, replacements: { [pattern: string]: string | boolean }): string | boolean {
|
||||
if (replacements) {
|
||||
const replacementPatterns = Object.getOwnPropertyNames(replacements);
|
||||
for (let patternIndex = 0; patternIndex < replacementPatterns.length; patternIndex++) {
|
||||
const pattern = replacementPatterns[patternIndex];
|
||||
const regexp = new RegExp(pattern);
|
||||
if (regexp.test(inputValue)) {
|
||||
const replacement = replacements[pattern];
|
||||
|
||||
// To avoid bug-prone evaluation order dependencies, we only respond to the first name match per file
|
||||
if (typeof (replacement) === 'boolean') {
|
||||
return replacement;
|
||||
} else {
|
||||
return inputValue.replace(regexp, replacement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No match
|
||||
return inputValue;
|
||||
}
|
||||
|
||||
declare var module: any;
|
||||
(module).exports = MyGenerator;
|
||||
|
||||
Reference in New Issue
Block a user