Skip to content

Commit

Permalink
Merge pull request #29 from recognizegroup/RECGEN-56-post-entity-hook
Browse files Browse the repository at this point in the history
RECGEN-56 added post processing
  • Loading branch information
jeroenvleeming authored Aug 1, 2023
2 parents f772d45 + 875f95d commit 7322dd7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ jobs:
with:
node-version: 18.x
- name: Prepare generator
run: cd ../generator && yarn && yarn build && cd ../cli
run: cd ../generator && yarn && yarn build && yarn link && cd ../cli
- name: Prepare definition
run: cd ../definition && yarn && yarn build && cd ../cli
- name: Install dependencies
run: yarn
- name: Build
run: yarn lint
- name: yarn link generator
run: yarn link "@recognizebv/sc3000-generator"
- name: Build
run: yarn build
- name: Test
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ export default createDefinition()

```

## Development
In order to develop the tool, you will need to have Node.js and Yarn installed. After cloning the repository, you can build generator project by running the following command:
```yarn build ``` in the generator project directory.

In case you make changes to the generator project, you need to link the generator project to the cli project. You can do this by running the following command in the generator project directory:
```yarn link ``` in the generator project directory and ```yarn link @recognizegroup/sc3000-generator``` in the cli project directory.

To run or debug the cli project create a nodeJS configuration and select the cli/bin/dev file and add generate as parameter. You should have a `sc3000.definition.ts` file in the root of the cli project.

![img.png](img.png)


## 👋 About The Project

Expand Down
4 changes: 4 additions & 0 deletions cli/src/commands/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,14 @@ $ sc3000 generate --force
await loader.update(`Generating entity ${entity.name} with ${metaData.name}`)

await entityCodeProvider?.render(entityContext)
entityCodeProvider?.reset()
lockFile = await lockFileManager.addGeneratedEntity(generator, entity)
entityCodeProviderInvocations++
}
}

await projectCodeProvider?.postProcessing()
projectCodeProvider?.reset()
} catch (error) {
await loader.stop()

Expand Down
1 change: 1 addition & 0 deletions generator/src/enums/render-hook-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum RenderHookType {
beforeRender = 'beforeRender',
afterRender = 'afterRender',
finalize = 'finalize',
}
10 changes: 9 additions & 1 deletion generator/src/providers/code-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Context} from '../context/context'
import {Generator} from '../models/generator'
import {Renderer} from '../rendering/renderer'
import {RenderHookType} from '../enums/render-hook-type'

export abstract class CodeProvider<C extends Context> {
public renderer: Renderer;
Expand All @@ -15,6 +16,13 @@ export abstract class CodeProvider<C extends Context> {
this.renderer.setContext(context)
await this.generate(context)
await this.renderer.render()
await this.renderer.reset()
}

public reset() {
this.renderer.reset()
}

public async postProcessing() {
await this.renderer.executeHook(RenderHookType.finalize)
}
}
2 changes: 1 addition & 1 deletion generator/test/providers/code-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('code provider', () => {

expect(setContextSpy.calledOnce).to.be.true
expect(renderSpy.calledOnce).to.be.true
expect(resetSpy.calledOnce).to.be.true
expect(resetSpy.calledOnce).to.be.false
expect(setContextSpy.calledBefore(renderSpy)).to.be.true
expect(renderSpy.calledBefore(resetSpy)).to.be.true
})
Expand Down
Binary file added img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7322dd7

Please sign in to comment.