-
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.
* setup * feat: graph commands * chore: biomejs * chore: husky * docs: readme * fix: biome issues * feat: dep updates * chore: export as ESM
- Loading branch information
Showing
17 changed files
with
1,469 additions
and
3 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 @@ | ||
* @Netail |
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 @@ | ||
## Expected Behavior | ||
|
||
[Type here] | ||
|
||
## Actual Behavior | ||
|
||
[Type here] | ||
|
||
## Steps to Reproduce the Problem | ||
|
||
1. | ||
1. | ||
1. | ||
|
||
## Specifications | ||
|
||
- **Version**: | ||
- **Platform**: |
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,12 @@ | ||
## Summary | ||
|
||
<!-- Please include a summary of the changes and the related issue. --> | ||
|
||
Fixes # (issue) | ||
|
||
## Checklist | ||
|
||
- [ ] I have performed a self-review and cleanup of my code, ready to be merged | ||
- [ ] My code follows the style guidelines of this project | ||
- [ ] I have added/modified sufficient tests | ||
- [ ] I have made corresponding changes to the documentation |
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,5 @@ | ||
.DS_Store | ||
node_modules/ | ||
dist/ | ||
build/ | ||
.idea/ |
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 @@ | ||
yarn run format |
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,11 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"explorer.fileNesting.enabled": true, | ||
"explorer.fileNesting.expand": false, | ||
"explorer.fileNesting.patterns": { | ||
"*.js": "${capture}.test.js, ${capture}.spec.js", | ||
"*.ts": "${capture}.test.ts, ${capture}.test.tsx, ${capture}.spec.ts, ${capture}.spec.tsx", | ||
"*.tsx": "${capture}.test.ts, ${capture}.test.tsx, ${capture}.spec.ts, ${capture}.spec.tsx" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,51 @@ | ||
# Turbo Janitor | ||
Turborepo CLI helper for housekeeping | ||
# Turbo Kit | ||
|
||
Turborepo CLI for housekeeping | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install turbo-kit -D | ||
``` | ||
|
||
```sh | ||
yarn add turbo-kit -D | ||
``` | ||
|
||
```sh | ||
pnpm add turbo-kit -D | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
Usage: turbo-kit [options] [command] | ||
|
||
Options: | ||
-h, --help display help for command | ||
|
||
Commands: | ||
clean [files...] Cross env clean workspace | ||
dependencies Display Turbo monorepo dependencies graph | ||
dependents Display Turbo monorepo dependents graph | ||
updates Check if the dependencies of the workspace are up to date | ||
help [command] display help for command | ||
``` | ||
## Commands | ||
### `clean` | ||
Rimraf files cross environment (window/macos/linux) | ||
### `dependencies` | ||
Display a graph of dependencies within the monorepo. | ||
### `dependents` | ||
Display a graph of dependents within the monorepo. | ||
### `updates` | ||
Check if the dependencies of the workspace are up to date |
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,14 @@ | ||
{ | ||
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json", | ||
"formatter": { | ||
"enabled": true, | ||
"indentStyle": "tab", | ||
"indentWidth": 4 | ||
}, | ||
"javascript": { | ||
"formatter": { | ||
"quoteStyle": "single", | ||
"semicolons": "always" | ||
} | ||
} | ||
} |
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,40 @@ | ||
{ | ||
"name": "turbo-kit", | ||
"version": "1.0.0", | ||
"description": "Turborepo CLI for housekeeping", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Netail/turbo-kit.git" | ||
}, | ||
"type": "module", | ||
"files": ["dist"], | ||
"engines": { | ||
"node": "^18.18.0 || >=20.0.0", | ||
"npm": ">=8.12.1" | ||
}, | ||
"packageManager": "[email protected]", | ||
"bin": { | ||
"turbo-kit": "dist/cli.js" | ||
}, | ||
"scripts": { | ||
"build": "tsup --config tsup.config.json", | ||
"dev": "tsup --config tsup.config.json --watch", | ||
"format": "biome format --write", | ||
"prepare": "husky || true" | ||
}, | ||
"dependencies": { | ||
"@turbo/repository": "^0.0.1-canary.10", | ||
"chalk": "^5.3.0", | ||
"commander": "^12.1.0", | ||
"npm-check-updates": "^17.0.0-6" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.8.3", | ||
"@types/node": "^20.14.12", | ||
"husky": "^9.1.3", | ||
"tsup": "^8.2.3", | ||
"typescript": "^5.5.4" | ||
}, | ||
"keywords": ["turbo"] | ||
} |
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,33 @@ | ||
#!/usr/bin/env node | ||
|
||
import { Command } from 'commander'; | ||
import { clean } from '../commands/clean'; | ||
import { updates } from '../commands/updates'; | ||
import { dependenciesGraph, dependentsGraph } from '../commands/graph'; | ||
|
||
const program = new Command(); | ||
|
||
program.name('Turbo Kit').description('Turborepo CLI for housekeeping'); | ||
|
||
program | ||
.command('clean') | ||
.description('Delete a file or directory cross environment') | ||
.argument('[files...]', 'Files or directories to be deleted') | ||
.action((files) => clean({ files })); | ||
|
||
program | ||
.command('updates') | ||
.description('Check if the dependencies of the workspace are up to date') | ||
.action(() => updates()); | ||
|
||
program | ||
.command('dependencies') | ||
.description('Display Turbo monorepo dependencies graph') | ||
.action(() => dependenciesGraph()); | ||
|
||
program | ||
.command('dependents') | ||
.description('Display Turbo monorepo dependents graph') | ||
.action(() => dependentsGraph()); | ||
|
||
program.parse(); |
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,19 @@ | ||
import { rmSync } from 'node:fs'; | ||
|
||
interface CleanProps { | ||
files: string[]; | ||
} | ||
|
||
export const clean = ({ files }: CleanProps) => { | ||
for (const file of files) { | ||
try { | ||
rmSync(file, { recursive: true }); | ||
} catch (err) { | ||
if ((err as NodeJS.ErrnoException).code === 'ENOENT') { | ||
console.warn('Failed to delete file or directory:', file); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} | ||
}; |
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,38 @@ | ||
import { Workspace, type PackageDetails } from '@turbo/repository'; | ||
import chalk from 'chalk'; | ||
|
||
const graph = async (key: keyof PackageDetails) => { | ||
const workspace = await Workspace.find('.'); | ||
|
||
const packages = await workspace.findPackages(); | ||
const packagesWithGraph = await workspace.findPackagesWithGraph(); | ||
|
||
for (const pkg of packages) { | ||
const rawDependencies = packagesWithGraph[pkg.relativePath][key]; | ||
const dependencies = rawDependencies.map( | ||
(rawDep) => | ||
packages.find((pkg) => pkg.relativePath === rawDep)?.name, | ||
); | ||
|
||
console.log(chalk.underline(chalk.bold(pkg.name))); | ||
|
||
if (dependencies.length > 0) { | ||
dependencies.forEach((dep, idx) => { | ||
const isLast = dependencies.length === idx + 1; | ||
const prefix = isLast ? '└──' : '├──'; | ||
|
||
console.log(`${prefix} ${dep}${isLast ? '\n' : ''}`); | ||
}); | ||
} else { | ||
console.log('└── None...\n'); | ||
} | ||
} | ||
}; | ||
|
||
export const dependentsGraph = () => { | ||
graph('dependents'); | ||
}; | ||
|
||
export const dependenciesGraph = () => { | ||
graph('dependencies'); | ||
}; |
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,44 @@ | ||
import { Workspace } from '@turbo/repository'; | ||
import { run } from 'npm-check-updates'; | ||
import path from 'node:path'; | ||
import chalk from 'chalk'; | ||
|
||
export const updates = async () => { | ||
const workspace = await Workspace.find('.'); | ||
|
||
const packages = await workspace.findPackages(); | ||
|
||
if (packages.length === 0) { | ||
console.warn('[Turbo Kit] - No packages found...'); | ||
process.exit(1); | ||
} | ||
|
||
await packageUpdates('Root', 'package.json'); | ||
|
||
for (const pkg of packages) { | ||
await packageUpdates( | ||
pkg.name, | ||
path.join(pkg.relativePath, 'package.json'), | ||
); | ||
} | ||
}; | ||
|
||
const packageUpdates = async (name: string, path: string) => { | ||
console.log(chalk.underline(chalk.bold(name))); | ||
|
||
const upgrades = await run({ | ||
packageFile: path, | ||
}); | ||
|
||
const depsLength = Object.keys(upgrades || {}); | ||
if (upgrades && depsLength.length > 0) { | ||
Object.entries(upgrades).forEach(([key, value], idx) => { | ||
const isLast = depsLength.length === idx + 1; | ||
const prefix = isLast ? '└──' : '├──'; | ||
|
||
console.log(`${prefix} ${key} >> ${value}${isLast ? '\n' : ''}`); | ||
}); | ||
} else { | ||
console.log('└── None...\n'); | ||
} | ||
}; |
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,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ES2019"], | ||
"target": "ES2019", | ||
"moduleResolution": "Node", | ||
"baseUrl": "src", | ||
"outDir": "dist", | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"paths": { | ||
"@interfaces/*": ["./interfaces/*"], | ||
"@utils/*": ["./utils/*"] | ||
} | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"$schema": "https://cdn.jsdelivr.net/npm/tsup/schema.json", | ||
"entry": ["src/bin/cli.ts"], | ||
"format": ["esm"], | ||
"minify": false, | ||
"clean": true | ||
} |
Oops, something went wrong.