-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcheckMinRequiredVersion.ts
More file actions
21 lines (18 loc) · 960 Bytes
/
checkMinRequiredVersion.ts
File metadata and controls
21 lines (18 loc) · 960 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import * as semver from "semver";
import { configstore } from "./configstore";
import { FirebaseError } from "./error";
const pkg = require("../package.json"); // eslint-disable-line @typescript-eslint/no-var-requires
/**
* Checks if the CLI is on a recent enough version to use a command.
* Errors if a min version is found and the CLI is below the minimum required version.
* @param options
* @param key the motd key to that contains semver for the min version for a command.
*/
export function checkMinRequiredVersion(options: any, key: string) {
const minVersion = configstore.get(`motd.${key}`);
if (minVersion && semver.gt(minVersion, pkg.version)) {
throw new FirebaseError(
`This command requires at least version ${minVersion} of the CLI to use. To update to the latest version using npm, run \`npm install -g firebase-tools\`. For other CLI management options, see https://firebase.google.com/docs/cli#update-cli`,
);
}
}