-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Introduce SpecificationVersion class #431
Changes from 9 commits
0748ecf
84807a4
af1b134
8074615
1890a14
e4c2433
22f62de
7bd4c09
7630ad2
f1e97b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import logger from "@ui5/logger"; | ||
import {createReader} from "@ui5/fs/resourceFactory"; | ||
import SpecVersionComparator from "./utils/SpecVersionComparator.js"; | ||
|
||
/** | ||
* Abstract superclass for all projects and extensions | ||
|
@@ -50,10 +51,9 @@ class Specification { | |
const config = JSON.parse(JSON.stringify(configuration)); | ||
const {validate} = await import("../validation/validator.js"); | ||
|
||
if (config.specVersion === "0.1" || config.specVersion === "1.0" || | ||
config.specVersion === "1.1") { | ||
if (SpecVersionComparator.major(config.specVersion) <= 1) { | ||
const originalSpecVersion = config.specVersion; | ||
this._log.verbose(`Detected legacy specification version ${config.specVersion}, defined for ` + | ||
this._log.verbose(`Detected legacy Specification Version ${config.specVersion}, defined for ` + | ||
`${config.kind} ${config.metadata.name}. ` + | ||
`Attempting to migrate the project to a supported specification version...`); | ||
this._migrateLegacyProject(config); | ||
|
@@ -69,20 +69,12 @@ class Specification { | |
`Validation error after migration of ${config.kind} ${config.metadata.name}:`); | ||
this._log.verbose(err.message); | ||
throw new Error( | ||
`${config.kind} ${config.metadata.name} defines unsupported specification version ` + | ||
`${config.kind} ${config.metadata.name} defines unsupported Specification Version ` + | ||
`${originalSpecVersion}. Please manually upgrade to 2.0 or higher. ` + | ||
`For details see https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions - ` + | ||
`An attempted migration to a supported specification version failed, ` + | ||
`likely due to unrecognized configuration. Check verbose log for details.`); | ||
} | ||
} else if (config.specVersion !== "2.0" && | ||
config.specVersion !== "2.1" && config.specVersion !== "2.2" && | ||
config.specVersion !== "2.3" && config.specVersion !== "2.4" && | ||
config.specVersion !== "2.5" && config.specVersion !== "2.6") { | ||
throw new Error( | ||
`Unsupported specification version ${config.specVersion} defined in ${config.kind} ` + | ||
`${config.metadata.name}. Your UI5 CLI installation might be outdated. ` + | ||
`For details see https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions`); | ||
} else { | ||
await validate({ | ||
config, | ||
|
@@ -151,6 +143,17 @@ class Specification { | |
return this._specVersion; | ||
} | ||
|
||
/** | ||
* Returns an instance of a helper class allowing for convenient comparison | ||
* operations against this instance's Specification Version | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does everybody know what a Specification Version is? I'm wondering if this whole versioning business is explained somewhere in the documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a chapter in our documentation regarding that: https://sap.github.io/ui5-tooling/pages/Configuration/#specification-versions |
||
* | ||
* @public | ||
* @returns {@ui5/project/specifications/utils/SpecVersionComparator} | ||
*/ | ||
getSpecVersionComparator() { | ||
return new SpecVersionComparator(this.getSpecVersion()); | ||
} | ||
|
||
/** | ||
* Get the specification's generic version, as typically defined in a <code>package.json</code> | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I struggle a bit with the naming of both the class and the getter. Here it's used with
specVersion
as local variable which reads fine (specVersion is greater then or equal to 3.0). ButspecVersionComparator.gte("3.0")
would be strange.But I also don't have a better idea, also as
getSpecVersion()
already returns the string. My only idea is to combine both to havegetSpecVersion().toString()
andgetSpecVersion().gte("3.0")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not happy with the naming either.
I guess we could make this a
SpecificationVersion
class and have getSpecVersion() always return an instance of it. Indeed that might make things a bit simpler in the end.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that sounds good 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in latest commit. I think this is way better, since the main use of a project's spec version is to compare it anyways 👍