generator-gsndnn
Version:
Scaffolds DNN extensions, including Modules (Webforms, SPA, and MVC), Persona Bar, Skin Object, Library, Scheduler, and Hotcakes Commerce projects (based on the generator built by Matt Rutledge).
206 lines (177 loc) • 5.73 kB
JavaScript
'use strict';
const DnnGeneratorBase = require('../lib/DnnGeneratorBase');
const chalk = require('chalk');
module.exports = class extends DnnGeneratorBase {
constructor(args, opts) {
super(args, opts);
// This method adds support for a `--test` flag
this.option('noinstall');
}
prompting() {
const prompts = [
{
when: !this.options.name,
type: 'input',
name: 'name',
message: 'What is the name of your MVC (.NET Core) Module?',
default: this.appname,
validate: str => {
return str.length > 0;
}
},
{
when: !this.options.description,
type: 'input',
name: 'description',
message: 'Describe your module:',
validate: str => {
return str.length > 0;
}
}
];
return this.prompt(prompts).then(props => {
// To access props later use this.props.someAnswer;
props.currentDate = new Date();
props.namespace = this._pascalCaseName(this.options.company);
props.moduleName = this._pascalCaseName(props.name);
props.extensionType = "Modules";
this.props = props;
});
}
writing() {
this.log(chalk.white('Creating MVC (.NET Core) Module.'));
// mod: this follows the Upendo development/solution pattern
this.destinationRoot("Modules/");
let namespace = this.props.namespace;
let moduleName = this.props.moduleName;
let currentDate = this.props.currentDate;
let template = {
yourName: this.options.yourName,
company: this.options.company,
namespace: namespace,
moduleName: moduleName,
moduleFriendlyName: this.props.name,
description: this.props.description,
companyUrl: this.options.companyUrl,
emailAddy: this.options.emailAddy,
currentYear: currentDate.getFullYear(),
version: '1.0.0',
menuLinkName: this.props.menuLinkName,
parentMenu: this.props.parentMenu
};
this.fs.copyTpl(
this.templatePath('../../common/build/*.*'),
this.destinationPath(moduleName + '/_BuildScripts'),
template
);
this.fs.copyTpl(
this.templatePath('../../common/csproj/Providers/**'),
this.destinationPath(moduleName + '/Providers'),
template
);
this.fs.copyTpl(
this.templatePath('../../common/csproj/NuGet.config'),
this.destinationPath(moduleName + '/NuGet.config'),
template
);
// Do all templated copies
this.fs.copyTpl(
this.templatePath('../../common/src/**'),
this.destinationPath(moduleName + '/src/'),
template
);
this.fs.copyTpl(
this.templatePath('App_LocalResources/**'),
this.destinationPath(moduleName + '/App_LocalResources/'),
template
);
this.fs.copyTpl(
this.templatePath('_BuildScripts/**'),
this.destinationPath(moduleName + '/_BuildScripts/'),
template
);
this.fs.copyTpl(
this.templatePath('Components/**'),
this.destinationPath(moduleName + '/Components/'),
template
);
this.fs.copyTpl(
this.templatePath('Controllers/**'),
this.destinationPath(moduleName + '/Controllers/'),
template
);
this.fs.copyTpl(
this.templatePath('Models/**'),
this.destinationPath(moduleName + '/Models/'),
template
);
this.fs.copyTpl(
this.templatePath('src/**'),
this.destinationPath(moduleName + '/src/'),
template
);
this.fs.copyTpl(
this.templatePath('Views/**'),
this.destinationPath(moduleName + '/Views/'),
template
);
this.fs.copyTpl(
this.templatePath('RouteConfig.cs'),
this.destinationPath(moduleName + '/RouteConfig.cs'),
{
namespace: namespace,
moduleName: moduleName
}
);
this.fs.copyTpl(
this.templatePath('manifest.dnn'),
this.destinationPath(moduleName + '/' + moduleName + '.dnn'),
{
namespace: namespace,
moduleName: moduleName,
moduleFriendlyName: this.props.name,
description: this.props.description,
companyUrl: this.props.companyUrl,
emailAddy: this.props.emailAddy
}
);
this.fs.copyTpl(
this.templatePath('../../common/csproj/_Project.csproj'),
this.destinationPath(moduleName + '/' + moduleName + '.csproj'),
template
);
this.fs.copyTpl(
this.templatePath('package.json'),
this.destinationPath(moduleName + '/package.json'),
template
);
const pkgJson = {
devDependencies: {
// eslint-disable-next-line prettier/prettier
'archiver': '^3.0.0',
'copy-webpack-plugin': '^4.6.0',
'html-webpack-plugin': '^3.2.0',
// eslint-disable-next-line prettier/prettier
'marked': '^0.5.2',
// eslint-disable-next-line prettier/prettier
'webpack': '^4.27.1',
'webpack-cli': '^3.1.2',
'webpack-dev-server': '^3.1.10',
'webpack-node-externals': '^1.7.2'
}
};
// Extend package.json file in destination path
this.fs.extendJSON(this.destinationPath(moduleName + '/package.json'), pkgJson);
}
install() {
this._writeSolution();
this._defaultInstall();
}
end() {
this.log(chalk.white('Installed MVC Module npm Dependencies.'));
this.log(chalk.white('Running dotnet restore.'));
this.spawnCommand('dotnet', ['restore']);
process.chdir('../');
this.log(chalk.white('All Ready!'));
}
};