how to manage file dependencies in a website

125 views Asked by At

I am working on a website and gradually it become big. I am searching a tool or a method to know file dependencies.

for e.g.

I am using images/js/css files all over in website and before making any change or delete a file I want to know how many files (html,aspx) using that image/js/css file

thanks in advance :)

1

There are 1 answers

2
Queckezz On BEST ANSWER

You can build something like this pretty easily. You need to parse the given html into a tree and filter out the external dependencies. There is a module on npm for that called deps-html.

Assuming you have nodejs installed, you can install it with:

npm install --save deps-html

After that you can create a tree and count the dependencies:

var deps = require('deps-html');
var fs = require('fs');

var string = fs.readFileSync('/path/to/your/html');
// build the node tree
var ast = deps.parse(string);
// parse all the dependencies
var matches = deps.extract(ast);
// count
console.log(matches.length)

Then you can run it

> node count-deps.js

You can also get more specific and count the individual assets by accessing the assets type property:

matches.forEach(dep => console.log(dep.type))