Skip to content

Commit

Permalink
Merge pull request #122 from highmobility/feature/add-equals-diff-merge
Browse files Browse the repository at this point in the history
Updates API-s for Command, Capabilities and properties
  • Loading branch information
unematiii authored Mar 23, 2022
2 parents daf77ed + 5ee523e commit 6149c88
Show file tree
Hide file tree
Showing 92 changed files with 578 additions and 383 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rules:
- allowSeparatedGroups: true
ignoreCase: true
ignoreDeclarationSort: true
'@typescript-eslint/ban-types': off
'@typescript-eslint/explicit-module-boundary-types': off
'@typescript-eslint/no-non-null-assertion': off
settings:
Expand Down
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"yamljs": "^0.3.0"
},
"dependencies": {
"abab": "^2.0.5",
"ieee754": "^1.2.1",
"lodash.clonedeep": "^4.5.0",
"lodash.get": "^4.4.2",
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function printCapabilityClassDefinition(filename: string, declarations: ts.Node[
CapabilityBaseClassName,
),
),
printer(tsUtils.createImportDeclaration(`../configuration`, ConfigurationClassName)),
printer(tsUtils.createImportDeclaration(`../core/Configuration`, ConfigurationClassName)),
]
.join('\n')
.concat('\n'),
Expand Down
143 changes: 142 additions & 1 deletion scripts/generate-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Configuration,
MeasurementTypes,
Properties,
Property,
PropertyComponents,
TypeDefinition,
TypeDefinitions,
Expand Down Expand Up @@ -42,6 +43,128 @@ function createConfiguration() {
console.log('Successfully created configuration.');
}

export const getPropertyIdentityKey = (capabilityName: string) => (propertyName: string) => {
switch (capabilityName) {
case 'adas':
switch (propertyName) {
case 'lane_keep_assists_states':
case 'park_assists':
return 'location';
}

case 'charging':
switch (propertyName) {
case 'departure_times':
return 'state';
case 'reduction_times':
return 'start_stop';
}

case 'chassis_settings':
switch (propertyName) {
case 'current_spring_rates':
case 'maximum_spring_rates':
case 'minimum_spring_rates':
return 'axle';
}

case 'climate':
switch (propertyName) {
case 'hvac_weekday_starting_times':
return 'weekday';
}

case 'crash':
switch (propertyName) {
case 'incidents':
return 'location';
}

case 'dashboard_lights':
switch (propertyName) {
case 'bulb_failures':
return 'id';
case 'dashboard_lights':
return 'name';
}

case 'diagnostics':
switch (propertyName) {
case 'diesel_exhaust_filter_status':
return 'status';

case 'tire_pressures':
case 'tire_pressures_differences':
case 'tire_pressure_statuses':
case 'tire_pressures_targets':
case 'tire_temperatures':
case 'wheel_rpms':
return 'location';
}

case 'doors':
switch (propertyName) {
case 'inside_locks':
case 'locks':
case 'positions':
return 'location';
}

case 'lights':
switch (propertyName) {
case 'fog_lights':
case 'interior_lights':
case 'reading_lamps':
return 'location';
}

case 'race':
switch (propertyName) {
case 'accelerations':
return 'direction';
case 'brake_torque_vectorings':
return 'axle';
}

case 'seats':
switch (propertyName) {
case 'person_detected':
case 'seatbelts_state':
return 'location';
}

case 'tachograph':
switch (propertyName) {
case 'drivers_cards_present':
case 'drivers_working_states':
case 'drivers_time_states':
return 'driver_number';
}

case 'trips':
switch (propertyName) {
case 'end_address_components':
case 'start_address_components':
case 'thresholds':
return 'type';
}

case 'usage':
switch (propertyName) {
case 'driving_modes_activation_periods':
case 'driving_modes_energy_consumptions':
return 'driving_mode';
}

case 'windows':
switch (propertyName) {
case 'open_percentages':
case 'positions':
return 'location';
}
}
};

function mapStateProps({
properties,
state,
Expand All @@ -53,6 +176,20 @@ function mapStateProps({
return [];
}

function mapPropertyIdentityKeys(identityKeyFn: (name: string) => string | undefined) {
return function (property: Property) {
const key = identityKeyFn(property.name);
if (key) {
return {
...property,
identity_key: key,
};
}

return property;
};
}

function mapTypesToEntity<T extends TypeDefinition>(entity: T) {
return {
...entity,
Expand All @@ -76,11 +213,15 @@ function parseCapabilities() {
return CapabilitiesFileList.reduce<Configuration['capabilities']>(
(configurationObject, fileName) => {
const capability = parseYmlFile<Capability>(`${CapabilitiesPath}/${fileName}`);
const identityKeyFn = getPropertyIdentityKey(capability.name);

return {
...configurationObject,
[capability.name]: {
...capability,
properties: capability.properties.map((property) => mapTypesToEntity(property)),
properties: capability.properties
.map(mapTypesToEntity)
.map(mapPropertyIdentityKeys(identityKeyFn)),
state: mapStateProps(capability),
},
};
Expand Down
27 changes: 17 additions & 10 deletions scripts/generate-property-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { snakeCaseToPascalCase } from '@/utils/strings';
import { cleanOrCreateDirectory, printSourceFile } from './shared/utils';
import {
ConfigurationClassName,
PropertyClassName,
PropertyComponentsClassesPath,
PropertyTypeName,
} from './shared/constants';
import * as tsUtils from './shared/typescript';

Expand Down Expand Up @@ -55,7 +55,7 @@ function createConstructorDeclaration({ name }: PropertyComponent) {
undefined,
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier('Readonly'), [
ts.factory.createTypeReferenceNode(
ts.factory.createIdentifier(PropertyClassName),
ts.factory.createIdentifier(PropertyTypeName),
undefined,
),
]),
Expand All @@ -79,11 +79,8 @@ function createDataComponentValueTypeDefinitionOverride() {
[
ts.factory.createReturnStatement(
ts.factory.createPropertyAccessExpression(
ts.factory.createPropertyAccessExpression(
ts.factory.createThis(),
ts.factory.createIdentifier('property'),
),
ts.factory.createIdentifier('definition'),
ts.factory.createThis(),
ts.factory.createIdentifier('property'),
),
),
],
Expand Down Expand Up @@ -192,8 +189,8 @@ function printPropertyComponentClassDefinition(filename: string, classDeclaratio

const nodes = [
[
printer(tsUtils.createImportDeclaration(`../configuration`, ConfigurationClassName)),
printer(tsUtils.createImportDeclaration(`../core/${PropertyClassName}`, PropertyClassName)),
printer(tsUtils.createImportDeclaration(`../core/Configuration`, ConfigurationClassName)),
printer(tsUtils.createImportDeclaration(`../types`, PropertyTypeName)),
printer(tsUtils.createImportDeclaration(`../core/${BaseClassName}`, BaseClassName)),
]
.join('\n')
Expand All @@ -213,14 +210,23 @@ function printPropertyComponentsMetaData(classNames: string[], components: Prope
.map((className) => printer(tsUtils.createImportDeclaration(`./${className}`, className)))
.join('\n')
.concat('\n'),
printer(tsUtils.createImportDeclaration(`./types`, ComponentNameTypeName)).concat('\n\n'),
printer(createPropertyComponentClassMapDefinition(components)).concat('\n'),
printer(createPropertyComponentMapDefinition(components)).concat('\n'),
printer(createPropertyComponentNameDeclaration(components)),
];

printSourceFile(filename, nodes);
}

function printPropertyComponentsTypes(components: PropertyComponents) {
const filename = path.join(PropertyComponentsClassesPath, `types.ts`);
const printer = tsUtils.createPrinter(filename);

const nodes = [printer(createPropertyComponentNameDeclaration(components))];

printSourceFile(filename, nodes);
}

function printExportDefinitionsForPropertyComponents(classNames: string[]) {
const filename = path.join(PropertyComponentsClassesPath, `index.ts`);
const printer = tsUtils.createPrinter(filename);
Expand Down Expand Up @@ -257,6 +263,7 @@ function generatePropertyComponents() {

printExportDefinitionsForPropertyComponents(classNames);
printPropertyComponentsMetaData(classNames, components);
printPropertyComponentsTypes(components);

console.log('Successfully generated property components.');
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const PropertyComponentsClassesPath = resolve(SourcesPath, 'components');

export const ConfigurationClassName = 'Configuration';
export const CapabilityBaseClassName = 'Capability';
export const PropertyClassName = 'Property';
export const PropertyTypeName = 'Property';

export const EventsRegex = new RegExp(`events.`);
export const CustomTypesRegex = new RegExp(`types.`);
Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Adas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Browser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Capabilities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Charging.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/ChargingSession.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/ChassisSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Climate.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Crash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/CruiseControl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/DashboardLights.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Doors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/DriverFatigue.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
2 changes: 1 addition & 1 deletion src/capabilities/Engine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Capability } from '../core/Capability';
import { Configuration } from '../configuration';
import { Configuration } from '../core/Configuration';

import { UniversalProperties } from './properties';

Expand Down
Loading

0 comments on commit 6149c88

Please sign in to comment.