Skip to content

Commit 94ffc83

Browse files
authored
Merge pull request #31 from imLymei/beta
Beta
2 parents d14f314 + 97b2de4 commit 94ffc83

File tree

11 files changed

+271
-148
lines changed

11 files changed

+271
-148
lines changed

.github/workflows/release.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ name: Release
22
on:
33
push:
44
branches:
5-
- master # or main
5+
- master
66
- next
77
- beta
88

99
permissions:
10-
contents: read # for checkout
10+
contents: read
1111

1212
jobs:
1313
release:
1414
name: Release
1515
runs-on: ubuntu-latest
1616
permissions:
17-
contents: write # to be able to publish a GitHub release
18-
issues: write # to be able to comment on released issues
19-
pull-requests: write # to be able to comment on released pull requests
20-
id-token: write # to enable use of OIDC for npm provenance
17+
contents: write
18+
issues: write
19+
pull-requests: write
20+
id-token: write
2121
steps:
2222
- name: Checkout
2323
uses: actions/checkout@v4

CONTRIBUTING.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,41 @@ Welcome to the project! We're glad you're here and interested in contributing. B
44

55
## How to Contribute
66

7+
### Repository Structure
8+
9+
This repository uses a automated version release using the mains 3 branches:
10+
11+
- **master**: Contains the code on the actual `@latest` package channel.
12+
- **beta**: Contains the code on the actual `@beta` package channel.
13+
- **dev**: Contains the code of actual development, every `BREAKING CHANGE` and `feat` commit must be done on this branch.
14+
15+
### Step by Step
16+
717
1. **Fork the repository:** Click on the "Fork" button on the top right corner of the repository's page, then clone your fork locally.
818

9-
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.
19+
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.
1020

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

1323
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.
1424

15-
5. **Commit your changes:** Make meaningful and atomic commits. Please provide a clear and descriptive commit message for each commit.
25+
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.
1626

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

1929
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.
2030

2131
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.
2232

23-
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!
33+
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!
2434

2535
## Code of Conduct
2636

2737
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.
2838

2939
## Contributor License Agreement (CLA)
3040

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

3343
## Help and Support
3444

README.md

Lines changed: 116 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,185 +1,198 @@
1-
# Foji
1+
# Foji ⚒️
22

3-
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.
3+
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.
44

5-
## Features
5+
## 🚀 Features
66

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

19-
## Installation
12+
## 📦 Installation
2013

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

25-
```shell
19+
```bash
2620
npm i foji -g
2721
```
2822

29-
## Usage
23+
## 🚦 Usage
3024

31-
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.
25+
Foji stores your commands and configurations in its configuration file (`~/.config/foji.json`). You can access it using:
26+
27+
```bash
28+
foji config
29+
```
30+
31+
Or open it directly:
32+
33+
```bash
34+
foji config -f
35+
```
3236

3337
### Running a Command
3438

35-
To run a `command` just use:
39+
To execute a saved `command`:
3640

37-
```shell
41+
```bash
3842
foji [command name] [...command args]
3943
```
40-
Simple as that.
4144

42-
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.
45+
> [!TIP]
46+
> 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.
4347
44-
### Skipping a Argument
48+
### Skipping an Argument
4549

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

48-
```shell
49-
foji [command name] [argument one] _ [argument three]
52+
```bash
53+
foji [command name] [arg1] _ [arg3]
5054
```
5155

52-
## Creating and Updating the Configuration
56+
## ⚙️ Configuration Management
5357

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

56-
### Creating a New Command
60+
### Adding a New Command
5761

58-
To add a new `command` to the configuration file you can use the `add` command:
62+
To add a new command to the configuration:
5963

60-
```shell
64+
```bash
6165
foji add [command name] [command]
6266
```
6367

64-
All `commands` can have four types of `arguments`:
68+
Supported argument types:
6569

66-
1. Required arguments:
70+
1. **Required Arguments**:
71+
These arguments **must** be provided for the command to run.
6772

68-
- These arguments **must** be provided for the command to run:
73+
```json
74+
"command": "echo <requiredArgumentOne> <requiredArgumentTwo>"
75+
```
6976

70-
```json
71-
"command":"echo <requiredArgumentOne> <requiredArgumentTwo>"
72-
```
77+
2. **Optional Arguments**:
78+
These arguments **are not mandatory**. If not provided, they will be skipped.
7379

74-
2. Optional arguments:
80+
```json
81+
"command": "echo <requiredArgumentOne> <optionalArgumentOne?>"
82+
```
7583

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

78-
```json
79-
"command":"echo <requiredArgumentOne> <optionalArgumentOne?>"
80-
```
87+
```json
88+
"command": "echo <requiredArgumentOne> <optionalArgumentOne ?? My Default Value>"
89+
```
8190

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

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

86-
```json
87-
"command":"echo <requiredArgumentOne> <optionalArgumentOne??My Default Value>"
88-
```
98+
5. **Spread Argument**:
99+
Catches all the remaining arguments.
89100

90-
4. Ternaries:
101+
```json
102+
"command": "echo [<argOne>] {<argTwo...>}"
103+
```
91104

92-
- 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**.
105+
Example of usage:
93106

94-
```json
95-
"command":"echo i want pizza of <requiredArgumentOne> with <hasCheese?cheese:no cheese>"
107+
```bash
108+
foji command "my arg one" one two three --my --options
96109
```
97110

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

100-
incorrect:
101-
102-
```json
103-
"command": "do command <argOne?> <argTwo>"
113+
```bash
114+
echo [my arg one] {one two three --my --options}
104115
```
105116

106-
correct:
117+
> [!IMPORTANT]
118+
> **Always** provide required arguments **before** any optional ones.
107119
108-
```json
109-
"command": "do command <argOne> <argTwo?>"
110-
```
120+
### Removing a Command
111121

112-
### Remove a Command
122+
To remove a command:
113123

114-
To remove a `command` you can use the `remove` command
115-
116-
```shell
117-
foji remove [command name] [command]
124+
```bash
125+
foji remove [command name]
118126
```
119127

120-
### Configuration File Format
128+
## 🌐 Cloud Sync
121129

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

124-
```json
125-
{
126-
"gistUrl": "https://gist.github.com/.../...",
127-
"commands": {
128-
"next:create": "npx create-next-app@latest <dir ?? . >",
129-
"build": "npm run build:local",
130-
"next:dev": "npm run dev"
131-
}
132-
}
133-
```
132+
> [!NOTE]
133+
> Foji uses [Github CLI](https://cli.github.com/) to create, read and update your configuration gist.
134134
135-
### Upload Your Configuration File
135+
### Upload Configuration
136136

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

139-
```shell
139+
```bash
140140
foji upload
141141
```
142142

143-
### Download Your Configuration File
143+
### Download Configuration
144144

145-
To download a configuration file from someone else just run this command:
145+
To download a configuration file from a gist:
146146

147-
```shell
147+
```bash
148148
foji download [gist url]
149149
```
150150

151-
### Sync Your Configuration File
151+
### Sync Configuration
152152

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

155-
```shell
155+
```bash
156156
foji sync
157157
```
158158

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

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

163166
1. Clone the repository:
164167

165-
```shell
166-
git clone https://github.com/imLymei/foji.git
167-
cd foji
168-
```
168+
```bash
169+
git clone https://github.com/imLymei/foji.git
170+
cd foji
171+
```
169172

170-
2. Install the dependencies:
173+
2. Install dependencies:
171174

172-
```shell
173-
npm install
174-
```
175+
```bash
176+
npm install
177+
```
175178

176-
3. Build and install the project:
179+
3. Build the project:
177180

178-
```shell
179-
npm run build:local
180-
```
181+
```bash
182+
npm run build:local
183+
```
184+
185+
## 📜 Credits
186+
187+
This project makes use of several open-source libraries and tools. Special thanks to the following:
188+
189+
- [TypeScript](https://www.typescriptlang.org/) - Type-safe JavaScript.
190+
- [Commander](https://www.npmjs.com/package/commander) - CLI framework.
191+
- [@inquirer/prompts](https://www.npmjs.com/package/@inquirer/prompts) - Command-line prompts.
192+
- [semantic-release](https://www.npmjs.com/package/semantic-release) - Automates versioning and package publishing.
193+
- [fast-levenshtein](https://www.npmjs.com/package/fast-levenshtein) - Fast string distance algorithm.
181194

182-
## License
195+
## 📄 License
183196

184197
Foji is licensed under the MIT License.
185198

src/commands/downloadConfig.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Command } from 'commander';
22
import { basicGithubVerifications, getConfiguration } from '../lib/github';
33
import { confirm } from '@inquirer/prompts';
4-
import { createConfig, error } from '../lib/utils';
4+
import { Config, createConfig, error } from '../lib/utils';
55

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

2525
try {
26-
createConfig(JSON.parse(gist));
26+
const newConfig: Config = JSON.parse(gist);
27+
28+
delete newConfig.lettersSaved;
29+
30+
createConfig(newConfig);
2731
} catch {
2832
error('Something went wrong...');
2933
}

0 commit comments

Comments
 (0)