-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
187 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* This is a generated file, please regenerate and do not modify */ | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@hso/d365-cli", | ||
"version": "5.4.3", | ||
"version": "5.5.0", | ||
"author": "HSO Innovation <[email protected]> (http://www.hso.com)", | ||
"description": "HSO D365 Command Line Interface", | ||
"repository": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as shell from 'shelljs'; | ||
import {AdalRouter} from '../root/tools/AdalRouter'; | ||
import {NodeApi} from '../root/tools/NodeApi/NodeApi'; | ||
import fs from 'fs'; | ||
|
||
export class GlobalOptionSet extends AdalRouter { | ||
public static generateGlobalOptionSets(): Promise<void> { | ||
new GlobalOptionSet(); | ||
return null; | ||
} | ||
|
||
protected async onAuthenticated(): Promise<void> { | ||
await this.log(`Generating Global OptionSet`); | ||
await this.writeGlobalOptionSetsFile(); | ||
await this.log('Generated Global OptionSet'); | ||
} | ||
|
||
private async writeGlobalOptionSetsFile(): Promise<void> { | ||
await this.log(`Generating OptionSets/OptionSets.ts`); | ||
const globalOptionSetsString = await this.getGlobalOptionSetsString(); | ||
shell.cp('-r', `${__dirname}/OptionSets`, `src`); | ||
const optionSetFilepath = 'src/OptionSets/OptionSets.ts'; | ||
const fileData = String(fs.readFileSync(optionSetFilepath)); | ||
shell.ShellString(fileData + globalOptionSetsString).to(optionSetFilepath); | ||
shell.exec(`git add src/OptionSets`); | ||
await this.log(`Generated OptionSet/OptionSets.ts`); | ||
} | ||
|
||
private async getGlobalOptionSetsString(): Promise<string> { | ||
let optionSetStrings = ''; | ||
const optionSets = await NodeApi.getGlobalOptionSetDefinitions(this.bearer); | ||
for (const optionSet of optionSets) { | ||
const pascalSchemaName = GlobalOptionSet.capitalize(optionSet.Name); | ||
optionSetStrings += `export enum ${pascalSchemaName} {\n`; | ||
if (optionSet.OptionSetType === 'Boolean') { | ||
const {FalseOption, TrueOption} = optionSet; | ||
optionSetStrings += ` ${TrueOption.Label.UserLocalizedLabel.Label.replace(/\W/g, '')} = ${TrueOption.Value},\n`; | ||
optionSetStrings += ` ${FalseOption.Label.UserLocalizedLabel.Label.replace(/\W/g, '')} = ${FalseOption.Value},\n`; | ||
} else { | ||
const usedLabels: string[] = []; | ||
for (const option of optionSet.Options) { | ||
let label = option.Label.UserLocalizedLabel.Label.replace(/\W/g, ''); | ||
if (!usedLabels.includes(label)) { | ||
usedLabels.push(label); | ||
if (!label.charAt(0).match(/^[a-zA-Z]/)) { | ||
label = `Nr_${label}`; | ||
} | ||
optionSetStrings += ` ${label} = ${option.Value},\n`; | ||
} | ||
} | ||
} | ||
optionSetStrings += '}\n'; | ||
} | ||
if (optionSetStrings) { | ||
optionSetStrings += '\n'; | ||
} | ||
return optionSetStrings; | ||
} | ||
|
||
private static capitalize(text: string): string { | ||
return text.charAt(0).toUpperCase() + text.slice(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters