Skip to content

Commit

Permalink
Merge branch 'release/5.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nsteenbeek committed Jul 27, 2021
2 parents 511c9fe + 7d03207 commit 3904021
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 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.0.7",
"version": "5.1.0",
"author": "HSO Innovation <[email protected]> (http://www.hso.com)",
"description": "HSO D365 Command Line Interface",
"repository": {
Expand Down
5 changes: 2 additions & 3 deletions src/generator/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export class Entity extends AdalRouter {
}

private async generateEntity(): Promise<void> {
const folderPath = `src/${this.entityName}`;
if (!shell.test('-d', folderPath)) {
const serviceFilepath = `src/${this.entityName}/${this.entityName}.service.ts`;
if (!shell.test('-f', serviceFilepath)) {
const answers = await inquirer.prompt([{
type: 'input',
name: 'entityLogicalName',
Expand All @@ -59,7 +59,6 @@ export class Entity extends AdalRouter {
await this.addEntityFiles(this.entityName);
// Entity.registerWebpackConfig(this.entityName);
} else {
const serviceFilepath = `src/${this.entityName}/${this.entityName}.service.ts`;
const fileData = String(fs.readFileSync(serviceFilepath));
const match = fileData.match(new RegExp(`private static logicalName = '([a-zA-Z_]*)';`));
this.entityLogicalName = match[1];
Expand Down
3 changes: 2 additions & 1 deletion src/generator/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import colors from 'colors';
import * as shell from 'shelljs';
import {Entity} from './Entity';
import {Webresource} from './Webresource';
import {ModelRouter} from './ModelRouter';
import {EnvironmentVariable} from './EnvironmentVariable';
import {LicenseValidator} from './LicenseValidator';

Expand All @@ -19,7 +20,7 @@ export class Generator {
} else if (schematic.toLowerCase() === 'webresource') {
return Webresource.generateWebresource(name);
} else if(schematic.toLocaleLowerCase() === 'model') {
console.log(colors.red('Not supported anymore: please use Entity instead'));
return ModelRouter.generateModel(name);
} else if (schematic.toLowerCase() === 'licensevalidator') {
return LicenseValidator.generateLicenseValidator(name);
} else if(schematic.toLowerCase() === 'environmentvariable') {
Expand Down
58 changes: 58 additions & 0 deletions src/generator/ModelRouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {AdalRouter} from '../root/tools/AdalRouter';
import colors from 'colors';
import {Model} from './Model';
import * as shell from 'shelljs';
import * as inquirer from 'inquirer';
import {NodeApi} from '../root/tools/NodeApi/NodeApi';
import fs from 'fs';

export class ModelRouter extends AdalRouter {
public static async generateModel(entityName: string): 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]) {
console.log(colors.red(`No spaces allowed!`));
} else {
new ModelRouter(entityName);
}
return null;
}

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

protected async onAuthenticated(): Promise<void> {
const folderPath = `src/${this.entityName}`;
if (!shell.test('-d', folderPath)) {
const answers = await inquirer.prompt([{
type: 'input',
name: 'entityLogicalName',
message: 'Entity LogicalName:'
}]);
this.entityLogicalName = answers.entityLogicalName;
try {
await NodeApi.getEntityDefinition(this.entityLogicalName, this.bearer, ['PrimaryIdAttribute']);
} catch (e) {
console.log(colors.red(`Failed: Entity ${this.entityName} has no LogicalName ${this.entityLogicalName}`));
throw e;
}
shell.mkdir(`src/${this.entityName}`);
await Model.generateModel(this.bearer, this.entityName, this.entityLogicalName, async (message: string) => this.log(message));
// Entity.registerWebpackConfig(this.entityName);
} else {
const serviceFilepath = `src/${this.entityName}/${this.entityName}.service.ts`;
const fileData = String(fs.readFileSync(serviceFilepath));
const match = fileData.match(new RegExp(`private static logicalName = '([a-zA-Z_]*)';`));
this.entityLogicalName = match[1];
console.log(colors.green(`Entity ${this.entityName} already exist`));
await Model.generateModel(this.bearer, this.entityName, this.entityLogicalName, async (message: string) => this.log(message));
}
await this.log('Generating files finished');
}
}

0 comments on commit 3904021

Please sign in to comment.