Skip to content

Commit

Permalink
npm/firmware: add version constant
Browse files Browse the repository at this point in the history
This adds a string constant to get the firmware version of the files
included in the package.

Issue: pybricks/support#412
  • Loading branch information
dlech committed Aug 13, 2021
1 parent 97b45f9 commit 65a54b2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions npm/firmware/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version.ts
4 changes: 4 additions & 0 deletions npm/firmware/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased
### Added
- Added firmware version constant.

## 4.13.0-alpha.3 - 2021-07-19
### Changed
- Updated firmware to v3.1.0a3.
Expand Down
6 changes: 5 additions & 1 deletion npm/firmware/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import * as fs from 'fs';
import * as path from 'path';
import * as util from 'util';
import { FirmwareReader, FirmwareReaderErrorCode } from '.';
import { firmwareVersion, FirmwareReader, FirmwareReaderErrorCode } from '.';

const readFile = util.promisify(fs.readFile);

test('firmware version', () => {
expect(firmwareVersion).toMatch(/^\d+\.\d+\.\d+/);
});

test('bad zip data', async () => {
try {
await FirmwareReader.load(new Uint8Array(100));
Expand Down
8 changes: 7 additions & 1 deletion npm/firmware/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
// Copyright (c) 2020-2021 The Pybricks Authors

import JSZip, { JSZipObject } from 'jszip';
import {PACKAGE_VERSION} from './version';

/**
* String containing the firmware version.
*/
export const firmwareVersion = PACKAGE_VERSION.substring(PACKAGE_VERSION.lastIndexOf('v') + 1);

/**
* LEGO Powered Up Hub IDs
Expand Down
1 change: 1 addition & 0 deletions npm/firmware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"author": "The Pybricks Authors",
"license": "MIT",
"scripts": {
"prebuild": "node -p \"'export const PACKAGE_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > version.ts",
"build": "./download-firmware.py && tsc",
"test": "tsc && jest"
},
Expand Down

0 comments on commit 65a54b2

Please sign in to comment.