Skip to content

Commit

Permalink
wrap CLI with cli helper
Browse files Browse the repository at this point in the history
  • Loading branch information
raulfdm committed Aug 14, 2023
1 parent 5a1e817 commit d3f1d86
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-plants-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@codeowners-flow/cli': patch
---

Wrap CLI with cli helper
5 changes: 5 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Description

Closes #

## Changes
8 changes: 7 additions & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Instead of directly creating and maintaining the `CODEOWNERS` markup file, with
To understand the motivations behind this project, refer to the [root repository README](https://github.com/raulfdm/codeowners-manager/blob/main/README.md).

## Prerequisite

- Node 16 or later
- pnpm, yarn, or npm

## Getting started

The first step is to install `codeowners-flow` in your project:
Expand Down Expand Up @@ -45,7 +50,8 @@ export default {
After that, you can run the CLI:

```bash
npx codeowners-flow generate
pnpm codeowners-flow generate
# or npx codeowners-flow generate
```

The CLI will read your configuration and generate a `CODEOWNERS` file in the specified `outDir`:
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/index.cjs → packages/cli/bin/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
'use strict';

require('../dist/index.cjs');
import('../dist/index.js');
7 changes: 4 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"description": "A tool to script and manage the CODEOWNERS file programmatically",
"bin": {
"codeowners-flow": "./bin/index.cjs"
"codeowners-flow": "./bin/index.js"
},
"keywords": [
"codeowners",
Expand Down Expand Up @@ -50,14 +50,15 @@
"dependencies": {
"@manypkg/find-root": "2.2.1",
"cosmiconfig": "8.2.0",
"zod-validation-error": "1.3.1",
"zod": "3.21.4"
"zod": "3.21.4",
"zod-validation-error": "1.3.1"
},
"devDependencies": {
"@codeowners-flow/eslint": "workspace:*",
"@codeowners-flow/tsconfig": "workspace:*",
"@types/node": "16",
"eslint": "8.47.0",
"meow": "12.0.1",
"tsx": "3.12.7",
"typescript": "5.1.6",
"vite": "4.4.8",
Expand Down
46 changes: 37 additions & 9 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
import meow from 'meow';

import { generateCodeOwners } from './generate-codeowners.js';

generateCodeOwners()
.then(({ ownersPath }) => {
console.log('Codeowners file generated! 🎉');
console.log(`You can find it at: "${ownersPath}".\n`);
})
.catch((error) => {
console.error('Error generating CODEOWNERS file:', error);
process.exit(1);
});
const cli = meow(
`
Usage
$ codeowners-flow generate
Example
$ codeowners-flow generate
CODEOWNERS file generated! 🎉
You can find it at: "/path/to/CODEOWNERS".
`,
{
importMeta: import.meta,
},
);

const [command] = cli.input;

switch (command) {
case 'generate': {
generateCodeOwners()
.then(({ ownersPath }) => {
console.log('Codeowners file generated! 🎉');
console.log(`You can find it at: "${ownersPath}".\n`);
})
.catch((error) => {
console.error('Error generating CODEOWNERS file:', error);
process.exit(1);
});
break;
}
default: {
cli.showHelp();
}
}
Loading

0 comments on commit d3f1d86

Please sign in to comment.