Skip to content

Commit

Permalink
Merge branch 'release/5.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nsteenbeek committed Jul 27, 2021
2 parents 3904021 + 8014067 commit 0ee55b6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hso/d365-cli",
"version": "5.1.0",
"version": "5.2.0",
"author": "HSO Innovation <[email protected]> (http://www.hso.com)",
"description": "HSO D365 Command Line Interface",
"repository": {
Expand Down
22 changes: 16 additions & 6 deletions src/generator/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,44 @@ import {Enum} from './Enum';
import {AttributeFormContext} from './AttributeFormContext';
import {Form} from './Form';

interface EntityOptions {
skipForms?: boolean;
}

export class Entity extends AdalRouter {
public static async generateEntity(entityName: string): Promise<void> {
public static async generateEntity(entityName: string, options: EntityOptions): Promise<void> {
if (!entityName) {
console.log(colors.red('Entity name missing'));
} else if(!new RegExp('[A-Z]').test(entityName[0])) {
console.log(colors.red(`Entity name must be UpperCamelCase!`));
} else if (process.argv[5]) {
} else if (!options.skipForms && process.argv[5] || process.argv[6]) {
console.log(colors.red(`No spaces allowed!`));
} else {
new Entity(entityName);
new Entity(entityName, options);
}
return null;
}

private entityLogicalName: string;
private readonly entityName: string;
constructor(entityName: string) {
private readonly options: EntityOptions;
constructor(entityName: string, options: EntityOptions) {
super();
this.entityName = entityName;
this.options = options;
}

protected async onAuthenticated(): Promise<void> {
await this.generateEntity();
await this.log(`Generating files for Entity '${this.entityName}'<br/>Using entityLogicalName '${this.entityLogicalName}'</br>`);
await Model.generateModel(this.bearer, this.entityName, this.entityLogicalName, async (message: string) => this.log(message));
await Enum.generateEnum(this.bearer, this.entityName, this.entityLogicalName, async (message: string) => this.log(message));
await AttributeFormContext.generateFormContext(this.bearer, this.entityName, this.entityLogicalName, async (message: string) => this.log(message));
await Form.generateFormFiles(this.bearer, this.entityName, this.entityLogicalName, async (message: string) => this.log(message));
if (!this.options.skipForms) {
await AttributeFormContext.generateFormContext(this.bearer, this.entityName, this.entityLogicalName, async (message: string) => this.log(message));
await Form.generateFormFiles(this.bearer, this.entityName, this.entityLogicalName, async (message: string) => this.log(message));
} else {
await this.log('Skip generate form files');
}
await this.log('Generating files finished');
}

Expand Down
4 changes: 2 additions & 2 deletions src/generator/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {EnvironmentVariable} from './EnvironmentVariable';
import {LicenseValidator} from './LicenseValidator';

export class Generator {
public static generate(schematic: string, name: string): Promise<void> {
public static generate(schematic: string, name: string, options: unknown): Promise<void> {
const supportedSchematics = ['entity', 'webresource', 'model', 'licensevalidator', 'environmentvariable'];
if (!shell.test('-e', 'src')) {
console.log(colors.red(`You are not inside the project Webresources folder!`));
Expand All @@ -16,7 +16,7 @@ export class Generator {
} else if (!supportedSchematics.includes(schematic.toLowerCase())) {
console.log(colors.red(`Schematic ${schematic} not supported!`));
} else if (schematic.toLowerCase() === 'entity') {
return Entity.generateEntity(name);
return Entity.generateEntity(name, options);
} else if (schematic.toLowerCase() === 'webresource') {
return Webresource.generateWebresource(name);
} else if(schematic.toLocaleLowerCase() === 'model') {
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ program
program
.command('generate <schematic> [name]')
.alias('g')
.option('-s, --skipForms', 'Skip generating form files')
.description('Generates and/or modifies files bases on a schematic.')
.action((schematic: string, name: string) => {
Generator.generate(schematic, name);
.action((schematic: string, name: string, options) => {
Generator.generate(schematic, name, options);
})
.on('--help', () => {
Generator.showGenerateHelp();
Expand Down

0 comments on commit 0ee55b6

Please sign in to comment.