-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Dict } from 'cosmokit' | ||
import { Context } from '..' | ||
|
||
interface Node { | ||
name: string | ||
path: string | ||
children: Node[] | ||
tree: Dict<Node> | ||
} | ||
|
||
export default function apply(ctx: Context) { | ||
function createNode(path: string): Node { | ||
return { name: ctx.yakumo.workspaces[path].name, path, children: [], tree: {} } | ||
} | ||
|
||
function findParent(root: Node, path: string) { | ||
for (const prefix in root.tree) { | ||
if (path.startsWith(prefix)) return findParent(root.tree[prefix], path) | ||
} | ||
return root | ||
} | ||
|
||
function printNode(node: Node, indent: boolean[] = []) { | ||
const prefix = indent.map((isLastItem, index) => { | ||
const isLastIndent = index === indent.length - 1 | ||
return isLastIndent | ||
? isLastItem ? '└── ' : '├── ' | ||
: isLastItem ? ' ' : '│ ' | ||
}).join('') | ||
console.log(`${prefix}${node.name}${node.path ? ` (${node.path.slice(1)})` : ''}`) | ||
node.children.forEach((child, index) => { | ||
const isLast = index === node.children.length - 1 | ||
printNode(child, [...indent, isLast]) | ||
}) | ||
} | ||
|
||
ctx.register('list', async () => { | ||
const paths = Object.keys(ctx.yakumo.workspaces).sort() | ||
const root: Node = createNode(paths.shift()!) | ||
const total = paths.length | ||
let workspaces = 1 | ||
for (const path of paths) { | ||
const node = createNode(path) | ||
const parent = findParent(root, path) | ||
parent.children.push(node) | ||
if (ctx.yakumo.workspaces[path].workspaces) { | ||
parent.tree[path] = node | ||
workspaces++ | ||
} | ||
} | ||
printNode(root) | ||
console.log(`${total} packages, ${workspaces} workspaces`) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,5 @@ export default function apply(ctx: Context, config: Config = {}) { | |
} | ||
} | ||
} | ||
}, { | ||
manual: true, | ||
}) | ||
} |