Remove Yeoman generator - replace it with deprecation notice.

This commit is contained in:
Steve Sanderson
2017-08-22 14:33:30 -07:00
parent d6ae8829b6
commit eea2066a6d
4 changed files with 12 additions and 260 deletions

View File

@@ -1 +0,0 @@
/node_modules/

View File

@@ -1,14 +1,15 @@
Generates ASP.NET Core projects for single-page applications.
# Please use "dotnet new" templates instead
Can generate projects with:
As of .NET Core 2.0, it's no longer necessary to use Yeoman to create new Single-Page Application projects.
* Angular
* Aurelia
* Knockout
* React
* React with Redux
* Vue
Using the .NET Core 2.0 SDK, you can run any of the following commands in an empty directory, without needing to install any external packages first:
For more information about features and usage, see [this blog post](https://blogs.msdn.microsoft.com/webdev/2017/02/14/building-single-page-applications-on-asp-net-core-with-javascriptservices/).
* `dotnet new angular`
* `dotnet new react`
* `dotnet new redux`
To learn more about the underlying technologies, or to report any issues, see [this project's GitHub repo](https://github.com/aspnet/JavaScriptServices).
Or, if you want to create an Aurelia, Knockout, or Vue application, you should run `dotnet new --install Microsoft.AspNetCore.SpaTemplates::*` first. This will add `aurelia`, `knockout`, and `vue` templates to `dotnet new`.
#### This Yeoman generator is DEPRECATED
Please don't use `generator-aspnetcore-spa` to create new projects. Its output is outdated and no longer maintained. Instead, use `dotnet new` as described above (or if you're on Windows and use Visual Studio, you can just use *File->New Project* to create Angular, React, or React+Redux projects).

View File

@@ -1,238 +0,0 @@
import * as fs from 'fs';
import * as path from 'path';
import * as yeoman from 'yeoman-generator';
import * as uuid from 'node-uuid';
import * as glob from 'glob';
import * as semver from 'semver';
import * as chalk from 'chalk';
import { execSync } from 'child_process';
const yosay = require('yosay');
const toPascalCase = require('to-pascal-case');
const isWindows = /^win/.test(process.platform);
const generatorPackageJson = require(path.resolve(__dirname, '../package.json'));
// Paths matching these regexes will only be included if the user wants tests
const testSpecificPaths = [
/\.spec.ts$/, // Files ending '.spec.ts'
/(^|\/|\\)test($|\/|\\)/ // Files under any directory called 'test'
];
// These NPM dependencies will only be included if the user wants tests
const testSpecificNpmPackages = [
"@types/chai",
"@types/jasmine",
"chai",
"jasmine-core",
"karma",
"karma-chai",
"karma-chrome-launcher",
"karma-cli",
"karma-jasmine",
"karma-webpack"
];
type YeomanPrompt = (opt: yeoman.IPromptOptions | yeoman.IPromptOptions[], callback: (answers: any) => void) => void;
const optionOrPrompt: YeomanPrompt = require('yeoman-option-or-prompt');
interface TemplateConfig {
value: string; // Internal unique ID for Yeoman prompt
rootDir: string; // Which of the template root directories should be used
name: string; // Display name
tests: boolean;
}
const templates: TemplateConfig[] = [
{ value: 'angular', rootDir: 'angular', name: 'Angular', tests: true },
{ value: 'aurelia', rootDir: 'aurelia', name: 'Aurelia', tests: false },
{ value: 'knockout', rootDir: 'knockout', name: 'Knockout', tests: false },
{ value: 'react', rootDir: 'react', name: 'React', tests: false },
{ value: 'react-redux', rootDir: 'react-redux', name: 'React with Redux', tests: false },
{ value: 'vue', rootDir: 'vue', name: 'Vue', tests: false }
];
class MyGenerator extends yeoman.Base {
private _answers: any;
private _optionOrPrompt: YeomanPrompt;
constructor(args: string | string[], options: any) {
super(args, options);
this._optionOrPrompt = optionOrPrompt;
this.log(yosay('Welcome to the ASP.NET Core Single-Page App generator!\n\nVersion: ' + generatorPackageJson.version));
if (isWindows) {
assertNpmVersionIsAtLeast('3.0.0');
}
assertDotNetSDKVersionIsAtLeast('1.0.0');
}
prompting() {
this.option('projectguid');
const done = this.async();
this._optionOrPrompt([{
type: 'list',
name: 'framework',
message: 'Framework',
choices: templates
}], firstAnswers => {
const templateConfig = templates.filter(t => t.value === firstAnswers.framework)[0];
const furtherQuestions = [{
type: 'input',
name: 'name',
message: 'Your project name',
default: this.appname
}];
if (templateConfig.tests) {
furtherQuestions.unshift({
type: 'confirm',
name: 'tests',
message: 'Do you want to include unit tests?',
default: true as any
});
}
this._optionOrPrompt(furtherQuestions, answers => {
answers.framework = firstAnswers.framework;
this._answers = answers;
this._answers.framework = firstAnswers.framework;
this._answers.templateConfig = templateConfig;
this._answers.namePascalCase = toPascalCase(answers.name);
this._answers.projectGuid = this.options['projectguid'] || uuid.v4();
this._answers.sdkVersion = getDotNetSDKVersion();
done();
});
});
}
writing() {
const templateConfig = this._answers.templateConfig as TemplateConfig;
const templateRoot = this.templatePath(templateConfig.rootDir);
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]);
// Rename template_gitignore to .gitignore in output
if (path.basename(fn) === 'template_gitignore') {
outputFn = path.join(path.dirname(fn), '.gitignore');
}
// Decide whether to emit this file
const isTestSpecificFile = testSpecificPaths.some(regex => regex.test(outputFn));
const emitFile = (this._answers.tests || !isTestSpecificFile);
if (emitFile) {
let inputFullPath = path.join(templateRoot, fn);
let destinationFullPath = this.destinationPath(outputFn);
let deleteInputFileAfter = false;
if (path.basename(fn) === 'package.json') {
// Special handling for package.json, because we rewrite it dynamically
const tempPath = destinationFullPath + '.tmp';
this.fs.writeJSON(
tempPath,
rewritePackageJson(JSON.parse(fs.readFileSync(inputFullPath, 'utf8')), this._answers.tests),
/* replacer */ null,
/* space */ 2
);
inputFullPath = tempPath;
deleteInputFileAfter = true;
}
const outputDirBasename = path.basename(path.dirname(destinationFullPath));
if (outputDirBasename === 'dist') {
// Don't do token replacement in 'dist' files, as they might just randomly contain
// sequences like '<%=' even though they aren't actually template files
this.fs.copy(
inputFullPath,
destinationFullPath
);
} else {
this.fs.copyTpl(
inputFullPath,
destinationFullPath,
this._answers
);
}
if (deleteInputFileAfter) {
this.fs.delete(inputFullPath);
}
}
});
}
installingDeps() {
this.installDependencies({
npm: true,
bower: false,
callback: () => {
this.spawnCommandSync('dotnet', ['restore']);
this.spawnCommandSync('./node_modules/.bin/webpack', ['--config', 'webpack.config.vendor.js']);
this.spawnCommandSync('./node_modules/.bin/webpack');
}
});
}
}
function assertNpmVersionIsAtLeast(minVersion: string) {
const runningVersion = execSync('npm -v').toString();
if (!semver.gte(runningVersion, minVersion, /* loose */ true)) {
console.error(`This generator requires NPM version ${minVersion} or later. You are running NPM version ${runningVersion}`);
process.exit(1);
}
}
function assertDotNetSDKVersionIsAtLeast(minVersion: string) {
const runningVersion = getDotNetSDKVersion();
if (!runningVersion) {
console.error('Could not find dotnet tool on system path. Please install dotnet core SDK then try again.');
console.error('Try running "dotnet --version" to verify you have it.');
process.exit(1);
} else if (!semver.gte(runningVersion, minVersion, /* loose */ true)) {
console.error(`This generator requires dotnet SDK version ${minVersion} or later. You have version ${runningVersion}`);
console.error('Please update your dotnet SDK then try again. You can run "dotnet --version" to check your version.');
process.exit(1);
}
}
function getDotNetSDKVersion() {
try {
return execSync('dotnet --version').toString().replace(/\r|\n/g, '');
} catch (ex) {
return null;
}
}
function rewritePackageJson(contents, includeTests) {
if (!includeTests) {
// Delete any test-specific packages from dependencies and devDependencies
['dependencies', 'devDependencies'].forEach(dependencyListName => {
var packageList = contents[dependencyListName];
if (packageList) {
testSpecificNpmPackages.forEach(packageToRemove => {
delete packageList[packageToRemove];
});
if (Object.getOwnPropertyNames(packageList).length === 0) {
delete contents[dependencyListName];
}
}
});
// Delete any script called 'test'
const scripts = contents.scripts;
if (scripts && scripts.test) {
delete scripts.test;
if (Object.getOwnPropertyNames(scripts).length === 0) {
delete contents.scripts;
}
}
}
return contents;
}
declare var module: any;
(module).exports = MyGenerator;

View File

@@ -1,12 +1,9 @@
{
"name": "generator-aspnetcore-spa",
"version": "1.0.0",
"description": "Single-Page App templates for ASP.NET Core",
"description": "DEPRECATED. Do not use. Use 'dotnet new' to create ASP.NET Core Single-Page Application projects instead.",
"author": "Microsoft",
"license": "Apache-2.0",
"files": [
"app"
],
"keywords": [
"yeoman-generator"
],
@@ -18,12 +15,5 @@
"url": "https://github.com/aspnet/JavaScriptServices.git"
},
"dependencies": {
"chalk": "^1.1.3",
"glob": "^7.0.3",
"node-uuid": "^1.4.7",
"to-pascal-case": "^1.0.0",
"yeoman-generator": "^0.20.2",
"yeoman-option-or-prompt": "^1.0.2",
"yosay": "^1.1.1"
}
}