-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: bumps * fix: sort packages for stay consistency order * feat: list command * fix: ls on macos * fix: cleaner * bump package version
- Loading branch information
Showing
8 changed files
with
117 additions
and
28 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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Workspace } from '@turbo/repository'; | ||
import { generateAsciiTree } from '@utils/ascii-tree'; | ||
import chalk from 'chalk'; | ||
|
||
export const list = async () => { | ||
const workspace = await Workspace.find('.'); | ||
|
||
const packages = (await workspace.findPackages()).sort((a, b) => | ||
a.relativePath.localeCompare(b.relativePath), | ||
); | ||
|
||
const paths = packages.map( | ||
(pkg) => | ||
`${pkg.relativePath} | ${chalk.underline(chalk.bold(pkg.name))}`, | ||
); | ||
const tree = generateAsciiTree(paths); | ||
console.log(tree); | ||
}; |
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 @@ | ||
type TreeNode = { | ||
[key: string]: TreeNode | null; | ||
}; | ||
|
||
/** | ||
* Copied from | ||
* https://github.com/BuilderIO/micro-agent/blob/main/src/helpers/generate-ascii-tree.ts | ||
*/ | ||
export const generateAsciiTree = (paths: string[]): string => { | ||
const root: TreeNode = {}; | ||
|
||
// Construct the tree | ||
for (const path of paths) { | ||
const parsedPath = path.split(' | '); | ||
const parts = parsedPath.shift()?.split(/\/|\\/g) || []; | ||
|
||
if (parsedPath.length > 0) { | ||
const lastItem = parts.pop(); | ||
parts.push(`${lastItem} | ${parsedPath}`); | ||
} | ||
|
||
let current = root; | ||
|
||
parts.forEach((part, index) => { | ||
if (!current[part]) { | ||
current[part] = index === parts.length - 1 ? null : {}; | ||
} | ||
current = current[part] as TreeNode; | ||
}); | ||
} | ||
|
||
// Function to generate ASCII tree | ||
const generateTreeString = (node: TreeNode, prefix = ''): string => { | ||
const keys = Object.keys(node); | ||
let result = ''; | ||
|
||
keys.forEach((key, index) => { | ||
const isThisLast = index === keys.length - 1; | ||
result += `${prefix + (isThisLast ? '└── ' : '├── ') + key}\n`; | ||
|
||
// Generate subtree if the current node is a directory | ||
if (node[key]) { | ||
result += generateTreeString( | ||
node[key] as TreeNode, | ||
prefix + (isThisLast ? ' ' : '│ '), | ||
); | ||
} | ||
}); | ||
|
||
return result; | ||
}; | ||
|
||
return generateTreeString(root).trim(); | ||
}; |
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