UNPKG

firebase-ci

Version:

Simplified Firebase interaction for continuous integration including deploying hosting, functions, and database/storage rules.

79 lines (63 loc) 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.installDeps = installDeps; var _commandExists = _interopRequireDefault(require("command-exists")); var _files = require("./files"); var _commands = require("./commands"); var _async = require("./async"); var _logger = require("./logger"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } async function installDeps(opts = {}, settings = {}) { const { info } = opts; const { toolsVersion } = settings; const versionSuffix = toolsVersion ? `@${toolsVersion}` : ''; const npxExists = _commandExists.default.sync('npx'); (0, _logger.info)('Checking to see if firebase-tools is installed...'); const [versionErr, fbVersion] = await (0, _async.to)((0, _commands.runCommand)({ command: npxExists ? 'npx' : 'firebase', args: npxExists ? ['firebase', '--version'] : ['--version'], pipeOutput: false })); if (versionErr) { const getVersionErrMsg = 'Error attempting to check for firebase-tools version.'; (0, _logger.error)(getVersionErrMsg, versionErr); throw new Error(getVersionErrMsg); } const promises = []; if (settings.skipToolsInstall) { if (!fbVersion) { const missingFbTools = 'firebase-tools install skipped, and no existing version found!'; (0, _logger.error)(missingFbTools); throw new Error(missingFbTools); } (0, _logger.info)(`Installing of firebase-tools skipped based on config settings.`); } else { if (fbVersion) { (0, _logger.info)(`firebase-tools already exists, version: ${fbVersion}`); } else { promises.push((0, _commands.runCommand)({ command: 'npm', args: ['i', `firebase-tools${versionSuffix}`, `${info ? '' : '-q'}`], beforeMsg: 'firebase-tools does not already exist, installing...', errorMsg: 'Error installing firebase-tools.', successMsg: 'Firebase tools installed successfully!' })); } } if ((0, _files.functionsExists)() && !(0, _files.functionsNodeModulesExist)() && !settings.skipFunctionsInstall) { promises.push((0, _commands.runCommand)({ command: 'npm', args: ['i', '--prefix', 'functions'], beforeMsg: 'Running npm install in functions folder...', errorMsg: 'Error installing functions dependencies.', successMsg: 'Functions dependencies installed successfully!' })); } return Promise.all(promises); }