bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
64 lines (48 loc) • 2.52 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getMigrationVersions;
function _semver() {
const data = _interopRequireDefault(require("semver"));
_semver = function () {
return data;
};
return data;
}
function _logger() {
const data = _interopRequireDefault(require("../logger/logger"));
_logger = function () {
return data;
};
return data;
}
/**
* A function which get a migration manifest and versions, and return a sorted array of the migrations to run
* We are taking also the current version to prevent cases which a developer specify a migration to run for a
* future release, and we don't want it to run now
*
* @export
* @param {string} currentVersion - The current version of bit
* @param {string} storeVersion - The version of the store to check (for example scope version or .bit.map.json version)
* @param {Object} migratonManifest - A manifest which contain all the existing migrations
* @param {boolean} [verbose=false] - Print logs
* @returns {Object[]} - Sorted array of migrations to run
*/
function getMigrationVersions(currentVersion, storeVersion, migratonManifest, verbose = false) {
if (currentVersion === storeVersion) return []; // Get all the versions which contain at least one migration
const migrationsVersions = Object.keys(migratonManifest); // Get migration versions which is between the current version and the store version
const migrationsVersionsToRun = migrationsVersions.filter(version => _semver().default.satisfies(version, `>${storeVersion} <=${currentVersion}`)); // Sort the migration to run them from the oldest version to the newest (in case i update my client and there is few versions in between with
// migration process)
const sortedMigrationVersionsToRun = migrationsVersionsToRun.sort(_semver().default.compare); // Get the result with the actual functions
const sortedMigrationToRun = sortedMigrationVersionsToRun.map(migrationVersion => ({
[migrationVersion]: migratonManifest[migrationVersion]
}));
const infoMessage = sortedMigrationVersionsToRun.length ? `Found the following versions that need migration ${sortedMigrationVersionsToRun.join(', ')}` : 'none of the versions has migration to run';
_logger().default.debug(infoMessage);
if (verbose) {
console.log(infoMessage); // eslint-disable-line no-console
}
return sortedMigrationToRun;
}
;