generator-ngdotnet
Version:
491 lines (404 loc) • 14.5 kB
JavaScript
'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');
const del = require('delete');
var generateGuid = function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
/*jslint bitwise: true */
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
/*jslint bitwise: false */
return v.toString(16);
});
};
module.exports = class extends Generator {
prompting() {
// Have Yeoman greet the user.
this.log(yosay(
'Welcome to the ' + chalk.green('NG.Net') + ' generator!'
));
const prompts = [{
type: 'input',
name: 'projectName',
message: 'What is the name of your project',
default: this.appname
}];
return this.prompt(prompts).then(props => {
// To access props later use this.props.someAnswer;
this.props = props;
});
}
defaults() {
this.server_guid = generateGuid();
this.client_guid = generateGuid();
this.asaxentry = '<%@ Application Codebehind';
this.asaxexit = '%>';
this.project_name = this.props.projectName.replace(/ /g, "_");
}
writing() {
this.fs.copyTpl(
this.templatePath('_solution.sln'),
this.destinationPath(this.project_name + '.sln'),
{
server_guid: this.server_guid,
client_guid: this.client_guid
}
);
this.fs.copy(
this.templatePath('_.gitattributes'),
this.destinationPath('.gitattributes')
);
this.fs.copy(
this.templatePath('_.gitignore'),
this.destinationPath('.gitignore')
);
/////////////////////////////////////////////////////////////////////////////////////////////
//
// ##### # ### ####### # # ####### ##### ####### ###### #######
// # # # # # ## # # # # # # # # #
// # # # # # # # # # # # # # #
// # # # ##### # # # # # # # # # #####
// # # # # # # # # # # # # # #
// # # # # # # ## # # # # # # # #
// ##### ####### ### ####### # # # ##### ####### ###### #######
//
/////////////////////////////////////////////////////////////////////////////////////////////
this.fs.copy(
this.templatePath('client/_client.csproj.user'),
this.destinationPath('client/client.csproj.user')
);
this.fs.copyTpl(
this.templatePath('client/_client.csproj'),
this.destinationPath('client/client.csproj'),
{
client_guid: this.client_guid
}
);
this.fs.copy(
this.templatePath('client/_build.bat'),
this.destinationPath('client/build.bat')
);
this.fs.copy(
this.templatePath('client/_tslint.json'),
this.destinationPath('client/tslint.json')
);
this.fs.copy(
this.templatePath('client/_tsconfig.json'),
this.destinationPath('client/tsconfig.json')
);
this.fs.copyTpl(
this.templatePath('client/_README.md'),
this.destinationPath('client/README.md'),
{
project_name: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('client/_package.json'),
this.destinationPath('client/package.json'),
{
project_name: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('client/_angular.json'),
this.destinationPath('client/angular.json'),
{
project_name: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('client/_.gitignore'),
this.destinationPath('client/.gitignore')
);
this.fs.copy(
this.templatePath('client/_.editorconfig'),
this.destinationPath('client/.editorconfig')
);
this.fs.copy(
this.templatePath('client/e2e/_tsconfig.e2e.json'),
this.destinationPath('client/e2e/tsconfig.e2e.json')
);
this.fs.copy(
this.templatePath('client/e2e/_protractor.conf.js'),
this.destinationPath('client/e2e/protractor.conf.js')
);
this.fs.copyTpl(
this.templatePath('client/e2e/src/_app.e2e-spec.ts'),
this.destinationPath('client/e2e/src/app.e2e-spec.ts'),
{
project_name: this.project_name
}
);
this.fs.copy(
this.templatePath('client/e2e/src/_app.po.ts'),
this.destinationPath('client/e2e/src/_app.po.ts')
);
this.fs.copy(
this.templatePath('client/src/_tslint.json'),
this.destinationPath('client/src/tslint.json')
);
this.fs.copy(
this.templatePath('client/src/_browserslist'),
this.destinationPath('client/src/browserslist')
);
this.fs.copy(
this.templatePath('client/src/_tsconfig.spec.json'),
this.destinationPath('client/src/tsconfig.spec.json')
);
this.fs.copy(
this.templatePath('client/src/_tsconfig.app.json'),
this.destinationPath('client/src/tsconfig.app.json')
);
this.fs.copy(
this.templatePath('client/src/_test.ts'),
this.destinationPath('client/src/test.ts')
);
this.fs.copy(
this.templatePath('client/src/_styles.scss'),
this.destinationPath('client/src/styles.scss')
);
this.fs.copy(
this.templatePath('client/src/_polyfills.ts'),
this.destinationPath('client/src/polyfills.ts')
);
this.fs.copy(
this.templatePath('client/src/_main.ts'),
this.destinationPath('client/src/main.ts')
);
this.fs.copyTpl(
this.templatePath('client/src/_karma.conf.js'),
this.destinationPath('client/src/karma.conf.js'),
{
project_name: this.project_name
}
);
this.fs.copy(
this.templatePath('client/src/_favicon.ico'),
this.destinationPath('client/src/favicon.ico')
);
this.fs.copyTpl(
this.templatePath('client/src/_index.html'),
this.destinationPath('client/src/index.html'),
{
project_name: this.project_name
}
);
this.fs.copy(
this.templatePath('client/src/environments/_environment.prod.ts'),
this.destinationPath('client/src/environments/environment.prod.ts')
);
this.fs.copy(
this.templatePath('client/src/environments/_environment.ts'),
this.destinationPath('client/src/environments/environment.ts')
);
this.fs.copy(
this.templatePath('client/src/assets/_.gitkeep'),
this.destinationPath('client/src/assets/.gitkeep')
);
this.fs.copy(
this.templatePath('client/src/app/_app.module.ts'),
this.destinationPath('client/src/app/app.module.ts')
);
this.fs.copy(
this.templatePath('client/src/app/_app-routing.module.ts'),
this.destinationPath('client/src/app/app-routing.module.ts')
);
this.fs.copy(
this.templatePath('client/src/app/_app.component.html'),
this.destinationPath('client/src/app/app.component.html')
);
this.fs.copy(
this.templatePath('client/src/app/_app.component.scss'),
this.destinationPath('client/src/app/app.component.scss')
);
this.fs.copy(
this.templatePath('client/src/app/_app.component.ts'),
this.destinationPath('client/src/app/app.component.ts')
);
this.fs.copy(
this.templatePath('client/src/app/home/_home.component.scss'),
this.destinationPath('client/src/app/home/home.component.scss')
);
this.fs.copy(
this.templatePath('client/src/app/home/_home.component.html'),
this.destinationPath('client/src/app/home/home.component.html')
);
this.fs.copy(
this.templatePath('client/src/app/home/_home.component.ts'),
this.destinationPath('client/src/app/home/home.component.ts')
);
this.fs.copy(
this.templatePath('client/src/app/shared/_test.service.ts'),
this.destinationPath('client/src/app/shared/test.service.ts')
);
this.fs.copy(
this.templatePath('client/src/app/translate/_index.ts'),
this.destinationPath('client/src/app/translate/index.ts')
);
this.fs.copy(
this.templatePath('client/src/app/translate/_lang-en.ts'),
this.destinationPath('client/src/app/translate/lang-en.ts')
);
this.fs.copy(
this.templatePath('client/src/app/translate/_lang-fr.ts'),
this.destinationPath('client/src/app/translate/lang-fr.ts')
);
this.fs.copy(
this.templatePath('client/src/app/translate/_translate.pipe.ts'),
this.destinationPath('client/src/app/translate/translate.pipe.ts')
);
this.fs.copy(
this.templatePath('client/src/app/translate/_translate.service.ts'),
this.destinationPath('client/src/app/translate/translate.service.ts')
);
this.fs.copy(
this.templatePath('client/src/app/translate/_translations.ts'),
this.destinationPath('client/src/app/translate/translations.ts')
);
this.fs.copy(
this.templatePath('client/src/app/interceptors/_dev-interceptor.ts'),
this.destinationPath('client/src/app/interceptors/dev-interceptor.ts')
);
/////////////////////////////////////////////////////////////////
//
// ##### ####### ###### # # ####### ######
// # # # # # # # # # #
// # # # # # # # # #
// ##### ##### ###### # # ##### ######
// # # # # # # # # #
// # # # # # # # # # #
// ##### ####### # # # ####### # #
//
// ##### ####### ###### #######
// # # # # # # #
// # # # # # #
// # # # # # #####
// # # # # # #
// # # # # # # #
// ##### ####### ###### #######
//
/////////////////////////////////////////////////////////////////
this.fs.copy(
this.templatePath('server/_Web.config'),
this.destinationPath('server/Web.config')
);
this.fs.copy(
this.templatePath('server/_Web.Debug.config'),
this.destinationPath('server/Web.Debug.config')
);
this.fs.copy(
this.templatePath('server/_Web.Release.config'),
this.destinationPath('server/Web.Release.config')
);
this.fs.copy(
this.templatePath('server/_server.csproj.user'),
this.destinationPath('server/server.csproj.user')
);
this.fs.copyTpl(
this.templatePath('server/_server.csproj'),
this.destinationPath('server/server.csproj'),
{
server_guid: this.server_guid
}
);
this.fs.copy(
this.templatePath('server/_packages.config'),
this.destinationPath('server/packages.config')
);
this.fs.copyTpl(
this.templatePath('server/_Global.asax'),
this.destinationPath('server/Global.asax'),
{
name_space: this.project_name,
asaxentry: this.asaxentry,
asaxexit: this.asaxexit
}
);
this.fs.copyTpl(
this.templatePath('server/_Global.asax.cs'),
this.destinationPath('server/Global.asax.cs'),
{
name_space: this.project_name
}
);
this.fs.copy(
this.templatePath('server/_favicon.ico'),
this.destinationPath('server/favicon.ico')
);
this.fs.copy(
this.templatePath('server/_ApplicationInsights.config'),
this.destinationPath('server/ApplicationInsights.config')
);
this.fs.copyTpl(
this.templatePath('server/Properties/_AssemblyInfo.cs'),
this.destinationPath('server/Properties/AssemblyInfo.cs'),
{
name_space: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('server/Controllers/_HomeController.cs'),
this.destinationPath('server/Controllers/HomeController.cs'),
{
name_space: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('server/Controllers/_ValuesController.cs'),
this.destinationPath('server/Controllers/ValuesController.cs'),
{
name_space: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('server/App_Start/_BundleConfig.cs'),
this.destinationPath('server/App_Start/BundleConfig.cs'),
{
name_space: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('server/App_Start/_FilterConfig.cs'),
this.destinationPath('server/App_Start/FilterConfig.cs'),
{
name_space: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('server/App_Start/_RouteConfig.cs'),
this.destinationPath('server/App_Start/RouteConfig.cs'),
{
name_space: this.project_name
}
);
this.fs.copyTpl(
this.templatePath('server/App_Start/_WebApiConfig.cs'),
this.destinationPath('server/App_Start/WebApiConfig.cs'),
{
name_space: this.project_name
}
);
this.fs.copy(
this.templatePath('server/ng/_placeholder.txt'),
this.destinationPath('server/ng/placeholder.txt')
);
this.fs.copy(
this.templatePath('tools/_nuget.exe'),
this.destinationPath('tools/nuget.exe')
);
this.fs.copy(
this.templatePath('server/Views/_Web.config'),
this.destinationPath('server/Views/Web.config')
);
this.fs.copy(
this.templatePath('server/Views/Home/_index.cshtml'),
this.destinationPath('server/Views/Home/index.cshtml')
);
}
install() {
var path = process.cwd();
this.spawnCommand(path + '\\tools\\nuget.exe', ['install', path + '\\server\\packages.config', '-OutputDirectory', path + '\\packages']);
this.spawnCommand('yarn', ['install'], { cwd: 'client' })
}
};