All files / src/systemTools cleaner.js

50.94% Statements 27/53
28.57% Branches 6/21
66.67% Functions 2/3
55.17% Lines 16/29

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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 602x 2x 2x 2x   2x 2x   2x 1x 1x       1x 1x 1x                     1x     1x 1x                                           2x            
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) {
        await removeDirs(pathsToRemove);
 
        const buildDirs = [
            c.paths.project.builds.dir,
            c.paths.project.assets.dir
        ];
        const { confirmBuilds } = await inquirer.prompt({
            name: 'confirmBuilds',
            type: 'confirm',
            message: `Do you also want to clean your platformBuilds and platformAssets? \n${chalk.red(buildDirs.join('\n'))}`,
        });
        if (confirmBuilds) {
            await removeDirs(buildDirs);
        }
    }
};
 
export { rnvClean };