Skip to content

Commit

Permalink
Merge pull request #31 from imLymei/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
imLymei authored Sep 27, 2024
2 parents d14f314 + 97b2de4 commit 94ffc83
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 148 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ name: Release
on:
push:
branches:
- master # or main
- master
- next
- beta

permissions:
contents: read # for checkout
contents: read

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
contents: write
issues: write
pull-requests: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
18 changes: 14 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,41 @@ Welcome to the project! We're glad you're here and interested in contributing. B

## How to Contribute

### Repository Structure

This repository uses a automated version release using the mains 3 branches:

- **master**: Contains the code on the actual `@latest` package channel.
- **beta**: Contains the code on the actual `@beta` package channel.
- **dev**: Contains the code of actual development, every `BREAKING CHANGE` and `feat` commit must be done on this branch.

### Step by Step

1. **Fork the repository:** Click on the "Fork" button on the top right corner of the repository's page, then clone your fork locally.

2. **Create a new branch:** Make your changes in a new branch created from the `main` branch. Choose a descriptive name for your branch related to the issue or feature you're working on.
2. **Create a new branch:** Make your changes in a new branch created from the `dev` branch or `main` for `fix` or others specific situations. Choose a descriptive name for your branch related to the issue or feature you're working on.

3. **Make your changes:** Implement the changes or additions you'd like to contribute. Please follow any existing coding style and conventions.

4. **Test your changes:** Ensure that your changes do not break existing functionality. If you're adding new features, include tests to cover your code.

5. **Commit your changes:** Make meaningful and atomic commits. Please provide a clear and descriptive commit message for each commit.
5. **Commit your changes:** Make meaningful and atomic commits. Please provide a [clear and descriptive commit message](https://www.conventionalcommits.org/en/v1.0.0/#summary) for each commit.

6. **Push your changes:** Once your changes are ready, push your branch to your fork of the repository.

7. **Create a Pull Request (PR):** Go back to the original repository and navigate to the Pull Requests tab. Click on "New Pull Request" and choose your branch as the compare branch. Fill out the PR template with relevant information and details about your changes.

8. **Review and address feedback:** Be open to feedback and iterate on your changes if necessary. Respond promptly to any comments or requests for changes from the maintainers.

9. **Merge your PR:** Once your PR has been approved and all checks have passed, a maintainer will merge your changes into the main branch. Congratulations on your contribution!
9. **Merge your PR:** Once your PR has been approved and all checks have passed, a maintainer will merge your changes into the respective branch. Congratulations on your contribution!

## Code of Conduct

Please note that this project is governed by our [Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project, you agree to abide by its terms.

## Contributor License Agreement (CLA)

By contributing to this project, you agree to license your contributions under the [project's license](LICENSE.md).
By contributing to this project, you agree to license your contributions under the [project's license](LICENSE).

## Help and Support

Expand Down
219 changes: 116 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,185 +1,198 @@
# Foji
# Foji ⚒️

Foji is a command-line interface (CLI) tool designed to help you automate and manage your coding tasks. It allows you to run custom codes and handle custom parameters.
Foji is a powerful command-line interface (CLI) tool designed to streamline and automate long or repetitive commands in your daily workflow. With Foji, you can define and execute custom commands, integrate custom parameters, and simplify complex processes, reducing the need to repeatedly type lengthy commands.

## Features
## 🚀 Features

- [x] Run custom codes
- [x] Handle custom parameters
- [x] Conditional handler for arguments
- [x] Support for default arguments
- [x] Support for optional arguments
- [x] Add commands to configuration file
- [x] Remove commands from the configuration file
- [x] Can run commands directly
- [x] Configuration can be saved on cloud
- [x] Configuration can be downloaded from cloud
- [x] Local configuration can be synced from cloud
- [x] Run custom commands with flexible argument handling.
- [x] Supports options, conditional, and spread arguments for advanced customization.
- [x] Easily add, edit and remove commands in the CLI.
- [x] Sync configuration to the cloud.

## Installation
## 📦 Installation

Before installing Foji, make sure you have [Node.js](https://nodejs.org/) installed on your machine.
> [!IMPORTANT]
> Foji requires [Node.js](https://nodejs.org/) to be installed on your system. Make sure you have it installed before proceeding.
To install Foji globally, run the following command:
To install Foji, run the following command:

```shell
```bash
npm i foji -g
```

## Usage
## 🚦 Usage

Foji saves your commands and your configuration url at it's configuration file (`~/.config/foji.json`). You can access the `.config` directory using `foji config` or open the file directly using `foji config -f` command.
Foji stores your commands and configurations in its configuration file (`~/.config/foji.json`). You can access it using:

```bash
foji config
```

Or open it directly:

```bash
foji config -f
```

### Running a Command

To run a `command` just use:
To execute a saved `command`:

```shell
```bash
foji [command name] [...command args]
```
Simple as that.

If you don't provide a valid command name Foji will list all available commands, it includes default commands (eg.: `add`, `remove` and `sync`) and your own commands.
> [!TIP]
> If you don’t provide a valid command name, Foji will list all available commands, including default commands like `add`, `remove`, and `sync`, along with any custom commands you've added.
### Skipping a Argument
### Skipping an Argument

You also can skip a (optional) argument using "_":
If you want to skip an optional argument, use the `_` symbol:

```shell
foji [command name] [argument one] _ [argument three]
```bash
foji [command name] [arg1] _ [arg3]
```

## Creating and Updating the Configuration
## ⚙️ Configuration Management

Foji provides easy ways to add `commands` to the configuration file (or create it if it does not exist):
Foji allows you to easily create and update your command configurations.

### Creating a New Command
### Adding a New Command

To add a new `command` to the configuration file you can use the `add` command:
To add a new command to the configuration:

```shell
```bash
foji add [command name] [command]
```

All `commands` can have four types of `arguments`:
Supported argument types:

1. Required arguments:
1. **Required Arguments**:
These arguments **must** be provided for the command to run.

- These arguments **must** be provided for the command to run:
```json
"command": "echo <requiredArgumentOne> <requiredArgumentTwo>"
```

```json
"command":"echo <requiredArgumentOne> <requiredArgumentTwo>"
```
2. **Optional Arguments**:
These arguments **are not mandatory**. If not provided, they will be skipped.

2. Optional arguments:
```json
"command": "echo <requiredArgumentOne> <optionalArgumentOne?>"
```

- These arguments **are not** mandatory. If not provided, they will add nothing to the command.
3. **Optional Arguments with Default Values**:
If not provided, a default value will be used.

```json
"command":"echo <requiredArgumentOne> <optionalArgumentOne?>"
```
```json
"command": "echo <requiredArgumentOne> <optionalArgumentOne ?? My Default Value>"
```

3. Optional arguments with default values:
4. **Ternary Arguments**:
Works as a boolean argument, only checking whether it was passed.

- Similar to optional arguments, but if not provided, they will add a default value. `<options??--ts --tailwind --src>`
```json
"command": "echo i want pizza of <requiredArgumentOne> with <hasCheese ? cheese : no cheese>"
```

```json
"command":"echo <requiredArgumentOne> <optionalArgumentOne??My Default Value>"
```
5. **Spread Argument**:
Catches all the remaining arguments.

4. Ternaries:
```json
"command": "echo [<argOne>] {<argTwo...>}"
```

- These arguments function like boolean arguments. Any value passed will be ignored by the CLI; it only checks **whether the argument was passed or not**.
Example of usage:

```json
"command":"echo i want pizza of <requiredArgumentOne> with <hasCheese?cheese:no cheese>"
```bash
foji command "my arg one" one two three --my --options
```

Note that all `Required arguments` must be provided **BEFORE** any of the other arguments
The resulting final command would be:

incorrect:

```json
"command": "do command <argOne?> <argTwo>"
```bash
echo [my arg one] {one two three --my --options}
```

correct:
> [!IMPORTANT]
> **Always** provide required arguments **before** any optional ones.
```json
"command": "do command <argOne> <argTwo?>"
```
### Removing a Command

### Remove a Command
To remove a command:

To remove a `command` you can use the `remove` command

```shell
foji remove [command name] [command]
```bash
foji remove [command name]
```

### Configuration File Format
## 🌐 Cloud Sync

Foji's configuration manage your `commands` and it's `url`:
You can easily sync your configurations using cloud services.

```json
{
"gistUrl": "https://gist.github.com/.../...",
"commands": {
"next:create": "npx create-next-app@latest <dir ?? . >",
"build": "npm run build:local",
"next:dev": "npm run dev"
}
}
```
> [!NOTE]
> Foji uses [Github CLI](https://cli.github.com/) to create, read and update your configuration gist.
### Upload Your Configuration File
### Upload Configuration

To Upload your configuration to your gist (or create one if your configuration do not have yet) just run:
To upload your configuration to a gist (or create a new gist if one doesn’t exist):

```shell
```bash
foji upload
```

### Download Your Configuration File
### Download Configuration

To download a configuration file from someone else just run this command:
To download a configuration file from a gist:

```shell
```bash
foji download [gist url]
```

### Sync Your Configuration File
### Sync Configuration

Update you configuration file from it's url
To sync your local configuration with its URL:

```shell
```bash
foji sync
```

## Development
> [!CAUTION]
> Be careful when syncing from external sources. Always verify the origin of the gist to avoid overriding your custom commands.
## 🛠️ Development

If you want to contribute to Foji or customize it to your needs, you can clone the repository and build it yourself:
If you want to contribute or customize Foji, follow these steps:

1. Clone the repository:

```shell
git clone https://github.com/imLymei/foji.git
cd foji
```
```bash
git clone https://github.com/imLymei/foji.git
cd foji
```

2. Install the dependencies:
2. Install dependencies:

```shell
npm install
```
```bash
npm install
```

3. Build and install the project:
3. Build the project:

```shell
npm run build:local
```
```bash
npm run build:local
```

## 📜 Credits

This project makes use of several open-source libraries and tools. Special thanks to the following:

- [TypeScript](https://www.typescriptlang.org/) - Type-safe JavaScript.
- [Commander](https://www.npmjs.com/package/commander) - CLI framework.
- [@inquirer/prompts](https://www.npmjs.com/package/@inquirer/prompts) - Command-line prompts.
- [semantic-release](https://www.npmjs.com/package/semantic-release) - Automates versioning and package publishing.
- [fast-levenshtein](https://www.npmjs.com/package/fast-levenshtein) - Fast string distance algorithm.

## License
## 📄 License

Foji is licensed under the MIT License.

Expand Down
8 changes: 6 additions & 2 deletions src/commands/downloadConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Command } from 'commander';
import { basicGithubVerifications, getConfiguration } from '../lib/github';
import { confirm } from '@inquirer/prompts';
import { createConfig, error } from '../lib/utils';
import { Config, createConfig, error } from '../lib/utils';

const downloadConfig = new Command('download')
.alias('d')
Expand All @@ -23,7 +23,11 @@ const downloadConfig = new Command('download')
if (!update) process.exit(0);

try {
createConfig(JSON.parse(gist));
const newConfig: Config = JSON.parse(gist);

delete newConfig.lettersSaved;

createConfig(newConfig);
} catch {
error('Something went wrong...');
}
Expand Down
Loading

0 comments on commit 94ffc83

Please sign in to comment.