Skip to content

Commit fe2b98b

Browse files
hayata-suenagakevinslinSeriousBugKaan Barmore-Genc
authored
feat(cli): add a cli command that generates a packed-circles visualization of workspace (#3057)
* add gitignore to dendron-viz * add cli command * import dendron-viz from dendron-cli * prefix unused variable with underscore * Add watch script * Add dependencies needed for repo-visualizer * Add scripts for repo-visualizer * remove unnecessary scripts & adjust tsconfig * copy code from repo-visualizer * format code & add --jsx option * use dynamic import for es module package * fix esm issue * add script to copy non-ts files to lib * solve merge conflicts * draft visualize command * removed unused dependencies, files, and variables * remove the use of @actions/core * await generateSVG * fix package.json * clean up * Revert "await generateSVG" This reverts commit b381063. * Revert "Revert "await generateSVG"" This reverts commit 5a8bccf. * change console output * add visualize command to tasks * chore: fix ts build issues & refactor * rebuild the project * fix ts and eslint issues * use dendron engine from dendron-cli * fix: remove circular dependency * fix: remote circular dependency * replace getNoteByFnameFromEngine with findNotes * chore: upgrade dependencies * fix: untrack build directory * fix: export type * terminate cli command after generating svg files * add test for new cli command * transform esm modules for tests Co-authored-by: Kaan Barmore-Genç <[email protected]> * take output dir name instead of file name * test VisualizeCLICommand * change file name * modify test dir for visualize task * gitignore svg files * chore: remove console.log * fix: fix file path to check * fix: avoid time out for cli test * fix: change file name * fix: address pr reviews * fix: increase timeout for viz cli cmd spec * update package versions * fix: correct package versioning & reset yarn.lock * reduce timeout from 5e4 to 3e4 * fix: fix TS2731 * fix: resolve duplicate type declaration * chore: reset lock file * Revert "reduce timeout from 5e4 to 3e4" This reverts commit 9627d8e. * Revert "update package versions" This reverts commit bf0bda4. * chore: bring yarn.lock from master * take lock file from master & bump viz deps Co-authored-by: Kevin <[email protected]> Co-authored-by: Kaan Barmore-Genç <[email protected]> Co-authored-by: Kaan Barmore-Genc <[email protected]>
1 parent ba59325 commit fe2b98b

26 files changed

+1247
-18
lines changed

babel.config.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
module.exports = {
22
presets: [
3-
['@babel/preset-env', {targets: {node: 'current'}}],
4-
'@babel/preset-typescript',
3+
[
4+
"@babel/preset-env",
5+
{ targets: { node: "current" }, modules: "commonjs" },
6+
],
7+
"@babel/preset-typescript",
58
],
69
};

jest.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const commonConfig = {
77
snapshotSerializers: ["jest-serializer-path"],
88
testEnvironment: "node",
99
testPathIgnorePatterns: ["utils.ts"],
10+
transformIgnorePatterns: [
11+
// These are ESM modules that need to be transpiled before Jest can run them
12+
"/node_modules/(?!(d3.*|internmap|delaunator|robust-predicates)/)",
13+
],
1014
};
1115

1216
module.exports = {

packages/common-all/src/env.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function getOrThrow<T = any>(
6464
opts = _.defaults(opts, { shouldThrow: true });
6565
const maybeValue = obj[k];
6666
if (_.isUndefined(maybeValue) && opts.shouldThrow) {
67-
throw Error(`no ${k} in ${JSON.stringify(obj)}`);
67+
throw Error(`no ${String(k)} in ${JSON.stringify(obj)}`);
6868
}
6969
return maybeValue;
7070
}

packages/dendron-cli/.vscode/tasks.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,12 @@
9898
{
9999
"label": "publish --help",
100100
"type": "shell",
101-
"command": "node --inspect ${workspaceFolder}/lib/bin/dendron-cli publish --help --wsRoot ${workspaceFolder}/../../test-workspace ",
101+
"command": "node --inspect ${workspaceFolder}/lib/bin/dendron-cli publish --help --wsRoot ${workspaceFolder}/../../test-workspace "
102+
},
103+
{
104+
"label": "visualize",
105+
"type": "shell",
106+
"command": "node --inspect ${workspaceFolder}/lib/bin/dendron-cli visualize --wsRoot ${workspaceFolder}/../../test-workspace",
102107
"problemMatcher": []
103108
}
104109
]

packages/dendron-cli/bin/dendron-cli.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { PublishPodCLICommand } from "../src/commands/publishPod";
1515
import { SeedCLICommand } from "../src/commands/seedCLICommand";
1616
import { VaultCLICommand } from "../src/commands/vaultCLICommand";
1717
import { WorkspaceCLICommand } from "../src/commands/workspaceCLICommand";
18+
import { VisualizeCLICommand } from "../src/commands/visualizeCLICommand";
1819
// import { WorkspaceCLICommand } from "../src/commands/workspace";
1920

2021
if (_.isUndefined(env("LOG_LEVEL", { shouldThrow: false }))) {
@@ -35,6 +36,7 @@ new SeedCLICommand().buildCmd(buildYargs);
3536
new DevCLICommand().buildCmd(buildYargs);
3637
new PublishCLICommand().buildCmd(buildYargs);
3738
new ExportPodV2CLICommand().buildCmd(buildYargs);
39+
new VisualizeCLICommand().buildCmd(buildYargs);
3840

3941
// eslint-disable-next-line no-unused-expressions
4042
buildYargs.strictCommands().demandCommand(1).help().argv;

packages/dendron-cli/src/commands/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export * from "./devCLICommand";
1414
export * from "./publishCLICommand";
1515
export * from "./base";
1616
export { ExportPodV2CLICommand } from "./exportPodV2";
17+
export * from "./visualizeCLICommand";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { generateSVG, InputArgs } from "@dendronhq/dendron-viz";
2+
import { Argv } from "yargs";
3+
import { CLICommand, CommandCommonProps } from "./base";
4+
import { setupEngine, setupEngineArgs, SetupEngineResp } from "./utils";
5+
6+
type CommandOpts = InputArgs & SetupEngineResp & CommandCommonProps;
7+
8+
export { CommandOpts as VisualizeCLICommandOpts };
9+
10+
export class VisualizeCLICommand extends CLICommand {
11+
constructor() {
12+
super({
13+
name: "visualize",
14+
desc: "generates a packed circles visualization of Dendron workspace",
15+
});
16+
}
17+
18+
buildArgs(args: Argv) {
19+
super.buildArgs(args);
20+
setupEngineArgs(args);
21+
args.option("out", { description: "path to the output file " });
22+
}
23+
24+
async enrichArgs(args: any) {
25+
/* Instantiate an engine and pass it to the execute method as part of the argument */
26+
const engineArgs = await setupEngine(args);
27+
return { data: { ...args, ...engineArgs } };
28+
}
29+
30+
async execute(opts: CommandOpts) {
31+
await generateSVG(opts);
32+
return { exit: true };
33+
}
34+
}

packages/dendron-viz/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
coverage/
2+
node_modules/
3+
npm-debug.log*
4+
.nyc_output
5+
lib
6+
lib_test
7+
src/proto-*
8+
stdout

packages/dendron-viz/lib/index.d.ts

Whitespace-only changes.

packages/dendron-viz/lib/index.js

-4
This file was deleted.

packages/dendron-viz/package.json

+16-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,24 @@
2525
"clean": "rimraf lib && rimraf coverage",
2626
"prepublishOnly": "yarn build",
2727
"prebuild": "yarn clean",
28-
"build": "yarn compile",
29-
"buildCI": "yarn compile",
30-
"compile": "tsc -p tsconfig.build.json "
28+
"build": "yarn copyNonTSFiles && yarn compile",
29+
"buildCI": "yarn copyNonTSFiles && yarn compile",
30+
"copyNonTSFiles": "mkdir -p lib && cp ./src/loadModule.js lib/",
31+
"compile": "tsc -p tsconfig.build.json",
32+
"watch": "yarn copyNonTSFiles && yarn compile --watch"
33+
},
34+
"dependencies": {
35+
"@dendronhq/common-all": "^0.100.1",
36+
"@dendronhq/engine-server": "^0.100.1",
37+
"d3": "^7.0.0",
38+
"lodash": "^4.17.21",
39+
"micromatch": "^4.0.4",
40+
"react": "^17.0.2",
41+
"react-dom": "^17.0.2",
42+
"yargs": "^17.4.1"
3143
},
3244
"devDependencies": {
45+
"@types/micromatch": "^4.0.2",
3346
"rimraf": "^2.6.2"
3447
},
3548
"engines": {
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable react/require-default-props */
2+
import uniqueId from "lodash/uniqueId";
3+
import React, { useMemo } from "react";
4+
5+
interface CircleTextProps {
6+
r: number;
7+
rotate?: number;
8+
text: string;
9+
style?: any;
10+
fill?: string;
11+
stroke?: string;
12+
strokeWidth?: string;
13+
}
14+
export const CircleText = ({
15+
r = 10,
16+
rotate = 0,
17+
text = "",
18+
...props
19+
}: CircleTextProps) => {
20+
const id = useMemo(() => uniqueId("CircleText--"), []);
21+
22+
return (
23+
<>
24+
<path
25+
fill="none"
26+
d={[
27+
["M", 0, r].join(" "),
28+
["A", r, r, 0, 0, 1, 0, -r].join(" "),
29+
["A", r, r, 0, 0, 1, 0, r].join(" "),
30+
].join(" ")}
31+
id={id}
32+
transform={`rotate(${rotate})`}
33+
style={{ pointerEvents: "none" }}
34+
/>
35+
<text textAnchor="middle" {...props}>
36+
<textPath href={`#${id}`} startOffset="50%">
37+
{text}
38+
</textPath>
39+
</text>
40+
</>
41+
);
42+
};

0 commit comments

Comments
 (0)