soaping
v1.1.4
Published
Searches for unused files(.js, .png, etc) doing string comparison in a given file.
Downloads
5
Maintainers
Readme
Soaping
This dev-dependency is intended for erasing unused files in a project. It basically identifies if a file name is being imported or required by other files. If a specific file (*.js, *.png, etc.) is not being called from anywhere else, it's a candidate for being erased.
It's perfect for web projects that are using the import
or require
keyword.
This library only suggests wich files you could delete. With that information you could decide which files remove from your project.
Use cases
- Find images in a project that are not being used anywhere
- Delete js files that got unused in a particular project
Install library
npm install --save-dev soaping
Install library and create config.js file
npm install --save-dev soaping && cp ./node_modules/config.js config.js
Config file
To get this going, you will have to create a config file. Below you have an example of config.js file. You'll need to execute this config file by doing the following:
node config.js
This is how it works:
- you specify a directory of files that you want to find out whether they are being used or not
- you specify a directory where you will do the search. In this directory, all the files will be scanned
- This scanning process will do a string comparison finding out if a given file name is being imported
- If the file name is not being recalled from anywhere else, that file name will be shown as files to delete
Configuration of the config file
// Example of config.js file
const soaping = require('soaping');
const PATH_TO_ICON_RESOURCES = './src/resources/images';
const PATH_TO_ICON_ASSETS = './components/ui/icon/assets';
const PATH_TO_UI = './commons/components/ui';
const PATH_TO_SRC = './src';
const settings = {
stages: [
{
fileFilter: ['*.png'],
excludeFiles: ['/*@[1-3]x.png'],
listOfSources: [PATH_TO_ICON_ASSETS, PATH_TO_ICON_RESOURCES],
listOfEnds: [PATH_TO_SRC, PATH_TO_UI],
keepExtension: true,
},
{
fileFilter: ['*.js'],
excludeFiles: ['.test*', 'App'],
listOfSources: [PATH_TO_UI, PATH_TO_SRC],
listOfEnds: [PATH_TO_UI, PATH_TO_SRC],
keepExtension: false,
},
],
};
soaping(settings, (ixStage, fileName) => {
console.log('Stage:', ixStage, ' - File to Remove:', fileName);
});
There a few things to mention of this config file:
fileFilter
: will search only this type of files (e.g.: *.png, *.js)excludeFiles
: all the file names that don't need to be included in the scanning processlistOfSources
: directories that contain the files that are going to be searched (it takes only the names of the files as strings)listOfEnds
: directories that contain the files where the scanning will be performed. This scanning process will try to string match a given file name inside the content of a given file fromlistOfEnds
.keepExtension
: some files are imported with full extension while others not. Usually images are imported using*.jpg
. Use true in this case.- the
soaping
function takes thesettings
object and receives a callback - this callback has two arguments:
ixStage
and fileName ixStage
: stage of scanning processfileName
: the file name that should be removed
Tips
- Search images with
keepExtension: true
because images are called with its extension:
import imageExample from '../../imageExample.png';
var imageExample = require("../../imageExample.png");
- Search files with
keepExtension: false
because js files are called without its extension:
import jsFileExample from '../../jsFileExample';
var jsFileExample = require("../../jsFileExample");
License
MIT