mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-24 18:47:30 +00:00
Basically working Yeoman template generator generator
This commit is contained in:
58
templates/yeoman/src/generator/app/index.ts
Normal file
58
templates/yeoman/src/generator/app/index.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import * as path from 'path';
|
||||
import * as yeoman from 'yeoman-generator';
|
||||
import * as uuid from 'node-uuid';
|
||||
import * as glob from 'glob';
|
||||
const toPascalCase = require('to-pascal-case');
|
||||
|
||||
const templates = [
|
||||
{ value: 'angular-2', name: 'Angular 2' },
|
||||
{ value: 'knockout', name: 'Knockout' },
|
||||
{ value: 'react', name: 'React' },
|
||||
{ value: 'react-redux', name: 'React with Redux' }
|
||||
];
|
||||
|
||||
class MyGenerator extends yeoman.Base {
|
||||
private _answers: any;
|
||||
|
||||
constructor(args: string | string[], options: any) {
|
||||
super(args, options);
|
||||
}
|
||||
|
||||
prompting() {
|
||||
const done = this.async();
|
||||
|
||||
this.prompt([{
|
||||
type: 'list',
|
||||
name: 'framework',
|
||||
message: 'Framework',
|
||||
choices: templates
|
||||
}, {
|
||||
type: 'input',
|
||||
name: 'name',
|
||||
message: 'Your project name',
|
||||
default: this.appname
|
||||
}], answers => {
|
||||
this._answers = answers;
|
||||
this._answers.namePascalCase = toPascalCase(answers.name);
|
||||
this._answers.projectGuid = uuid.v4();
|
||||
done();
|
||||
})
|
||||
}
|
||||
|
||||
writing() {
|
||||
var templateRoot = this.templatePath(this._answers.framework);
|
||||
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]);
|
||||
|
||||
this.fs.copyTpl(
|
||||
path.join(templateRoot, fn),
|
||||
this.destinationPath(outputFn),
|
||||
this._answers
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
declare var module: any;
|
||||
(module).exports = MyGenerator;
|
||||
10
templates/yeoman/src/generator/package.json
Normal file
10
templates/yeoman/src/generator/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "generator-aspnet-spa",
|
||||
"version": "0.1.0",
|
||||
"description": "Single-Page App templates for ASP.NET Core",
|
||||
"files": ["templates"],
|
||||
"keywords": ["yeoman-generator"],
|
||||
"dependencies": {
|
||||
"yeoman-generator": "^0.20.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user