Skip to content

Commit

Permalink
Releases/1.0.0 preview1 (#1)
Browse files Browse the repository at this point in the history
- add apply rule & rules
- add open rule & rules
- add CI workflow
- add readme
- add logos
  • Loading branch information
Daniel-iel authored May 19, 2024
1 parent 25e507c commit 31022b6
Show file tree
Hide file tree
Showing 94 changed files with 4,246 additions and 37 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/blank.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: ci

on:
push:
tags:
- v*
branches: [main, releases/*]
pull_request:
branches: [main, feature/*, releases/*]

jobs:
build:
env:
APP: "${{ github.workspace }}/src"
PROJECT_TEST: "${{ github.workspace }}/src/ByReplace.Test"
PROJECT_SLN: "./src/ByReplace.sln"

runs-on: ubuntu-latest
strategy:
matrix:
dotnet-version: ["8.0.*"]

steps:
- uses: actions/checkout@v2

- name: Get Build Version 🏷️
run: |
Import-Module .\nupkgs\GetBuildVersion.psm1
Write-Host $Env:GITHUB_REF
$version = GetBuildVersion -VersionString $Env:GITHUB_REF
echo "BUILD_VERSION=$version" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
shell: pwsh

- name: Setup NuGet 🔧
uses: NuGet/setup-nuget@v1.0.5

- name: Setup .NET Core SDK ${{ matrix.dotnet-version }} 🔧
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet-version }}

- name: Install dotnet-format tool 🔧
run: dotnet tool install -g dotnet-format

- name: Clean Dependencies 📦
run: dotnet clean ${{env.PROJECT_SLN }}

- name: Restore Dependencies 📦
run: dotnet restore ${{env.PROJECT_SLN }}

- name: Build ⚙️
run: dotnet build ${{env.PROJECT_SLN }} -c Release -p:Version=$BUILD_VERSION --no-restore

- name: Format ♻️
run: dotnet format ${{env.APP }} -v diag --severity error --no-restore

- name: Test 🧪
run: dotnet test ${{env.PROJECT_SLN }} --configuration Release --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
57 changes: 57 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.vs
*/.vs
*/.vs/
*/.vs/*

.vscode
*/.vscode
*/.vscode/
*/.vscode/*

codeium_api_key
*/.easyTdd
.config
.idea

bin
*/bin*
*/bin/*
*/bin/

obj
*/obj*
*/obj/*
*/obj/

StrykerOutput
*/StrykerOutput*
*/StrykerOutput/*
*/StrykerOutput/

src/**/nupkg/*
*/src/*/nupkg/*
.user
*.user*

node_modules
*/node_modules

*.lock
*.lock*

BenchmarkDotNet.Artifacts
BenchmarkDotNet.Artifacts/*
*/BenchmarkDotNet.Artifacts/*

.sarif
.sarif/*
*/.sarif
*/.sarif/*

infer-out/*
*/infer-out

diagram.html

.cr
.cr/*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 SpinnerAlloc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
158 changes: 157 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,157 @@
# ByReplace
<div align="center">
<img src="./assets/br-logo-ascii.png?raw=true" alt="ByReplace Logo">
</div>

#

[![Contributors](https://img.shields.io/github/contributors/Daniel-iel/ByReplace)](https://www.nuget.org/packages/ByReplace/)
[![Activity](https://img.shields.io/github/commit-activity/m/Daniel-iel/ByReplace)](https://www.nuget.org/packages/ByReplace/)
[![CI](https://github.com/Daniel-iel/ByReplace/actions/workflows/ci.yml/badge.svg)](https://github.com/Daniel-iel/ByReplace/actions/workflows/ci.yml/badge.svg/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.md)
[![Downloads](https://img.shields.io/nuget/dt/ByReplace)](https://www.nuget.org/packages/ByReplace/)
[![Release](https://img.shields.io/nuget/v/ByReplace)](https://www.nuget.org/packages/ByReplace/)
[![Repo Size](https://img.shields.io/github/repo-size/Daniel-iel/ByReplace)](https://www.nuget.org/packages/ByReplace/)

# About

**ByReplace** is a powerful command-line interface (CLI) tool designed for efficiently executing find-and-replace operations within source files. This versatile utility enables users to seamlessly modify text within their codebase, enhancing productivity and streamlining development processes. Whether you're updating variable names, correcting typos, or implementing sweeping changes across multiple files, ByReplace has you covered.

# Get Started

To run ByReplace, you need [Dotnet 8](https://dotnet.microsoft.com/en-us/download). After installing the NuGet package, navigate to your terminal and execute the command `br -v`. If the installation was successful, the following text will be displayed in your terminal:

```shell
br

Commands:
apply Apply commands
rule Rule commands

Options:
-h, --help Show help message
--version Show version
```

# Installation

ByReplace is delivered via NuGet.

```shell
dotnet install -g ByReplace
```

# Creating the Configuration File

Create a configuration file with the following structure:

```shell
{
"Path": "",
"SkipDirectories": [""],
"Rules": [
{
"Name": "",
"Description": "",
"Skip": ["", ""],
"Extensions": ["", ""],
"Replacement": {
"Old": ["", ""],
"New": ""
}
}
]
}
```

# JSON Configuration Documentation

This document provides a detailed explanation of the structure and purpose of each field within the provided JSON configuration file.

## Path
- Type: String
- Purpose: Specifies the path where the operation should be performed. This can be a directory path or a file path depending on the context of the operation.
- Example: "C:\Users\User\Documents"

## SkipDirectories
- Type: Array of Strings
- Purpose: Lists directories that should be skipped during the operation. Each entry in the array represents a directory path.
- Example: ["Temp", "Logs"]

## Rules
- Type: Array of Objects
- Purpose: Defines a set of rules to apply during the operation. Each rule object contains specific configurations for how files or directories should be handled.

## Name
- Type: String
- Purpose: A descriptive name for the rule. Used for identification purposes.
- Example: "BackupRule"

## Description
- Type: String
- Purpose: Provides a brief description of what the rule does.
- Example: "Moves all .txt files to the backup folder."

## Skip
- Type: Array of Strings
- Purpose: Lists specific files or patterns of files to skip when applying this rule. Useful for excluding certain types of files from being processed.
- Example: [".tmp", "~"]

## Extensions
- Type: Array of Strings
- Purpose: Specifies the file extensions that this rule applies to. Only files with these extensions will be considered for processing according to this rule.
- Example: [".docx", ".pdf"]

## Replacement
- Type: Object
- Purpose: Contains configurations for replacing parts of the file paths or names as per the rule's requirements.

### Old
- Type: Array of Strings
- Purpose: Lists the old strings or patterns that should be replaced in the file paths or names.
- Example: ["temp", "backup"]

### New
- Type: String
- Purpose: The new string or pattern that replaces the old ones specified in the Old array.
- Example: "archive"

# Commands

## Apply

`apply rule`: Executes a specific rule from the configuration file.

- `-r`: Rule's name.
- `-p`: Path of files to execute the apply.
- `-f`: Folder's path that contains the configuration file.

```bash
br apply rule -r "Rule" -p "C:/three_files" -f "C:/"
```

`apply rules`: Executes all rules from the configuration file.
- `-p`: Path of files to execute the apply.
- `-f`: Folder's path that contains the configuration file.

```bash
br apply rules -p "C:/three_files" -f "C:/"
```

## Rule

`rule list-rules`: Lists all rules from the configuration file.

- `-f`: Folder's path that contains the configuration file.

```bash
br rule list-rules -f "C:/"
```

`rule open-rule`: Gets a rule by its name.

- `-n`: Rule's name.
- `-f`: Folder's path that contains the configuration file.

```bash
br rule open-rule -n "rule name" -f "C:/"
```
Binary file added assets/br-logo-ascii.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/br-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added docs/.gitkeep
Empty file.
34 changes: 34 additions & 0 deletions nupkgs/GetBuildVersion.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Function GetBuildVersion {
Param (
[string]$VersionString
)

# Process through regex
$VersionString -match "(?<major>\d+)(\.(?<minor>\d+))?(\.(?<patch>\d+))?(\-(?<pre>[0-9A-Za-z\-\.]+))?(\+(?<build>\d+))?" | Out-Null

if ($matches -eq $null) {
return "1.0.0-build"
}

# Extract the build metadata
$BuildRevision = [uint64]$matches['build']
# Extract the pre-release tag
$PreReleaseTag = [string]$matches['pre']
# Extract the patch
$Patch = [uint64]$matches['patch']
# Extract the minor
$Minor = [uint64]$matches['minor']
# Extract the major
$Major = [uint64]$matches['major']

$Version = [string]$Major + '.' + [string]$Minor + '.' + [string]$Patch;
if ($PreReleaseTag -ne [string]::Empty) {
$Version = $Version + '-' + $PreReleaseTag
}

if ($BuildRevision -ne 0) {
$Version = $Version + '.' + [string]$BuildRevision
}

return $Version
}
Empty file added samples/.gitkeep
Empty file.
Loading

0 comments on commit 31022b6

Please sign in to comment.