DEV Community

liajoy
liajoy

Posted on

How to extract features from a library

I've tried to extract features from open source library for a long time, i.e. PIXI.Transform from pixi.js or component of component library. In most cases, it's not difficult thing because most of these files haven't a complicated dependence tree. But I have some trouble when extract THREE.TextGeometry from three.js recently. You know, three.js is a fat library.
In fact, it's a simple work. There are some of implementations in open source community already, but I didn't find one of them can do these things directly. So I have to write a tool, it has features as follow:

  • Find dependencies of file.
  • Copy these dependencies as output according to the original directory structure.

1. Find dependencies

There are a number of libraries that can detect dependencies of file, but most of them return relative path to the dependency. For further work, an absolute path should be a better choice. So I resolve the relative path to an absolute path.

2. Copy dependencies

When we got absolute paths of all the dependent files, the rest work is so simple. Just need to copy all of them to the output directory. But there are something we need to pay attention to, for ensuring the directory structure is correct after copied, we should get the topmost level directory of these dependent files, base on that directory, we can build down the whole structure.

Conclusion

After these steps, a negligible tool comes. It saved me from extracting 30+ dependencies of THREE.TextGeometry. I can't image how much time will be taken without this tool. In daily work, it can helps a lot when migrate some file with dependence to another place.

If you are interested in it, you can find more information about it in hiway.

Top comments (0)