Skip to content

Commit

Permalink
include version checking in Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
metelkin committed Sep 11, 2024
1 parent b0d1503 commit 7c619ef
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 1 addition & 11 deletions bin/heta-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const fs = require('fs-extra');
const path = require('path');
const { Builder, StdoutTransport } = require('../src');
const YAML = require('js-yaml'); // https://www.npmjs.com/package/js-yaml
const semver = require('semver');
const { version, bugs } = require('../package');
const { bugs } = require('../package');
const colors = require('colors');
const { printVersionMessage } = require('./print-version-message');

Expand Down Expand Up @@ -106,15 +105,6 @@ async function main() {
opts.type !== undefined && (declaration.importModule.type = opts.type);
opts.export !== undefined && (declaration.export = exportItems);

// === wrong version throws, if no version stated than skip ===
let satisfiesVersion = declaration.builderVersion
? semver.satisfies(version, declaration.builderVersion)
: true;
if (!satisfiesVersion) {
process.stdout.write(`Version "${declaration.builderVersion}" stated in declaration file is not supported by the builder.\n`);
process.exit(2); // BRAKE
}

let minLogLevel = declaration?.options?.logLevel || 'info'; // set logLevel before declaration check

let builder = new Builder(
Expand Down
12 changes: 12 additions & 0 deletions src/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ ajv.addKeyword({keyword: "example"});
const Container = require('../container');
const HetaLevelError = require('../heta-level-error');
const ModuleSystem = require('../module-system');
const semver = require('semver');
const { version } = require('../../package');

/**
* Auxiliary class for performing compilation and storing a platform's options.
Expand Down Expand Up @@ -45,6 +47,7 @@ class Builder {
fileWriteHandler = (fn, text) => { throw new Error('File write is not set for Builder'); }, // must return undefined
transportArray = [] // Builder-level Transport
) {

// create container
this.container = new Container();
this.container._builder = this; // back reference to parent builder
Expand All @@ -67,6 +70,15 @@ class Builder {
});
throw new HetaLevelError('Wrong structure of platform file.');
}

// === wrong version throws, if no version stated than skip ===
let satisfiesVersion = declaration.builderVersion
? semver.satisfies(version, declaration.builderVersion)
: true;
if (!satisfiesVersion) {
let msg = `Version "${declaration.builderVersion}" stated in declaration file is not supported by the heta-compiler ${version}.`;
throw new HetaLevelError(msg);
}

// assign from declaration
Object.assign(this, declaration);
Expand Down

0 comments on commit 7c619ef

Please sign in to comment.