Skip to content

Commit

Permalink
Merge pull request citrineos#260 from citrineos/feat/normal-enums-ove…
Browse files Browse the repository at this point in the history
…r-const-enums

Feat/normal enums over const enums
  • Loading branch information
thanaParis authored Sep 18, 2024
2 parents 1766f25 + dc4084b commit bd36e62
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 97 deletions.
16 changes: 7 additions & 9 deletions 00_Base/json-schema-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ async function processJsonSchema(data, writeToFile = true) {
.compile(jsonSchema, id, {
style: { singleQuote: true, trailingComma: 'all' },
format: true,
enableConstEnums: false,
})
.then((ts) => {
// Add licence comment
Expand Down Expand Up @@ -251,18 +252,15 @@ function processNode(node) {

function extractEnums(ts) {
const pattern =
/^\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\nexport const enum (\w)* {(\s|\w|-|\.|=|'|,)*}\n*/gm;
const undocumentedPattern =
/^export const enum (\w)* {(\s|\w|-|\.|=|'|,)*}\n*/gm;
/^\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\nexport enum (\w)* {(\s|\w|-|\.|=|'|,)*}\n*/gm;
const undocumentedPattern = /^export enum (\w)* {(\s|\w|-|\.|=|'|,)*}\n*/gm;
const matches = ts.match(pattern);
let undocumentedMatches = ts.match(undocumentedPattern);

if (matches && undocumentedMatches) {
const namePattern = /export const enum (\w)*/g;
const namePattern = /export enum (\w)*/g;
matches.forEach((match) => {
const enumName = match
.match(namePattern)[0]
.replace('export const enum ', '');
const enumName = match.match(namePattern)[0].replace('export enum ', '');
undocumentedMatches = undocumentedMatches.filter(
(undocumentedMatch) => !undocumentedMatch.includes(enumName),
);
Expand All @@ -277,10 +275,10 @@ function extractEnums(ts) {

function splitEnum(enumDefinition) {
const commentPattern = /^\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\/\n/gm;
const namePattern = /export const enum (\w)*/g;
const namePattern = /export enum (\w)*/g;
const enumName = enumDefinition
.match(namePattern)[0]
.replace('export const enum ', '');
.replace('export enum ', '');
let enumDocumentation = enumDefinition.match(commentPattern);
enumDocumentation = enumDocumentation ? enumDocumentation[0] : '';
return { enumName, enumDocumentation, enumDefinition };
Expand Down
2 changes: 2 additions & 0 deletions 00_Base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export const LOG_LEVEL_OCPP = 10;

export * from './ocpp/model';

export { UpdateChargingStationPasswordRequest } from './ocpp/model/UpdateChargingStationPasswordRequest';

import {
AuthorizeRequestSchema,
BootNotificationRequestSchema,
Expand Down
Loading

0 comments on commit bd36e62

Please sign in to comment.