Skip to content

Commit

Permalink
Merge pull request #74 from arkahna/feature/FB-161_UpdateNxPluginDisc…
Browse files Browse the repository at this point in the history
…riptionsToMatchDocs

Update nx-plugin interface descriptions to match docs
  • Loading branch information
emlyn-arkahna authored Dec 15, 2023
2 parents 3772200 + e7cf148 commit a742288
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .changeset/quick-icons-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@featureboard/nx-plugin': patch
---

Update nx-plugin interface descriptions to match docs
Fix location bug with executor
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public WeatherForecastController(ILogger<WeatherForecastController> logger, IFea
}

[HttpGet(Name = "GetWeatherForecast")]
[FeatureFilter(BooleanFeature.AudiencesWrite, false)]
[FeatureFilter(BooleanFeature.ViewSubscribers, false)]
public ActionResult<WeatherForecast[]> Get()
{
if (_featureBoardClient.GetFeatureValue(features => features.AudiencesWrite, false))
if (_featureBoardClient.GetFeatureValue(features => features.ViewSubscribers, false))
{
return Ok(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Expand Down
3 changes: 3 additions & 0 deletions libs/code-generator/src/lib/code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export interface CodeGeneratorOptions {
interactive: boolean

tree: Tree
/**
* Relative path to the tree root
*/
relativeFilePath: string
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export function getDotNetNameSpace(tree: Tree, filePath: string): string {
if (namespace) return namespace

const parentDir = path.join(filePath, '..')
if (parentDir == filePath) throw new Error("Can't find .net project file")
if (parentDir == filePath || parentDir == '.')
throw new Error("Can't find .net project file")

return getDotNetNameSpace(tree, parentDir)
}
2 changes: 1 addition & 1 deletion libs/nx-plugin/executors.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"code-gen": {
"implementation": "./src/executors/code-gen/executor",
"schema": "./src/executors/code-gen/schema.json",
"description": "Generates FeatureBoard types for your chosen language"
"description": "Generates code based on FeatureBoard configuration."
}
}
}
4 changes: 2 additions & 2 deletions libs/nx-plugin/generators.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"code-gen": {
"factory": "./src/generators/code-gen/generator",
"schema": "./src/generators/code-gen/schema.json",
"description": "Generates FeatureBoard types for your chosen language"
"description": "Generate code based on FeatureBoard configuration."
},
"add-code-gen-target": {
"factory": "./src/generators/add-code-gen-target/generator",
"schema": "./src/generators/add-code-gen-target/schema.json",
"description": "Adds code gen to a projects targets"
"description": "Adds the code-gen executor to the project target."
}
}
}
1 change: 0 additions & 1 deletion libs/nx-plugin/src/executors/code-gen/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ describe('code-gen executor', () => {

it('should run successfully', async () => {
const output = await codeGenExecutor(options, context, tree)

expect(output?.success).toBe(true)
})

Expand Down
10 changes: 6 additions & 4 deletions libs/nx-plugin/src/executors/code-gen/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import {
getValidToken,
readCurrentOrganization,
} from '@featureboard/api-authentication'
import type { FeatureBoardAuth } from '@featureboard/code-generator'
import { codeGenerator } from '@featureboard/code-generator'
import type { ExecutorContext, Tree } from '@nx/devkit'
import { joinPathFragments } from '@nx/devkit'
import {
codeGenerator,
type FeatureBoardAuth,
} from '@featureboard/code-generator'
import { joinPathFragments, type ExecutorContext, type Tree } from '@nx/devkit'
import { FsTree, flushChanges, printChanges } from 'nx/src/generators/tree'
import { API_ENDPOINT, CLIENT_ID } from '../../shared/config'
import type { CodeGenExecutorSchema } from './schema'
Expand All @@ -15,6 +16,7 @@ export async function codeGenExecutor(
context: ExecutorContext,
tree?: Tree,
) {
console.log('codeGenExecutor', options)
if (!context.projectName) {
throw new Error('No projectName: name not found in in project.json')
}
Expand Down
10 changes: 5 additions & 5 deletions libs/nx-plugin/src/executors/code-gen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"type": "object",
"properties": {
"template": {
"description": "The type of the component",
"description": "The type of the generated code.",
"alias": "t",
"type": "string",
"x-prompt": {
"message": "The type of the component",
"message": "Select the template type",
"type": "list",
"items": [
{
Expand All @@ -33,15 +33,15 @@

"subFolder": {
"type": "string",
"description": "Sub-folder to add the generated code to.",
"description": "The target sub-folder of the project.",
"default": "./"
},

"dryRun": {
"type": "boolean",
"description": "Only show what would be generated.",
"description": "Only show what would be generated, don't modify files.",
"default": false
}
},
"required": ["template", "projectName", "featureBoardProductName"]
"required": ["template", "featureBoardProductName"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`AddCodeGenTarget generator > should update the project.json > apps/my-a
\\"saasy-icons\\": {
\\"executor\\": \\"@featureboard/nx-plugin:code-gen\\",
\\"outputs\\": [
\\"{projectRoot}/./src/features\\"
\\"{projectRoot}/src/features\\"
],
\\"options\\": {
\\"template\\": \\"dotnet-api\\",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe('AddCodeGenTarget generator', () => {
dryRun: false,
}

const root = 'apps/my-app'
addProjectConfiguration(tree, options.projectName, {
root: `apps/${options.projectName}`,
projectType: 'application',
Expand All @@ -38,8 +37,6 @@ describe('AddCodeGenTarget generator', () => {
it('should update the project.json', async () => {
await addCodeGenTargetGenerator(tree, options)

const project = readProjectConfiguration(tree, options.projectName)

const projectJson = tree
.listChanges()
.find((x) => x.path.endsWith('project.json'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function getCodeGenExecutorConfiguration(
}
return {
executor: '@featureboard/nx-plugin:code-gen',
outputs: [`{projectRoot}/${options.subFolder}`],
outputs: [`{projectRoot}/${options.subFolder}`.replace('/./', '/')],
options: codeGenOptions,
dependsOn: ['build'],
}
Expand Down
11 changes: 6 additions & 5 deletions libs/nx-plugin/src/generators/add-code-gen-target/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"properties": {
"projectName": {
"type": "string",
"description": "The name of the project to add the component to.",
"description": "The name of the project to add the target to.",
"alias": "p",
"$default": {
"$source": "projectName"
Expand All @@ -18,15 +18,16 @@
"type": "string",
"description": "The name of the target.",
"alias": "t",
"x-prompt": "What is the name of the target you want to add?"
"x-prompt": "What is the name of the target you want to add?",
"default": "code-gen"
},

"template": {
"description": "The type of the component",
"description": "The type of code the target should generate",
"alias": "t",
"type": "string",
"x-prompt": {
"message": "The type of the component",
"message": "The type of the generated code",
"type": "list",
"items": [
{
Expand All @@ -48,7 +49,7 @@

"subFolder": {
"type": "string",
"description": "Sub-folder to add the generated code to.",
"description": "The target sub-folder of the project .",
"default": "./"
}
},
Expand Down
13 changes: 7 additions & 6 deletions libs/nx-plugin/src/generators/code-gen/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"type": "object",
"properties": {
"template": {
"description": "The type of the component",
"description": "The type of the generated code.",
"alias": "t",
"type": "string",
"x-prompt": {
"message": "The type of the component",
"message": "Select the template type",
"type": "list",
"items": [
{
Expand All @@ -26,17 +26,18 @@

"projectName": {
"type": "string",
"description": "The name of the project to add the component to.",
"description": "The name of the project to add the generated code to.",
"alias": "p",
"$default": {
"$source": "projectName"
},
"x-prompt": "What is the name of the project you want to add the component to?"
"x-prompt": "What is the name of the project you want to add the generated code to?"
},

"featureBoardProductName": {
"type": "string",
"description": "The name of the FeatureBoard product you want to pull the types from."
"description": "The FeatureBoard product to pull the types from.",
"alias": "f"
},

"featureBoardApiKey": {
Expand All @@ -46,7 +47,7 @@

"subFolder": {
"type": "string",
"description": "Sub-folder to add the generated code to.",
"description": "The target sub-folder of the project.",
"default": "./"
}
},
Expand Down
21 changes: 21 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a742288

Please sign in to comment.