Skip to content

Commit

Permalink
feat(python): initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
kirinnee committed Nov 13, 2023
1 parent f3bc676 commit 3ca5aaa
Show file tree
Hide file tree
Showing 163 changed files with 3,381 additions and 50 deletions.
2 changes: 2 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ vars:

includes:
dotnet: sdks/dotnet/Taskfile.yaml
node: sdks/node/Taskfile.yaml
python: sdks/python/Taskfile.yaml
6 changes: 6 additions & 0 deletions nix/env.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ with packages;
];

main = [
python
poetry

go

dotnet

nodejs
bun

infisical
];

Expand Down
11 changes: 7 additions & 4 deletions nix/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,24 @@ let

# dotnet
xmlstarlet
# go
golangci-lint
go


#infra
docker;

python = python312;
poetry = (poetry.override { python3 = python311; });

npm = nodePackages.npm;
nodejs = nodejs_20;
}
);
sep-04-23 = (
with pkgs-sep-04-23;
{
inherit
# go
golangci-lint
go;
dotnet = dotnet-sdk_8;
}
);
Expand Down
8 changes: 8 additions & 0 deletions scripts/ci/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

set -eou pipefail

og="$(pwd)"

echo "🚀 Publishing .NET package"
./sdks/dotnet/scripts/ci/publish.sh
cd "${og}" || exit

echo "🚀 Publishing Python package"
./sdks/python/scripts/ci/publish.sh
cd "${og}" || exit

echo "🚀 Publishing npm package"
./sdks/node/scripts/ci/publish.sh
cd "${og}" || exit

echo "✅ All packages published"
2 changes: 2 additions & 0 deletions scripts/ci/update_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ echo "🤜 Updating .NET version to ${version}"
./sdks/dotnet/scripts/ci/update_version.sh "${version}"
echo "🤜 Updating Node version to ${version}"
./sdks/node/scripts/ci/update_version.sh "${version}"
echo "🤜 Updating Python version to ${version}"
./sdks/python/scripts/ci/update_version.sh "${version}"
Empty file added sdks/dotnet/README.MD
Empty file.
11 changes: 11 additions & 0 deletions sdks/dotnet/cyan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
username: ernest
name: dotnet-handlebar
description: .NET Handlebar to process templates
project: https://github.com/tr8team/template.nestjs
source: https://github.com/tr8team/template.nestjs
email: ernest@tr8.io
tags:
- dotnet
- handlerbar
- csharp
readme: README.MD
6 changes: 3 additions & 3 deletions sdks/dotnet/sulfone-helium-processor-api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
Console.WriteLine("HandleBarsConfig: {0}", handleBarsConfig.ToJson());
var files = fileHelper.ResolveAll();
var handlebars = Handlebars.CreateSharedEnvironment(new HandlebarsConfiguration { TextEncoder = null });
var parsed = files.Select(x =>
{
try
{
return x with
{
BaseWrite = Handlebars.Compile(x.BaseWrite)(handleBarsConfig?.Vars ?? new Dictionary<string, string>()),
Content = Handlebars.Compile(x.Content)(handleBarsConfig?.Vars ?? new Dictionary<string, string>())
Relative = handlebars.Compile(x.Relative)(handleBarsConfig?.Vars ?? new Dictionary<string, string>()),
Content = handlebars.Compile(x.Content)(handleBarsConfig?.Vars ?? new Dictionary<string, string>())
};
}
catch (Exception e)
Expand Down
5 changes: 3 additions & 2 deletions sdks/dotnet/sulfone-helium/Api/Core/CoreMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public static class CyanMapper
{
public static CyanPlugin ToDomain(this CyanPluginReq req)
{

return new CyanPlugin
{
Name = req.Name,
Config = req.Config.ToDynamic(),
Config = req.Config.ToDynamic(),
};
}

public static CyanGlob ToDomain(this CyanGlobReq req)
{
return new CyanGlob
{
Root = req.Root,
Glob = req.Glob,
Exclude = req.Exclude,
Type = req.Type switch
Expand Down Expand Up @@ -96,6 +96,7 @@ public static CyanGlobRes ToResp(this CyanGlob data)
{
return new CyanGlobRes()
{
Root = data.Root,
Glob = data.Glob,
Exclude = data.Exclude,
Type = data.Type.ToResp(),
Expand Down
1 change: 1 addition & 0 deletions sdks/dotnet/sulfone-helium/Api/Core/CyanReq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace sulfone_helium.Api.Core;

public struct CyanGlobReq
{
public string? Root { get; init; }
public string Glob { get; init; }
public string[] Exclude { get; init; }
public string Type { get; init; }
Expand Down
1 change: 1 addition & 0 deletions sdks/dotnet/sulfone-helium/Api/Core/CyanRes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace sulfone_helium.Api.Core;

public struct CyanGlobRes
{
public string? Root { get; init; }
public string Glob { get; init; }
public string[] Exclude { get; init; }
public string Type { get; init; }
Expand Down
5 changes: 2 additions & 3 deletions sdks/dotnet/sulfone-helium/Domain/Core/Cyan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum GlobType

public class CyanGlob
{
public string? Root { get; init; }
public required string Glob { get; init; }
public required string[] Exclude { get; init; }
public required GlobType Type { get; init; }
Expand All @@ -30,6 +31,4 @@ public class Cyan
{
public required IEnumerable<CyanProcessor> Processors { get; init; }
public required IEnumerable<CyanPlugin> Plugins { get; init; }

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,34 @@ public IEnumerable<VirtualFileStream> ReadAsStream(CyanGlob glob)
matcher.AddIncludePatterns(new[] { glob.Glob });
matcher.AddExcludePatterns(glob.Exclude);

var matchingFiles = matcher.GetResultsInFullPath(this.ReadDir)
.Select(x => Path.GetRelativePath(this.ReadDir, x))
var globRoot = this.GlobDir(glob);

var matchingFiles = matcher.GetResultsInFullPath(globRoot)
.Select(x => Path.GetRelativePath(globRoot, x))
.ToArray();
return matchingFiles.Select(x =>
new VirtualFileStream(
File.OpenText(Path.Combine(this.ReadDir, x)),
File.OpenText(Path.Combine(globRoot, x)),
File.CreateText(Path.Combine(this.WriteDir, x))
)
);
}

private string GlobDir(CyanGlob glob) => Path.Combine(this.ReadDir, glob.Root ?? ".");

public IEnumerable<VirtualFileReference> Get(CyanGlob glob)
{
Matcher matcher = new();
matcher.AddIncludePatterns(new[] { glob.Glob });
matcher.AddExcludePatterns(glob.Exclude);

var matchingFiles = matcher.GetResultsInFullPath(this.ReadDir)
.Select(x => Path.GetRelativePath(this.ReadDir, x))
var globRoot = this.GlobDir(glob);
var matchingFiles = matcher.GetResultsInFullPath(globRoot)
.Select(x => Path.GetRelativePath(globRoot, x))
.ToArray();

return matchingFiles.Select(x =>
new VirtualFileReference(this.ReadDir, this.WriteDir, x)
new VirtualFileReference(globRoot, this.WriteDir, x)
);
}

Expand All @@ -78,12 +84,14 @@ public void Copy(CyanGlob copy)
matcher.AddIncludePatterns(new[] { copy.Glob });
matcher.AddExcludePatterns(copy.Exclude);

var matchingFiles = matcher.GetResultsInFullPath(this.ReadDir)
.Select(x => Path.GetRelativePath(this.ReadDir, x))
var globRoot = this.GlobDir(copy);

var matchingFiles = matcher.GetResultsInFullPath(globRoot)
.Select(x => Path.GetRelativePath(globRoot, x))
.ToArray();

var files = matchingFiles.Select(x =>
(Path.Join(this.ReadDir, x), Path.Join(this.WriteDir, x))
(Path.Join(globRoot, x), Path.Join(this.WriteDir, x))
);

foreach (var (read, write) in files)
Expand Down
5 changes: 4 additions & 1 deletion sdks/node/src/api/core/core_mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
SelectQ,
TextQ,
} from "../../domain/core/question.js";
import { QuestionType } from "../../domain/core/question.js";

import type {
CheckboxQuestionRes,
ConfirmQuestionRes,
Expand All @@ -44,6 +44,7 @@ import {
} from "../../domain/core/answer.js";
import { AnswerRes } from "./answer_res.js";
import { AnswerReq, isBoolAnswerReq, isStringAnswerReq } from "./answer_req.js";
import { QuestionType } from "../../domain/core/question.js";

export class CyanMapper {
static pluginReqToDomain(req: CyanPluginReq): CyanPlugin {
Expand All @@ -65,6 +66,7 @@ export class CyanMapper {
}
})();
return {
root: req.root,
glob: req.glob,
exclude: req.exclude,
type,
Expand Down Expand Up @@ -121,6 +123,7 @@ export class CyanMapper {

static globToResp(data: CyanGlob): CyanGlobRes {
return {
root: data.root,
glob: data.glob,
exclude: data.exclude,
type: this.globTypeToResp(data.type),
Expand Down
1 change: 1 addition & 0 deletions sdks/node/src/api/core/cyan_req.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface CyanGlobReq {
readonly root?: string;
readonly glob: string;
readonly exclude: string[];
readonly type: string;
Expand Down
1 change: 1 addition & 0 deletions sdks/node/src/api/core/cyan_res.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface CyanGlobRes {
readonly root?: string;
glob: string;
exclude: string[];
type: string;
Expand Down
4 changes: 0 additions & 4 deletions sdks/node/src/api/core/question_res.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,27 @@ interface DateQuestionRes {
}

interface CheckboxQuestionRes {
type: string;
message: string;
desc?: string | null;
options: string[];
type: "checkbox"; // Type discriminator value
}

interface PasswordQuestionRes {
type: string;
message: string;
desc?: string | null;
confirmation?: boolean | null;
type: "password"; // Type discriminator value
}

interface SelectQuestionRes {
type: string;
message: string;
options: string[];
desc?: string | null;
type: "select"; // Type discriminator value
}

interface TextQuestionRes {
type: string;
message: string;
default?: string | null;
desc?: string | null;
Expand Down
2 changes: 0 additions & 2 deletions sdks/node/src/domain/core/answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ interface StringArrayAnswer {
answer: string[];
}

// TypeScript equivalent of the C# record StringAnswer
interface StringAnswer {
answer: string;
}

// TypeScript equivalent of the C# record BoolAnswer
interface BoolAnswer {
answer: boolean;
}
Expand Down
1 change: 1 addition & 0 deletions sdks/node/src/domain/core/cyan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum GlobType {
}

interface CyanGlob {
root?: string;
glob: string;
exclude: string[];
type: GlobType;
Expand Down
4 changes: 0 additions & 4 deletions sdks/node/src/domain/core/cyan_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ interface ICyanTemplate {
template(inquirer: IInquirer, determinism: IDeterminism): Promise<Cyan>;
}

// TypeScript equivalent of the C# interface ICyanExtension
interface ICyanExtension {
extension(
inquirer: IInquirer,
Expand All @@ -23,18 +22,15 @@ interface ICyanExtension {
): Promise<Cyan>;
}

// TypeScript equivalent of the C# interface ICyanProcessor
interface ICyanProcessor {
process(
input: CyanProcessorInput,
fileHelper: CyanFileHelper,
): Promise<ProcessorOutput>;
}

// TypeScript equivalent of the C# interface ICyanPlugin
interface ICyanPlugin {
plugin(input: CyanPluginInput): Promise<PluginOutput>;
}

// export all
export type { ICyanTemplate, ICyanExtension, ICyanProcessor, ICyanPlugin };
Loading

0 comments on commit 3ca5aaa

Please sign in to comment.