Add generate-versions-h.js and versions.h. Execute generate-versions-h.js from make-release.js

This commit is contained in:
László Monda
2017-12-14 15:41:20 +01:00
parent 5862a34f18
commit 94af52892c
3 changed files with 84 additions and 0 deletions

41
scripts/generate-versions-h.js Executable file
View File

@@ -0,0 +1,41 @@
#!/usr/bin/env node
const fs = require('fs');
const versionPropertyPrefixes = ['firmware', 'deviceProtocol', 'moduleProtocol', 'userConfig', 'hardwareConfig'];
const patchVersions = ['Major', 'Minor', 'Patch'];
const package = JSON.parse(fs.readFileSync(`${__dirname}/package.json`));
const versionVariables = versionPropertyPrefixes.map(versionPropertyPrefix => {
const versionPropertyName = `${versionPropertyPrefix}Version`
const versionPropertyValues = package[versionPropertyName].split('.');
return patchVersions.map(patchVersion => {
const versionPropertyValue = versionPropertyValues.shift();
const versionPropertyMacroName = `${versionPropertyPrefix}${patchVersion}Version`.split(/(?=[A-Z])/).join('_').toUpperCase()
return ` #define ${versionPropertyMacroName} ${versionPropertyValue}`;
}).join('\n') + '\n';
}).join('\n');
fs.writeFileSync(`${__dirname}/../shared/versions.h`,
`// Please do not edit this file by hand!
// It is to be regenerated by /scripts/generate-versions-h.js
#ifndef __VERSIONS_H__
#define __VERSIONS_H__
// Includes:
#include "fsl_common.h"
// Typedefs:
typedef struct {
uint16_t major;
uint16_t minor;
uint16_t patch;
} version_t;
// Variables:
${versionVariables}
#endif
`);

View File

@@ -5,6 +5,8 @@ require('shelljs/global');
config.fatal = true;
config.verbose = true;
exec(`${__dirname}/generate-versions-h.js`);
const package = JSON.parse(fs.readFileSync(`${__dirname}/package.json`));
const version = package.firmwareVersion;
const releaseName = `uhk-firmware-${version}`;

41
shared/versions.h Normal file
View File

@@ -0,0 +1,41 @@
// Please do not edit this file by hand!
// It is to be regenerated by /scripts/generate-versions-h.js
#ifndef __VERSIONS_H__
#define __VERSIONS_H__
// Includes:
#include "fsl_common.h"
// Typedefs:
typedef struct {
uint16_t major;
uint16_t minor;
uint16_t patch;
} version_t;
// Variables:
#define FIRMWARE_MAJOR_VERSION 6
#define FIRMWARE_MINOR_VERSION 0
#define FIRMWARE_PATCH_VERSION 0
#define DEVICE_PROTOCOL_MAJOR_VERSION 3
#define DEVICE_PROTOCOL_MINOR_VERSION 0
#define DEVICE_PROTOCOL_PATCH_VERSION 0
#define MODULE_PROTOCOL_MAJOR_VERSION 3
#define MODULE_PROTOCOL_MINOR_VERSION 0
#define MODULE_PROTOCOL_PATCH_VERSION 0
#define USER_CONFIG_MAJOR_VERSION 4
#define USER_CONFIG_MINOR_VERSION 0
#define USER_CONFIG_PATCH_VERSION 0
#define HARDWARE_CONFIG_MAJOR_VERSION 1
#define HARDWARE_CONFIG_MINOR_VERSION 0
#define HARDWARE_CONFIG_PATCH_VERSION 0
#endif