In Yeoman generator, support passing args from command line (e.g., --framework=angular-2)

This commit is contained in:
SteveSandersonMS
2016-09-13 13:44:51 +01:00
parent 80f740a9ed
commit 7f841ff840
2 changed files with 8 additions and 2 deletions

View File

@@ -5,6 +5,9 @@ import * as glob from 'glob';
const yosay = require('yosay'); const yosay = require('yosay');
const toPascalCase = require('to-pascal-case'); const toPascalCase = require('to-pascal-case');
type YeomanPrompt = (opt: yeoman.IPromptOptions | yeoman.IPromptOptions[], callback: (answers: any) => void) => void;
const optionOrPrompt: YeomanPrompt = require('yeoman-option-or-prompt');
const templates = [ const templates = [
{ value: 'angular-2', name: 'Angular 2' }, { value: 'angular-2', name: 'Angular 2' },
{ value: 'knockout', name: 'Knockout' }, { value: 'knockout', name: 'Knockout' },
@@ -14,16 +17,18 @@ const templates = [
class MyGenerator extends yeoman.Base { class MyGenerator extends yeoman.Base {
private _answers: any; private _answers: any;
private _optionOrPrompt: YeomanPrompt;
constructor(args: string | string[], options: any) { constructor(args: string | string[], options: any) {
super(args, options); super(args, options);
this._optionOrPrompt = optionOrPrompt;
this.log(yosay('Welcome to the ASP.NET Core Single-Page App generator!')); this.log(yosay('Welcome to the ASP.NET Core Single-Page App generator!'));
} }
prompting() { prompting() {
const done = this.async(); const done = this.async();
this.prompt([{ this._optionOrPrompt([{
type: 'list', type: 'list',
name: 'framework', name: 'framework',
message: 'Framework', message: 'Framework',

View File

@@ -1,6 +1,6 @@
{ {
"name": "generator-aspnetcore-spa", "name": "generator-aspnetcore-spa",
"version": "0.2.6", "version": "0.2.7",
"description": "Single-Page App templates for ASP.NET Core", "description": "Single-Page App templates for ASP.NET Core",
"author": "Microsoft", "author": "Microsoft",
"license": "Apache-2.0", "license": "Apache-2.0",
@@ -15,6 +15,7 @@
"node-uuid": "^1.4.7", "node-uuid": "^1.4.7",
"to-pascal-case": "^1.0.0", "to-pascal-case": "^1.0.0",
"yeoman-generator": "^0.20.2", "yeoman-generator": "^0.20.2",
"yeoman-option-or-prompt": "^1.0.2",
"yosay": "^1.1.1" "yosay": "^1.1.1"
} }
} }