Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into feature/visualizer
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbgt committed Jan 7, 2025
2 parents c17205f + 6d3fb12 commit 5ad34d0
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 18 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ This will initialize the `.napirc` configuration file, which is essential for ma

NanoAPI relies on **annotations** to split your codebase. Annotations mark API endpoints, methods, and groups in your code, guiding how monolithic projects are refactored into microservices.

> **Important:** Before running `napi split`, you need to **annotate your codebase**. If you're not familiar with the process, see [Split with Annotations](#split-with-annotations) for a detailed guide and examples.
> **Important:** Before running `napi split run`, you need to **annotate your codebase**. If you're not familiar with the process, see [Split with Annotations](#split-with-annotations) for a detailed guide and examples.
```bash
napi split configure
Expand All @@ -102,7 +102,7 @@ napi split configure
This will launch the configuration UI. It allows you to configure and preview how your codebase will be split.

```bash
napi split
napi split run
```

This command allow you to split your codebase. You can use this in your CI pipeline if needed.
Expand Down Expand Up @@ -146,7 +146,7 @@ Split the codebase into smaller, more manageable pieces based on annotations. Th
> **Important:** This process relies on annotation (see [Split with Annotations](#split-with-annotations)).
```bash
napi split
napi split run
```

Note: This command uses the .napirc configuration file.
Expand Down Expand Up @@ -252,7 +252,7 @@ Automatically generate annotations for large codebases using the CLI with AI sup
napi split annotate openai --apiKey="sk-**"
```

**Note:** LLMs can make mistakes. We recommend reviewing AI-generated annotations carefully before running `napi split` to avoid unexpected behavior in the resulting microservices.
**Note:** LLMs can make mistakes. We recommend reviewing AI-generated annotations carefully before running `napi split run` to avoid unexpected behavior in the resulting microservices.

You can use annotations to specify how to split your code.
Simply add them above blocks of code that is handling or registering an endpoint
Expand All @@ -274,7 +274,7 @@ app.post("/api/v1/orders", (req, res) => {

You can view more examples in the [examples](/examples/)

Running `napi split` with the following annotations will generate modular services based on these annotations. You'll have a `Users` service and an `Orders` service, each containing the respective endpoint.
Running `napi split run` with the following annotations will generate modular services based on these annotations. You'll have a `Users` service and an `Orders` service, each containing the respective endpoint.

## Using the UI

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## [Unreleased]

## [0.0.29] - 2025-01-07

Fix split command by renaming it to avoid conflicts

## [0.0.28] - 2025-01-07

fix the path of app_dist directory to fix bug in production

## [0.0.27] - 2025-01-02

Change command names
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nanoapi.io/napi",
"version": "0.0.27",
"version": "0.0.29",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cli/handlers/splitAnnotate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function handler(
}

export default {
command: "split annotate openai",
command: "annotate openai",
describe: "Annotate a program, needed for splitting",
builder,
handler,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/cli/handlers/splitConfigure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async function handler(
}

export default {
command: "split configure",
describe: "Configure how napi split your program with the UI",
command: "configure",
describe: "Configure napi split your program with the UI",
builder: {},
handler,
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
writeSplitsToDisk,
} from "../../splitRunner/splitRunner";

async function splitCommandHandler(
async function splitRunCommandHandler(
entrypointPath: string, // Path to the entrypoint file
outputDir: string, // Path to the output directory
) {
Expand Down Expand Up @@ -61,7 +61,7 @@ async function handler(
}

try {
await splitCommandHandler(napiConfig.entrypoint, napiConfig.out);
await splitRunCommandHandler(napiConfig.entrypoint, napiConfig.out);
} catch (error) {
trackEvent(TelemetryEvents.CLI_SPLIT_COMMAND, {
message: "Split command error",
Expand All @@ -72,7 +72,7 @@ async function handler(
}

export default {
command: "split",
command: "run",
description: "Split a program into multiple ones",
builder: {},
handler,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/cli/helpers/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export async function runServer(
}),
);
} else {
app.use(express.static(path.join(__dirname, "../app_dist")));
// TODO find a better way to get dist directory. If we move this file, it will break
app.use(express.static(path.join(__dirname, "../../../app_dist")));
}

const port = await findAvailablePort(3000);
Expand Down
19 changes: 15 additions & 4 deletions packages/cli/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { hideBin } from "yargs/helpers";
import { checkVersionMiddleware } from "./helpers/checkNpmVersion";
import { globalOptions } from "./helpers/options";
import initCommand from "./handlers/init";
import splitHandler from "./handlers/split";
import splitRunHandler from "./handlers/splitRun";
import splitAnnotateHandler from "./handlers/splitAnnotate";
import splitConfigureHandler from "./handlers/splitConfigure";
import visualizerHandler from "./handlers/visualizer";
Expand All @@ -21,9 +21,20 @@ export function initCli() {
})
.options(globalOptions)
.command(initCommand)
.command(splitHandler)
.command(splitAnnotateHandler)
.command(splitConfigureHandler)
.command({
command: "split",
describe: "split your program",
builder: (yargs) => {
return yargs
.command(splitAnnotateHandler)
.command(splitConfigureHandler)
.command(splitRunHandler)
.demandCommand(1, "You need to specify a valid command");
},
handler: () => {
// do nothing, we are handling the subcommands
},
})
.command(visualizerHandler)
.parse();
}

0 comments on commit 5ad34d0

Please sign in to comment.