Skip to content

add max_depth parameter #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ For example: dist,node_modules

Default: node_modules,bower_components,dist,out,build,eject,.next,.netlify,.yarn,.vscode,package-lock.json,yarn.lock

## `max_depth`

The maximum number of nested folders to show files within. A higher number will take longer to render.

Default: 5

## Example usage

You'll need to run the `actions/checkout` Action beforehand, to check out the code.
Expand All @@ -34,6 +40,7 @@ You'll need to run the `actions/checkout` Action beforehand, to check out the co
- name: Update diagram
uses: githubocto/repo-visualizer@main
with:
output_file: 'images/diagram.svg'
excluded_paths: 'dist,node_modules'
output_file: "images/diagram.svg"
excluded_paths: "dist,node_modules"
max_depth: 9
```
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
excluded_paths:
description: "A list of paths to exclude from the diagram, separated by commas. For example: dist,node_modules"
required: false
max_depth:
description: "The maximum number of nested folders to show files within. Default: 9"
required: false
runs:
using: "node12"
main: "index.js"
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16678,8 +16678,7 @@ var colorTheme = "file";
var looseFilesId = "__structure_loose_file__";
var width = 1e3;
var height = 1e3;
var maxDepth = 9;
var Tree = ({ data, filesChanged = [] }) => {
var Tree = ({ data, filesChanged = [], maxDepth = 9 }) => {
const [selectedNodeId, setSelectedNodeId] = (0, import_react2.useState)(null);
const cachedPositions = (0, import_react2.useRef)({});
const cachedOrders = (0, import_react2.useRef)({});
Expand Down Expand Up @@ -17170,11 +17169,13 @@ var main = async () => {
`${username}@users.noreply.github.com`
]);
core.endGroup();
const maxDepth = core.getInput("max_depth") || 9;
const excludedPathsString = core.getInput("excluded_paths") || "node_modules,bower_components,dist,out,build,eject,.next,.netlify,.yarn,.git,.vscode,package-lock.json,yarn.lock";
const excludedPaths = excludedPathsString.split(",").map((str) => str.trim());
const data = await processDir(`./`, excludedPaths);
const componentCodeString = import_server.default.renderToStaticMarkup(/* @__PURE__ */ import_react3.default.createElement(Tree, {
data
data,
maxDepth: +maxDepth
}));
const outputFile = core.getInput("output_file") || "./diagram.svg";
await import_fs2.default.writeFileSync(outputFile, componentCodeString);
Expand Down
3 changes: 1 addition & 2 deletions src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ const colorTheme = "file";
const looseFilesId = "__structure_loose_file__";
const width = 1000;
const height = 1000;
const maxDepth = 9;
export const Tree = ({ data, filesChanged = [] }: Props) => {
export const Tree = ({ data, filesChanged = [], maxDepth = 9 }: Props) => {
const [selectedNodeId, setSelectedNodeId] = useState(null);
const cachedPositions = useRef<{ [key: string]: [number, number] }>({});
const cachedOrders = useRef<{ [key: string]: string[] }>({});
Expand Down
3 changes: 2 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ const main = async () => {
core.endGroup()


const maxDepth = core.getInput("max_depth") || 9
const excludedPathsString = core.getInput("excluded_paths") || "node_modules,bower_components,dist,out,build,eject,.next,.netlify,.yarn,.git,.vscode,package-lock.json,yarn.lock"
const excludedPaths = excludedPathsString.split(",").map(str => str.trim())
const data = await processDir(`./`, excludedPaths);

const componentCodeString = ReactDOMServer.renderToStaticMarkup(
<Tree data={data} />
<Tree data={data} maxDepth={+maxDepth} />
);

const outputFile = core.getInput("output_file") || "./diagram.svg"
Expand Down