r2g icon indicating copy to clipboard operation
r2g copied to clipboard

r2g rename node_modules dirs

Open ORESoftware opened this issue 5 years ago • 0 comments

'use strict'

const fs = require('fs');
const path = require('path');
let current = path.dirname(process.cwd());
const home = process.env.HOME;

let renameThisDir = 'node_modules';
let renameTo = 'r2g_nodemodules';


if (process.argv[2] === 'undo') {
    // swap the variables
    [renameTo, renameThisDir] = [renameThisDir, renameTo];
}

while (current.length >= home.length) {
    
    let nm = path.resolve(current, renameThisDir);
    let renamed = path.resolve(current, renameTo);
    
    fs.stat(nm, (err, stats) => {
        
        if (!(stats && stats.isDirectory())) {
            return
        }
        
        fs.rename(nm, renamed, err => {
            err ? console.error(err.message) :
                console.log('renamed:', nm, 'to:', renamed)
        });
    });
    
    current = path.join(current, '..');
}

ORESoftware avatar Nov 02 '18 01:11 ORESoftware