четверг, 8 августа 2019 г.

Remove files after "npm install" command

Файл remove-files.js:

var fs = require('fs');

var doNotRemoveFiles =  [
    'remove-files.js',
    'node_modules',
    '@types',
    'dist',
    'docs',
    'src',
    'tests',
    '.gitignore',
    '.npmignore',
    '.npmrc',
    '.stylelintrc',
    'karma.conf.js',
    'package.json',
    'postcss.config.js',
    'readme.md',
    'tsconfig.json',
    'tslint.json',
    'webpack.config.js',
];

fs.readdir('./', function (error, fileNames) {
    if (error) {throw error;}
    var fileNamesCounter = fileNames.length;
    fileNames.forEach(function (fileName) {
        var len = doNotRemoveFiles.length;
        while (len--) {
            if (doNotRemoveFiles[len] === fileName) {return;}
        }
        fs.stat('./' + fileName, function (error, stats) {
            if (stats.isFile()) {
                fs.unlink('./' + fileName, function (error) {
                    if (error) {throw error;}
                    fileNamesCounter--;
                    if (fileNamesCounter === 0) {
                        console.log('DONE');
                    }
                });
            } else if (stats.isDirectory()) {
                fs.rmdir('./' + fileName, function (error) { // Remove empty "etc" directory.
                    if (error) {throw error;}
                    fileNamesCounter--;
                    if (fileNamesCounter === 0) {
                        console.log('DONE');
                    }
                });
            }
        });
    });
});

1 комментарий:

  1. If you're looking to lose kilograms then you absolutely have to get on this brand new personalized keto meal plan diet.

    To create this keto diet service, licenced nutritionists, fitness couches, and professional chefs united to provide keto meal plans that are efficient, painless, cost-efficient, and delicious.

    Since their grand opening in 2019, hundreds of people have already remodeled their figure and well-being with the benefits a good keto meal plan diet can give.

    Speaking of benefits: clicking this link, you'll discover 8 scientifically-certified ones given by the keto meal plan diet.

    ОтветитьУдалить