What is ember-cli-version-checker?
The ember-cli-version-checker package is a utility for checking the versions of npm and bower dependencies in Ember CLI projects. It helps ensure compatibility and manage dependencies effectively.
What are ember-cli-version-checker's main functionalities?
Check Dependency Version
This feature allows you to check if a specific dependency version is less than a given version. In this example, it checks if the 'ember-source' version is less than '3.0.0'.
const VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let dep = checker.for('ember-source', 'npm');
if (dep.lt('3.0.0')) {
console.log('ember-source version is less than 3.0.0');
}
Check Multiple Dependencies
This feature allows you to check multiple dependencies at once. In this example, it checks if both 'ember-source' and 'jquery' versions are less than '3.0.0'.
const VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let emberDep = checker.for('ember-source', 'npm');
let jqueryDep = checker.for('jquery', 'bower');
if (emberDep.lt('3.0.0') && jqueryDep.lt('3.0.0')) {
console.log('Both ember-source and jquery versions are less than 3.0.0');
}
Check Dependency Range
This feature allows you to check if a dependency version falls within a specified range. In this example, it checks if the 'ember-source' version is between '2.0.0' and '3.0.0'.
const VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let dep = checker.for('ember-source', 'npm');
if (dep.satisfies('>=2.0.0 <3.0.0')) {
console.log('ember-source version is between 2.0.0 and 3.0.0');
}
Other packages similar to ember-cli-version-checker
semver
The 'semver' package is a widely-used utility for parsing, validating, and comparing semantic versioning (semver) strings. It provides similar functionality for version checking but is not specific to Ember CLI projects. It is more general-purpose and can be used in any JavaScript project.
npm-check
The 'npm-check' package is a tool for checking for outdated, incorrect, and unused dependencies in npm projects. While it provides some overlapping functionality with ember-cli-version-checker, it is more focused on overall dependency management and maintenance rather than specific version checks within Ember CLI projects.
yarn
The 'yarn' package manager includes built-in functionality for checking and managing dependency versions. It provides a more comprehensive solution for dependency management, including version checks, but is not specific to Ember CLI projects. It is an alternative to npm with additional features for dependency resolution and management.
Ember CLI Version Checker
Makes determining if a compatible version of a given NPM or Bower package that is present.
Usage
assertAbove
Throws an error with the given message if a minimum version isn't met.
var VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
init: function() {
var checker = new VersionChecker(this);
checker.for('ember-cli', 'npm').assertAbove('2.0.0');
}
};
You can also provide a specific message as the third argument to assertAbove
if you'd like to customize the output.
var VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
init: function() {
var checker = new VersionChecker(this);
checker.for('ember-cli', 'npm').assertAbove('2.0.0', 'To use awesome-addon you must have ember-cli 2.0.0');
}
};
satisfies
Returns true
if the packages version is above the specified comparison range.
var VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
init: function() {
var checker = new VersionChecker(this);
var dep = checker.for('ember-cli', 'npm');
if (dep.isAbove('2.0.0')) {
} else {
};
}
};
Real World Example
You want to provide two different sets of templates, based on the currently running Ember version.
var path = require('path');
var VersionChecker = require('ember-cli-version-checker');
module.exports = {
name: 'awesome-addon',
treeForAddonTemplates: function(tree) {
var checker = new VersionChecker(this);
var dep = checker.for('ember', 'bower');
var baseTemplatesPath = path.join(this.root, 'addon/templates');
if (dep.satisfies('>= 1.13.0') {
return this.treeGenerator(path.join(baseTemplatesPath, 'current'));
} else {
return this.treeGenerator(path.join(baseTemplatesPath, 'legacy'));
}
}
};