UNPKG

installist

Version:
40 lines (39 loc) 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.installist = exports.DepType = void 0; const chalk = require('chalk'); const execa = require('execa'); const Listr = require('listr'); var DepType; (function (DepType) { DepType[DepType["MAIN"] = 0] = "MAIN"; DepType[DepType["DEV"] = 1] = "DEV"; })(DepType = exports.DepType || (exports.DepType = {})); const depTypeSaveString = { [DepType.MAIN]: '--save', [DepType.DEV]: '--save-dev' }; function installist(packages, dir, depType) { const listItems = packages.map((item) => { return { title: item, task: async () => { try { await execa('npm', ['install', '--prefix', dir, depTypeSaveString[depType], item]); } catch (error) { throw new Error(chalk.red(`error installing ${item}.`) + `You may try installing ${item} directly by running ` + `npm install ${depTypeSaveString[depType]} ${item}' directly and see what messages are reported. ` + `Here is the error reported:\n${error}`); } }, }; }); return new Listr(listItems); } exports.installist = installist; module.exports = { installist, DepType, };