Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix path handling on windows and add contribution section in README.md #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,76 @@ napi split configure

We welcome contributions from the community. Please read our [contributing guide](https://github.com/nanoapi-io/napi/blob/main/.github/CONTRIBUTING.md) for details on how to get involved.

### Setting up the Development Environment

1. Fork the repository

2. Clone your forked repository:

```bash
git clone https://github.com/your-username/napi.git
cd napi
```

3. Install dependencies:

```bash
npm install
```

### Running the Project

The project consists of two main parts: the frontend in the `packages/app` folder and the CLI in the `packages/cli` folder.

#### Running the Frontend

In your first terminal:

```bash
npm run dev:app
```

This will start the Vite development server on http://localhost:3001

#### Running the CLI with Examples

In a second terminal, you can run commands using the examples and start the local server. Here's how to do it on different platforms:

##### Windows

```bash
# Initialize a project (replace with your actual path)
npm run dev:cli -- init -- --workdir="C:\Users\your-username\Projects\napi\examples\node\express"

# Open the UI configuration
npm run dev:cli -- split configure -- --workdir="C:\Users\your-username\Projects\napi\examples\node\express"
```

##### Linux/macOS

```bash
# Initialize a project (replace with your actual path)
npm run dev:cli -- init -- --workdir="/home/your-username/projects/napi/examples/node/express"

# Open the UI configuration
npm run dev:cli -- split configure -- --workdir="/home/your-username/projects/napi/examples/node/express"
```

### Example Project Structure

The `examples/node/express` directory contains a sample Express.js application that you can use for testing. After running the `init` command, it will create a `.napirc` file in the example project with the following configuration:

```json
{
"entrypoint": "src/index.js",
"out": "napi_dist"
}
```

This configuration tells napi where to find the main entry point of the application and where to output the generated microservices.

> **Note**: Always use absolute paths when specifying the `workdir` parameter. Replace the example paths above with the actual full path to your project directory.

## License

`napi` is licensed under the [Sustainable Use License](https://github.com/nanoapi-io/napi/blob/main/LICENSE.md).
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.

14 changes: 11 additions & 3 deletions packages/cli/src/api/helpers/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const syncSchema = z.object({
path: z.string(),
method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]).optional(),
group: z.string().optional(),
}),
})
),
});

Expand All @@ -29,15 +29,23 @@ export const splitSchema = z.object({
});

function isValidFilePath(filePath: string) {
// Try with original path
if (!fs.existsSync(filePath)) {
return false;
// Try with relative path
const relativePath = path.relative(process.cwd(), filePath);
if (!fs.existsSync(relativePath)) {
return false;
}
filePath = relativePath;
}

try {
if (!fs.statSync(filePath).isFile()) {
return false;
}
} catch {
return false;
}
return path.isAbsolute(filePath) && !/[<>:"|?*]/.test(filePath);

return path.isAbsolute(filePath) || process.platform === "win32";
}