Skip to content
Prettier for File Structures
TypeScript JavaScript
Branch: develop
Clone or download
waynevanson and sQVe refactor: code cleanup (#62)
* adds comment to "customResolve"

* renames "addEdge" to "addEdgeToGraph"

* code cleanup for "makeImportPath"

* use null coelascing instead of 'or' conditional

* code cleanup for "findSharedParent"

* fix broken import o "addEdgeToGraph"

* removes comment in "makeImportPath"

* remove comment from "getExtensionFromImport"

* declares "getExtensionFromImport" before usage

* use "if" body instead of a break.

* Apply suggestions from code review

Co-Authored-By: Oskar Grunning <oskargrunning@gmail.com>

Co-authored-by: Oskar Grunning <oskargrunning@gmail.com>
Latest commit 4850774 Feb 23, 2020

README.md

destiny

Prettier for File Structures

npm version contributions welcome


Motivation: https://www.youtube.com/watch?v=rGYbrIf-y58

example transformation

What does this do?

  1. Scans a folder for all the files in it
  2. Creates a directed graph based on how the JavaScript/TypeScript files import each other example directed graph
  3. Creates a fractal representation of the graph (following similar rules outlined here: https://hackernoon.com/fractal-a-react-app-structure-for-infinite-scale-4dab943092af)
  4. Moves existing files into the fractal structure
  5. Fixes imports
  6. Removes all empty folders
  7. Prints files that are "unused" (not imported by anyone and doesn't import anything)

The end result is a "prettified" file structure.

Disclaimer

  • This is a work in progress and 100% has bugs of some kind in it
  • BEFORE running this tool on your codebase, make sure you have commited to git or made a backup (I don't expect the tool to destroy your work (although it's possible), but just in case you don't like the results)
  • Snapshot tests don't format correctly
  • Only works on JavaScript/TypeScript codebases (althought this concept could probably be extended to any language)

How to run it

npx destiny src/**/*.*

This tool might be useless

It might be better to just name your folders.

Why did you name it destiny?

The name could be "Destiny" maybe. Like the file was meant to be there.

Contributing

pull requests are welcome :)

You can’t perform that action at this time.