UNPKG

@nodearch/cli

Version:
71 lines (70 loc) 2.97 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Command } from '@nodearch/command'; import { fileURLToPath } from 'node:url'; import ncu from 'npm-check-updates'; import { LocalAppService } from '../../local-app.service.js'; import { Logger } from '@nodearch/core'; import { NpmService } from '../new/npm.service.js'; let NcuCommand = class NcuCommand { constructor(localAppService, logger, npmService) { this.localAppService = localAppService; this.logger = logger; this.npmService = npmService; this.command = 'ncu'; this.describe = 'Check for npm packages updates using npm-check-updates'; this.builder = { upgrade: { alias: 'u', type: 'boolean', describe: 'upgrade package.json dependencies', default: false } }; } async handler(options) { if (!this.localAppService.isAppDir) return; const rootPath = fileURLToPath(this.localAppService.info.paths.rootDir); const pkgPath = fileURLToPath(this.localAppService.info.paths.pkg); this.logger.info('Checking for npm packages updates...'); const upgraded = await ncu.run({ packageFile: pkgPath, upgrade: options.upgrade, silent: true, jsonUpgraded: true, color: true }); if (!upgraded) { this.logger.info('No npm packages updates found!'); return; } const pkgs = Object.entries(upgraded).map(([Name, Version]) => ({ Name, Version })); if (!pkgs.length) { this.logger.info('All packages are up to date!'); return; } console.table(pkgs, ['Name', 'Version']); if (!options.upgrade) { this.logger.info('To upgrade the npm packages run -> nodearch ncu -u'); return; } this.logger.info('Running npm i'); await this.npmService.install(rootPath); this.logger.info('Npm packages upgraded successfully!'); } }; NcuCommand = __decorate([ Command(), __metadata("design:paramtypes", [LocalAppService, Logger, NpmService]) ], NcuCommand); export { NcuCommand };