UNPKG

npm-check-extras

Version:

CLI app to check for outdated and unused dependencies, and run update/delete action over selected ones

43 lines (42 loc) 1.46 kB
import fs from 'node:fs'; import path from 'node:path'; import * as R from 'ramda'; import { v4 as uuidv4 } from 'uuid'; const hasHistory = () => { // eslint-disable-next-line n/prefer-global/process const pathToFile = path.join(process.cwd(), '.npm-check-history.json'); return fs.existsSync(pathToFile); }; const readHistory = () => { // eslint-disable-next-line n/prefer-global/process const pathToFile = path.join(process.cwd(), '.npm-check-history.json'); if (hasHistory()) return JSON.parse(fs.readFileSync(pathToFile).toString()); return undefined; }; const getGroupedHistory = () => { const content = readHistory(); if (!content) return 'There is no history for this project. You can store a history by doing some actions with enabled flag.'; return JSON.stringify(content); }; const getHistoryJson = () => { const content = readHistory(); return R.defaultTo({}, content); }; const formatHistoryData = (data) => { const oper = []; R.forEach((k) => { R.forEach((operation) => { oper.push({ id: uuidv4(), date: k, name: R.prop('name', operation), operation: R.prop('operation', operation), command: R.prop('command', operation), }); }, data[k]); }, R.keys(data)); return oper; }; export { getGroupedHistory, getHistoryJson, hasHistory, formatHistoryData };