Compare commits

...

14 Commits

Author SHA1 Message Date
0da1ccd480 Used package.json for versioning
All checks were successful
Build a new image for the MycroForge docs / build (push) Has been skipped
2024-10-19 13:59:01 +02:00
e2940941a8 Fixed typo
All checks were successful
Build a new image for the MycroForge docs / build (push) Has been skipped
2024-10-13 18:45:23 +02:00
12a16be6ed Added trimming for the VERSION variable 2024-10-13 18:43:15 +02:00
768136696f Added echos to build job
All checks were successful
Build a new image for the MycroForge docs / build (push) Successful in 1m11s
2024-10-13 18:40:59 +02:00
3de2322524 Renamed test job to build
All checks were successful
Build a new image for the MycroForge docs / build (push) Successful in 1m10s
2024-10-13 18:37:18 +02:00
b777d5c899 Changed run name in build.yml
All checks were successful
Build a new image for the MycroForge docs / test (push) Successful in 1m18s
2024-10-13 18:33:42 +02:00
cbf465f444 Piped password into docker login command
All checks were successful
Build a new image for the MycroForge docs / test (push) Successful in 1m50s
2024-10-13 14:36:32 +02:00
abbb0fde41 Fixed secret references
Some checks failed
Build a new image for the MycroForge docs / test (push) Failing after 4s
2024-10-13 14:35:25 +02:00
994b4c3761 Removed dotnet config section and uncommented code
All checks were successful
Build a new image for the MycroForge docs / test (push) Successful in 4s
2024-10-13 14:31:55 +02:00
b85e424dbe Removed test and commented build
All checks were successful
Build a new image for the MycroForge docs / test (push) Successful in 5s
2024-10-13 14:30:28 +02:00
4edae0830f Removed dotnet action
All checks were successful
Build a new image for the MycroForge docs / test (push) Successful in 5s
2024-10-13 14:28:03 +02:00
fd04ffbc19 Added build pipeline
All checks were successful
Build a new image for the MycroForge docs / test (push) Successful in 26s
2024-10-13 14:25:25 +02:00
0747a730ee Fixed command plugins section 2024-10-13 13:22:00 +02:00
84b2628bd7 Fixed command plugins section 2024-10-12 17:30:26 +02:00
3 changed files with 61 additions and 52 deletions

View File

@@ -0,0 +1,39 @@
name: Build a new image for the MycroForge docs
run-name: ${{ gitea.actor }} triggered a build for the MycroForge docs image
on: [ push ]
jobs:
build:
runs-on: ubuntu-latest
if: gitea.ref == 'refs/heads/main'
steps:
- uses: https://github.com/actions/checkout@v4
- name: "Build and push Docker image"
run: |
IMAGE_NAME="git.devdisciples.com/devdisciples/m4gdocs"
IMAGE_VERSION=$(npm pkg get version --workspaces=false | tr -d \")
VERSIONED_IMAGE_TAG="$IMAGE_NAME:$IMAGE_VERSION"
LATEST_IMAGE_TAG="$IMAGE_NAME:latest"
# Login to the registry
echo ${{ secrets.DOCKER_PASS }} | docker login git.devdisciples.com --username ${{ secrets.DOCKER_USER }} --password-stdin
# Check if the image exists.
# EXISTS = 0 if the image was found else 1.
EXISTS=$(docker manifest inspect $VERSIONED_IMAGE_TAG > /dev/null 2>&1; echo $?)
# If the image does not exist, then build it.
if [[ $EXISTS -eq 1 ]]; then
echo "Building image $VERSIONED_IMAGE_TAG"
docker build -t $VERSIONED_IMAGE_TAG -t $LATEST_IMAGE_TAG .
echo "Building image $VERSIONED_IMAGE_TAG"
docker push $VERSIONED_IMAGE_TAG
echo "Building image $LATEST_IMAGE_TAG"
docker push $LATEST_IMAGE_TAG
# Else notify the user that the image tag already exists and exit with status code 1.
else
echo "Image $VERSIONED_IMAGE_TAG already exists, you should probably increment the version."
exit 1
fi

View File

@@ -27,58 +27,26 @@ dotnet add package --source devdisciples --version 1.0.0 MycroForge.PluginTempla
## Initialize a plugin package
Generate a template plugin project by running the following command.
Generate a plugin project by running the following command.
```
m4g plugin init My.Dotenv.Plugin
m4g plugin init Dotenv.Plugin DotenvCommand dotenv
```
This should generate the following folder structure.
```
My.Dotenv.Plugin
┣ 📜HelloWorldCommand.cs
┣ 📜HelloWorldCommandPlugin.cs
┗ 📜My.Dotenv.Plugin.csproj
```
Rename the following files. Also rename the classes in these files, the easiest way in `vscode` is to right click the class name and select the `Rename symbol` action. Note that this action does not (necessarily) rename the files!
```
HelloWorldCommand.cs => DotenvCommand.cs
HelloWorldCommandPlugin.cs => DotenvCommandPlugin.cs
```
Modify `Name` property in `DotenvCommandPlugin.cs`.
```cs
// Before
public class DotenvCommandPlugin : ICommandPlugin
{
public string Name => "My.Plugin";
public void RegisterServices(IServiceCollection services)
{
services.AddScoped<ISubCommandOf<RootCommand>, HelloWorldCommand>();
}
}
// After
public class DotenvCommandPlugin : ICommandPlugin
{
public string Name => "My.Dotenv.Plugin";
public void RegisterServices(IServiceCollection services)
{
services.AddScoped<ISubCommandOf<RootCommand>, HelloWorldCommand>();
}
}
Dotenv.Plugin
┣ 📜Dotenv.Plugin.csproj
┣ 📜DotenvCommand.cs
┗ 📜DotenvCommandPlugin.cs
```
Modify `DotenvCommand.cs`.
```cs
// Before
public class DotenvCommand : Command, ISubCommandOf<RootCommand>
{
private readonly Argument<string> NameArgument =
@@ -90,7 +58,7 @@ public class DotenvCommand : Command, ISubCommandOf<RootCommand>
private readonly ProjectContext _context;
public DotenvCommand(ProjectContext context) :
base("hello", "An example command generated by dotnet new using the m4gp template")
base("dotenv", "A basic command plugin generated by the 'm4g plugin init' command")
{
_context = context;
AddArgument(NameArgument);
@@ -102,37 +70,38 @@ public class DotenvCommand : Command, ISubCommandOf<RootCommand>
{
name = allCaps ? name.ToUpper() : name;
await _context.CreateFile("hello_world.txt",
await _context.CreateFile("dotenv.txt",
$"Hello {name}!",
"This file was generated by your custom command!"
"This file was generated by the 'm4g dotenv' command!"
);
}
}
// After
public class DotenvCommand : Command, ISubCommandOf<RootCommand>
{
private readonly Argument<string> VarsArgument =
new(name: "vars", description: "Env vars to include in the .env file separated by ';'");
private readonly Option<bool> PrintOption =
private readonly Option<bool> OverwriteOption =
new(aliases: ["-o", "--overwrite"], description: "Overwrite the .env file if it exists");
private readonly ProjectContext _context;
public DotenvCommand(ProjectContext context) :
// dotenv = the name of the sub command that will be added to the m4g command
base("dotenv", "Generate a .env file in the current directory")
{
_context = context;
AddArgument(VarsArgument);
AddOption(PrintOption);
this.SetHandler(ExecuteAsync, VarsArgument, PrintOption);
AddOption(OverwriteOption);
this.SetHandler(ExecuteAsync, VarsArgument, OverwriteOption);
}
private async Task ExecuteAsync(string vars, bool overwrite)
{
var path = Path.Join(Environment.CurrentDirectory, ".env");
var content = string.Join(Environment.NewLine, vars.Split(';'));
if (File.Exists(path))
{
@@ -143,9 +112,9 @@ public class DotenvCommand : Command, ISubCommandOf<RootCommand>
}
Console.WriteLine($"File {path} already exists, add the -o or --overwrite flag to overwrite it.");
return;
}
var content = string.Join(Environment.NewLine, vars.Split(';'));
await _context.CreateFile(".env", content);
}
}
@@ -153,7 +122,7 @@ public class DotenvCommand : Command, ISubCommandOf<RootCommand>
## Install the plugin
Open a terminal an make sure you're in the root directory of the plugin, i.e. the `My.Dotenv.Plugin` folder.
Open a terminal an make sure you're in the root directory of the plugin, i.e. the `Dotenv.Plugin` folder.
Run the following command to install the plugin.
```
@@ -169,7 +138,7 @@ Try running `m4g dotenv "FIRSTNAME=JOHN;LASTNAME=JOE"`, this should generate a `
## Uninstall the plugin
Uninstall the plugin by running `m4g plugin install My.Dotenv.Plugin`.
Uninstall the plugin by running `m4g plugin uninstall Dotenv.Plugin`.
## Resources

View File

@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "0.0.0",
"name": "m4gdocs",
"version": "0.0.1",
"private": true,
"scripts": {
"docusaurus": "docusaurus",
@@ -43,5 +43,6 @@
},
"engines": {
"node": ">=18.0"
}
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}