forked from criticalmanufacturing/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonas Maia
authored and
Jonas Maia
committed
Apr 11, 2024
1 parent
cba0b4d
commit c9e52fa
Showing
14 changed files
with
342 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO.Abstractions; | ||
using System.Text.Json; | ||
using Cmf.CLI.Constants; | ||
using Cmf.CLI.Core; | ||
using Cmf.CLI.Core.Attributes; | ||
using Cmf.CLI.Core.Enums; | ||
using Cmf.CLI.Core.Objects; | ||
using Cmf.CLI.Utilities; | ||
|
||
namespace Cmf.CLI.Commands.New | ||
{ | ||
/// <summary> | ||
/// Generates the Grafana folder structure | ||
/// </summary> | ||
[CmfCommand("grafana", ParentId = "new")] | ||
public class GrafanaCommand : LayerTemplateCommand | ||
{ | ||
/// <summary> | ||
/// constructor | ||
/// </summary> | ||
public GrafanaCommand() : base("grafana", PackageType.Grafana) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// constructor | ||
/// </summary> | ||
/// <param name="fileSystem"></param> | ||
public GrafanaCommand(IFileSystem fileSystem) : base("grafana", PackageType.Grafana, fileSystem) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override List<string> GenerateArgs(IDirectoryInfo projectRoot, IDirectoryInfo workingDir, List<string> args) | ||
{ | ||
if (ExecutionContext.Instance.ProjectConfig.MESVersion.Major < 10) | ||
{ | ||
throw new CliException("Version unsupported, available in MES >= 10"); | ||
} | ||
|
||
var isRepositoryType = ExecutionContext.Instance.ProjectConfig.RepositoryType == RepositoryType.App; | ||
|
||
args.AddRange(new[] | ||
{ | ||
"--app", isRepositoryType.ToString(), | ||
"--projectName", ExecutionContext.Instance.ProjectConfig.ProjectName.Replace(" ", ""), | ||
}); | ||
return args; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Cmf.CLI.Builders; | ||
using Cmf.CLI.Core.Enums; | ||
using Cmf.CLI.Core.Objects; | ||
|
||
namespace Cmf.CLI.Handlers | ||
{ | ||
/// <summary> | ||
/// Grafana package type handler. | ||
/// </summary> | ||
/// <seealso cref="PackageTypeHandler" /> | ||
public class GrafanaPackageTypeHandler : PackageTypeHandler | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="GrafanaPackageTypeHandler" /> class. | ||
/// </summary> | ||
/// <param name="cmfPackage">The CMF package.</param> | ||
public GrafanaPackageTypeHandler(CmfPackage cmfPackage) : base(cmfPackage) | ||
{ | ||
cmfPackage.SetDefaultValues | ||
( | ||
targetLayer: "Grafana", | ||
isInstallable: true, | ||
isUniqueInstall: true, | ||
steps: new List<Step>() | ||
{ | ||
new(StepType.DeployFiles) | ||
{ | ||
ContentPath = "**/**" | ||
}, | ||
} | ||
); | ||
|
||
IEnumerable<IBuildCommand> buildSteps = cmfPackage.BuildSteps?.Select(pbs => new SingleStepCommand() { BuildStep = pbs } as IBuildCommand); | ||
|
||
if (buildSteps != null && buildSteps.Any()) { | ||
BuildSteps = buildSteps.ToArray(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
cmf-cli/resources/template_feed/grafana/.template.config/template.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"author": "Critical Manufacturing", | ||
"classifications": [ | ||
"cli" | ||
], | ||
"description": "Generate a new Grafana package", | ||
"name": "Grafana Package", | ||
"identity": "cmf-cli.new.grafana", | ||
"groupIdentity": "cmf-cli.new.grafana", | ||
"shortName": "grafana", | ||
"tags": { | ||
"language": "C#", | ||
// Specify that this template is in C#. | ||
"type": "project" | ||
}, | ||
"sourceName": "Grafana.Package", | ||
"preferNameDirectory": true, | ||
"symbols": { | ||
"name": { | ||
"type": "parameter", | ||
"datatype": "string", | ||
"description": "The custom package name", | ||
"displayName": "Package Name", | ||
"replaces": "<%= $CLI_PARAM_CustomPackageName %>" | ||
}, | ||
"packageVersion": { | ||
"type": "parameter", | ||
"datatype": "string", | ||
"description": "The custom package version", | ||
"displayName": "Package Version", | ||
"replaces": "<%= $CLI_PARAM_CustomPackageVersion %>", | ||
"fileRename": "%version%" | ||
}, | ||
"projectName": { | ||
"type": "parameter", | ||
"datatype": "string", | ||
"replaces": "<%= $CLI_PARAM_ProjectName %>", | ||
"fileRename": "%ProjectName%" | ||
}, | ||
"app": { | ||
"type": "parameter", | ||
"datatype": "bool", | ||
"defaultValue": "False", | ||
"description": "Indicates that repository type is app if true" | ||
} | ||
}, | ||
"sources": [ | ||
{ | ||
"modifiers": [ | ||
{ | ||
"condition": "!app", | ||
"exclude": "Grafana.Package/%version%/datasources/criticalmanufacturing-grpc-datasource.json" | ||
} | ||
] | ||
} | ||
] | ||
} |
Empty file.
9 changes: 9 additions & 0 deletions
9
cmf-cli/resources/template_feed/grafana/Grafana.Package/%version%/dashboards/dashboards.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: 1 | ||
|
||
providers: | ||
- name: Default | ||
folder: <%= $CLI_PARAM_ProjectName %> | ||
type: file | ||
options: | ||
path: /etc/grafana/provisioning/dashboards | ||
foldersFromFilesStructure: true |
20 changes: 20 additions & 0 deletions
20
.../grafana/Grafana.Package/%version%/datasources/criticalmanufacturing-grpc-datasource.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"id": 1, | ||
"uid": "KHanA1bVk", | ||
"orgId": 1, | ||
"name": "criticalmanufacturing-grpc-datasource", | ||
"type": "criticalmanufacturing-grpc-datasource", | ||
"typeName": "CMF gRPC Datasource", | ||
//keep it? | ||
"typeLogoUrl": "public/plugins/criticalmanufacturing-grpc-datasource/img/logo.svg", | ||
"access": "proxy", | ||
"url": "", | ||
"user": "", | ||
"database": "", | ||
"basicAuth": false, | ||
"isDefault": false, | ||
"jsonData": { | ||
"endpoint": "#uri:port#" | ||
}, | ||
"readOnly": false | ||
} |
12 changes: 12 additions & 0 deletions
12
...li/resources/template_feed/grafana/Grafana.Package/%version%/datasources/datasources.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: 1 | ||
|
||
datasources: | ||
#if (app) | ||
- name: CMF gRPC Datasource | ||
type: criticalmanufacturing-grpc-datasource | ||
uid: #UID# | ||
jsonData: | ||
endpoint: #container-name:port# | ||
#else | ||
~ | ||
#endif |
15 changes: 15 additions & 0 deletions
15
cmf-cli/resources/template_feed/grafana/Grafana.Package/cmfpackage.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"packageId": "<%= $CLI_PARAM_CustomPackageName %>", | ||
"version": "<%= $CLI_PARAM_CustomPackageVersion %>", | ||
"description": "Cmf Custom <%= $CLI_PARAM_ProjectName %> <%= $CLI_PARAM_CustomPackageName %> Package", | ||
"packageType": "Grafana", | ||
"contentToPack": [ | ||
{ | ||
"source": "$(version)/*", | ||
"target": "", | ||
"ignoreFiles": [ | ||
"../.cmfpackageignore" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters