Compare commits
13 Commits
f547a0e132
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| e2940941a8 | |||
| 12a16be6ed | |||
| 768136696f | |||
| 3de2322524 | |||
| b777d5c899 | |||
| cbf465f444 | |||
| abbb0fde41 | |||
| 994b4c3761 | |||
| b85e424dbe | |||
| 4edae0830f | |||
| fd04ffbc19 | |||
| 0747a730ee | |||
| 84b2628bd7 |
39
.gitea/workflows/build.yml
Normal file
39
.gitea/workflows/build.yml
Normal 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="$(cat version.txt | tr -d '[:space:]')"
|
||||||
|
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
|
||||||
@@ -27,58 +27,26 @@ dotnet add package --source devdisciples --version 1.0.0 MycroForge.PluginTempla
|
|||||||
|
|
||||||
## Initialize a plugin package
|
## 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.
|
This should generate the following folder structure.
|
||||||
|
|
||||||
```
|
```
|
||||||
My.Dotenv.Plugin
|
Dotenv.Plugin
|
||||||
┣ 📜HelloWorldCommand.cs
|
┣ 📜Dotenv.Plugin.csproj
|
||||||
┣ 📜HelloWorldCommandPlugin.cs
|
┣ 📜DotenvCommand.cs
|
||||||
┗ 📜My.Dotenv.Plugin.csproj
|
┗ 📜DotenvCommandPlugin.cs
|
||||||
```
|
|
||||||
|
|
||||||
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>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Modify `DotenvCommand.cs`.
|
Modify `DotenvCommand.cs`.
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
// Before
|
// Before
|
||||||
|
|
||||||
public class DotenvCommand : Command, ISubCommandOf<RootCommand>
|
public class DotenvCommand : Command, ISubCommandOf<RootCommand>
|
||||||
{
|
{
|
||||||
private readonly Argument<string> NameArgument =
|
private readonly Argument<string> NameArgument =
|
||||||
@@ -90,7 +58,7 @@ public class DotenvCommand : Command, ISubCommandOf<RootCommand>
|
|||||||
private readonly ProjectContext _context;
|
private readonly ProjectContext _context;
|
||||||
|
|
||||||
public DotenvCommand(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;
|
_context = context;
|
||||||
AddArgument(NameArgument);
|
AddArgument(NameArgument);
|
||||||
@@ -102,37 +70,38 @@ public class DotenvCommand : Command, ISubCommandOf<RootCommand>
|
|||||||
{
|
{
|
||||||
name = allCaps ? name.ToUpper() : name;
|
name = allCaps ? name.ToUpper() : name;
|
||||||
|
|
||||||
await _context.CreateFile("hello_world.txt",
|
await _context.CreateFile("dotenv.txt",
|
||||||
$"Hello {name}!",
|
$"Hello {name}!",
|
||||||
"This file was generated by your custom command!"
|
"This file was generated by the 'm4g dotenv' command!"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// After
|
// After
|
||||||
|
|
||||||
public class DotenvCommand : Command, ISubCommandOf<RootCommand>
|
public class DotenvCommand : Command, ISubCommandOf<RootCommand>
|
||||||
{
|
{
|
||||||
private readonly Argument<string> VarsArgument =
|
private readonly Argument<string> VarsArgument =
|
||||||
new(name: "vars", description: "Env vars to include in the .env file separated by ';'");
|
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");
|
new(aliases: ["-o", "--overwrite"], description: "Overwrite the .env file if it exists");
|
||||||
|
|
||||||
private readonly ProjectContext _context;
|
private readonly ProjectContext _context;
|
||||||
|
|
||||||
public DotenvCommand(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")
|
base("dotenv", "Generate a .env file in the current directory")
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
AddArgument(VarsArgument);
|
AddArgument(VarsArgument);
|
||||||
AddOption(PrintOption);
|
AddOption(OverwriteOption);
|
||||||
this.SetHandler(ExecuteAsync, VarsArgument, PrintOption);
|
this.SetHandler(ExecuteAsync, VarsArgument, OverwriteOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ExecuteAsync(string vars, bool overwrite)
|
private async Task ExecuteAsync(string vars, bool overwrite)
|
||||||
{
|
{
|
||||||
var path = Path.Join(Environment.CurrentDirectory, ".env");
|
var path = Path.Join(Environment.CurrentDirectory, ".env");
|
||||||
|
var content = string.Join(Environment.NewLine, vars.Split(';'));
|
||||||
|
|
||||||
if (File.Exists(path))
|
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.");
|
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);
|
await _context.CreateFile(".env", content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,7 +122,7 @@ public class DotenvCommand : Command, ISubCommandOf<RootCommand>
|
|||||||
|
|
||||||
## Install the plugin
|
## 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.
|
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
|
||||||
|
|
||||||
Uninstall the plugin by running `m4g plugin install My.Dotenv.Plugin`.
|
Uninstall the plugin by running `m4g plugin uninstall Dotenv.Plugin`.
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
|
|||||||
@@ -43,5 +43,6 @@
|
|||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0"
|
"node": ">=18.0"
|
||||||
}
|
},
|
||||||
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
||||||
}
|
}
|
||||||
|
|||||||
1
version.txt
Normal file
1
version.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0.0.1
|
||||||
Reference in New Issue
Block a user