Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A code gen for typescript #63

Merged
merged 7 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/cli/src/commands/code-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import { promptForOrganization } from '../lib/prompt-for-organization'
import { titleText } from '../lib/title-text'

// Code Gen
const templateChoices: Template[] = ['dotnet-api']
const templateChoices: Template[] = ['dotnet-api', 'typescript']

export function codeGenCommand() {
return new Command('code-gen')
.description(`A Code generator for FeatureBoard`)
.option('-o, --output <path>', 'Output path')
.option('-g, --organizationId <id>', 'The Orgnization Id')
.option('-g, --organizationId <id>', 'The Organization Id')
.addOption(
new Option(
'-t, --template <template>',
Expand Down
4 changes: 2 additions & 2 deletions apps/cli/src/commands/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function loginCommand() {
!!process.env['CI'],
)
.action(
actionRunner(async function codeGen(options) {
actionRunner(async function login(options) {
if (!options.nonInteractive) {
console.log(titleText)
}
Expand All @@ -46,7 +46,7 @@ export function loginCommand() {
})
})

server.listen(REDIRECT_PORT, async () => {
server.listen(REDIRECT_PORT, 'localhost', async () => {
if (options.nonInteractive) {
console.log(
`Please authenticate at: http://localhost:${REDIRECT_PORT}`,
Expand Down
111 changes: 0 additions & 111 deletions libs/code-generator/src/lib/__snapshots__/code-generator.spec.js.snap

This file was deleted.

124 changes: 21 additions & 103 deletions libs/code-generator/src/lib/__snapshots__/code-generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -108,114 +108,32 @@ public class FeatureFilterAttribute : FeatureFilterAttributeBase
"
`;

exports[`code-generator > template: dotnet-api > should produce the expected features files > apps/my-app/Project.FeatureBoard.MyApp.csproj 1`] = `""`;
exports[`code-generator > template: typescript > should produce the expected features files > apps/my-app/featureboard-features.ts 1`] = `
"export interface SaaSyIconsFeatures {

exports[`code-generator template: dotnet-api should produce the expected features files: apps/my-app/Features.cs 1`] = `
"using FeatureBoard.DotnetSdk.Attributes;
using FeatureBoard.DotnetSdk.Models;
using System.Runtime.Serialization;
// Requires attribution
emlyn-arkahna marked this conversation as resolved.
Show resolved Hide resolved
//
'requires-attribution': boolean

namespace Project.FeatureBoard.MyApp;
// Allow edits
// Allows the user to edit colour, backgrounds
'allow-edits': boolean

// Features
public class Features : IFeatures
{
[FeatureKeyName("requires-attribution")]
public bool RequiresAttribution { get; set; }
[FeatureKeyName("allow-edits")]
public bool AllowEdits { get; set; }
[FeatureKeyName("number-custom-collections")]
public decimal NumberCustomCollections { get; set; }
[FeatureKeyName("team-management")]
public bool TeamManagement { get; set; }
[FeatureKeyName("custom-collections")]
public CustomCollections CustomCollections { get; set; }
[FeatureKeyName("view-subscribers")]
public bool ViewSubscribers { get; set; }
}
// Number custom collections
//
'number-custom-collections': number

// Team management
//
'team-management': boolean

// Options Enums
// Custom collections
//
'custom-collections': 'Disabled' | 'Enabled' | 'Shared'

//Custom collections
public enum CustomCollections
{
[EnumMember(Value = "Disabled")]
Disabled,
[EnumMember(Value = "Enabled")]
Enabled,
[EnumMember(Value = "Shared")]
Shared,
// View subscribers
//
'view-subscribers': boolean
}

// Type Enums
public enum BooleanFeature
{
RequiresAttribution,
AllowEdits,
TeamManagement,
ViewSubscribers,
}
public enum NumberFeature
{
NumberCustomCollections,
}
public enum StringFeature
{
}

// Feature Gate attribute
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class FeatureFilterAttribute : FeatureFilterAttributeBase
{
protected override string Feature { get; }
protected override object DefaultValue { get; }
protected override object? IsEqualTo { get; }
private readonly Dictionary<string, string> _featureKeyLookup = new()
{
{ "RequiresAttribution", "requires-attribution" },
{ "AllowEdits", "allow-edits" },
{ "NumberCustomCollections", "number-custom-collections" },
{ "TeamManagement", "team-management" },
{ "ViewSubscribers", "view-subscribers" },
};

public FeatureFilterAttribute(BooleanFeature feature, bool defaultValue)
{
Feature = _featureKeyLookup.GetValueOrDefault(feature.ToString()) ?? feature.ToString();
DefaultValue = defaultValue;
}

public FeatureFilterAttribute(BooleanFeature feature, bool isEqualTo, bool defaultValue)
{
Feature = _featureKeyLookup.GetValueOrDefault(feature.ToString()) ?? feature.ToString();
IsEqualTo = isEqualTo;
DefaultValue = defaultValue;
}

public FeatureFilterAttribute(StringFeature feature, string isEqualTo, string defaultValue)
{
Feature = _featureKeyLookup.GetValueOrDefault(feature.ToString()) ?? feature.ToString();
IsEqualTo = isEqualTo;
DefaultValue = defaultValue;
}

public FeatureFilterAttribute(NumberFeature feature, decimal isEqualTo, decimal defaultValue)
{
Feature = _featureKeyLookup.GetValueOrDefault(feature.ToString()) ?? feature.ToString();
IsEqualTo = isEqualTo;
DefaultValue = defaultValue;
}

public FeatureFilterAttribute(CustomCollections isEqualTo, CustomCollections defaultValue)
{
Feature = "custom-collections";
IsEqualTo = isEqualTo;
DefaultValue = defaultValue;
}

}
"
export type SaaSyIconsFeature = keyof SaaSyIconsFeatures"
`;

exports[`code-generator template: dotnet-api should produce the expected features files: apps/my-app/Project.FeatureBoard.MyApp.csproj 1`] = `""`;
4 changes: 4 additions & 0 deletions libs/code-generator/src/lib/api/get-project-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export async function getProjectFeatures(
}>(apiEndpoint, `projects/${project.id}/features`, auth)
}

export interface FeatureBoardProject {
id: string
name: string
}
export interface FeatureBoardFeature {
name: string
created: string
Expand Down
Loading
Loading