UNPKG

generator-dyn365

Version:
189 lines (175 loc) 7.37 kB
'use strict'; let baseName; let pluginNameSpace; let pluginProjectPath; let workflowNameSpace; let workflowProjectPath; let webResourcesNameSpace; let webResourceProjectPath; let delegateNameSpace; let delegateProjectPath; let businessDomainNameSpace; let businessDomainProjectPath; let solutionNameSpace; let fullSlnPath; const Generator = require('yeoman-generator'); module.exports = class extends Generator { constructor(args, opts) { super(args, opts); this.log('Initializing...'); } async prompting() { this.answers = await this.prompt([{ type: 'input', name: 'companyName', message: 'What is the name of your company?', default: 'Company', store: true }, { type: 'input', name: 'customerName', message: 'What is the name of your customer?', default: 'Customer' }, { type: 'confirm', name: 'pluginProject', message: 'Do you want to create a plugin project?' }, { type: 'confirm', name: 'workflowProject', message: 'Do you want to create a workflow project?' }, { type: 'confirm', name: 'webResourcesProject', message: 'Do you want to create a webresource project?' }, { type: 'confirm', name: 'delegateProject', message: 'Do you want to work with Delegate A/S Daxif?' }, { type: 'input', name: 'publisherPrefix', message: 'What do you want to use as publisher prefix?', store: true, when: function( answers ) { return !!answers.delegateProject; } }, { type: 'confirm', name: 'businessDomain', message: 'Do you want to use early bound entities?', store: true, when: function( answers ) { return !!answers.delegateProject; } }]) } main() { baseName = this.answers.companyName + '.' + this.answers.customerName + '.Crm'; solutionNameSpace = baseName + '.Extensions'; fullSlnPath = this.destinationPath() + '\\' + solutionNameSpace + '.sln'; pluginNameSpace = baseName + '.Plugins'; pluginProjectPath = this.destinationPath() + '\\' + pluginNameSpace + '\\' + pluginNameSpace + '.csproj'; workflowNameSpace = baseName + '.Workflows'; workflowProjectPath = this.destinationPath() + '\\' + workflowNameSpace + '\\' + workflowNameSpace + '.csproj'; webResourcesNameSpace = baseName + '.WebResources'; webResourceProjectPath = this.destinationPath() + '\\' + webResourcesNameSpace + '\\' + webResourcesNameSpace + '.csproj'; delegateNameSpace = baseName + '.Delegate'; delegateProjectPath = this.destinationPath() + '\\' + delegateNameSpace + '\\' + delegateNameSpace + '.csproj'; businessDomainNameSpace = baseName + '.BusinessDomain'; businessDomainProjectPath = this.destinationPath() + '\\' + businessDomainNameSpace + '\\' + businessDomainNameSpace + '.csproj'; if (this.answers.pluginProject) { this.fs.copyTpl( this.templatePath('Plugin.cs'), this.destinationPath(pluginNameSpace + '\\' + 'Plugin.cs'), { company: this.answers.companyName, customer: this.answers.customerName } ); this.fs.copyTpl( this.templatePath('ExamplePlugin.cs'), this.destinationPath(pluginNameSpace + '\\' + 'ExamplePlugin.cs'), { company: this.answers.companyName, customer: this.answers.customerName } ); this.fs.copy( this.templatePath('EmptyProject.csproj'), this.destinationPath(pluginNameSpace + '\\' + pluginNameSpace + '.csproj') ); } if (this.answers.workflowProject) { this.fs.copy( this.templatePath('EmptyProject.csproj'), this.destinationPath(workflowNameSpace + '\\' + workflowNameSpace + '.csproj') ); } if (this.answers.webResourcesProject) { this.fs.copy( this.templatePath('EmptyProject.csproj'), this.destinationPath(webResourcesNameSpace + '\\' + webResourcesNameSpace + '.csproj') ); this.fs.write(webResourcesNameSpace + '\\src\\js\\.gitkeep', '.gitkeep'); this.fs.write(webResourcesNameSpace + '\\ts\\.gitkeep', '.gitkeep'); } if (this.answers.delegateProject) { this.fs.copy( this.templatePath('EmptyProject.csproj'), this.destinationPath(delegateNameSpace + '\\' + delegateNameSpace + '.csproj') ); this.fs.copy( this.templatePath('SolutionFiles\\README.md'), this.destinationPath(delegateNameSpace + '\\' + 'README.md') ); this.fs.copyTpl( this.templatePath('DelegateScripts'), this.destinationPath(delegateNameSpace + '\\' + 'Scripts'), { company: this.answers.companyName, customer: this.answers.customerName, prefix: this.answers.publisherPrefix } ); } if (this.answers.businessDomain) { this.fs.copy( this.templatePath('EmptyProject.csproj'), this.destinationPath(businessDomainNameSpace + '\\' + businessDomainNameSpace + '.csproj') ); this.fs.copy( this.templatePath('XrmContext'), this.destinationPath(delegateNameSpace + '\\' + 'XrmContext') ); } } installing() { if (this.answers.pluginProject || this.answers.workflowProject || this.answers.delegateProject) { this.spawnCommandSync('dotnet', ['new', 'sln', '--name', solutionNameSpace]) this.log('Creating your solution and adding the projects...') setTimeout(() => { if (this.answers.pluginProject) { this.spawnCommandSync('dotnet', ['sln', fullSlnPath, 'add', pluginProjectPath]); this.spawnCommandSync('dotnet', ['add', pluginProjectPath, 'package', 'Microsoft.CrmSdk.CoreAssemblies']); } if (this.answers.workflowProject) { this.spawnCommandSync('dotnet', ['sln', fullSlnPath, 'add', workflowProjectPath]); this.spawnCommandSync('dotnet', ['add', workflowProjectPath, 'package', 'Microsoft.CrmSdk.CoreAssemblies']); this.spawnCommandSync('dotnet', ['add', workflowProjectPath, 'package', 'Microsoft.CrmSdk.Workflow']); } if (this.answers.webResourcesProject) { this.spawnCommandSync('dotnet', ['sln', fullSlnPath, 'add', webResourceProjectPath]); } if (this.answers.delegateProject) { this.spawnCommandSync('dotnet', ['sln', fullSlnPath, 'add', delegateProjectPath]); this.spawnCommandSync('dotnet', ['add', delegateProjectPath, 'package', 'Delegate.Daxif']); this.spawnCommandSync('dotnet', ['add', delegateProjectPath, 'package', 'Microsoft.CrmSdk.CoreAssemblies']); } if (this.answers.businessDomain) { this.spawnCommandSync('dotnet', ['sln', fullSlnPath, 'add', businessDomainProjectPath]); this.spawnCommandSync('dotnet', ['add', businessDomainProjectPath, 'package', 'Microsoft.CrmSdk.CoreAssemblies']); this.spawnCommandSync('dotnet', ['add', delegateProjectPath, 'package', 'Delegate.XrmContext']); } this.spawnCommandSync('dotnet', ['build', '--configuration', 'Release']); }, 200); } } };