All files / src/systemTools cleaner.js

64.29% Statements 27/42
35.29% Branches 6/17
66.67% Functions 2/3
66.67% Lines 16/24

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 454x 4x 4x 4x   4x 4x   4x 1x 1x       1x 1x 1x                     1x     1x 1x                 4x        
import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
import inquirer from 'inquirer';
 
import { removeDirs } from './fileutils';
import { logTask } from './logger';
 
const rnvClean = async (c, skipQuestion = false) => {
    logTask('rnvClean');
    const pathsToRemove = [
        c.paths.project.nodeModulesDir,
        path.join(c.paths.project.dir, 'package-lock.json')
    ];
    let msg = chalk.red('./node_modules\n./package-lock.json\n');
    const packagesFolder = path.join(c.paths.project.dir, 'packages');
    if (fsI.existsSync(packagesFolder)) {
        fs.readdirSync(packagesFolder).forEach((dir) => {
            if (dir === '.DS_Store') {
                pathsToRemove.push(path.join(packagesFolder, dir));
                msg += chalk.red(`./packages/${dir}\n`);
            } else {
                pathsToRemove.push(path.join(packagesFolder, dir, 'node_modules'));
                pathsToRemove.push(path.join(packagesFolder, dir, 'package-lock.json'));
                msg += chalk.red(`./packages/${dir}/node_modules\n./packages/${dir}/package-lock.json\n`);
            }
        });
    }E
 
 
    if (skipQuestion) {
        return removeDirs(pathsToRemove);
    }
 
    const { confirm } = await inquirer.prompt({
        name: 'confirm',
        type: 'confirm',
        message: `Are you sure you want to remove these files/folders? \n${msg}`,
    });
 
    if (confirm) return removeDirs(pathsToRemove);
};
 
export { rnvClean };