Skip to content

Commit

Permalink
turbo-kit v1 (#1)
Browse files Browse the repository at this point in the history
* setup

* feat: graph commands

* chore: biomejs

* chore: husky

* docs: readme

* fix: biome issues

* feat: dep updates

* chore: export as ESM
  • Loading branch information
Netail authored Jul 28, 2024
1 parent 8229b67 commit 4c0a6a6
Show file tree
Hide file tree
Showing 17 changed files with 1,469 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @Netail
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE.md
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**:
12 changes: 12 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
node_modules/
dist/
build/
.idea/
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn run format
11 changes: 11 additions & 0 deletions .vscode/settings.json
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"
}
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Maikel
Copyright (c) 2024 Netail

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
53 changes: 51 additions & 2 deletions README.md
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
14 changes: 14 additions & 0 deletions biome.json
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"
}
}
}
40 changes: 40 additions & 0 deletions package.json
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"]
}
33 changes: 33 additions & 0 deletions src/bin/cli.ts
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();
19 changes: 19 additions & 0 deletions src/commands/clean.ts
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;
}
}
}
};
38 changes: 38 additions & 0 deletions src/commands/graph.ts
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');
};
44 changes: 44 additions & 0 deletions src/commands/updates.ts
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');
}
};
17 changes: 17 additions & 0 deletions tsconfig.json
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/*"]
}
}
}
7 changes: 7 additions & 0 deletions tsup.config.json
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
}
Loading

0 comments on commit 4c0a6a6

Please sign in to comment.